From 5b38c532a2f9bfc9b37e399e01ed60f8efe275ba Mon Sep 17 00:00:00 2001 From: r4sas Date: Sun, 2 Jun 2019 14:27:38 +0000 Subject: [PATCH] [wip][v2] json bytes2str in decode (#13) --- pbincli/actions.py | 5 ++++- pbincli/format.py | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pbincli/actions.py b/pbincli/actions.py index 9c67d60..db968d3 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -33,6 +33,7 @@ def send(args, api_client): request = paste.getJSON() + if args.debug: print("Passphrase:\t{}".format(paste.getHash())) if args.debug: print("Request:\t{}".format(request)) # If we use dry option, exit now @@ -89,10 +90,12 @@ def get(args, api_client): print("Paste received!") version = result['v'] if 'v' in result else 1 + if args.debug: print("Paste version:\t{}\n".format(version)) paste.setVersion(version) if version == 2: - if args.debug: print("Message:\t{}\nAuthentication data:\t{}".format(result['ct'], result['adata'])) + #if args.debug: print("Message:\t{}\nAuthentication data:\t{}".format(result['ct'], result['adata'])) + if args.debug: print("Authentication data:\t{}".format(result['adata'])) paste.setHash(passphrase) paste.loadJSON(result) diff --git a/pbincli/format.py b/pbincli/format.py index 4d8d238..bf4de13 100644 --- a/pbincli/format.py +++ b/pbincli/format.py @@ -22,6 +22,7 @@ class Paste: def setVersion(self, version): + if self._debug: print("Set paste version to {}".format(version)) self._version = version @@ -114,16 +115,16 @@ class Paste: from json import loads as json_decode if self._version == 2: - iv = b64decode(self._paste['adata'][0][0]) - salt = b64decode(self._paste['adata'][0][1]) + iv = b64decode(self._data['adata'][0][0]) + salt = b64decode(self._data['adata'][0][1]) key = self.__deriveKey(salt) - cipher = self.__initializeCipher(key, iv, self._paste['adata']) + cipher = self.__initializeCipher(key, iv, self._data['adata']) # Cut the cipher text into message and tag - cipher_text_tag = b64decode(self._paste['ct']) + cipher_text_tag = b64decode(self._data['ct']) cipher_text = cipher_text_tag[:-CIPHER_TAG_BYTES] cipher_tag = cipher_text_tag[-CIPHER_TAG_BYTES:] - cipher_message = json_decode(decompress(cipher.decrypt_and_verify(cipher_text, cipher_tag), self._version)) + cipher_message = json_decode(decompress(cipher.decrypt_and_verify(cipher_text, cipher_tag), self._version).decode()) self._text = cipher_message['paste'].encode() if 'attachment' in cipher_message and 'attachment_name' in cipher_message: