-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.py
More file actions
81 lines (68 loc) · 2.63 KB
/
lock.py
File metadata and controls
81 lines (68 loc) · 2.63 KB
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
import os
import argparse
from Crypto.Random import random
import subprocess
def getFlags():
#parse command line args
parser = argparse.ArgumentParser()
parser.add_argument("-d", dest = 'directory', help="Enter directory to lock", required = True)
parser.add_argument("-p", dest = 'pubKeyFile', help="Enter action public key file", required = True)
parser.add_argument("-r", dest = 'privKeyFile', help= "Enter action private key file", required=True)
parser.add_argument("-vk", dest = 'valFile', help= "Enter validate pubkey file", required=True)
args = parser.parse_args()
return args
def verifyUnlocker(args):
command = "python2.7 rsa-validate.py -k " + args.valFile + " -m " + args.pubKeyFile + " -s " + args.pubKeyFile + "-casig"
#print("Command: %s" % command)
result = subprocess.check_output([command], shell=True)
if(result.strip() == "True"):
#print("Verified")
return
else:
sys.exit("Unverified unlocker")
def randAESKey():
val = random.getrandbits(128)
val = str(val)
val = val[0:16]
return int(val)
def rsaEnc(args, key):
command = "python2.7 rsa-enc.py -k " + args.pubKeyFile + " -i " + str(key)
result = subprocess.check_output([command], shell=True)
return result.strip()
def printManifest(encryptedKey):
fd = open("symManifest", "w")
fd.write(encryptedKey)
fd.close()
def signManifest(lock_priv):
command = "python2.7 rsa-sign.py -k " + lock_priv + " -m symManifest -s symManifest-casig"
subprocess.call([command], shell=True)
def encryptDir(directory, key):
currentdir = os.getcwd()
newlist = []
for letter in currentdir:
newlist.append(letter)
for i in range(0, len(newlist)):
if newlist[i] == ' ':
newlist[i] = "\ "
currentdir = ''.join(newlist)
for root, dirs, files in os.walk(directory):
os.chdir(directory)
for file in files:
encryptFile(file, key, currentdir)
tagFile(file, key, currentdir)
def encryptFile(file, key, currentdir):
command = "python2.7 " + currentdir + "/cbc-enc.py -k " + str(key) + " -i " + file + " -o " + file
subprocess.call([command], shell=True)
def tagFile(file, key, currentdir):
command = "python2.7 " + currentdir + "/cbcmac-tag_2.py -k " + str(key) + " -m " + file + " -t " + file + "-tag"
subprocess.call([command], shell=True)
def main():
args = getFlags()
check = verifyUnlocker(args)
key = randAESKey()
encryptedKey = rsaEnc(args, key)
printManifest(encryptedKey)
signManifest(args.privKeyFile)
encryptDir(args.directory, key)
if __name__ == "__main__":
main()