diff --git a/pbincli/actions.py b/pbincli/actions.py index 3df38d8..3966442 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -135,18 +135,7 @@ def get(args, api_client): if version == 1 and 'meta' in result and 'burnafterreading' in result['meta'] and result['meta']['burnafterreading']: print("Burn afrer reading flag found. Deleting paste...") - result = api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'})) - - if args.debug: print("Delete response:\t{}\n".format(result)) - - if 'status' in result and not result['status']: - print("Paste successfully deleted!") - elif 'status' in result and result['status']: - print("Something went wrong...\nError:\t\t{}".format(result['message'])) - exit(1) - else: - print("Something went wrong...\nError: Empty response.") - exit(1) + api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'})) elif 'status' in result and result['status']: print("Something went wrong...\nError:\t\t{}".format(result['message'])) @@ -164,15 +153,4 @@ def delete(args, api_client): if args.debug: print("PasteID:\t{}\nToken:\t\t{}".format(pasteid, token)) - result = api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':token})) - - if args.debug: print("Response:\t{}\n".format(result)) - - if 'status' in result and not result['status']: - print("Paste successfully deleted!") - elif 'status' in result and result['status']: - print("Something went wrong...\nError:\t\t{}".format(result['message'])) - exit(1) - else: - print("Something went wrong...\nError: Empty response.") - exit(1) + api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':token})) diff --git a/pbincli/api.py b/pbincli/api.py index 1a136f8..19846d9 100644 --- a/pbincli/api.py +++ b/pbincli/api.py @@ -32,20 +32,27 @@ class PrivateBin: def delete(self, request): - result = requests.post( - url = self.server, - headers = self.headers, - proxies = self.proxy, - data = request) - # using try as workaround for versions < 1.3 due to we cant detect # if server used version 1.2, where auto-deletion is added try: - return result.json() + result = requests.post( + url = self.server, + headers = self.headers, + proxies = self.proxy, + data = request).json() except ValueError as e: # unable parse response as json because it can be empty (1.2), so simulate correct answer from json import loads as json_loads - return json_loads('{"status":0}') + result = json_loads('{"status":0}') + + if not result['status']: + print("Paste successfully deleted!") + elif result['status']: + print("Something went wrong...\nError:\t\t{}".format(result['message'])) + exit(1) + else: + print("Something went wrong...\nError: Empty response.") + exit(1) def getVersion(self): diff --git a/pbincli/format.py b/pbincli/format.py index d80a217..c21ce57 100644 --- a/pbincli/format.py +++ b/pbincli/format.py @@ -120,6 +120,14 @@ class Paste: return cipher + def __preparePassKey(self): + if self._password: + digest = sha256(self._password.encode("UTF-8")).hexdigest() + return b64encode(self._key) + digest.encode("UTF-8") + else: + return b64encode(self._key) + + def __decompress(self, s): if self._version == 2: if self._compression == 'zlib': @@ -178,11 +186,7 @@ class Paste: from hashlib import sha256 from sjcl import SJCL - if self._password: - digest = sha256(self._password.encode("UTF-8")).hexdigest() - password = b64encode(self._key) + digest.encode("UTF-8") - else: - password = b64encode(self._key) + password = self.__preparePassKey() cipher_text = json_decode(self._data['data']) @@ -245,11 +249,7 @@ class Paste: self._data = {'expire':expiration,'formatter':formatter,'burnafterreading':int(burnafterreading),'opendiscussion':int(discussion)} - if self._password: - digest = sha256(self._password.encode("UTF-8")).hexdigest() - password = b64encode(self._key) + digest.encode("UTF-8") - else: - password = b64encode(self._key) + password = self.__preparePassKey() if self._debug: print("Password:\t{}".format(password))