mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:56:30 +00:00
fix id problems with day/winter switch
This commit is contained in:
@@ -2,6 +2,8 @@ import base64
|
||||
import hashlib
|
||||
import os
|
||||
from hashlib import sha384
|
||||
from credentials cimport Credentials
|
||||
from hardware_service cimport HardwareInfo
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import padding
|
||||
@@ -24,14 +26,14 @@ cdef class Security:
|
||||
encrypted_chunk = encryptor.update(chunk)
|
||||
res.extend(encrypted_chunk)
|
||||
res.extend(encryptor.finalize())
|
||||
return res
|
||||
return bytes(res)
|
||||
|
||||
@staticmethod
|
||||
cdef decrypt_to(input_stream, key):
|
||||
cdef bytes aes_key = hashlib.sha256(key.encode('utf-8')).digest()
|
||||
cdef bytes iv = input_stream.read(16)
|
||||
|
||||
cdef cipher = Cipher(algorithms.AES(<bytes>aes_key), modes.CBC(<bytes>iv), backend=default_backend())
|
||||
cdef cipher = Cipher(algorithms.AES(<bytes>aes_key), modes.CFB(<bytes>iv), backend=default_backend())
|
||||
cdef decryptor = cipher.decryptor()
|
||||
|
||||
cdef bytearray res = bytearray()
|
||||
@@ -40,8 +42,22 @@ cdef class Security:
|
||||
res.extend(decrypted_chunk)
|
||||
res.extend(decryptor.finalize())
|
||||
|
||||
unpadder = padding.PKCS7(128).unpadder() # AES block size is 128 bits (16 bytes)
|
||||
return unpadder.update(res) + unpadder.finalize()
|
||||
return bytes(res)
|
||||
|
||||
@staticmethod
|
||||
cdef get_hw_hash(HardwareInfo hardware):
|
||||
cdef str key = f'Azaion_{hardware.mac_address}_{hardware.cpu}_{hardware.gpu}'
|
||||
return Security.calc_hash(key)
|
||||
|
||||
@staticmethod
|
||||
cdef get_api_encryption_key(Credentials creds, str hardware_hash):
|
||||
cdef str key = f'{creds.email}-{creds.password}-{hardware_hash}-#%@AzaionKey@%#---'
|
||||
return Security.calc_hash(key)
|
||||
|
||||
@staticmethod
|
||||
cdef get_model_encryption_key():
|
||||
cdef str key = '-#%@AzaionKey@%#---234sdfklgvhjbnn'
|
||||
return Security.calc_hash(key)
|
||||
|
||||
@staticmethod
|
||||
cdef calc_hash(str key):
|
||||
|
||||
Reference in New Issue
Block a user