public Task <KeyResponse <KeyRegisterResponse> > RegisterAsync(KeyRegisterRequest request, CancellationToken cancellationToken = new CancellationToken(), bool invididualAttestation = false) { if (request == null) { throw new ArgumentNullException(nameof(request)); } log.Info(">> register"); var applicationSha256 = request.ApplicationSha256; var challengeSha256 = request.ChallengeSha256; log.Info(" -- Inputs --"); log.Info(" applicationSha256: " + applicationSha256.ToHexString()); log.Info(" challengeSha256: " + challengeSha256.ToHexString()); var userPresent = userPresenceVerifier.VerifyUserPresence(); if ((userPresent & UserPresenceVerifierConstants.UserPresentFlag) == 0) { return(TestOfUserPresenceRequired <KeyRegisterResponse>()); } var keyPair = keyPairGenerator.GenerateKeyPair(applicationSha256, challengeSha256); var keyHandle = keyHandleGenerator.GenerateKeyHandle(applicationSha256, keyPair); dataStore.StoreKeyPair(keyHandle, keyPair); var userPublicKey = keyPairGenerator.EncodePublicKey(keyPair.PublicKey); var signedData = RawMessageCodec.EncodeKeyRegisterSignedBytes(applicationSha256, challengeSha256, keyHandle, userPublicKey); log.Info("Signing bytes " + signedData.ToHexString()); var signature = crypto.Sign(signedData, certificatePrivateKey); log.Info(" -- Outputs --"); log.Info(" userPublicKey: " + userPublicKey.ToHexString()); log.Info(" keyHandle: " + keyHandle.ToHexString()); log.Info(" vendorCertificate: " + vendorCertificate); log.Info(" signature: " + signature.ToHexString()); log.Info("<< register"); var response = new KeyRegisterResponse(userPublicKey, keyHandle, vendorCertificate, signature); var responseData = RawMessageCodec.EncodeKeyRegisterResponse(response).Segment(); var apdu = new ApduResponse(ApduResponseStatus.NoError, responseData); var keyResponse = new KeyResponse <KeyRegisterResponse>(apdu, response, KeyResponseStatus.Success); return(TaskEx.FromResult(keyResponse)); }
/// <exception cref="U2FException" /> public KeyRegisterResponse Register(KeyRegisterRequest keyRegisterRequest) { if (keyRegisterRequest == null) { throw new ArgumentNullException(nameof(keyRegisterRequest)); } log.Info(">> register"); var applicationSha256 = keyRegisterRequest.ApplicationSha256; var challengeSha256 = keyRegisterRequest.ChallengeSha256; log.Info(" -- Inputs --"); log.Info(" applicationSha256: " + applicationSha256.ToHexString()); log.Info(" challengeSha256: " + challengeSha256.ToHexString()); var userPresent = userPresenceVerifier.VerifyUserPresence(); if ((userPresent & UserPresenceVerifierConstants.UserPresentFlag) == 0) { throw new U2FException("Cannot verify user presence"); } var keyPair = keyPairGenerator.GenerateKeyPair(applicationSha256, challengeSha256); var keyHandle = keyHandleGenerator.GenerateKeyHandle(applicationSha256, keyPair); dataStore.StoreKeyPair(keyHandle, keyPair); var userPublicKey = keyPairGenerator.EncodePublicKey(keyPair.PublicKey); var signedData = RawMessageCodec.EncodeKeyRegisterSignedBytes(applicationSha256, challengeSha256, keyHandle, userPublicKey); log.Info("Signing bytes " + signedData.ToHexString()); var signature = crypto.Sign(signedData, certificatePrivateKey); log.Info(" -- Outputs --"); log.Info(" userPublicKey: " + userPublicKey.ToHexString()); log.Info(" keyHandle: " + keyHandle.ToHexString()); log.Info(" vendorCertificate: " + vendorCertificate); log.Info(" signature: " + signature.ToHexString()); log.Info("<< register"); return(new KeyRegisterResponse(userPublicKey, keyHandle, vendorCertificate, signature)); }