Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(KC-797) security-audit report/sync Improvements/Fixes: #1271

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions keepercommander/commands/security_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def register_command_info(aliases, command_info):

sync_email_help = 'email of target vault\'s owner. Accepts multiple values. Supports the following pseudo-users: @all'
sync_parser.add_argument('email', type=str, nargs='+', help=sync_email_help)
sync_verbose_help = 'run and show the latest security-audit report immediately after sync'
sync_parser.add_argument('-v', '--verbose', action='store_true', help=sync_verbose_help)
sync_parser.add_argument('-f', '--force', action='store_true', help='do sync non-interactively')
sync_parser.error = raise_parse_exception
sync_parser.exit = suppress_exit

Expand Down Expand Up @@ -343,7 +346,7 @@ def decrypt_security_data(sec_data, k): # type: (bytes, RSAPrivateKey) -> Dict[
decrypted = None
if sec_data:
try:
decrypted = crypto.decrypt_rsa(sec_data, k)
decrypted = crypto.decrypt_rsa(sec_data, k, pad_plaintext=True)
except Exception as e:
error = f'Decrypt fail (incremental data): {e}'
self.get_error_report_builder().update_report_data(error)
Expand Down Expand Up @@ -529,11 +532,12 @@ def confirm_sync():
f' scores.'
confirm_txt = f'{hard_sync_desc}\n\n{confirm_txt}'
prompt_txt = f'{prompt_title}{sync_targets}\n\n{confirm_txt}'
if confirm(prompt_txt):
if kwargs.get('force') or confirm(prompt_txt):
api.communicate_rest(params, rq, 'enterprise/clear_security_data')
# Re-calculate and save new security scores
sar_cmd = SecurityAuditReportCommand()
return sar_cmd.execute(params, save=True)
if kwargs.get('verbose'):
sar_cmd = SecurityAuditReportCommand()
return sar_cmd.execute(params, save=True)
else:
logging.info(f'Security-data ({sync_type}) sync aborted')

Expand Down
8 changes: 7 additions & 1 deletion keepercommander/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ def encrypt_rsa(data, rsa_key):
return rsa_key.encrypt(data, PKCS1v15())


def decrypt_rsa(data, rsa_key):
def decrypt_rsa(data, rsa_key, pad_plaintext=False):
size_diff = (rsa_key.key_size >> 3) - len(data)
if pad_plaintext and size_diff:
pad_bytes = bytes(size_diff)
pad_bytearray = bytearray([b for b in pad_bytes])
data_bytearray = bytearray([b for b in data])
data = bytes(pad_bytearray + data_bytearray)
return rsa_key.decrypt(data, PKCS1v15())


Expand Down
Loading