Saturday, 21 November 2015

XML : Calculation of SHA1 Digest or a Xades SignedProperties is not working

I have the following XML File :

  <xad:SignedProperties Id="Sig_20151117_172752_SP">                  <xad:SignedSignatureProperties>                      <xad:SigningTime>2015-11-17T16:27:59Z</xad:SigningTime>                      <xad:SigningCertificate>                          <xad:Cert>                              <xad:CertDigest>                                  <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>                                  <ds:DigestValue>vkVMqVMRsiSbo3Zgvk9sTfVtRDs=</ds:DigestValue>                              </xad:CertDigest>                              <xad:IssuerSerial>                                  <ds:X509IssuerName>CN=CERTEUROPE ADVANCED CA V4, OU=0002 434202180, O=Certeurope, C=FR</ds:X509IssuerName>                                  <ds:X509SerialNumber>747583</ds:X509SerialNumber>                              </xad:IssuerSerial>                          </xad:Cert>                      </xad:SigningCertificate>                      <xad:SignaturePolicyIdentifier>                          <xad:SignaturePolicyId>                              <xad:SigPolicyId>                                  <xad:Identifier>1234567</xad:Identifier>                                  <xad:Description>Description de la politique de signature numérique</xad:Description>                              </xad:SigPolicyId>                              <xad:SigPolicyHash>                                  <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>                                  <ds:DigestValue>ZXphcmxramhxZGY=</ds:DigestValue>                              </xad:SigPolicyHash>                              <xad:SigPolicyQualifiers>                                  <xad:SigPolicyQualifier>                                      <xad:SPURI>1234567</xad:SPURI>                                  </xad:SigPolicyQualifier>                              </xad:SigPolicyQualifiers>                          </xad:SignaturePolicyId>                      </xad:SignaturePolicyIdentifier>                      <xad:SignerRole>                          <xad:ClaimedRoles/>                      </xad:SignerRole>                  </xad:SignedSignatureProperties>                  <xad:SignedDataObjectProperties>                      <xad:CommitmentTypeIndication>                          <xad:CommitmentTypeId>                              <xad:Identifier>1.2.840.113549.1.9.16.6.1</xad:Identifier>                              <xad:Description>1.2.840.113549.1.9.16.6.1</xad:Description>                          </xad:CommitmentTypeId>                          <xad:ObjectReference>#D0-Reference</xad:ObjectReference>                      </xad:CommitmentTypeIndication>                  </xad:SignedDataObjectProperties>              </xad:SignedProperties>    

(I indented it on purpose, at start, its linear XML).

I need to obtain the following Digest :

  <ds:Reference Id="Sig_20151117_172752_SP-Reference" Type="http://uri.etsi.org/01903/#SignedProperties" URI="#Sig_20151117_172752_SP">              <ds:Transforms>                  <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>              </ds:Transforms>              <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>              <ds:DigestValue>euEROs8DacsBe3xqXBY5T+M07AI=</ds:DigestValue>          </ds:Reference>    

I'm using Canonicalization C14N to do so.

I tried to add those namespaces into the first tag :

xmlns:xad="http://uri.etsi.org/01903/v1.3.2#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"

In the following orders :

Or

But none of those attempts would work. Is there something missing ? (Here's the C# method I use to calculate the SHA-1 Digest :

  public string CalculateHashSHA1(string input)          {              using (SHA1Managed sha1 = new SHA1Managed())              {                  return Convert.ToBase64String(sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input)));              }          }    

No comments:

Post a Comment