-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasswordLoad.py
69 lines (57 loc) · 2.04 KB
/
passwordLoad.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
import os
import sys
import time
from pathlib import Path
from Crypto.PublicKey import RSA
from Crypto.Util import asn1
from base64 import b64decode
import pickle
statusDir = Path("/tmp/status404")
if(statusDir.is_dir()):
pass
else:
os.mkdir("/tmp/status404")
print("passwordSave functionality starting")
customerName = input("Enter the customer name: ")
deviceName = input("Enter the device name: ")
# TO BE FETCHED FROM THE DATABASE
# DEVICE NAME CAN BE DEVICE IP + PORT
passwordName = customerName + "-" + deviceName
passwordLocation = "/passwordDatabase/"
baseDir = Path(passwordLocation)
print("passwordLocation = " + passwordLocation)
if(baseDir.is_dir()):
print("Directory exists, continuing with the process")
else:
print("NO SUCH DIRECTORY EXIT, EXITING THE SCRIPT")
sys.exit(2)
passwordFile = Path(passwordLocation + passwordName)
passwordPath = passwordLocation + passwordName
print("passwordFile = " + passwordPath)
if(passwordFile.is_file()):
print("passwordFile exists, continuing with the process")
else:
print("FILE DOES NOT EXIST, EXITING THE SCRIPT")
sys.exit(2)
passwordKeyName = customerName + "-" + deviceName
passwordKeyLocation = "/passwordKeyDatabase/"
passwordKeyDir = Path(passwordKeyLocation)
print("passwordKeyLocation = " + passwordKeyLocation)
if(passwordKeyDir.is_dir()):
print("Directory exists, continuing with the process")
else:
print("NO SUCH DIRECTORY EXIT, EXITING THE SCRIPT")
sys.exit(2)
passwordKeyFile = Path(passwordKeyLocation + passwordKeyName + ".pem")
passwordKeyPath = passwordKeyLocation + passwordKeyName + ".pem"
print("passwordKeyFile = " + passwordKeyPath)
if(passwordKeyFile.is_file()):
print("passwordKeyFile exists, continuing with the process")
else:
print("FILE DOES NOT EXIST, EXITING THE SCRIPT")
sys.exit(2)
with open(passwordPath, 'rb') as t:
encryptedDevicePassword = pickle.load(t)
privateKeyFile = open(passwordKeyPath, 'rb')
privateKey = RSA.importKey(privateKeyFile.read())
print(privateKey.decrypt(encryptedDevicePassword).decode('utf-8'))