Java - Axis2 + Rampart: The signature or decryption was invalid

 
Vista:
sin imagen de perfil

Axis2 + Rampart: The signature or decryption was invalid

Publicado por Mike_HDF (1 intervención) el 11/11/2015 09:54:55
Buenas,

Tengo el siguiente problema con un cliente que estoy desarrollando para un web service que usa Axis2 y Rampart:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
        [DEBUG] -2015-11-09 10:50:41,324- SignatureProcessor --> Found signature element
    [ERROR] -2015-11-09 10:50:41,324- AxisEngine --> The signature or decryption was invalid
    org.apache.axis2.AxisFault: The signature or decryption was invalid
        at org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(RampartReceiver.java:180)
        at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:95)
        at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
        at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
        at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:168)
        at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:364)
        at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
        at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
        at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
        at es.juntadeandalucia.webservice.sspp.SSPPWebServiceProxyServiceStub.consultarFactura(SSPPWebServiceProxyServiceStub.java:545)
...
Caused by: org.apache.ws.security.WSSecurityException: The signature or decryption was invalid
    at org.apache.ws.security.processor.SignatureProcessor.handleToken(SignatureProcessor.java:185)
    at org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngine.java:396)
    at org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngine.java:304)
    at org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngine.java:249)
    at org.apache.rampart.RampartEngine.process(RampartEngine.java:149)
    at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)
    ... 12 more

