Created
October 13, 2022 13:50
-
-
Save jjtroberts/2b80b1b5cf6c1d32cc8dc96c1101b9a8 to your computer and use it in GitHub Desktop.
SES IAM Converter
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
#!/usr/bin/env python3 | |
import hmac | |
import hashlib | |
import base64 | |
import argparse | |
# Values that are required to calculate the signature. These values should | |
# never change. | |
DATE = "11111111" | |
SERVICE = "ses" | |
MESSAGE = "SendRawEmail" | |
TERMINAL = "aws4_request" | |
VERSION = 0x04 | |
def sign(key, msg): | |
return hmac.new(key, msg.encode('utf-8'), hashlib.sha256).digest() | |
def calculateKey(secretAccessKey, region): | |
signature = sign(("AWS4" + secretAccessKey).encode('utf-8'), DATE) | |
signature = sign(signature, region) | |
signature = sign(signature, SERVICE) | |
signature = sign(signature, TERMINAL) | |
signature = sign(signature, MESSAGE) | |
signatureAndVersion = bytes([VERSION]) + signature | |
smtpPassword = base64.b64encode(signatureAndVersion) | |
print(smtpPassword.decode('utf-8')) | |
def main(): | |
parser = argparse.ArgumentParser(description='Convert a Secret Access Key for an IAM user to an SMTP password.') | |
parser.add_argument('--secret', | |
help='The Secret Access Key that you want to convert.', | |
required=True, | |
action="store") | |
parser.add_argument('--region', | |
help='The name of the AWS Region that the SMTP password will be used in.', | |
required=True, | |
choices=['us-east-1','us-west-2','eu-west-1'], | |
action="store") | |
args = parser.parse_args() | |
calculateKey(args.secret,args.region) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment