-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathencrypt_aws_key.py
97 lines (78 loc) · 2.79 KB
/
encrypt_aws_key.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
encrypt_aws_key v0.01
genetic trade simulator
Copyright 2011 Brian Monkaba
This file is part of ga-bitbot.
ga-bitbot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ga-bitbot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ga-bitbot. If not, see <http://www.gnu.org/licenses/>.
"""
from Crypto.Cipher import AES
from Crypto import Random
import hashlib
import json
import time
import random
print "\n\nga-bitbot Amazon Web Service (AWS) API Key Encryptor v0.1a"
print "-" * 30
print "\n\n"
print "Enter the AWS Access Key ID:"
key = raw_input()
print "\nEnter the AWS Secret Access Key:"
secret = raw_input()
print "\nEnter the Topic ARN to publish to:"
print "* This must be created in the SNS tab of the AWS Management Console"
topic_arn = raw_input()
print "\n\nEnter an encryption password:"
print "(This is the password ga-bitbot will require to publish text messages with the Amazon SNS service)"
password = raw_input()
print "\n"
try:
f = open('./config/salt.txt','r')
salt = f.read()
f.close()
print "Using the current local password salt..."
except:
print "Generating the local password salt..."
pre_salt = str(time.time() * random.random() * 1000000) + 'H7gfJ8756Jg7HBJGtbnm856gnnblkjiINBMBV734'
salt = hashlib.sha512(pre_salt).digest()
f = open('./config/salt.txt','w')
f.write(salt)
f.close()
print "\n"
print "Generating the encrypted API KEY file..."
hash_pass = hashlib.sha256(password + salt).digest()
iv = Random.new().read(AES.block_size)
encryptor = AES.new(hash_pass, AES.MODE_CBC,iv)
text = json.dumps({"key":key,"secret":secret,"topic_arn":topic_arn})
#pad the text
pad_len = 16 - len(text)%16
text += " " * pad_len
ciphertext = iv + encryptor.encrypt(text)
f = open('./config/aws_api_key.txt','w')
f.write(ciphertext)
f.close()
print "Verifying encrypted file..."
f = open('./config/aws_api_key.txt','r')
d = f.read()
f.close()
f = open('./config/salt.txt','r')
salt = f.read()
f.close()
hash_pass = hashlib.sha256(password + salt).digest()
decryptor = AES.new(hash_pass, AES.MODE_CBC,d[:AES.block_size])
text = decryptor.decrypt(d[AES.block_size:])
try:
d = json.loads(text)
except:
print "Failed verification...try again."
else:
print "Passed verification."
print "\nDon't forget your password:",password," This is what ga-bitbot will request to enable the AWS text messaging service."