-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
executable file
·528 lines (451 loc) · 25.1 KB
/
gui.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#!/usr/bin/python3
import os
import math
import easygui
import datetime
import subprocess
import traceback
import traceback
from gencodes import *
from cryptomodule import *
from xorotp import *
from otp import *
class gen_args():
def __init__(self):
self.codes = easygui.multchoicebox(msg='Select codes to generate',title='Select', choices=['All','OTP','AES','Auth','Brevity'])
if self.codes:
self.formats = easygui.multchoicebox(msg='Select formats to generate',title='Select', choices=['All','PDF','pickle','txt'])
if self.codes and self.formats:
self.all = 'All' in self.codes and 'All' in self.formats
self.allcodes = 'All' in self.codes
self.allformats = 'All' in self.formats
self.brevity = 'Brevity' in self.codes
self.aes = 'AES' in self.codes
self.otp = 'OTP' in self.codes
self.auth = 'Auth' in self.codes
self.pdf = 'PDF' in self.formats
self.txt = 'txt' in self.formats
self.pickle = 'pickle' in self.formats
v = str( 1.2 )
titlebar = 'ECCS GUI'+v
args_keeppad = os.path.isfile('testmode')
try:
with open('.usecodes','r') as file:
codes_set = file.read()
codebook_aes = 'codebooks'+os.sep+codes_set+'_aespad.pickle'
codebook_auth = 'codebooks'+os.sep+codes_set+'_auth.pickle'
codebook_brevity = 'codebooks'+os.sep+codes_set+'_brevitycodes.pickle'
codebook_otp = 'codebooks'+os.sep+codes_set+'_otp.pickle'
keyfileid = codes_set.split('_')[1]
except:
codes_set = None
codebook_aes = None
codebook_otp = None
codebook_auth = None
codebook_brevity = None
keyfileid = None
try:
with open('.usedkey','r') as file:
keyname = file.read()
rsa_key = RSA_key()
rsa_key.import_key_file('rsakeys'+os.sep+keyname, args.p)
except:
rsa_key = None
while 1:
try:
mainmsg = 'Encrypted Covert Communication System\n\nUsing codes: {}'.format(codes_set)
if args_keeppad: mainmsg+='\n\nWARNING: TEST MODE ON, CODES WILL NOT BE CLEARED AFTER USE'
else: mainmsg+='\n\nWARNING: Live mode on, codes WILL be cleared after use'
ch = easygui.choicebox(msg=mainmsg,
title=titlebar,
choices=["AES Encrypt",
"AES Decrypt",
"AES File Encrypt",
"AES File Decrypt",
"One Time Pad Encrypt",
"One Time Pad Decrypt",
"Authentify",
"RSA-AES Encrypt",
"RSA-AES Decrypt",
"RSA-AES File Encrypt",
"RSA-AES File Decrypt",
"Generate RSA Key",
#"Steghide Embed File",
#"Steghide Extract File",
"File XOR-OTP Encrypt",
"File XOR-OTP Decrypt",
"Generate XOR-OTP Key file",
"Select codebooks",
"Generate codebooks",
"Securely wipe file",
"DESTROY CODEBOOKS",
"TEST MODE TOGGLE",
"Exit"])
if ch=='Exit' or ch==None: break
elif ch == 'Select codebooks':
date = datetime.datetime.utcnow().strftime("%Y-%m-%d")
dat = easygui.multenterbox(msg='Enter key values\nMake sure keys are in codebooks folder and not renamed', title=titlebar, fields=['Codepads Date','Codepads ID'], values=[date,'00000'])
if not dat:
continue
codes_set = dat[0]+'_'+dat[1]
keyfileid = dat[1]
with open('.usecodes','w') as file:
file.write(codes_set)
codebook_aes = 'codebooks'+os.sep+codes_set+'_aespad.pickle'
codebook_auth = 'codebooks'+os.sep+codes_set+'_auth.pickle'
codebook_brevity = 'codebooks'+os.sep+codes_set+'_brevitycodes.pickle'
codebook_otp = 'codebooks'+os.sep+codes_set+'_otp.pickle'
files = True
if not os.path.isfile(codebook_aes): files = False
if not os.path.isfile(codebook_auth): files = False
if not os.path.isfile(codebook_brevity): files = False
if not os.path.isfile(codebook_otp): files = False
if not files:
easygui.msgbox("Error: no such files",titlebar)
codes_set = None
codebook_aes = None
codebook_otp = None
codebook_auth = None
codebook_brevity = None
elif ch in ["AES Encrypt","AES Decrypt","AES File Encrypt","AES File Decrypt"]:
args_e = ch in ["AES Encrypt","AES File Encrypt"]
args_d = ch in ["AES Decrypt","AES File Decrypt"]
args_key1 = None
args_key2 = None
args_iv = None
args_b64 = True
args_rawkey = False
if args_e:
keymode = easygui.indexbox(msg='Choose key mode', title=titlebar, choices=('Plain key', 'Pickle keys','Generate one'), default_choice='Plain key')
else:
keymode = easygui.indexbox(msg='Choose key mode', title=titlebar, choices=('Plain key', 'Pickle keys'), default_choice='Plain key')
if keymode == 1:
if not codebook_aes:
keyfile = easygui.fileopenbox(msg="Select Pickle file", title=titlebar, default='*_aespad.pickle', filetypes=["*.pickle"], multiple=False)
else:
keyfile = codebook_aes
else:
keyfile = None
args_keyfile = keyfile
if keymode == 2:
args_key1 = Random.new().read(16)
args_key2 = Random.new().read(16)
args_iv = Random.new().read(AES.block_size)
keymsg = 'Key 1/2: '+binascii.b2a_hex(args_key1).decode() + '\nKey 2/2: ' + binascii.b2a_hex(args_key2).decode() + '\nIV: '+binascii.b2a_hex(args_iv).decode()
easygui.textbox(msg="Encryption keys and IV below. Use Control+C to copy.",title=titlebar,text=keymsg)
else:
enterkeys = easygui.multenterbox(msg='Enter Key halves and IV', title=titlebar, fields=['Key 1','Key 2','Initialization Vector'], values=[])
if not enterkeys:
continue
args_key1, args_key2, args_iv = enterkeys
if args_keyfile:
with open(args_keyfile, 'rb') as f:
codebook = pickle.load(f)
try:
key1 = binascii.a2b_hex(codebook[args_key1.upper()])
key2 = binascii.a2b_hex(codebook[args_key2.upper()])
binkey = key1+key2
biniv = binascii.a2b_hex(codebook[args_iv.upper()])
except:
easygui.msgbox("Error: Key indexes not found, maybe they have been deleted after being used",titlebar)
continue
else:
binkey = args_key1+args_key2
biniv = args_iv
if ch in ["AES File Encrypt","AES File Decrypt"]:
args_file = easygui.fileopenbox(msg="Select file to encrypt/decrypt", title=titlebar, default='*', multiple=False)
if not args_file: continue
else:
args_file = None
if args_file:
if args_e:
filename = args_file
with open(filename,'rb') as file:
filecontent = file.read()
encfile = AESencrypt(filecontent, binkey, biniv, True)
encfile = binascii.b2a_hex(encfile)
with open(filename+'.enc','wb') as file:
file.write(encfile)
easygui.msgbox("File encrypted\nNew file name:{}".format(filename+'.enc'),titlebar)
elif args_d:
filename = args_file
with open(filename,'rb') as file:
filecontent = file.read()
newfilename = filename[:filename.find('.enc')]
filecontent = binascii.a2b_hex(filecontent)
decfile = AESdecrypt(filecontent, binkey, biniv,True)
with open(newfilename,'wb') as file:
file.write(decfile)
easygui.msgbox("File decrypted\nNew file name:{}".format(newfilename),titlebar)
else:
args_message = easygui.textbox(msg="Enter the message below",text='',title=titlebar)
if not args_message:
continue
if args_e:
a = AESencrypt(args_message, binkey, biniv)
if args_keyfile:
message = PEM.encode(a,'AES MESSAGE {} {}'.format(keyfileid, args_key1.upper()+args_key2.upper()+args_iv.upper()))
else:
message = PEM.encode(a,'AES MESSAGE')
easygui.textbox(msg="Encrypted message below. Use Control+C to copy.",title=titlebar,text=message)
elif args_d:
#print(str([args_message]))
a = PEM.decode(args_message)[0]
message = AESdecrypt(a, binkey, biniv,False)
easygui.textbox(msg="Decrypted message below. Use Control+C to copy.",title=titlebar,text=message)
if args_keyfile and not args_keeppad:
overwrite = '00000000000000000000000000000000'
codebook[args_key1.upper()] = overwrite
codebook[args_key2.upper()] = overwrite
codebook[args_iv.upper()] = overwrite
with open(args_keyfile, 'wb') as f:
pickle.dump(codebook, f, pickle.HIGHEST_PROTOCOL)
with open(args_keyfile, 'rb') as f:
codebook = pickle.load(f)
del codebook[args_key1.upper()]
del codebook[args_key2.upper()]
del codebook[args_iv.upper()]
with open(args_keyfile, 'wb') as f:
pickle.dump(codebook, f, pickle.HIGHEST_PROTOCOL)
elif ch in ["One Time Pad Encrypt","One Time Pad Decrypt"]:
try:
args_e = ch == "One Time Pad Encrypt"
args_d = ch == "One Time Pad Decrypt"
args_board = 'ct46'
args_brevity = True
if not codebook_otp:
args_pad = easygui.fileopenbox(msg="Select Pickle file", title=titlebar, default='*_otp.pickle', filetypes=["*.pickle"], multiple=False)
else:
args_pad = codebook_otp
padid = args_pad.split('/')
padid = padid[len(padid)-1].split('_')[1]
firstavail = None
args_message = easygui.textbox(msg="Enter the message below",text='',title=titlebar)
if args_message == None:
continue
if args_e or args_d:
with open(args_pad, 'rb') as f:
padbook = pickle.load(f)
for i in range(0,1000):
msgno=str(i+1)
while len(msgno)<5:
msgno='0'+msgno
if msgno in padbook:
firstavail = msgno
break
cipher = checkerboard(args_board.lower(),padbook[msgno])
if args_brevity:
if not codebook_brevity:
codebook_brevity = easygui.fileopenbox(msg="Select Brevity Codes Pickle file", title=titlebar, default='*_brevitycodes.pickle', filetypes=["*.pickle"], multiple=False)
cipher.brevity = True
with open(codebook_brevity, 'rb') as f:
cipher.codebook = pickle.load(f)
cipher.reversecodebook = {}
for i in cipher.codebook:
cipher.reversecodebook[cipher.codebook[i].lower()] = i
if args_e:
try:
encrypted = padid+cipher.encrypt(args_message,firstavail)
except Exception as e:
easygui.msgbox("Error!\n"+str(e)+'\n'+str(type(e)),titlebar)
continue
if not args_keeppad: cipher.purgepad(args_pad)
easygui.textbox(msg="Encrypted message below. Use Control+C to copy.",title=titlebar,text=encrypted)
elif args_d:
padid = args_message[:6]
msgno = args_message[6:11]
decrypted = cipher.decrypt(args_message[6:])
goodpad, message = decrypted
if not args_keeppad and goodpad: cipher.purgepad(args_pad)
easygui.textbox(msg="Decrypted message below. Use Control+C to copy.",title=titlebar,text=message)
except Exception as e:
easygui.msgbox("Error!\n"+traceback.format_exc(),titlebar)
elif ch == 'Generate codebooks':
args = gen_args()
if args.codes != None and args.formats != None:
if not (args.aes or args.otp or args.auth or args.all or args.allcodes):
raise argparse.ArgumentTypeError('Error: pick one type of code book')
if not (args.pdf or args.txt or args.pickle or args.all or args.allformats):
raise argparse.ArgumentTypeError('Error: pick one format')
date = datetime.datetime.utcnow().strftime("%Y-%m-%d")
padid = ''.join(random.choice('1234567890') for _ in range(5))
padlen = 100
if not os.path.exists('codebooks'):
os.mkdir('codebooks')
if args.brevity or args.all or args.allcodes:
gen_brevity(date,padid, args)
print('Brevity codes generated')
if args.aes or args.all or args.allcodes:
gen_aes(date,padid, args)
print('AES codes generated')
if args.auth or args.all or args.allcodes:
gen_auth(date,padid, args)
print('Authentifier generated')
if args.otp or args.all or args.allcodes:
gen_otp(padlen,date,padid, args)
print('One Time Pad generated')
easygui.msgbox('Crypto pads {} {} generated'.format(padid,date),titlebar)
elif ch == 'Authentify':
if not codebook_auth:
authtable = easygui.fileopenbox(msg="Select Pickle file", title=titlebar, default='*_auth.pickle', filetypes=["*.pickle"], multiple=False)
else:
authtable = codebook_auth
code = easygui.enterbox(msg="Enter code\nGrid coords in Letter-Number format or 4-character Auth code", title=titlebar)
with open(authtable, 'rb') as f:
padbook = pickle.load(f)
if len(code)==3:
easygui.msgbox('Code: '+padbook[code.upper()],titlebar)
elif len(code)==5:
if code in padbook.values():
easygui.msgbox('Code: '+padbook.keys()[padbook.values().index(code.upper())],titlebar)
else:
easygui.msgbox( 'Auth failed, code not found',titlebar)
else:
easygui.msgbox('Invalid code',titlebar)
elif ch == 'Securely wipe file':
args_file = easygui.fileopenbox(msg="Select file to encrypt/decrypt", title=titlebar, default='*.*',filetypes='*', multiple=True)
print(args_file)
if args_file is not None:
confirm = easygui.ynbox(msg='ARE YOU SURE?\nWiping this file will destroy it forever.',title=titlebar)
if confirm:
if type(args_file) == str:
files2wipe = [args_file]
elif type(args_file) == list:
files2wipe = []
for fn in args_file:
files2wipe.append(fn)
commands=[]
for fn in files2wipe:
commands.append('shred -zuv -n 3 "{}"'.format(fn))
for cmde in commands:
execproc = subprocess.Popen(cmde, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
cmdoutput = execproc.stdout.read() + execproc.stderr.read()
#print(cmdoutput)
easygui.msgbox('File wiped',titlebar)
elif ch == 'Generate RSA Key':
if not os.path.exists('rsakeys'):
os.mkdir('rsakeys')
enterkeys = easygui.multpasswordbox(msg='Enter Key name, size (2048, 3084, 4096) and encryption passphrase', title=titlebar, fields=['Filename','Size','Passphrase'], values=[])
if not enterkeys:
continue
args_name, args_size, args_key = enterkeys
Alice = RSA_key()
Alice.gen_key(int(args_size))
pubfn = '{}_{}_public.asc'.format(args_name,args_size)
sfn = '{}_{}.asc'.format(args_name,args_size)
with open('rsakeys{}{}'.format(os.sep,pubfn), "w",encoding='utf-8') as file:
file.write(Alice.export_public_key())
with open('rsakeys{}{}'.format(os.sep,sfn), "w",encoding='utf-8') as file:
file.write(Alice.export_private_key(args_key))
print('Exported secret key', sfn)
print('Exported public key',pubfn)
easygui.msgbox("Keys generated\nSecret key: {}\nPublic key: {}".format(sfn,pubfn),titlebar)
elif ch in ["RSA-AES Encrypt","RSA-AES Decrypt","RSA-AES File Encrypt","RSA-AES File Decrypt"]:
args_e = ch in ["RSA-AES Encrypt","RSA-AES File Encrypt"]
args_d = ch in ["RSA-AES Decrypt","RSA-AES File Decrypt"]
args_file = ch in ["RSA-AES File Encrypt","RSA-AES File Decrypt"]
MyKey = RSA_key()
HisKey = RSA_key()
fn1 = easygui.fileopenbox(msg="Select secret sender keyfile", title=titlebar, default='rsakeys'+os.sep+'*.asc', multiple=False)
if not fn1: continue
fn1p = easygui.passwordbox("Enter passphrase to unlock key",title=titlebar)
fn2 = easygui.fileopenbox(msg="Select public receiver keyfile", title=titlebar, default='rsakeys'+os.sep+'*.asc', multiple=False)
if not fn2: continue
print(fn1,fn1p,fn2)
MyKey.import_key_file(fn1,fn1p)
HisKey.import_key_file(fn2)
if args_file:
args_message = easygui.fileopenbox(msg="Select file", title=titlebar, default='*', multiple=False)
isfile = True
if args_e:
filename = args_message
with open(filename,'rb') as file:
filecontent = file.read()
hash = SHA512.new()
hash.update(filecontent)
encfile = rsaaes_encrypt(MyKey, HisKey, filecontent,True)
with open(filename+'.enc','wb') as file:
file.write(encfile)
easygui.msgbox('File encrypted at {}\nSHA512: {}'.format(filename+'.enc',hash.hexdigest()),titlebar)
elif args_d:
filename = args_message
with open(filename,'rb') as file:
filecontent = file.read()
newfilename = filename[:filename.find('.enc')]
decfile = rsaaes_decrypt(MyKey, HisKey, filecontent, True)
#print('Signature verifies:',decfile['verify'],decfile['hash'])
with open(newfilename,'wb') as file:
file.write(decfile['msg'])
easygui.msgbox('File decrypted at {}\nSignature verifies: {}\nSHA512: {}'.format(newfilename,decfile['verify'],decfile['hash']),titlebar)
else:
args_message = easygui.textbox(msg="Enter the message below",text='',title=titlebar)
if not args_message:
continue
if args_e:
enc = rsaaes_encrypt(MyKey, HisKey, args_message).decode()
easygui.textbox(msg="Encrypted message",title=titlebar,text=str(enc))
elif args_d:
dec = rsaaes_decrypt(MyKey, HisKey, args_message)
if dec['verify']:
verify = 'VERIFIED'
else:
verify = 'FAILED VERIFICATION'
easygui.textbox(msg="Decrypted message\nMessage signature: "+verify,title=titlebar,text=dec['msg'])
elif ch == "Generate XOR-OTP Key file":
xor = XORcrypter()
params = easygui.multenterbox(msg='Enter file name and number of 10kb blocks', title=titlebar, fields=['Filename','Blocks'], values=[])
if not params:
continue
filename, size = params
xor.genkeyfile(size, filename)
easygui.msgbox('Generated {} blocks of {} kilobytes of random data in {}_xorotp.pickle'.format(size, xor.kb, filename),titlebar)
elif ch in ["File XOR-OTP Encrypt","File XOR-OTP Decrypt"]:
xor = XORcrypter()
if ch == "File XOR-OTP Encrypt":
mode = 'e'
else:
mode = 'd'
file2xor = easygui.fileopenbox(msg="Select file to XOR", title=titlebar, default='*', multiple=False)
keyfile = easygui.fileopenbox(msg="Select XOR keyfile", title=titlebar, default='*', multiple=False)
if not file2xor or not keyfile: continue
filename = xor.xorfile(mode, keyfile, file2xor, args_keeppad)
easygui.msgbox("File {} XOR'ed to {}".format(file2xor, filename),titlebar)
elif ch == 'DESTROY CODEBOOKS':
confirm = easygui.ynbox(msg='ARE YOU SURE?',title=titlebar)
if confirm:
commands = ['shred -zv -n 1 *_otp.*',
'shred -zv -n 1 *_aespad.*',
'shred -zv -n 1 *_auth.*',
'shred -zv -n 1 *_brevitycodes.*',
'shred -zv -n 1 *.asc',
'shred -zv -n 1 */*_otp.*',
'shred -zv -n 1 */*_aespad.*',
'shred -zv -n 1 */*_auth.*',
'shred -zv -n 1 */*_brevitycodes.*',
'shred -zv -n 1 */*.asc',
'rm *_otp.*',
'rm *_aespad.*',
'rm *_auth.*',
'rm *_brevitycodes.*',
'rm *.asc',
'rm */*_otp.*',
'rm */*_aespad.*',
'rm */*_auth.*',
'rm */*_brevitycodes.*'
'rm */*.asc',]
for cmde in commands:
execproc = subprocess.Popen(cmde, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
cmdoutput = execproc.stdout.read() + execproc.stderr.read()
#print(cmdoutput)
easygui.msgbox('Codebooks wiped',titlebar)
elif ch == 'TEST MODE TOGGLE':
if not args_keeppad:
confirm = easygui.ynbox(msg='ARE YOU SURE?\nTurning off Live mode will prevent ECCS from clearing used keys, making it easy to crack messages if they are reused in a real environment.',title=titlebar)
else:
confirm = True
if confirm:
args_keeppad = not args_keeppad
except Exception:
error = traceback.format_exc()
easygui.msgbox(msg="An error has occured\n"+error,title=titlebar)
print(error)