diff options
| author | 2020-02-20 15:07:52 +0000 | |
|---|---|---|
| committer | 2020-02-20 15:07:52 +0000 | |
| commit | b260c80c31f64a82fcbcc57929e64a0b7b4dc322 (patch) | |
| tree | cd124989c5d96a4548c113c2fb7b6ada68ca92ef | |
| parent | add option to encrypt channel_log log files line-by-line (diff) | |
| signature | ||
add bin/bitbot-log to read/decrypt channel_log files
| -rwxr-xr-x | bin/bitbot-log | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/bin/bitbot-log b/bin/bitbot-log new file mode 100755 index 00000000..da6d0c8b --- /dev/null +++ b/bin/bitbot-log @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import argparse + +arg_parser = argparse.ArgumentParser( + description="BitBot log decrypting utility") + +arg_parser.add_argument("key", + help="Location of private key for decrypting given log file") +arg_parser.add_argument("log", help="Location of the log file to decrypt") + +args = arg_parser.parse_args() + +import base64 +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.asymmetric import padding + +def a_decrypt(key, data): + out = key.decrypt(base64.b64decode(data), padding.OAEP( + mgf=padding.MGF1(algorithm=hashes.SHA256()), + algorithm=hashes.SHA256(), label=None)) + return out.decode("utf8") + +with open(args.key, "rb") as key_file: + key_content = key_file.read() +key = serialization.load_pem_private_key( + key_content, password=None, backend=default_backend()) + +with open(args.log) as log_file: + lines = log_file.read().split("\n") +lines = filter(None, lines) + +for line in lines: + if line[0] == "\x02": + line = a_decrypt(key, line[1:]) + print(line) |
