(self, params, **kwargs)
| 2440 | return reset_password_parser |
| 2441 | |
| 2442 | def execute(self, params, **kwargs): |
| 2443 | current_password = kwargs.get('current_password') |
| 2444 | is_sso_user = params.settings.get('sso_user', False) |
| 2445 | if is_sso_user: |
| 2446 | allow_alternate_passwords = False |
| 2447 | if 'booleans' in params.enforcements: |
| 2448 | allow_alternate_passwords = next((x.get('value') for x in params.enforcements['booleans'] |
| 2449 | if x.get('key') == 'allow_alternate_passwords'), False) |
| 2450 | if not allow_alternate_passwords: |
| 2451 | logging.warning('You do not have the required privilege to perform this operation.') |
| 2452 | return |
| 2453 | |
| 2454 | try: |
| 2455 | current_salt = api.communicate_rest(params, None, 'authentication/get_salt_and_iterations', |
| 2456 | rs_type=APIRequest_pb2.Salt) |
| 2457 | except error.KeeperApiError as kae: |
| 2458 | if is_sso_user and kae.result_code == 'doesnt_exist': |
| 2459 | current_salt = None |
| 2460 | else: |
| 2461 | raise kae |
| 2462 | |
| 2463 | is_delete_alternate = kwargs.get('delete_alternate') |
| 2464 | if is_delete_alternate: |
| 2465 | if is_sso_user: |
| 2466 | logging.info('Deleting SSO Master Password for \"%s\"', params.user) |
| 2467 | else: |
| 2468 | logging.warning('\"%s\" in not SSO account', params.user) |
| 2469 | return |
| 2470 | else: |
| 2471 | if is_sso_user: |
| 2472 | logging.info('%s SSO Master Password for \"%s\"', |
| 2473 | 'Changing' if current_salt else 'Setting', params.user) |
| 2474 | else: |
| 2475 | logging.info('Changing Master Password for \"%s\"', params.user) |
| 2476 | |
| 2477 | if current_salt: |
| 2478 | auth_hash = crypto.derive_keyhash_v1(current_password, current_salt.salt, current_salt.iterations) |
| 2479 | rq = APIRequest_pb2.MasterPasswordReentryRequest() |
| 2480 | rq.pbkdf2Password = utils.base64_url_encode(auth_hash) |
| 2481 | rq.action = APIRequest_pb2.UNMASK |
| 2482 | try: |
| 2483 | rs = api.communicate_rest(params, rq, 'authentication/validate_master_password', |
| 2484 | rs_type=APIRequest_pb2.MasterPasswordReentryResponse, payload_version=1) |
| 2485 | if rs.status != APIRequest_pb2.MP_SUCCESS: |
| 2486 | logging.info('Failed to change password') |
| 2487 | except: |
| 2488 | logging.warning('Current password incorrect') |
| 2489 | return |
| 2490 | else: |
| 2491 | current_password = '' |
| 2492 | |
| 2493 | if is_delete_alternate: |
| 2494 | if current_salt: |
| 2495 | uid_rq = APIRequest_pb2.UidRequest() |
| 2496 | uid_rq.uid.append(current_salt.uid) |
| 2497 | api.communicate_rest(params, uid_rq, 'authentication/delete_v2_alternate_password') |
| 2498 | logging.info('SSO Master Password has been deleted') |
| 2499 | else: |
nothing calls this directly
no test coverage detected