MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / get_device_id

Method get_device_id

keepercommander/loginv3.py:850–885  ·  view source on GitHub ↗
(params, new_device=False)

Source from the content-addressed store, hash-verified

848
849 @staticmethod
850 def get_device_id(params, new_device=False): # type: (KeeperParams, bool) -> bytes
851 if new_device:
852 print('Resetting device token', file=sys.stderr)
853 params.device_token = None
854 if 'device_token' in params.config:
855 del params.config['device_token']
856 if params.device_private_key:
857 params.device_private_key = None
858 if 'private_key' in params.config:
859 del params.config['private_key']
860
861 if not params.device_token:
862 private, public = crypto.generate_ec_key()
863
864 rq = APIRequest_pb2.DeviceRegistrationRequest()
865 rq.clientVersion = rest_api.CLIENT_VERSION
866 rq.deviceName = CommonHelperMethods.get_device_name()
867 rq.devicePublicKey = crypto.unload_ec_public_key(public)
868
869 api_request_payload = APIRequest_pb2.ApiRequestPayload()
870 api_request_payload.payload = rq.SerializeToString()
871
872 rs = rest_api.execute_rest(params.rest_context, 'authentication/register_device', api_request_payload)
873
874 if type(rs) == bytes:
875 register_device_rs = APIRequest_pb2.Device()
876 register_device_rs.ParseFromString(rs)
877
878 # A globally unique device id for each device encrypted by the device token key
879 params.device_token = utils.base64_url_encode(register_device_rs.encryptedDeviceToken)
880 params.device_private_key = utils.base64_url_encode(crypto.unload_ec_private_key(private))
881 loader.store_config_properties(params)
882 else:
883 raise KeeperApiError(rs['error'], rs['message'])
884
885 return utils.base64_url_decode(params.device_token)
886
887 @staticmethod
888 def requestDeviceVerificationMessage(params: KeeperParams,

Callers 4

loginMethod · 0.80
rename_deviceMethod · 0.80
executeMethod · 0.80
executeMethod · 0.80

Calls 2

KeeperApiErrorClass · 0.85
get_device_nameMethod · 0.80

Tested by

no test coverage detected