Fix: fix CI failure.(#11837)
This commit is contained in:
parent
c00f2cdde2
commit
fc333aaa79
2 changed files with 12 additions and 17 deletions
|
|
@ -15,13 +15,11 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||||
from cryptography.hazmat.primitives import padding
|
from cryptography.hazmat.primitives import padding
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
import base64
|
|
||||||
|
|
||||||
|
|
||||||
class BaseCrypto:
|
class BaseCrypto:
|
||||||
|
|
@ -294,13 +292,12 @@ class CryptoUtil:
|
||||||
Returns:
|
Returns:
|
||||||
Encrypted data (bytes)
|
Encrypted data (bytes)
|
||||||
"""
|
"""
|
||||||
import time
|
# import time
|
||||||
start_time = time.time()
|
# start_time = time.time()
|
||||||
encrypted = self.crypto.encrypt(data)
|
encrypted = self.crypto.encrypt(data)
|
||||||
end_time = time.time()
|
# end_time = time.time()
|
||||||
# logging.info(f"Encryption completed, data length: {len(data)} bytes, time: {(end_time - start_time)*1000:.2f} ms")
|
# logging.info(f"Encryption completed, data length: {len(data)} bytes, time: {(end_time - start_time)*1000:.2f} ms")
|
||||||
return encrypted
|
return encrypted
|
||||||
# return self.crypto.encrypt(data)
|
|
||||||
|
|
||||||
def decrypt(self, encrypted_data):
|
def decrypt(self, encrypted_data):
|
||||||
"""
|
"""
|
||||||
|
|
@ -312,13 +309,12 @@ class CryptoUtil:
|
||||||
Returns:
|
Returns:
|
||||||
Decrypted data (bytes)
|
Decrypted data (bytes)
|
||||||
"""
|
"""
|
||||||
import time
|
# import time
|
||||||
start_time = time.time()
|
# start_time = time.time()
|
||||||
decrypted = self.crypto.decrypt(encrypted_data)
|
decrypted = self.crypto.decrypt(encrypted_data)
|
||||||
end_time = time.time()
|
# end_time = time.time()
|
||||||
# logging.info(f"Decryption completed, data length: {len(encrypted_data)} bytes, time: {(end_time - start_time)*1000:.2f} ms")
|
# logging.info(f"Decryption completed, data length: {len(encrypted_data)} bytes, time: {(end_time - start_time)*1000:.2f} ms")
|
||||||
return decrypted
|
return decrypted
|
||||||
# return self.crypto.decrypt(encrypted_data)
|
|
||||||
|
|
||||||
|
|
||||||
# Test code
|
# Test code
|
||||||
|
|
@ -330,7 +326,7 @@ if __name__ == "__main__":
|
||||||
encrypted = crypto.encrypt(test_data)
|
encrypted = crypto.encrypt(test_data)
|
||||||
decrypted = crypto.decrypt(encrypted)
|
decrypted = crypto.decrypt(encrypted)
|
||||||
|
|
||||||
print(f"AES Test:")
|
print("AES Test:")
|
||||||
print(f"Original: {test_data}")
|
print(f"Original: {test_data}")
|
||||||
print(f"Encrypted: {encrypted}")
|
print(f"Encrypted: {encrypted}")
|
||||||
print(f"Decrypted: {decrypted}")
|
print(f"Decrypted: {decrypted}")
|
||||||
|
|
@ -343,7 +339,7 @@ if __name__ == "__main__":
|
||||||
encrypted_sm4 = crypto_sm4.encrypt(test_data)
|
encrypted_sm4 = crypto_sm4.encrypt(test_data)
|
||||||
decrypted_sm4 = crypto_sm4.decrypt(encrypted_sm4)
|
decrypted_sm4 = crypto_sm4.decrypt(encrypted_sm4)
|
||||||
|
|
||||||
print(f"SM4 Test:")
|
print("SM4 Test:")
|
||||||
print(f"Original: {test_data}")
|
print(f"Original: {test_data}")
|
||||||
print(f"Encrypted: {encrypted_sm4}")
|
print(f"Encrypted: {encrypted_sm4}")
|
||||||
print(f"Decrypted: {decrypted_sm4}")
|
print(f"Decrypted: {decrypted_sm4}")
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,8 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from common.crypto_utils import CryptoUtil
|
from common.crypto_utils import CryptoUtil
|
||||||
from common.decorator import singleton
|
# from common.decorator import singleton
|
||||||
|
|
||||||
class EncryptedStorageWrapper:
|
class EncryptedStorageWrapper:
|
||||||
"""Encrypted storage wrapper that wraps existing storage implementations to provide transparent encryption"""
|
"""Encrypted storage wrapper that wraps existing storage implementations to provide transparent encryption"""
|
||||||
|
|
@ -66,7 +65,7 @@ class EncryptedStorageWrapper:
|
||||||
|
|
||||||
return self.storage_impl.put(bucket, fnm, encrypted_binary, tenant_id)
|
return self.storage_impl.put(bucket, fnm, encrypted_binary, tenant_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(f"Failed to encrypt and store data: {bucket}/{fnm}")
|
logging.exception(f"Failed to encrypt and store data: {bucket}/{fnm}, error: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get(self, bucket, fnm, tenant_id=None):
|
def get(self, bucket, fnm, tenant_id=None):
|
||||||
|
|
@ -96,7 +95,7 @@ class EncryptedStorageWrapper:
|
||||||
return decrypted_binary
|
return decrypted_binary
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(f"Failed to get and decrypt data: {bucket}/{fnm}")
|
logging.exception(f"Failed to get and decrypt data: {bucket}/{fnm}, error: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def rm(self, bucket, fnm, tenant_id=None):
|
def rm(self, bucket, fnm, tenant_id=None):
|
||||||
|
|
@ -260,7 +259,7 @@ def create_encrypted_storage(storage_impl, algorithm=None, key=None, encryption_
|
||||||
wrapper.encryption_enabled = encryption_enabled
|
wrapper.encryption_enabled = encryption_enabled
|
||||||
|
|
||||||
if encryption_enabled:
|
if encryption_enabled:
|
||||||
logging.info(f"Encryption enabled in storage wrapper")
|
logging.info("Encryption enabled in storage wrapper")
|
||||||
else:
|
else:
|
||||||
logging.info("Encryption disabled in storage wrapper")
|
logging.info("Encryption disabled in storage wrapper")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue