fuck finally

This commit is contained in:
shim_ 2018-07-19 23:18:43 +02:00
parent 4a41f768c2
commit 0c803ba912

View File

@ -42,20 +42,20 @@ class EncryptedScreenshot:
self.metadata["hash"] = image_digest self.metadata["hash"] = image_digest
unencrypted_metadata = bson.dumps(self.metadata) unencrypted_metadata = bson.dumps(self.metadata)
if len(unencrypted_metadata) % 16 != 0: if len(unencrypted_metadata) % 16 != 0:
unencrypted_metadata += ' ' * (16 - len(unencrypted_metadata) % 16) unencrypted_metadata += b' ' * (16 - len(unencrypted_metadata) % 16)
(encryptor, iv) = self.encryptor(len(unencrypted_metadata)) (encryptor, iv) = self.encryptor(len(unencrypted_metadata))
encrypted_metadata = [] encrypted_metadata = b''
encrypted_metadata += encryptor(unencrypted_metadata) encrypted_metadata += encryptor(unencrypted_metadata)
encrypted_metadata = iv + str(bytearray(encrypted_metadata)) encrypted_metadata = iv + encrypted_metadata
print("Metadata: %s" % str(encrypted_metadata).encode("base64").replace("\n", "")) #print("Metadata: %s" % str(encrypted_metadata).encode("base64").replace("\n", ""))
#print("%s %s" % (str(encrypted_metadata[:16]).encode("hex"), str(encrypted_metadata[16:]).encode("hex"))) #print("%s %s" % (str(encrypted_metadata[:16]).encode("hex"), str(encrypted_metadata[16:]).encode("hex")))
#print("Unencrypted: %s" % (unencrypted_metadata.encode("hex"))) #print("Unencrypted: %s" % (unencrypted_metadata.encode("hex")))
print("Password %s" % self.password) #print("Password %s" % self.password)
print(bson.loads(unencrypted_metadata)) #print(bson.loads(unencrypted_metadata))
fields = { fields = {
"image": encrypted_image, "image": encrypted_image,
@ -73,8 +73,8 @@ class EncryptedScreenshot:
def encryptor(self,length=0): def encryptor(self,length=0):
iv = os.urandom(16) iv = os.urandom(16)
nonce = int.from_bytes(binascii.hexlify(iv), byteorder='little') nonce = int(binascii.hexlify(iv), 16)
ctr = Counter.new(128, nonce, 16) ctr = Counter.new(128,initial_value = nonce)# initial_value = nonce)
print("IV: %s" % binascii.hexlify(iv)) print("IV: %s" % binascii.hexlify(iv))
cipher = AES.new(self.passphrase(), AES.MODE_CTR, counter=ctr) cipher = AES.new(self.passphrase(), AES.MODE_CTR, counter=ctr)
@ -95,7 +95,7 @@ class EncryptedScreenshot:
def encrypt(self, file): def encrypt(self, file):
filesize = os.path.getsize(file) filesize = os.path.getsize(file)
(encryptor, iv) = self.encryptor(filesize) (encryptor, iv) = self.encryptor(filesize)
binary = [] binary = b''
digest = hashlib.sha256() digest = hashlib.sha256()
with open(file, 'rb') as infile: with open(file, 'rb') as infile:
# binary += struct.pack('<Q', filesize) # binary += struct.pack('<Q', filesize)
@ -107,7 +107,7 @@ class EncryptedScreenshot:
pass # chunk += ' ' * (16 - len(chunk) % 16) pass # chunk += ' ' * (16 - len(chunk) % 16)
digest.update(chunk) digest.update(chunk)
binary += encryptor(chunk) binary += encryptor(chunk)
return (digest.digest(), iv + str(bytearray(binary))) return (digest.digest(), iv + binary)
from Crypto.Signature import PKCS1_v1_5 from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA256 from Crypto.Hash import SHA256
@ -131,8 +131,8 @@ class Signer:
def signature(self,data): def signature(self,data):
signed = self.sign(data) signed = self.sign(data)
return {"signed-hash": signed, return {"signed-hash": signed,
"signature-algorithm": "SHA-256/%s" % unicode("RSA" if self.mode == RSA else "DSA"), "signature-algorithm": "SHA-256/%s" % ("RSA" if self.mode == RSA else "DSA"),
"key-id": unicode(self.privateKeyId) "key-id": (self.privateKeyId)
} }