-
-
Save ivorpad/f0bfd962c9e4a1cdc6b2c30a37ba1258 to your computer and use it in GitHub Desktop.
Convert AWS IAM credentials to AWS SMTP credentials
This file contains hidden or 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
const crypto = require("crypto"); | |
const secretAccessKey = ""; // AWS_ACCESS_KEY_SECRET | |
const regionName = "us-east-1"; | |
// Assuming you've already set up your SES Policy on your IAM User: | |
// { | |
// "Version": "2012-10-17", | |
// "Statement": [ | |
// { | |
// "Effect":"Allow", | |
// "Action":["ses:SendEmail", "ses:SendRawEmail"], | |
// "Resource":"*" | |
// } | |
// ] | |
// } | |
const date = "11111111"; | |
const service = "ses"; | |
const terminal = "aws4_request"; | |
const message = "SendRawEmail"; | |
const versionInBytes = [4]; // Signature Version 4 | |
const kDate = sign(date, "AWS4" + secretAccessKey); | |
const kRegion = sign(regionName, kDate); | |
const kService = sign(service, kRegion); | |
const kTerminal = sign(terminal, kService); | |
const kMessage = sign(message, kTerminal); | |
const signatureAndVersion = Buffer.from([...versionInBytes, ...kMessage]); | |
const smtpPassword = signatureAndVersion.toString("base64"); | |
console.log(smtpPassword); | |
function sign(string, key) { | |
const hmac = crypto.createHmac("sha256", key); | |
hmac.update(string); | |
return hmac.digest(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment