1

I Want sign XML doc. I am doing following for generating signature(ruby).

unsigned_xml = <<-xml
  <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
 </note>
 xml

sdoc = Xmldsig::SignedDocument.new(unsigned_xml)
signature_xml = File.read('signature.xml')
sdoc.document.children.children.last.add_next_sibling(signature_xml)
privkey = OpenSSL::PKey::RSA.new(File.read('bd-key.pem'))
sdoc.sign(privkey)

Please see signature.xml and output below,

signature.xml

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
  <SignedInfo>
    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <Reference URI="">
      <Transforms>
        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
      </Transforms>
      <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
      <DigestValue/>
    </Reference>
  </SignedInfo>
  <SignatureValue/>
  <KeyInfo>
    <KeyValue>
      <RSAKeyValue>
        <Modulus></Modulus>
        <Exponent></Exponent>
      </RSAKeyValue>
    </KeyValue>
  </KeyInfo>
</Signature>

output.xml

<?xml version="1.0"?>
<note>
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
   <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
  <SignedInfo>
    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <Reference URI="">
      <Transforms>
        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
      </Transforms>
      <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
      <DigestValue>IssCQWd+dCUvTL9QuVgE/TzecC3wSbzQQ71CLrjpJGQ=</DigestValue>
    </Reference>
  </SignedInfo>
  <SignatureValue>COI61D+lQ1lLJ17wIBKr+O2kV4au97BMqM+EVPePw6g/itAq4UGBueGhANvYvElzyQcd12dTyh3QUhh/4rUorP6PXuO6eF6f9m13h3rRUupgeKaQbE65j1uvOGj1uXqMoNEuNHSUatATBkXJlfg3PCQfKyywHmW2GTtSKsvfj7WaQ7X9qnJMaCJXdOFS7eEFZ5C9KIutxIKRrH+YsaibwkVOfBYoVNVF08PjUfEpUMHCL6+z2WedRSwLxDPe0ByAN3eLsqGfVOLPSXvB7q3Y+sjE9cE5+vIxHlKhNzlYYayaY0B8Txa79b/g2Rl3fcajKHqVH+FD2lGFVdfktrksjg==</SignatureValue>
  <KeyInfo>
    <KeyValue>
      <RSAKeyValue>
        <Modulus/>
        <Exponent/>
      </RSAKeyValue>
    </KeyValue>
  </KeyInfo>
</Signature>
</note>

But 3rd party service return SIGNATURE MISMATCHING when posting above XML payload. I think issue is due to Modulus and Exponent are missing from output.xml.

My question is how to generate Modulus and Exponent?

Mike
  • 11
  • 1

0 Answers0