|
|
@ -1,6 +1,6 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
|
|
|
|
|
|
import os, sys, tempfile,getopt |
|
|
|
import os, sys, tempfile, getopt, json |
|
|
|
from cryptography.fernet import Fernet |
|
|
|
from cryptography.fernet import Fernet |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
def main(): |
|
|
@ -36,11 +36,19 @@ def main(): |
|
|
|
clear = f.decrypt(crypt) |
|
|
|
clear = f.decrypt(crypt) |
|
|
|
tmp.write(clear) |
|
|
|
tmp.write(clear) |
|
|
|
tmp.flush() |
|
|
|
tmp.flush() |
|
|
|
|
|
|
|
loop = 1 |
|
|
|
|
|
|
|
while loop == 1: |
|
|
|
# Now, lets open our favorite editor to edit the file |
|
|
|
# Now, lets open our favorite editor to edit the file |
|
|
|
os.system(os.getenv('EDITOR', 'vim') + ' ' + tmp.name) |
|
|
|
os.system(os.getenv('EDITOR', 'vim') + ' ' + tmp.name) |
|
|
|
# We closed the editor, we just have to open the cleartext file, encrypt its content |
|
|
|
# We closed the editor, we just have to open the cleartext file, encrypt its content |
|
|
|
# and save it |
|
|
|
# and save it |
|
|
|
clear = open(tmp.name, 'rb').read() |
|
|
|
clear = open(tmp.name, 'rb').read() |
|
|
|
|
|
|
|
loop = 0 |
|
|
|
|
|
|
|
# Validate JSON data. Edit agin if not valid |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
json.loads(clear) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
loop = 1 |
|
|
|
wcrypt = open(args[0], 'wb') |
|
|
|
wcrypt = open(args[0], 'wb') |
|
|
|
wcrypt.write(f.encrypt(clear)) |
|
|
|
wcrypt.write(f.encrypt(clear)) |
|
|
|
wcrypt.flush() |
|
|
|
wcrypt.flush() |
|
|
|