PeculiarVentures / xadesjs

A pure Typescript/Javascript implementation of XAdES based on XMLDSIGjs. (Keywords: WebCrypto, XMLDSIG, XADES, eIDAS, Trust List, X.509, CRL, OCSP)
https://xadesjs.com
MIT License
141 stars 49 forks source link

Truncated signd XML #109

Closed johnhenga closed 4 years ago

johnhenga commented 4 years ago

DS Detected signedXML.xml.txt Hi, I am facing a curios scenario when I passed the attached file (named "DS Not detected signedXML.xml.txt") to this website ('https://validation.teda.th/webportal/#/validate), it could not detect the signature element in the file. However the website managed to detect signature element when another file generated by csdes4j with similar element(named " DS Detected signedXML.xml.txt") Here's the code I am using for generate "DS Not detect signedXML.xml.txt". Thank you for your help.

async function createEnvelopedSignature(keys, algorithm, signingXml, options) { const signedXml = new xadesjs.SignedXml(); const hash = !(options && options.hash) ? "SHA-256" : options.hash; const signingOptions = { references: [ { hash, transforms: ["enveloped"], uri: '' }, ], }; if (options) { if (options.certificate) { signingOptions.x509 = [options.certificate]; signingOptions.signingCertificate = options.certificate; signingOptions.id = options.id } if (options.policy) { signingOptions.policy = options.policy; } } const testSign1 = () => { var time = Date.now() const doc = fs.readFileSync("./ETDA-invoice.xml", { encoding: "utf8" }); const signingXml = xadesjs.Parse(doc);

getKeyP('private-0700040000000000-')
    .then(async (key) => {
        key.algorithm.hash.name = 'SHA-512'
        const algorithm = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-512" };
        await createEnvelopedSignature(key, algorithm, signingXml, {
            id: `xmldsig-${time}`,
            hash: 'SHA-512',
            references: [{ hash: "SHA-512", transforms: ["enveloped"] }],
            certificate: "MIIGgTCCBGmgAwIBAgIUeaHFHm5f58zYv20JfspVJ3hossYwDQYJKoZIhvcNAQEFBQAwgZIxCzAJBgNVBAYTAk5MMSAwHgYDVQQKExdRdW9WYWRpcyBUcnVzdGxpbmsgQi5WLjEoMCYGA1UECxMfSXNzdWluZyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTE3MDUGA1UEAxMuUXVvVmFkaXMgRVUgSXNzdW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MGCiqGSIb3LwEBCQIEBTADAgEBMA4GA1UdDwEB/wQEAwIGQDAfBgNVHSMEGDAWgBTg+A751LXyf0kjtsN5x6M1H4Z6iDA7BgNVHR8ENDAyMDCgLqAshipodHRwOi8vY3JsLnF1b3ZhZGlzZ2xvYmFsLmNvbS9xdmV1Y2FnMi5jcmwwHQYDVR0OBBYEFDc3hgIFJTDamDEeQczI7Lot4uaVMA0GCSqGSIb3DQEBBQUAA4ICAQAZ8EZ48RgPimWY6s4LjZf0M2MfVJmNh06Jzmf6fzwYtDtQLKzIDk8ZtosqYpNNBoZIFICMZguGRAP3kuxWvwANmrb5HqyCzXThZVPJTmKEzZNhsDtKu1almYBszqX1UV7IgZp+jBZ7FyXzXrXyF1tzXQxHGobDV3AEE8vdzEZtwDGpZJPnEPCBzifdY+lrrL2rDBjbv0VeildgOP1SIlL7dh1O9f0T6T4ioS6uSdMt6b/OWjqHadsSpKry0A6pqfOqJWAhDiueqgVB7vus6o6sSmfG4SW9EWW+BEZ510HjlQU/JL3PPmf+Xs8s00sm77LJ/T/1hMUuGp6TtDsJe+pPBpCYvpm6xu9GL20CsArFWUeQ2MSnE1jsrb00UniCKslcM63pU7I0VcnWMJQSNY28OmnFESPK6s6zqoN0ZMLhwCVnahi6pouBwTb10M9/Anla9xOT42qxiLr14S2lHy18aLiBSQ4zJKNLqKvIrkjewSfW+00VLBYbPTmtrHpZUWiCGiRS2SviuEmPVbdWvsBUaq7OMLIfBD4nin1FlmYnaG9TVmWkwVYDsFmQepwPDqjPs4efAxzkgUFHWn0gQFbqxRocKrCsOvCDHOHORA97UWcThmgvr0Jl7ipvP4Px//tRp08blfy4GMzYls5WF8f6JaMrNGmpfPasd9NbpBNp7A=="
        });
        fs.writeFileSync("./signed.xml", xmlCore.Stringify(signingXml), { flag: 'w' });
    })
console.log('done ', time)

}

DS Detected signedXML.xml.txt

DS Not detected signedXML.xml.txt

johnhenga commented 4 years ago

Hi, Please ignore my previous files. The following files should be more obvious. The newly attached files came from the same program. The signature element in "signedXML.xml.txt" could not be detected but the other one got reformmated then the website managed to detect the signature element. Sorry for the trouble.

signedXML.xml.txt signedXML formatted.xml.txt

johnhenga commented 4 years ago

.

rmhrisk commented 4 years ago

So issue is resolved?

johnhenga commented 4 years ago

So issue is resolved? Not really, the signed XML passed several other validation tools. It's probably best to revisit this issue after new info acquired. Your team's contribution is truly admired.