I've been struggling for several days about how to compute the digest for the SignedProperties element in a XAdES signature. I have a reference XML file with the two digest values computed (the file being signed and and the signed properties), and I know it's good because it passes the verifiers. I computed the right digest value for the file being signed, but whatever I give as an input to the digest method (I use OpenSSL), I cannot get the same value that in the reference file. Of course my own file don't pass the verifier after that. I use the following command to compute the digest:
openssl dgst -sha256 -binary myfile.xml | openssl base64
I recorded the file myfile.xml by extracting the SignedProperties element of the reference file and saved it as is.
<xades:SignedProperties Id="xmldsig-f6a6a2a1-87af-4720-8eed-cf4532e99106-signedprops"><xades:SignedSignatureProperties><xades:SigningTime>2015-09-22T09:02:48.624+02:00</xades:SigningTime><xades:SigningCertificate><xades:Cert><xades:CertDigest><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>cAJECbIzXZiLH+ILWPrM5jfA13GKcEC8t1qe7/BxqBM=</ds:DigestValue></xades:CertDigest><xades:IssuerSerial><ds:X509IssuerName>CN=thawte SHA256 Code Signing CA,O=thawte\, Inc.,C=US</ds:X509IssuerName><ds:X509SerialNumber>13010307134774063901853305426952669967</ds:X509SerialNumber></xades:IssuerSerial></xades:Cert></xades:SigningCertificate></xades:SignedSignatureProperties><xades:SignedDataObjectProperties><xades:DataObjectFormat ObjectReference="#xmldsig-f6a6a2a1-87af-4720-8eed-cf4532e99106-ref0"><xades:Description>signature détachée du fichier indexfile.txt</xades:Description><xades:MimeType>text/plain</xades:MimeType></xades:DataObjectFormat></xades:SignedDataObjectProperties></xades:SignedProperties></xades:SignedProperties>
Apparently, I should get the value :
6JK3GHDL25+EIRefNMQJ3SOGSI8uzQ45PiziMomZkYs=
But I can't get it. I don't know if some transformations or canonicalization must be applied, the specification is very vague about this part. It's encoded in UTF-8, no line feeds.
Does anyone how to do this ? Any trick ?
I finally found out how to obtain the right digest value. Apparently, the same canonicalization algorithm must be applied to the SignedProperties element, although this is not described precisely in the recommendation. I missed two important things in generating the canonized form :
<DigestMethod/>
becomes <DigestMethod></DigestMethod>
Anyway the correct canonized form for this subset is :
<xades:SignedProperties xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" Id="SignedProperties"><xades:SignedSignatureProperties><xades:SigningTime>2015-09-22T09:02:48.624+02:00</xades:SigningTime><xades:SigningCertificate><xades:Cert><xades:CertDigest><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></ds:DigestMethod><ds:DigestValue>cAJECbIzXZiLH+ILWPrM5jfA13GKcEC8t1qe7/BxqBM=</ds:DigestValue></xades:CertDigest><xades:IssuerSerial><ds:X509IssuerName>CN=thawte SHA256 Code Signing CA,O=thawte\, Inc.,C=US</ds:X509IssuerName><ds:X509SerialNumber>13010307134774063901853305426952669967</ds:X509SerialNumber></xades:IssuerSerial></xades:Cert></xades:SigningCertificate></xades:SignedSignatureProperties><xades:SignedDataObjectProperties><xades:DataObjectFormat ObjectReference="#SignedFile"><xades:Description>signature détachée du fichier indexfile.txt</xades:Description><xades:MimeType>text/plain</xades:MimeType></xades:DataObjectFormat></xades:SignedDataObjectProperties></xades:SignedProperties>