Ejemplo n.º 1
0
        public U2FRegistrationResponse(byte[] bytes)
        {
            int offset = 1;
            var pubkey = new byte[65];

            Array.Copy(bytes, offset, pubkey, 0, pubkey.Length);
            offset += pubkey.Length;
            var len = bytes[offset];

            offset++;
            var keyhandle = new byte[len];

            Array.Copy(bytes, offset, keyhandle, 0, keyhandle.Length);
            offset += keyhandle.Length;

            var certsig = new byte[bytes.Length - offset];

            Array.Copy(bytes, offset, certsig, 0, certsig.Length);

            UserPubKey             = pubkey;
            KeyHandle              = new KeyHandle(keyhandle);
            AttestationCertificate = new X509Certificate2(certsig);
            Signature              = new byte[certsig.Length - AttestationCertificate.RawData.Length];
            Array.Copy(certsig, AttestationCertificate.RawData.Length, Signature, 0, Signature.Length);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 public U2FAuthenticationResponse Authenticate(byte[] challenge, AppId applicationId, KeyHandle keyHandle, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(AuthenticateAsync(challenge, applicationId, keyHandle, cancellationToken).GetAwaiter().GetResult());
 }
Ejemplo n.º 4
0
        public U2FRegistrationResponse(byte[] bytes)
        {
            int offset = 1;
            var pubkey = new byte[65];
            Array.Copy(bytes, offset, pubkey, 0, pubkey.Length);
            offset += pubkey.Length;
            var len = bytes[offset];
            offset++;
            var keyhandle = new byte[len];
            Array.Copy(bytes, offset, keyhandle, 0, keyhandle.Length);
            offset += keyhandle.Length;

            var certsig = new byte[bytes.Length - offset];
            Array.Copy(bytes, offset, certsig, 0, certsig.Length);

            UserPubKey = pubkey;
            KeyHandle = new KeyHandle(keyhandle);
            AttestationCertificate = new X509Certificate2(certsig);
            Signature = new byte[certsig.Length - AttestationCertificate.RawData.Length];
            Array.Copy(certsig, AttestationCertificate.RawData.Length, Signature, 0, Signature.Length);
        }
Ejemplo n.º 5
0
        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);
        }