-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasyPGPeasy.py
236 lines (213 loc) · 9.89 KB
/
EasyPGPeasy.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
# EasyPGPeasy.py
# !/usr/bin/env python
# -*- coding: utf-8 -*-
from src.Functions import all_imp
"""Creates the menu window and makes all the encryption, decryption, signing and verification process, automating
file saving and file reading, pasting from clipboard."""
access_rights = 0o755
copied, error1, error2, fin, paste = "", "", "", "", ""
curr_path = all_imp.os.getcwd()
done, event, lang, mode = False, None, "eng", None
imported = curr_path + "/Imported"
keys = curr_path + "/Keys"
output = curr_path + "/Output"
encrypted = output + "/Encrypted"
decrypted = output + "/Decrypted"
signed = output + "/Signed"
verified = output + "/Verified"
out_dec, out_sig = "", ""
password = ""
values = {}
window_title = ""
# Folder creations.
if not (all_imp.os.path.exists(imported)):
try:
all_imp.os.mkdir(imported, access_rights)
except OSError:
folder_error_eng = ["Creation of the directory %s failed." % imported, "Error creating folder!"]
folder_error_esp = ["Ha fallado la creación del directorio %s." % imported, "¡Error creando fichero!"]
if lang == "eng":
error1 = folder_error_eng[0]
error2 = folder_error_eng[1]
elif lang == "esp":
error1 = folder_error_esp[0]
error2 = folder_error_esp[1]
all_imp.pSG.popup_auto_close(error1, auto_close_duration = 2, button_type = 5, title = error2)
if not (all_imp.os.path.exists(keys)):
try:
all_imp.os.mkdir(keys, access_rights)
except OSError:
folder_error_eng = ["Creation of the directory %s failed." % keys, "Error creating folder!"]
folder_error_esp = ["Ha fallado la creación del directorio %s. " % keys, "¡Error creando fichero!"]
if lang == "eng":
error1 = folder_error_eng[0]
error2 = folder_error_eng[1]
elif lang == "esp":
error1 = folder_error_esp[0]
error2 = folder_error_esp[1]
all_imp.pSG.popup_auto_close(error1, auto_close_duration = 2, button_type = 5, title = error2)
if not (all_imp.os.path.exists(output)):
try:
all_imp.os.mkdir(output, access_rights)
except OSError:
folder_error_eng = ["Creation of the directory %s failed." % output, "Error creating folder!"]
folder_error_esp = ["Ha fallado la creación del directorio %s." % output, "¡Error creando fichero!"]
if lang == "eng":
error1 = folder_error_eng[0]
error2 = folder_error_eng[1]
elif lang == "esp":
error1 = folder_error_esp[0]
error2 = folder_error_esp[1]
all_imp.pSG.popup_auto_close(error1, auto_close_duration = 2, button_type = 5, title = error2)
if not (all_imp.os.path.exists(encrypted)):
try:
all_imp.os.mkdir(encrypted, access_rights)
except OSError:
folder_error_eng = ["Creation of the directory %s failed." % encrypted, "Error creating folder!"]
folder_error_esp = ["Ha fallado la creación del directorio %s." % encrypted, "¡Error creando fichero!"]
if lang == "eng":
error1 = folder_error_eng[0]
error2 = folder_error_eng[1]
elif lang == "esp":
error1 = folder_error_esp[0]
error2 = folder_error_esp[1]
all_imp.pSG.popup_auto_close(error1, auto_close_duration = 2, button_type = 5, title = error2)
if not (all_imp.os.path.exists(decrypted)):
try:
all_imp.os.mkdir(decrypted, access_rights)
except OSError:
folder_error_eng = ["Creation of the directory %s failed." % decrypted, "Error creating folder!"]
folder_error_esp = ["Ha fallado la creación del directorio %s." % decrypted, "¡Error creando fichero!"]
if lang == "eng":
error1 = folder_error_eng[0]
error2 = folder_error_eng[1]
elif lang == "esp":
error1 = folder_error_esp[0]
error2 = folder_error_esp[1]
all_imp.pSG.popup_auto_close(error1, auto_close_duration = 2, button_type = 5, title = error2)
if not (all_imp.os.path.exists(signed)):
try:
all_imp.os.mkdir(signed, access_rights)
except OSError:
folder_error_eng = ["Creation of the directory %s failed." % signed, "Error creating folder!"]
folder_error_esp = ["Ha fallado la creación del directorio %s." % signed, "¡Error creando fichero!"]
if lang == "eng":
error1 = folder_error_eng[0]
error2 = folder_error_eng[1]
elif lang == "esp":
error1 = folder_error_esp[0]
error2 = folder_error_esp[1]
all_imp.pSG.popup_auto_close(error1, auto_close_duration = 2, button_type = 5, title = error2)
if not (all_imp.os.path.exists(verified)):
try:
all_imp.os.mkdir(verified, access_rights)
except OSError:
folder_error_eng = ["Creation of the directory %s failed." % verified, "Error creating folder!"]
folder_error_esp = ["Ha fallado la creación del directorio %s." % verified, "¡Error creando fichero!"]
if lang == "eng":
error1 = folder_error_eng[0]
error2 = folder_error_eng[1]
elif lang == "esp":
error1 = folder_error_esp[0]
error2 = folder_error_esp[1]
all_imp.pSG.popup_auto_close(error1, auto_close_duration = 2, button_type = 5, title = error2)
while True:
# Create menu.
while mode is None:
lang, mode = all_imp.menu.create_menu(lang, imported, keys)
mes_enc_eng, mes_enc_esp, mes_dec_eng, mes_dec_esp, mes_sig_eng, mes_sig_esp = all_imp.eds_layout.crem_enc_dec()
# Encryption selected.
if mode == 15:
key = imported + "/v_imported_public.asc"
if all_imp.os.path.isfile(key):
event, mode, values = all_imp.enc.em(encrypted, event, key, lang, mes_enc_eng, mes_enc_esp)
else:
no_pub_eng = ["Public key to encrypt file does not exist.", "Error encrypting!"]
no_pub_esp = ["La clave pública para file el mensaje no existe.", "¡Error cifrando!"]
if lang == "eng":
error1 = no_pub_eng[0]
error2 = no_pub_eng[1]
elif lang == "esp":
error1 = no_pub_esp[0]
error2 = no_pub_esp[1]
all_imp.pSG.popup_error(error1, title = error2)
mode = None
# Decryption selected.
elif mode == 20:
key = keys + "/private.asc"
mes = imported + "/v_imported_message.txt"
if all_imp.os.path.isfile(key):
event, mode, values = all_imp.dec.dm(decrypted, event, key, lang, mes, mes_dec_eng, mes_dec_esp)
else:
no_priv_eng = ["Private key to decrypt message does not exist.", "Error decrypting!"]
no_priv_esp = ["La clave privada para descifrar el mensaje no existe.", "¡Error descifrando!"]
if lang == "eng":
error1 = no_priv_eng[0]
error2 = no_priv_eng[1]
elif lang == "esp":
error1 = no_priv_esp[0]
error2 = no_priv_esp[1]
all_imp.pSG.popup_error(error1, title = error2)
mode = None
# Signing selected.
elif mode == 30:
key = keys + "/private.asc"
enc = encrypted + "/encrypted_message.txt"
if all_imp.os.path.isfile(key):
event, mode, values = all_imp.sig.sm(enc, event, key, lang, mes_sig_eng, mes_sig_esp, signed)
else:
no_priv_eng = ["Private key to sign message does not exist.", "Error signing!"]
no_priv_esp = ["La clave privada para firmar el mensaje no existe.", "¡Error firmando!"]
if lang == "eng":
error1 = no_priv_eng[0]
error2 = no_priv_eng[1]
elif lang == "esp":
error1 = no_priv_esp[0]
error2 = no_priv_esp[1]
all_imp.pSG.popup_error(error1, title = error2)
mode = None
# Verifying selected.
elif mode == 40:
key = imported + "/v_imported_public.asc"
mes = imported + "/v_imported_message.txt"
sig = imported + "/v_imported_signature.txt"
if all_imp.os.path.isfile(key):
if all_imp.os.path.isfile(sig):
event, mode, values = all_imp.ver.vm(event, key, lang, mes, sig, verified)
else:
no_ver_eng = ["Signature to verify message is not imported.", "Error verifying!"]
no_ver_esp = ["La firma para verificar el mensaje no está importado.", "¡Error verificando!"]
if lang == "eng":
error1 = no_ver_eng[0]
error2 = no_ver_eng[1]
elif lang == "esp":
error1 = no_ver_esp[0]
error2 = no_ver_esp[1]
all_imp.pSG.popup_error(error1, title = error2)
mode = None
else:
no_pub_eng = ["Public key to verify message is not imported.", "Error verifying!"]
no_pub_esp = ["La clave pública para verificar el mensaje no está importado.", "¡Error verificando!"]
if lang == "eng":
error1 = no_pub_eng[0]
error2 = no_pub_eng[1]
elif lang == "esp":
error1 = no_pub_esp[0]
error2 = no_pub_esp[1]
all_imp.pSG.popup_error(error1, title = error2)
mode = None
# Perform encryption of plaintext message.
if event == "enc":
key = imported + "/v_imported_public.asc"
event, mode, values = all_imp.enc.ef(encrypted, event, key, lang, mes_enc_eng, mes_enc_esp, values)
# Perform decryption of encrypted message
if event == "dec":
key = keys + "/private.asc"
event, mode, values = all_imp.dec.df(decrypted, event, key, lang, mes_dec_eng, mes_dec_esp, values)
# Perfonm singing of message.
if event == "sig":
key = keys + "/private.asc"
event, mode, values = all_imp.sig.sf(event, key, lang, mes_sig_eng, mes_sig_esp, signed, values)
# Exit tool.
if event == 600:
all_imp.sys.exit(0)