Skip to content

Commit

Permalink
cleanup private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ms264556 committed Feb 17, 2024
1 parent 10e45a8 commit 9f3c551
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions aioruckus/backupsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ def open_backup(self, backup_path: str) -> io.BytesIO:
with open(backup_path, "rb") as backup_file:
magic = backup_file.read(4)
if magic == b'RKSF':
return self.open_commscope_backup(backup_file)
return self.__open_commscope_backup(backup_file)
else:
backup_file.seek(0)
return self.open_tac_backup(backup_file)
return self.__open_tac_backup(backup_file)

@classmethod
def decrypt_key(cls, cipher_bytes: bytes) -> bytes:
def __decrypt_key(cls, cipher_bytes: bytes) -> bytes:
padded_key = pow(int.from_bytes(cipher_bytes, 'big'), 65537, 23559046888044776627569879690471525499427612616504460325607886880157810091042540109382540840072568820382270758180649018860535002041926018790203547085546162549326945200443019963900872654422143820799219291504478283808912964667353808795633808052022964371726410677357834881346022671448243831605466569511830964339444687659616502868745663064525218488470606514409811838671765944249166136071060850237167429125523755638111097424494275181385870987411479009552515816450089719197508371290305110717762578033949377936003949760003095430389967102852124783026450284389704957901428442687247403657819155956894836033683283023293306459081).to_bytes(256, 'big')
return padded_key[padded_key.index(b'\x00', 2) + 1:]

def open_tac_backup(self, backup_file: io.BufferedReader) -> io.BytesIO:
def __open_tac_backup(self, backup_file: io.BufferedReader) -> io.BytesIO:
"""Return the decrypted TAC backup file"""
(xor_int, xor_flip) = struct.unpack('QQ', b')\x1aB\x05\xbd,\xd6\xf25\xad\xb8\xe0?T\xc58')
struct_int8 = struct.Struct('Q')
Expand All @@ -66,26 +66,26 @@ def open_tac_backup(self, backup_file: io.BufferedReader) -> io.BytesIO:
return output_file

@classmethod
def skip_block(cls, backup_file: io.BufferedReader) -> None:
def __skip_block(cls, backup_file: io.BufferedReader) -> None:
backup_file.seek(1, SEEK_CUR)
block_length = int.from_bytes(backup_file.read(4), byteorder='big', signed=False)
backup_file.seek(block_length, SEEK_CUR)

@classmethod
def get_block_length(cls, backup_file: io.BufferedReader) -> bytes:
def __get_block_length(cls, backup_file: io.BufferedReader) -> bytes:
backup_file.seek(1, SEEK_CUR)
return int.from_bytes(backup_file.read(4), byteorder='big', signed=False)

def open_commscope_backup(self, backup_file: io.BufferedReader) -> io.BytesIO:
def __open_commscope_backup(self, backup_file: io.BufferedReader) -> io.BytesIO:
"""Return the decrypted CommScope Content Manager backup file"""
backup_file.seek(4, SEEK_CUR)
encrypted_key = backup_file.read(self.get_block_length(backup_file))
key = self.decrypt_key(encrypted_key)
encrypted_key = backup_file.read(self.__get_block_length(backup_file))
key = self.__decrypt_key(encrypted_key)

self.skip_block(backup_file) # digest
self.skip_block(backup_file) # signature
self.__skip_block(backup_file) # digest
self.__skip_block(backup_file) # signature

decrypted_length = self.get_block_length(backup_file)
decrypted_length = self.__get_block_length(backup_file)
encrypted_bytes = backup_file.read()
cipher = Cipher(algorithms.AES(key), modes.ECB(), backend=default_backend())
decryptor = cipher.decryptor()
Expand Down

0 comments on commit 9f3c551

Please sign in to comment.