perf(sandbox): optimize code encryption handling
This commit is contained in:
@@ -12,9 +12,10 @@ def encrypt_code(code: bytes, key: bytes) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
Base64 encoded encrypted code
|
Base64 encoded encrypted code
|
||||||
"""
|
"""
|
||||||
|
key_length = len(key)
|
||||||
encrypted_code = bytearray(len(code))
|
encrypted_code = bytearray(len(code))
|
||||||
for i in range(len(code)):
|
for i in range(len(code)):
|
||||||
encrypted_code[i] = code[i] ^ key[i % 64]
|
encrypted_code[i] = code[i] ^ key[i % key_length]
|
||||||
encoded_code = base64.b64encode(encrypted_code).decode("utf-8")
|
encoded_code = base64.b64encode(encrypted_code).decode("utf-8")
|
||||||
return encoded_code
|
return encoded_code
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ sys.excepthook = excepthook
|
|||||||
# Load security library if available
|
# Load security library if available
|
||||||
lib = ctypes.CDLL("./libpython.so")
|
lib = ctypes.CDLL("./libpython.so")
|
||||||
lib.init_seccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool]
|
lib.init_seccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool]
|
||||||
lib.init_seccomp.restype = None
|
lib.init_seccomp.restype = None # TODO: raise error info
|
||||||
|
|
||||||
# Get running path
|
# Get running path
|
||||||
running_path = sys.argv[1]
|
running_path = sys.argv[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user