-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difference from javax.xml.crypto.dsig and xml-crypto signature value #486
Comments
Yes. At least I have an idea. Dunno about others. BTW. You considered this to be a bug at xml-crypto due to reporting bug issue instead of discussion post. Whats your xml-crypto version and node version and steps to reproduce bug. (What was your exact JDK version) |
In case your JDK version was some of those affected by following:
|
I suggested #486 (comment) as answer to your question's About splitting every 76th character (the https://www.w3.org/TR/2002/REC-xmldsig-core-20020212/#sec-SignatureValue https://www.w3.org/TR/xmlschema-2/#base64Binary Quick internet search provided following thread regarding xmlsig's base64 stuff: There are also other threads about same stuff (with same subject) at that mailing list with emails from xmlsig spec contributors. About link you provided to pix-proxy-samples...it does not reveal anything about version of implementation of |
The Java implementation passes our internal tool validation but node xml-crypto does not We don't have access to the internal tool validation of the signature I just wanna produce the same signature value both in Java and node Im trying to understand why they differ and how to make both the same |
Having such material gives something to work with. Without such material continuation of this discussion is pointless. |
Here is example how xmlsec1 was used at one case as a reference implementation: #212 (comment) Note: that case was related to signing (and more specifically to find out lack of implicit C14N during signing and how adding it explicitly lined digest values and thus signatures between different tools). Sidenote: if you would have posted full signed document (signed by xml-crypto) one could see whether there is chance that your root cause is same. |
Here is the spec https://www.bcb.gov.br/content/estabilidadefinanceira/cedsfn/Manual_de_Seguranca_PIX.pdf It is in Portuguese (Brazil), you could easily translate it It has some specific references style You can also check some examples in the unit tests of the aws repo |
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Envelope xmlns="https://www.bcb.gov.br/pi/pacs.008/1.4">
<AppHdr>
<Fr>
<FIId>
<FinInstnId>
<Othr>
<Id>00038166</Id>
</Othr>
</FinInstnId>
</FIId>
</Fr>
<To>
<FIId>
<FinInstnId>
<Othr>
<Id>99999010</Id>
</Othr>
</FinInstnId>
</FIId>
</To>
<BizMsgIdr>M0003816612345678901234567890123</BizMsgIdr>
<MsgDefIdr>pacs.008.spi.1.4</MsgDefIdr>
<CreDt>2020-01-01T08:30:12.000Z</CreDt>
<Sgntr/>
</AppHdr>
<Document>
<FIToFICstmrCdtTrf>
<GrpHdr>
<MsgId>M0003816612345678901234567890123</MsgId>
<CreDtTm>2020-01-01T08:30:12.000Z</CreDtTm>
<NbOfTxs>1</NbOfTxs>
<SttlmInf>
<SttlmMtd>CLRG</SttlmMtd>
</SttlmInf>
<PmtTpInf>
<InstrPrty>HIGH</InstrPrty>
</PmtTpInf>
</GrpHdr>
<CdtTrfTxInf>
<PmtId>
<EndToEndId>E9999901012341234123412345678900</EndToEndId>
<TxId>90000</TxId>
</PmtId>
<IntrBkSttlmAmt Ccy="BRL">1000.00</IntrBkSttlmAmt>
<AccptncDtTm>2020-01-01T08:30:00.000Z</AccptncDtTm>
<ChrgBr>SLEV</ChrgBr>
<Dbtr>
<Nm>Fulano da Silva</Nm>
<Id>
<PrvtId>
<Othr>
<Id>70000000000</Id>
</Othr>
</PrvtId>
</Id>
</Dbtr>
<DbtrAcct>
<Id>
<Othr>
<Id>500000</Id>
<Issr>3000</Issr>
</Othr>
</Id>
<Tp>
<Cd>CACC</Cd>
</Tp>
</DbtrAcct>
<DbtrAgt>
<FinInstnId>
<ClrSysMmbId>
<MmbId>10000000</MmbId>
</ClrSysMmbId>
</FinInstnId>
</DbtrAgt>
<CdtrAgt>
<FinInstnId>
<ClrSysMmbId>
<MmbId>20000000</MmbId>
</ClrSysMmbId>
</FinInstnId>
</CdtrAgt>
<Cdtr>
<Id>
<PrvtId>
<Othr>
<Id>80000000000</Id>
</Othr>
</PrvtId>
</Id>
</Cdtr>
<CdtrAcct>
<Id>
<Othr>
<Id>600000</Id>
<Issr>4000</Issr>
</Othr>
</Id>
<Tp>
<Cd>SVGS</Cd>
</Tp>
</CdtrAcct>
<RmtInf>
<Ustrd>Campo livre [0]</Ustrd>
</RmtInf>
</CdtTrfTxInf>
</FIToFICstmrCdtTrf>
</Document>
</Envelope> signed <?xml version="1.0" encoding="UTF-8" standalone="no"?><Envelope xmlns="https://www.bcb.gov.br/pi/pacs.008/1.4">
<AppHdr>
<Fr>
<FIId>
<FinInstnId>
<Othr>
<Id>00038166</Id>
</Othr>
</FinInstnId>
</FIId>
</Fr>
<To>
<FIId>
<FinInstnId>
<Othr>
<Id>99999010</Id>
</Othr>
</FinInstnId>
</FIId>
</To>
<BizMsgIdr>M0003816612345678901234567890123</BizMsgIdr>
<MsgDefIdr>pacs.008.spi.1.4</MsgDefIdr>
<CreDt>2020-01-01T08:30:12.000Z</CreDt>
<Sgntr><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><ds:Reference URI="#9115a29c-1246-4de2-8d33-d3c8549efac3"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>Kmg8b7mLCJtFj1co5CvLBusbRQcpq2rurd87Fy1VmMA=</ds:DigestValue></ds:Reference><ds:Reference URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>0mtmawoDDPLwAAAkSYdy0JmPf5oS55rHZjsXOASzY4c=</ds:DigestValue></ds:Reference><ds:Reference><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>UP6Uy9SYzwVsO+djbyusrydi2/If22U4bEHZt/NJhH0=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>IhddKqaN3zNXNN30h6+7RYL6tdAQZmf0UqPnrBwlL5K/cjS6J8ph3DVGODQDWZHNHXqReOiHaAzT
svR5SnBYek2/Z0rmzs1zuf3pYOKb5n2K/EnG6uLot/lWILd9oOYBJcN5eYRNF70sKcEy5pE0TuEJ
y1yh0EQKWSOACuESLNH+FH71sFpBXJSgOSj6FVQ0utZc1A4YdvPZZCsayOmSVHqwBgRSGHG05k4b
C7rX5xhXT4ezMEqk4XXTVZD42j6LFcB09Hvq5RNOqrspRlguztOwl23M6iAtsbmCfgDbG2w0B8HQ
yFw8maLMVGbfz2WONs6gRasdaEKVnEe1rhnKwg==</ds:SignatureValue><ds:KeyInfo Id="9115a29c-1246-4de2-8d33-d3c8549efac3"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=client.pix.aws.com,OU=PIX,O=AWS,L=Sao Paulo,ST=SP,C=BR</ds:X509IssuerName><ds:X509SerialNumber>2004099543</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></ds:KeyInfo></ds:Signature></Sgntr></AppHdr>
<Document>
<FIToFICstmrCdtTrf>
<GrpHdr>
<MsgId>M0003816612345678901234567890123</MsgId>
<CreDtTm>2020-01-01T08:30:12.000Z</CreDtTm>
<NbOfTxs>1</NbOfTxs>
<SttlmInf>
<SttlmMtd>CLRG</SttlmMtd>
</SttlmInf>
<PmtTpInf>
<InstrPrty>HIGH</InstrPrty>
</PmtTpInf>
</GrpHdr>
<CdtTrfTxInf>
<PmtId>
<EndToEndId>E9999901012341234123412345678900</EndToEndId>
<TxId>90000</TxId>
</PmtId>
<IntrBkSttlmAmt Ccy="BRL">1000.00</IntrBkSttlmAmt>
<AccptncDtTm>2020-01-01T08:30:00.000Z</AccptncDtTm>
<ChrgBr>SLEV</ChrgBr>
<Dbtr>
<Nm>Fulano da Silva</Nm>
<Id>
<PrvtId>
<Othr>
<Id>70000000000</Id>
</Othr>
</PrvtId>
</Id>
</Dbtr>
<DbtrAcct>
<Id>
<Othr>
<Id>500000</Id>
<Issr>3000</Issr>
</Othr>
</Id>
<Tp>
<Cd>CACC</Cd>
</Tp>
</DbtrAcct>
<DbtrAgt>
<FinInstnId>
<ClrSysMmbId>
<MmbId>10000000</MmbId>
</ClrSysMmbId>
</FinInstnId>
</DbtrAgt>
<CdtrAgt>
<FinInstnId>
<ClrSysMmbId>
<MmbId>20000000</MmbId>
</ClrSysMmbId>
</FinInstnId>
</CdtrAgt>
<Cdtr>
<Id>
<PrvtId>
<Othr>
<Id>80000000000</Id>
</Othr>
</PrvtId>
</Id>
</Cdtr>
<CdtrAcct>
<Id>
<Othr>
<Id>600000</Id>
<Issr>4000</Issr>
</Othr>
</Id>
<Tp>
<Cd>SVGS</Cd>
</Tp>
</CdtrAcct>
<RmtInf>
<Ustrd>Campo livre [0]</Ustrd>
</RmtInf>
</CdtTrfTxInf>
</FIToFICstmrCdtTrf>
</Document>
</Envelope>
|
Now....how is that related to xml-crypto? Are you saying that xml-crypto fails to verify signature? Does xmlsec1 verify that signature? Or Are you saying that if xml-crypto would be used to sign that document then output of xml-crypto cannot be verified by xmlsec1? Provide JS file which signs that document with xml-crypto so that we can see how you tried to do that and output also. Also keep in mind that xml-crypto is unable to sign keyinfo (as discussed at #481 ) so you have to modify your example (which is signing keyinfo also) accordingly (I gather that you are debugging another aspect). And where is the certificate / public key which can be used for signature verification. |
It is all in the aws repo |
Good. Then there chance that you hand out direct link. No-one else except youself is getting any money to run around to gather material or debugging this on behalf of you. btw. I copy pasted your example signed xml to https://tools.chilkat.io/xmlDsigVerify.cshtml It said:
Note: there is no way chilkat could say that signature is valid because cert is not available. But now you have another track which is: explain yourself why unrelated (from xml-crypto pov) tool is unable to calculate same digest values as your reference implementation. Consider consulting also xmlsec1 tool's opinion. Lets continue after you have sorted things out between your reference implementation and xmlsec1 and chilkat. And keep in mind that no matter what xml-crypto is currently unable to sign keyinfo. |
I could made xml-crypto to calculate the same digest I have a custom implementation to sign KeyInfo, not generic enough for this package yet The digest value are correct and the same as Java implementation However the signature value has this difference |
|
|
Adding more context to this issue for future generations who might land here via some search engine. Based on content of this comment: #486 (comment) This issue seems to be at the end of the day "same" as: or at least very close to that in terms of how signature should be constructed (if we think how this issue might be related to xml-crypto). Author of #204 was kind enought to describe expected signature content (without having to use any translator to translate portuguese document):
Regarding
So (IMHO) it seems that at the end of the day one has to construct signature without the help of xml-crypto because at least I can't figure out how xml-crypto would be made aware which part of the document should be handled when reference without URI is added. This second opinion backs aforementioned interpretation: https://stackoverflow.com/questions/15522098/java-xmldsig-reference-with-no-uri/18526152#18526152 About those extra xml entities (which started this whole discussion)...its something java stack related. |
This is the SignedInfo canonilized
it generates this hash in node
and it generates this hash in java/kotlin
do you have an idea why java signature has #xD;\n ?
The text was updated successfully, but these errors were encountered: