#NEWLINE# def register( self , request , facet = 'https://www.example.com' ) : #NEWLINE# #INDENT# '\n        RegisterRequest = {\n            "version": "U2F_V2",\n            "challenge": string, //b64 encoded challenge\n            "appId": string, //app_id\n        }\n        ' #NEWLINE# if ( not isinstance ( request , RegisterRequest ) ) : #NEWLINE# #INDENT# request = RegisterRequest ( request ) #NEWLINE# #UNINDENT# if ( request . version != 'U2F_V2' ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Unsupported U2F version: %s' % request . version ) ) #NEWLINE# #UNINDENT# client_data = ClientData ( typ = 'navigator.id.finishEnrollment' , challenge = request [ 'challenge' ] , origin = facet ) #NEWLINE# client_data = client_data . json . encode ( 'utf-8' ) #NEWLINE# client_param = sha_256 ( client_data ) #NEWLINE# priv_key = ec . generate_private_key ( CURVE , default_backend ( ) ) #NEWLINE# pub_key = priv_key . public_key ( ) . public_bytes ( Encoding . DER , PublicFormat . SubjectPublicKeyInfo ) #NEWLINE# pub_key = pub_key [ ( - 65 ) : ] #NEWLINE# key_handle = rand_bytes ( 64 ) #NEWLINE# app_param = request . appParam #NEWLINE# self . keys [ key_handle ] = ( priv_key , app_param ) #NEWLINE# cert_priv = load_pem_private_key ( CERT_PRIV , password = None , backend = default_backend ( ) ) #NEWLINE# cert = CERT #NEWLINE# data = ( ( ( ( b'\x00' + app_param ) + client_param ) + key_handle ) + pub_key ) #NEWLINE# signer = cert_priv . signer ( ec . ECDSA ( hashes . SHA256 ( ) ) ) #NEWLINE# signer . update ( data ) #NEWLINE# signature = signer . finalize ( ) #NEWLINE# raw_response = ( ( ( ( ( b'\x05' + pub_key ) + int2byte ( len ( key_handle ) ) ) + key_handle ) + cert ) + signature ) #NEWLINE# return RegisterResponse ( registrationData = websafe_encode ( raw_response ) , clientData = websafe_encode ( client_data ) )