Skip to content

Commit

Permalink
security-audit-report error-reporting improvement: add result of de…
Browse files Browse the repository at this point in the history
…coding incremental data using detected encoding when first decoding attempt fails
  • Loading branch information
aaunario-keeper committed Jul 24, 2024
1 parent a5ff5c7 commit af1db61
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions keepercommander/commands/security_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from json import JSONDecodeError
from typing import Dict, List, Optional, Any
from charset_normalizer import detect
from charset_normalizer import detect, from_bytes

from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey

Expand Down Expand Up @@ -356,10 +356,16 @@ def decrypt_security_data(sec_data, k): # type: (bytes, RSAPrivateKey) -> Dict[
try:
decoded = decrypted_bytes.decode()
except UnicodeDecodeError as ude:
detected_encoding = detect(decrypted_bytes).get('encoding')
error = f'Failed to decode incremental data, (possible) encoding: {detected_encoding}'
error = f'Failed to decode incremental data: {decrypted_bytes}'
self.get_error_report_builder().update_report_data(error)
self.get_error_report_builder().update_report_data(decrypted_bytes)
try:
detected_encoding = detect(decrypted_bytes).get('encoding')
decoded_guess = from_bytes(decrypted_bytes).best().output()
detected_encoding_msg = f'Using detected encoding ({detected_encoding}), decoded = {decoded_guess}'
self.get_error_report_builder().update_report_data(detected_encoding_msg)
except:
pass

return
except Exception as e:
error = f'Decode fail: {e}'
Expand Down

0 comments on commit af1db61

Please sign in to comment.