I'm trying to implement AWS4 authentication betwee...
# suitescript
k
I'm trying to implement AWS4 authentication between NS and AWS. Basically it requires you to successively generate HMACs of elements of the secret and request (like date, service name etc) which become the key for the next HMAC. I thought the N/crypto module would help me but it seems that it will only create HMACs for with keys stored in the secrets management. Obviously this will not work - does anyone have any ideas?
e
Are you just trying to generate a signature to connect to Amazon's API?
k
yes
e
I used Crypto.JS from Google and wrote some wrapper functions to handle that. That's step one.
function getAWSSignatureKey(key, dateStamp, regionName, serviceName) {
var kDate = CryptoJS.HmacSHA256(dateStamp, "AWS4" + key); var kRegion = CryptoJS.HmacSHA256(regionName, kDate); var kService = CryptoJS.HmacSHA256(serviceName, kRegion); var kSigning = CryptoJS.HmacSHA256("aws4_request", kService); return kSigning; }
that's my function for generating the AWS signature
This is how I'm calling that function.
var signing_key = CryptoJS.getAWSSignatureKey(secret_key, datestamp, region, service); var signingsha256Data = CryptoJS.createHmacSHA256Crypto(string_to_sign, signing_key) var signature = CryptoJS.HmacSHA256ToHexCrypto(signingsha256Data);
k
sweet, thanks dude
I'll take a look
👍 1
e
the other two functions in my CryptoJS library module are
function createHmacSHA256Crypto(stringToHmac, secret) { return CryptoJS.HmacSHA256(stringToHmac, secret); } function HmacSHA256ToHexCrypto(signingsha256Data) { return CryptoJS.enc.Hex.stringify(signingsha256Data); }