summaryrefslogtreecommitdiff
path: root/bin/ses-password-convert.py
blob: 326fcdcb52b8e4a2eec86f169c87fd22be0d421a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
"""
SES SMTP Password Converter

A user's SMTP username is the same as their AWS Access Key ID, their password
is generated by passing the private key through this algorithm. See the page
below for further documentation.

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
"""

import sys
import hmac
import base64
import hashlib

VERSION = b"\x02"
MESSAGE = b"SendRawEmail"
key = sys.argv[1].encode("us-ascii")

mac = hmac.new(key, digestmod=hashlib.sha256)
mac.update(MESSAGE)
hash = mac.digest()

print(base64.b64encode(VERSION + hash).decode("us-ascii"))