node.jssoaphashcryptographyamadeus

Issue creating password digest for Amadeus SOAP API


I followed the instructions in the docs and tried to do the same formula in Node, however, I'm not able to correctly authenticate with the server as I receive an 11|Session| response. I assume that error is in response to incorrectly set nonce and/or password digest.

The formula: Base64(SHA1($NONCE + $TIMESTAMP + SHA1($CLEARPASSWORD)))

The variables: $CLEARPASSWORD=AMADEUS, $TIMESTAMP=2015-09-30T14:12:15Z, $NONCE=c2VjcmV0bm9uY2UxMDExMQ==.

The expected hash: +LzcaRc+ndGAcZIXmq/N7xGes+k=

The code I tried was:

const crypto = require('crypto')
const hashedPassword = crypto.createHash('sha1').update(CLEARPASSWORD).digest() // Returns a buffer
crypto.createHash('sha1').update(NONCE + TIMESTAMP + hashedPassword).digest('base64') // Returns a Base64 String

However, this returns DDcZEaS5AtoVaZhsARy9MqV+Y34=. And if I change the nonce to its plain string secretnonce10111, then I get gHOoqyDb9YJBrk30iabSO8nKxio= which still isn't correct.

I'm not sure what could be the issue.


Solution

  • I finally figured out what was wrong. The problem was I was trying to concatenate a string with a Buffer, when I should have just made everything a buffer from the start.

    So, instead of

    const hashedPassword = crypto.createHash('sha1').update(CLEARPASSWORD).digest()
    crypto.createHash('sha1').update(NONCE + TIMESTAMP + hashedPassword).digest('base64')
    

    It should have been

    const buffer = Buffer.concat([Buffer.from(NONCE), Buffer.from(TIMESTAMP), nodeCrypto.createHash('sha1').update(CLEARPASSWORD).digest()])
    const hashedPassword = nodeCrypto.createHash("sha1").update(buffer).digest("base64")