Skip to content

Instantly share code, notes, and snippets.

@bmacauley
Created March 19, 2017 12:08
Show Gist options
  • Save bmacauley/daef565e025a1b61eb5bd159d1cafaad to your computer and use it in GitHub Desktop.
Save bmacauley/daef565e025a1b61eb5bd159d1cafaad to your computer and use it in GitHub Desktop.
an attempt to convert AWS IAM credentials to the SES sort as per the instructions found here: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html#Obtaining Amazon SES SMTP Credentials by Converting AWS Credentials
def hash_IAM(user_password):
#http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
if DEBUG: debug_message("Hashing for IAM to SES values")
AWS_SECRET_ACCESS_KEY = user_password
AWS_MESSAGE = "SendRawEmail"
#in Python 2, str are bytes
signature = hmac.new(
key=AWS_SECRET_ACCESS_KEY,
#byte[] rawSignature = mac.doFinal(MESSAGE.getBytes());
msg=AWS_MESSAGE,
digestmod=hashlib.sha256
).digest()
signature = chr(2) + signature
signature = base64.b64encode(signature)
return signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment