Created
January 12, 2018 16:44
-
-
Save simonr-cb/c07f5eb252eebbb418408e033b44dcdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var secret = SHIPFAST_HMAC_SECRET | |
var hmac | |
... | |
... | |
var obfuscatedSecretData = Buffer.from(secret, 'base64') | |
var shipFastAPIKeyData = new Buffer("QXBwcm9vdidzIHRvdGFsbHkgYXdlc29tZSEh") | |
for (var i = 0; i < Math.min(obfuscatedSecretData.length, shipFastAPIKeyData.length); i++) { | |
obfuscatedSecretData[i] ^= shipFastAPIKeyData[i] | |
} | |
var obfuscatedSecret = new Buffer(obfuscatedSecretData).toString('base64') | |
hmac = crypto.createHmac('sha256', Buffer.from(obfuscatedSecret, 'base64')) | |
... | |
... | |
// Compute the request HMAC using the HMAC SHA-256 algorithm | |
... | |
... | |
// Check to see if our HMAC matches the one sent in the request header | |
// and send an error response if it doesn't | |
if (ourShipFastHMAC != requestShipFastHMAC) { | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment