#!/bin/python3 import os import sys import logging import argparse import json from lib import symmetric_encryption logging.basicConfig(format='%(levelname)s\t- %(message)s') logger = logging.getLogger() logger.setLevel(logging.INFO) BASE_DIR = os.path.join(os.path.expanduser('~'), '.sio/') #send to stdout contents of decrypted file # encrypted file - encryption metadata def decryptFile(args): parser = argparse.ArgumentParser() parser.add_argument('encrypted', nargs='?', default=None) parser.add_argument('metadata', nargs='?', default=None) args = parser.parse_args() if not args.encrypted or not args.metadata: logger.error("Need encrypted file and it's metadata.") sys.exit(1) # If first argument is not a file or not found if (not os.path.isfile(BASE_DIR + args.encrypted)): logger.error("File '" + args.encrypted + "' not found.") sys.exit(1) if (not os.path.isfile(BASE_DIR + args.metadata)): logger.error("File '" + args.metadata + "' not found.") sys.exit(1) #Decrypt file metadata = json.loads(BASE_DIR + args.metadata) content = symmetric_encryption.decrypt_file(args.encrypted) # Send decrypted content to stdout sys.stdout.write(content) sys.exit(0) if __name__ == '__main__': decryptFile(sys.argv[1:])