node.jsxmlcryptojsws-security

Using xml-crypto with PSHA1


Is it possible to use XML Crypto using a PSHA1 (http://schemas.xmlsoap.org/ws/2005/02/trust/CK/PSHA1) key?

I have both secrets and generate a PSHA1 key string using them, however this fails with:

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line

I'm not what format this key needs to be in to be accepted, it's not a PEM certificate, just a string based on 2 provided nonce's. One provided by the client during the request and one provided by the server in the response.

const sig = new SignedXml();
sig.addReference("/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='Security']/*[local-name()='Timestamp']");
sig.signingKey = '<SIGNING_KEY>';
sig.computeSignature(xml);
fs.writeFileSync('signed.xml', sig.getSignedXml());

It fails on the signer.sign line here:

this.getSignature = function(signedInfo, signingKey) {
  var signer = crypto.createSign("RSA-SHA1")
  signer.update(signedInfo)
  var res = signer.sign(signingKey, 'base64')
  return res
}

Solution

  • The PSHA1 algorithm isn't implemented in the Crypto Library, but there's a PSHA1 npm package you can use to generate the secret key. After that you can generate a SHA1 hash using the message and key in the standard way.

    I asked a very similar question here, which answers the question: https://stackoverflow.com/a/55053741/5065447