Reputation: 170
For a project, XML files are dynamically generated. After a while, these XML files need to be signed using the XAdES-T protocol. The signature must be included in the XML file.
To do that, I generate a Timestamp Query (TSQ) from the XML file. It is created based on the SHA256 hash of the XML file. After that, I send the TSQ to FreeTSA (Timestamp Authority). The response consists of two elements:
Now here comes the hard part. The signature must be included in the XML using dsig:Signature
. Based on the W3 documentation:
I tried the following XML:
<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>
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue></ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
MIIFUDADAgEAMIIFRwYJKoZIhvcNAQcCoIIFODCCBTQCAQMxDzANBglghkgBZQMEAgMFADCCAY4GCyqGSIb3DQEJEAEEoIIBfQSCAXkwggF1AgEBBgQqAwQBMDEwDQYJYIZIAWUDBAIBBQAEIHY4mbyU5g4mM3CRUjMSjILz19kk0jYmuoZSCI6hnXQqAgQAzfxZGA8yMDIxMDgyNTExMzcwN1oBAf8CCHdmnjv+m4i4oIIBEaSCAQ0wggEJMREwDwYDVQQKEwhGcmVlIFRTQTEMMAoGA1UECxMDVFNBMXYwdAYDVQQNE21UaGlzIGNlcnRpZmljYXRlIGRpZ2l0YWxseSBzaWducyBkb2N1bWVudHMgYW5kIHRpbWUgc3RhbXAgcmVxdWVzdHMgbWFkZSB1c2luZyB0aGUgZnJlZXRzYS5vcmcgb25saW5lIHNlcnZpY2VzMRgwFgYDVQQDEw93d3cuZnJlZXRzYS5vcmcxIjAgBgkqhkiG9w0BCQEWE2J1c2lsZXphc0BnbWFpbC5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swHdNMrLETK2vPd646wZfsKTSOqjbzi5ljrS03FsElhxujcrwjGLOs1l/EyAIM0an1lroHnu5n2MH5KLMvPJqjLIqn0jEsxXk8JU+kpqUpcTaTKq24VbvqYO/WeyfD1t2t9ExhPgxAaBf6lm9R7AdbxpWJTl0rP4h3YMq/h5z2U2TYAYXQ3aiXQZR0VvUJbPI22thftdhsNDC0v+fU=
</ds:SignatureValue>
</ds:Signature>
But the status (according to this website) is always "invalid".
What is the correct way to append the Timestamp Response to an XML file?
Upvotes: 1
Views: 790
Reputation: 5230
The best solution in PHP to work with Xades documents is: https://github.com/bseddon/xml-signer
Provides signing and verification of XML documents for PHP focussing on support for signatures that are compliant with the XAdES specification.
I have signed a xml with LTA and timestamping. It´s very easy and well documented!
Thanks to @bseddon!
Upvotes: 1
Reputation: 108
I'm a developer of an open-source project for creation and validation of electronic signatures.
The problem within your signature is that your signature contains a ds:Reference not referencing any content. It shall refer an element within the signature file or a detached document. The ds:DigestValue element shall contain digests of the referenced content after applied tranformations.
For a simple XMLDSig signature you can get familiar studying this specification.
For extended information about electronic signatures, including advanced and qualified electronic signatures, you can take a look on the documentation. The project is in Java, but the documentation contains a lot of generic information about the signatures and available formats and ways to create it.
Upvotes: 1