public void CanEnrollAndAuthenticate() { var appId = new AppId(Encoders.Hex.DecodeData("d2e42c173c857991d5e1b6c81f3e07cbb9d5f57431fe41997c9445c14ce61ec4")); var challenge = Encoders.Hex.DecodeData("e6425678fbd7d3d8e311fbfb1db8d26c37cf9f16ac81c95848998a76ce3d3768"); U2FClient u2f = U2FClient.GetHIDU2F().First(); // Refuse registration Debugger.Break(); CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(5000); Assert.Throws<OperationCanceledException>(() => u2f.Register(challenge, appId, cts.Token)); // Accept registration Debugger.Break(); var reg = u2f.Register(challenge, appId); Assert.NotNull(reg); // Refuse login Debugger.Break(); cts = new CancellationTokenSource(); cts.CancelAfter(5000); Assert.Throws<OperationCanceledException>(() => u2f.Authenticate(challenge, appId, reg.KeyHandle, cts.Token)); // Accept registration Debugger.Break(); var login = u2f.Authenticate(challenge, appId, reg.KeyHandle); Assert.NotNull(login); Assert.True(login.UserPresence); }
public U2FAuthenticationResponse Authenticate(byte[] challenge, AppId applicationId, KeyHandle keyHandle, CancellationToken cancellationToken = default(CancellationToken)) { return(AuthenticateAsync(challenge, applicationId, keyHandle, cancellationToken).GetAwaiter().GetResult()); }
public async Task <U2FAuthenticationResponse> AuthenticateAsync(byte[] challenge, AppId applicationId, KeyHandle keyHandle, CancellationToken cancellationToken = default(CancellationToken)) { if (challenge == null) { throw new ArgumentNullException("challenge"); } if (challenge.Length != 32) { throw new ArgumentException("Challenge should be 32 bytes"); } if (applicationId == null) { throw new ArgumentNullException("applicationId"); } var data = new byte[64 + 1 + keyHandle.Length]; Array.Copy(challenge, 0, data, 0, 32); Array.Copy(applicationId.GetBytes(true), 0, data, 32, 32); data[64] = (byte)keyHandle.Length; Array.Copy(keyHandle.GetBytes(true), 0, data, 65, keyHandle.Length); var result = await this.ExchangeApdu(INS_SIGN, 0x03, 0x00, data, cancellationToken).ConfigureAwait(false); return(new U2FAuthenticationResponse(result)); }
public Task <U2FRegistrationResponse> RegisterAsync(AppId applicationId, CancellationToken cancellationToken = default(CancellationToken)) { return(RegisterAsync(RandomUtils.GetBytes(32), applicationId, cancellationToken)); }
public U2FRegistrationResponse Register(byte[] challenge, AppId applicationId, CancellationToken cancellationToken = default(CancellationToken)) { return(RegisterAsync(challenge, applicationId, cancellationToken).GetAwaiter().GetResult()); }
public U2FRegistrationResponse Register(byte[] challenge, AppId applicationId, CancellationToken cancellationToken = default(CancellationToken)) { if(challenge == null) throw new ArgumentNullException("challenge"); if(challenge.Length != 32) throw new ArgumentException("Challenge should be 32 bytes"); if(applicationId == null) throw new ArgumentNullException("applicationId"); var data = new byte[64]; Array.Copy(challenge, 0, data, 0, 32); Array.Copy(applicationId.GetBytes(true), 0, data, 32, 32); var result = this.ExchangeApdu(INS_ENROLL, 0x03, 0x00, data, cancellationToken); return new U2FRegistrationResponse(result); }
public U2FRegistrationResponse Register(AppId applicationId, CancellationToken cancellationToken = default(CancellationToken)) { return Register(RandomUtils.GetBytes(32), applicationId, cancellationToken); }
public U2FAuthenticationResponse Authenticate(byte[] challenge, AppId applicationId, KeyHandle keyHandle, CancellationToken cancellationToken = default(CancellationToken)) { if(challenge == null) throw new ArgumentNullException("challenge"); if(challenge.Length != 32) throw new ArgumentException("Challenge should be 32 bytes"); if(applicationId == null) throw new ArgumentNullException("applicationId"); var data = new byte[64 + 1 + keyHandle.Length]; Array.Copy(challenge, 0, data, 0, 32); Array.Copy(applicationId.GetBytes(true), 0, data, 32, 32); data[64] = (byte)keyHandle.Length; Array.Copy(keyHandle.GetBytes(true), 0, data, 65, keyHandle.Length); var result = this.ExchangeApdu(INS_SIGN, 0x03, 0x00, data, cancellationToken); return new U2FAuthenticationResponse(result); }