|
|
@ -89,17 +89,18 @@ class Paste: |
|
|
|
return b64encode(self._key).decode() |
|
|
|
return b64encode(self._key).decode() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setHash(self, hash): |
|
|
|
def setHash(self, passphrase): |
|
|
|
if self._version == 2: |
|
|
|
if self._version == 2: |
|
|
|
from base58 import b58decode |
|
|
|
from base58 import b58decode |
|
|
|
self._key = b58decode(hash) |
|
|
|
self._key = b58decode(passphrase) |
|
|
|
else: |
|
|
|
else: |
|
|
|
self._key = b64decode(hash) |
|
|
|
self._key = b64decode(passphrase) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __deriveKey(self, salt): |
|
|
|
def __deriveKey(self, salt): |
|
|
|
from Crypto.Protocol.KDF import PBKDF2 |
|
|
|
from Crypto.Protocol.KDF import PBKDF2 |
|
|
|
from Crypto.Hash import HMAC, SHA256 |
|
|
|
from Crypto.Hash import HMAC, SHA256 |
|
|
|
|
|
|
|
|
|
|
|
# Key derivation, using PBKDF2 and SHA256 HMAC |
|
|
|
# Key derivation, using PBKDF2 and SHA256 HMAC |
|
|
|
return PBKDF2( |
|
|
|
return PBKDF2( |
|
|
|
self._key + self._password.encode(), |
|
|
|
self._key + self._password.encode(), |
|
|
@ -116,12 +117,15 @@ class Paste: |
|
|
|
@classmethod |
|
|
|
@classmethod |
|
|
|
def __initializeCipher(self, key, iv, adata): |
|
|
|
def __initializeCipher(self, key, iv, adata): |
|
|
|
from pbincli.utils import json_encode |
|
|
|
from pbincli.utils import json_encode |
|
|
|
|
|
|
|
|
|
|
|
cipher = AES.new(key, AES.MODE_GCM, nonce=iv, mac_len=CIPHER_TAG_BYTES) |
|
|
|
cipher = AES.new(key, AES.MODE_GCM, nonce=iv, mac_len=CIPHER_TAG_BYTES) |
|
|
|
cipher.update(json_encode(adata)) |
|
|
|
cipher.update(json_encode(adata)) |
|
|
|
return cipher |
|
|
|
return cipher |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __preparePassKey(self): |
|
|
|
def __preparePassKey(self): |
|
|
|
|
|
|
|
from hashlib import sha256 |
|
|
|
|
|
|
|
|
|
|
|
if self._password: |
|
|
|
if self._password: |
|
|
|
digest = sha256(self._password.encode("UTF-8")).hexdigest() |
|
|
|
digest = sha256(self._password.encode("UTF-8")).hexdigest() |
|
|
|
return b64encode(self._key) + digest.encode("UTF-8") |
|
|
|
return b64encode(self._key) + digest.encode("UTF-8") |
|
|
@ -243,7 +247,6 @@ class Paste: |
|
|
|
self._data = {'v':2,'adata':adata,'ct':b64encode(ciphertext + tag).decode(),'meta':{'expire':expiration}} |
|
|
|
self._data = {'v':2,'adata':adata,'ct':b64encode(ciphertext + tag).decode(),'meta':{'expire':expiration}} |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
from hashlib import sha256 |
|
|
|
|
|
|
|
from sjcl import SJCL |
|
|
|
from sjcl import SJCL |
|
|
|
|
|
|
|
|
|
|
|
self._data = {'expire':expiration,'formatter':formatter,'burnafterreading':int(burnafterreading),'opendiscussion':int(discussion)} |
|
|
|
self._data = {'expire':expiration,'formatter':formatter,'burnafterreading':int(burnafterreading),'opendiscussion':int(discussion)} |
|
|
|