diff --git a/bitwardenBackup.py b/bitwardenBackup.py index 1f20c01..1debfe3 100644 --- a/bitwardenBackup.py +++ b/bitwardenBackup.py @@ -55,14 +55,20 @@ def build_logger(level): return logger def read_config_file(config_file): + logger.debug("Starting to read config file and decrypt contents") + logger.debug("Using config file: {}".format(config_file)) config = configparser.ConfigParser() config.read(config_file) sections = config.sections() + logger.debug("Found following sections...") accounts = dict() for section in sections: - accounts[decrypt(client, section)] = dict() + email = decrypt(client, section) + logger.debug("Sections: {}".format(email)) + accounts[email] = dict() for key in config[section]: - accounts[decrypt(client, section)][key] = decrypt(client, config[section][key]) + accounts[email][key] = decrypt(client, config[section][key]) + logger.debug("Finished reading config file and decrypting contents") return accounts def create_encryption_key(client): @@ -160,15 +166,12 @@ def decrypt(client, data): array_json = base64.b64decode(data) array = json.loads(array_json) if array['version'] == 1: - decrypt_v1(client, data) + decrypt_v1(client, array) else: logger.error("Unable to detemine encryption version.") - -def decrypt_v1(client, data): +def decrypt_v1(client, array): try: - array_json = base64.b64decode(data) - array = json.loads(array_json) logger.debug("Dict of info: {}".format(array)) key_id = array['cipher_key_id'] iv = base64.b64decode(array['iv']) @@ -282,6 +285,21 @@ if __name__ == "__main__": dest="config", help="Edit configuration." ) + parser.add_option( + "-d", + "--decrypt", + action="store_true", + dest="decrypt", + ) + parser.add_option( + "-m", + "--message", + action="store", + type="str", + default="This is a secret message.", + dest="message", + help="The message to encrypt." + ) parser.add_option ( "-v", "--verbose", @@ -298,6 +316,10 @@ if __name__ == "__main__": client = client.ProxyKmipClient(config_file=pykmip_client_config_file) client.open() #print(encrypt(client, "test")) + + if opts.decrypt: + print(decrypt(client, opts.message)) + sys.exit(0) if opts.config: