Skip to content

Commit

Permalink
security-audit-report error-reporting improvement: detect encoding …
Browse files Browse the repository at this point in the history
…of data and add to report when decoding fails
  • Loading branch information
aaunario-keeper authored and sk-keeper committed Jul 24, 2024
1 parent 2667666 commit a3b3661
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion keepercommander/commands/security_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from json import JSONDecodeError
from typing import Dict, List, Optional, Any
from charset_normalizer import detect

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

Expand Down Expand Up @@ -355,8 +356,10 @@ def decrypt_security_data(sec_data, k): # type: (bytes, RSAPrivateKey) -> Dict[
try:
decoded = decrypted_bytes.decode()
except UnicodeDecodeError as ude:
error = f'Decode fail: {decrypted_bytes}'
detected_encoding = detect(decrypted_bytes).get('encoding')
error = f'Failed to decode incremental data, (possible) encoding: {detected_encoding}'
self.get_error_report_builder().update_report_data(error)
self.get_error_report_builder().update_report_data(decrypted_bytes)
return
except Exception as e:
error = f'Decode fail: {e}'
Expand Down

0 comments on commit a3b3661

Please sign in to comment.