-
Notifications
You must be signed in to change notification settings - Fork 0
/
seskey.py
60 lines (52 loc) · 2.1 KB
/
seskey.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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-2', #US East (Ohio)
'us-east-1', #US East (N. Virginia)
'us-west-2', #US West (Oregon)
'ap-south-1', #Asia Pacific (Mumbai)
'ap-northeast-2', #Asia Pacific (Seoul)
'ap-southeast-1', #Asia Pacific (Singapore)
'ap-southeast-2', #Asia Pacific (Sydney)
'ap-northeast-1', #Asia Pacific (Tokyo)
'ca-central-1', #Canada (Central)
'eu-central-1', #Europe (Frankfurt)
'eu-west-1', #Europe (Ireland)
'eu-west-2', #Europe (London)
'sa-east-1', #South America (Sao Paulo)
'us-gov-west-1' #AWS GovCloud (US)
],
action="store")
args = parser.parse_args()
calculateKey(args.secret,args.region)
main()