El caso es que, con el modo de depuración activado, puedo ver que la respuesta del servidor llega sin problemas (el servidor ha entendido la petición:

1
2
3
4
5
6
MESSAGE --> *********************** RampartReceiver received
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:mustUnderstand="1"><wsu:Timestamp wsu:Id="TS-325689"><wsu:Created>2015-11-09T09:50:32.814Z</wsu:Created><wsu:Expires>2015-11-09T09:55:32.814Z</wsu:Expires></wsu:Timestamp><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-325690"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soapenv"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#Id-2035567893"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>K5mCE0Dj4Wwj4znhc187j7wwimU=</ds:DigestValue></ds:Reference><ds:Reference URI="#TS-325689"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse soapenv"/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>8uj+HkuaQqIG3wqvoI55nVlOTvk=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>j4lfl7vZERA4rEpytOGZBYsYJgeqgGYNvg30he9VQhV7NMP/97ai0A4yTCyQ7mzaxElpbJv44G8n
glyT7cKtWKQhxdNAzWFgJZxk1vlUU1fp71+Ir03QmK2BK66UweYiNVRG856QtPc3HUlU+Hl6u8Pr
5OwMjctNJPq12FbrvypKVRim5AFFMtbNDAocmxrBk9A7EKhx054aVB0H0+6DJGPU0515NuhehnuG
DXltdtrPwCMGxuCVfxmtzNNRGH3CcDmZqKxhmowHW4bFeaTythlop2a0U5qt94UdouX92WVp9qe3
8sZJe3TLTfOgB3bfxwfnJNKRNWU+EejlfyWJyA==</ds:SignatureValue><ds:KeyInfo Id="KI-DB4429187CBE7B32591447062632815488534"><wsse:SecurityTokenReference wsu:Id="STR-DB4429187CBE7B32591447062632815488535"><wsse:KeyIdentifier EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">8dOwG6A7zPuf1Y8RZp73BtYX5ME=</wsse:KeyIdentifier></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security></soapenv:Header><soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-2035567893"><sspp:consultarFacturaResponse xmlns:sspp="https://webservice.juntadeandalucia.es/sspp"><return><numero_registro>id46564897897</numero_registro><tramitacion><codigo_estado>2600</codigo_estado><descripcion_estado>Rechazada</descripcion_estado><motivo_estado>RCF06001. En las facturas emitidas en euros, alguno de los importes de las líneas tiene más de dos decimales o no es numérico. Se incumple la regla 6a del anexo II de la Orden HAP/1650/2015</motivo_estado></tramitacion><anulacion><codigo_estado>4100</codigo_estado><descripcion_estado>No solicitada anulación</descripcion_estado></anulacion></return></sspp:consultarFacturaResponse></soapenv:Body></soapenv:Envelope>

El fichero policy utilizado es:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SigOnly">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
                        <sp:InitiatorToken>
                            <wsp:Policy>
                                <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                                    <wsp:Policy>
                                        <sp:WssX509V3Token10/>
                                    </wsp:Policy>
                                </sp:X509Token>
                            </wsp:Policy>
                        </sp:InitiatorToken>
                        <sp:RecipientToken>
                            <wsp:Policy>
                                <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
                                    <wsp:Policy>
                                        <sp:WssX509V3Token10/>
                                    </wsp:Policy>
                                </sp:X509Token>
                            </wsp:Policy>
                        </sp:RecipientToken>
                        <sp:AlgorithmSuite>
                            <wsp:Policy>
                                <sp:TripleDesRsa15/>
                            </wsp:Policy>
                        </sp:AlgorithmSuite>
                        <sp:Layout>
                            <wsp:Policy>
                                <sp:Strict/>
                            </wsp:Policy>
                        </sp:Layout>
                        <sp:IncludeTimestamp/>
                        <sp:OnlySignEntireHeadersAndBody/>
                    </wsp:Policy>
                </sp:AsymmetricBinding>
                <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
                        <sp:MustSupportRefKeyIdentifier/>
                        <sp:MustSupportRefIssuerSerial/>
                    </wsp:Policy>
                </sp:Wss10>
                <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <sp:Body/>
                </sp:SignedParts>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>

Así pues, la clase que he creado callback provee correctamente la contraseña para el certificado con el que se firma la petición. El problema debe ser que el certificado usado por el servidor para firmar la respuesta es distinto, pero no estoy seguro ni sé si se puede hacer algo con el objeto RampartConfig.

Esta es la parte del código utilizado para hacer la petición:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
String curDir = this.directorioActual();
      String AXIS2_XML = curDir + "\\conf\\axis2.xml";
      String AXIS2_REPOSITORY = curDir + "\\repository";
 
      ConfigurationContext cfgc = ConfigurationContextFactory
      .createConfigurationContextFromFileSystem(AXIS2_REPOSITORY,AXIS2_XML);
 
      //Configuramos el certificado con el que firmamos la petición
      CryptoConfig signcriptoInfo = new CryptoConfig();
      signcriptoInfo.setProvider(Merlin.class.getName());
 
      Properties properties = this.initializateCryptoProperties();
 
      signcriptoInfo.setProp(properties);
      String alias = "";
 
      /** AQUÍ HAY UN MONTÓN DE CÓDIGO IRRELEVANTE PARA OBTENER EL CERTIFICADO **/
      /** PERO EL ALIAS SALE CON VALOR CORRECTO **/
 
      //Configuramos la encriptación del mensaje
      CryptoConfig encriptcriptoInfo = new CryptoConfig();
      encriptcriptoInfo.setProp(properties);
      encriptcriptoInfo.setProvider(Merlin.class.getName());
 
      //Configuramos Rampart
      RampartConfig config = new RampartConfig();
      config.setUserCertAlias(alias);
      config.setPwCbClass(CertCallBack.class.getName());
      //config.setPolicyValidatorCbClass(CertCallBack.class.getName());
      config.setSigCryptoConfig(signcriptoInfo);
      config.setEncrCryptoConfig(encriptcriptoInfo);
      Policy ramapConfigPolicy = new Policy();
      ramapConfigPolicy.addAssertion(config);
 
      SSPPWebServiceProxyServiceStub webservice = new SSPPWebServiceProxyServiceStub(cfgc
      ,serviceURL,false);
 
      //Agregamos la configuración de Rampart al objeto webservice
      webservice._getServiceClient()
      .getAxisService().getPolicyInclude()
      .addPolicyElement(PolicyInclude.OPERATION_POLICY/*.ANON_POLICY*/, ramapConfigPolicy);
 
      ConsultarFacturaDocument docd = ConsultarFacturaDocument.Factory.newInstance();
      ConsultarFacturaDocument.ConsultarFactura doc = docd.addNewConsultarFactura();
      doc.setNumeroRegistro(numeroRegistro);
      docd.setConsultarFactura(doc);

He probado un par de constantes de la clase PolicyInclude al usar el método addPolicyElement que se encuentra en las últimas líneas sin que varíe el resultado.

¿Alguien con experiencia en el tema me puede orientar sobre dónde puede estar el problema? O también me vale saber si hay alguna manera de evitar que rampart valide la firma del mensaje, ya que la respuesta del servidor es válida.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder