Signature validation false
Asked Answered
B

0

6

I'm try to verify signature like this (it's PARes from Mastercard) and receive false every time, but xml from VISA work ok

Mastercard

<?xml version="1.0" encoding="UTF-8"?>
<ThreeDSecure><Message id="89e8bafa-755d-4ae9-a357-8641f13f057f"><PARes id="PARes-3cz1Jjfc"><version>1.0.2</version><Merchant><acqBIN>521324</acqBIN><merID>100000000000020</merID></Merchant><Purchase><xid>Z0FSSEFabjE1MTU2NTg2MTAzODY=</xid><date>20180111 08:16:50</date><purchAmount>1000</purchAmount><currency>643</currency><exponent>2</exponent></Purchase><pan>0000000000002290</pan><TX><time>20180111 08:17:00</time><status>Y</status><cavv>jNsniZHx4MT1DxEhZAITCFAAAAA=</cavv><eci>02</eci><cavvAlgorithm>3</cavvAlgorithm></TX></PARes><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"></CanonicalizationMethod><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></SignatureMethod><Reference URI="#PARes-3cz1Jjfc"><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod><DigestValue>8I/izdCJcp7wABf2YfFQbd4Ktxg=</DigestValue></Reference></SignedInfo><SignatureValue>IQuLAtGT8rEFp/a5bV9Wu8qiSXpTGtvkJaJCuPTrflwPFFwiSLuivfcInX8pzirmObPV9ue4Kn8YFu+ltiYg8g2sHMa6S9RfC330+/ntBL2XxNp6IO+s7anGsM5WOmd3Pt176Ft5DRDOpeJg8N9PtbhYPQ//TzzehApb9/EMnpFZKEnJbYYl5Wpa7gPV+iIJJryAdZF3CW3c6/ns/XzwQZ9Tfm9t24SRbF2U/Hkn7aD6MUug772hqNiOHQJ0gtdtDxR9KkQfh3aNq5EmS2MEgfoCkm8mUOO/fQEOMBy2fbgE4/JnDZ/7n2x/hDKZZn9oUv7BLvoM1IcjfYKRiEve7g==</SignatureValue><KeyInfo><X509Data><X509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0kHbkAe6pj6i65TpwEgEpywVl50oMmNKvXDNMznrAG6S9us+OHDjonOlmmyWmQxXdU1MzwdKzPjHfwl+Z6kByDXruHjEcNsx7P2rUTm/Bt3SWW1K48VfNNhVa/WctTZGJCrV3Zjl6A9g==</X509Certificate></X509Data></KeyInfo></Signature></Message></ThreeDSecure>

My validation code

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder builder = dbf.newDocumentBuilder();

        final InputStream stream = new ByteArrayInputStream(xmlDoc.getBytes(StandardCharsets.UTF_8));
        Document doc = builder.parse(stream);

        NodeList nl = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
        if (nl.getLength() == 0) {
            throw new XMLSignatureException("Cannot find Signature element");
        }


        DOMValidateContext valContext = new DOMValidateContext(new X509KeySelector(keysFile, keyPassword), nl.item(0));

Element PARes = (Element) doc.getElementsByTagName("PARes").item(0);
            valContext.setIdAttributeNS(PARes, null, "id");

        XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");

        // Unmarshal the XMLSignature.
        XMLSignature signature = factory.unmarshalXMLSignature(valContext);

        // Validate the XMLSignature.

        boolean coreValidity = signature.validate(valContext);

I've add additional code for get reason of failure

 // Check core validation status
        if (coreValidity == false) {
            System.err.println("Signature failed core validation");
            boolean sv = signature.getSignatureValue().validate(valContext);
            System.out.println("signature validation status: " + sv);
            // check the validation status of each Reference
            Iterator<?> i = signature.getSignedInfo().getReferences().iterator();
            for (int j = 0; i.hasNext(); j++) {
                boolean refValid = ((Reference) i.next()).validate(valContext);
                System.out.println("ref[" + j + "] validity status: "
                        + refValid);
            }
        } else {
            System.out.println("Signature passed core validation");
        }

and have got this result

Signature failed core validation
signature validation status: false
ref[0] validity status: true

How to avoid signature validation false or how to debug the reason. at standard page there is information

Note, there may be valid signatures that some signature applications are unable to validate. Reasons for this include failure to implement optional parts of this specification, inability or unwillingness to execute specified algorithms, or inability or unwillingness to dereference specified URIs (some URI schemes may cause undesirable side effects), etc.

But how to avoid this problem. I know that signature is valid but ... One difference between good and wrong validated xml it's format reference id In good xml without - just digits or alphabets

RAW incoming data

//VISA

String PaRes = "eJzNWWnPo1aW/itR+qNVYTcmcl7psi8GA2b1lxH7DsZgg/n1g+2qypukeqY7Go3akmU4nHuWe5bnHry38muSsKckul2Tj72aDEOQJT8V8W8/hwmFIhSBf4FxHP6CEyT6JYgD6gtO7eJgi6VpEKY/f+x1YCbDa4Fbl2JFK+1VxtLZ+694lk1RASvLPbkORdd+IL/Av6B76Nvtqu0a5UE7fuyDqKcl7QPHSHKH7aGvt/smuUrsBwJ/+qDwHnqT99Dv6/Xb82pYPZiL+COyZ9UWZt8oOUS1bEwrI/RoqYvKVr/toSfHPg7G5AOFkR2MIOhPCP4rhv9KrJpf9P3lKQ403W2V/dS+hz5T9uteXZM2enxs8XXJ97t9Ml+6Nlk5Vie/X++h3427BO3HH5whSHKVvVL3lvexH4vmT0YRv+Kr8hd9P4zBeBs+/D309WofBff7BwCAps1ICk6y6+N2ZU75Bbw/q7Mvln0SFR8wsRq1/r5WgTrrrsWYN09T/0jYQ09ToFdYP/anImtXZdfkp7mp2+G3n/NxvPwKQdM0/TJhv3TXDEJXRyCYglaGeCiyf/z8XpXEUpt2/9YyJmi7toiCuliCcc0QNRnzLv7pu20/EmOZT0kIZHLMl1XUlwjB2y9PCowhxCoT+rHQT579K1r+bOx1CL4MeYA8FfxJ0MfeTNLkmRHJT7Yp/fbzP/5pXbBFlgzj39H/TfdnCd/kOUF9Sz6ceQm9boux8kaNQnr0kN0WBhol+M+0+My5h74b/NWbd+g+bdGbsZMudqV08aCiCnTXS+BZ+RlU8Q4eJU91azQJbzaPjogjzAFzeBinYcEj6TFFEG9SFt0JM4sXXIxmxayiR7zoqRFfyzQcfQLNVoEzEZxandxqCK9nvsX7m37G7LEnEFtkBrhX11r0Ym2yQoXBUEUiOP/EUnaP1hyxGUKu2UTnKYTqrup9khNufJBmriDD2yJWRX5H2caWpaaIg4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dbdUIMxDm5YIp5M65qmrmBMglGixflNnOIfyiosH+160C+X4Xg3y7n/l+c/N2t/x2A/56Hfrjzfg///EfRHiyaQ\\u003d\\u003d";

Code for decoding

String pares = new String(decompress(response), Charset.forName("UTF-8"));

private byte[] decompress(String PARes) throws IOException, DataFormatException
    {
        BASE64Decoder decoder = new BASE64Decoder();
        final byte[] compressedData = decoder.decodeBuffer(PARes);

        // Create the decompressor and give it the data to compress
        Inflater decompressor = new Inflater();
        decompressor.setInput(compressedData);

        // Create an expandable byte array to hold the decompressed data
        ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);

        // Decompress the data
        byte[] buf = new byte[1024];
        while (!decompressor.finished())
        {
            int count = decompressor.inflate(buf);
            bos.write(buf, 0, count);
        }
        bos.close();

        // Get the decompressed data
        return bos.toByteArray();
    }
Bilateral answered 11/1, 2018 at 11:12 Comment(5)
See "What If the XML Signature Fails to Validate?" here. "signature validation status: false" means that the cryptographic verification has failed. Have you modified the signature in any way?Keep in mind that white space, indentation or change of encoding is significantNeoma
Signature is valid 100%. I't was received from bank. But there is only one thing I'm decode this data from base64 and unzip it. And everything vork ok for Visa value and domestic paymet system and wrong for Mastercard But mastercard in UTF-8 code May by it's a reason. But hash reference is trueBilateral
Encoding can become a headache. Could you post a base64 sample before decoding it?Neoma
Added two raw incoming strings. Visa work, Mastercard - don't work And code for decodingBilateral
Got same result testing your examples. Assuming that the mastercard signature is presumably correct, you could try Apache Santuario. It is an alternative implementation of XML-SignatureNeoma

© 2022 - 2024 — McMap. All rights reserved.