示例#1
0
        private void VerifyCred(string format, ReadOnlySpan <byte> authData, ReadOnlySpan <byte> x5C, ReadOnlySpan <byte> signature)
        {
            var ext = FidoExtensions.None;

            if (UseHmac)
            {
                ext |= FidoExtensions.HmacSecret;
            }

            if (BlobKey != null)
            {
                ext |= FidoExtensions.LargeBlobKey;
            }

            using (var cred = new FidoCredential()) {
                cred.SetType(FromKeyType(Type));
                cred.SetClientData(Cd);
                cred.Rp = new FidoCredentialRp
                {
                    Id   = "localhost",
                    Name = "sweet home localhost"
                };

                cred.AuthData = authData;
                cred.SetExtensions(ext);
                if (ResidentKey)
                {
                    cred.SetResidentKeyRequired(true);
                }

                if (UserVerificationRequired)
                {
                    cred.SetUserVerificationRequried(true);
                }

                cred.SetX509(x5C);
                cred.Signature = signature;
                cred.Format    = format;
                cred.Verify();

                if (PublicKey != null)
                {
                    if (Type == KeyType.ECDSA)
                    {
                        WriteEcPublicKey(cred.PublicKey);
                    }
                    else
                    {
                        WriteRsaPublicKey(cred.PublicKey.ToArray());
                    }
                }

                if (CredentialId != null)
                {
                    File.WriteAllBytes(CredentialId, cred.Id.ToArray());
                }
            }
        }
示例#2
0
        private void OnExecute()
        {
            Fido2Settings.Flags = FidoFlags.Debug;
            var ext = FidoExtensions.None;

            if (UseHmac)
            {
                ext |= FidoExtensions.HmacSecret;
            }

            if (BlobKey != null)
            {
                ext |= FidoExtensions.LargeBlobKey;
            }

            using (var cred = new FidoCredential()) {
                using (var dev = new FidoDevice()) {
                    dev.Open(Device);
                    if (ForceU2F)
                    {
                        dev.ForceU2F();
                    }

                    if (Exclude != null)
                    {
                        var credId = File.ReadAllBytes(Exclude);
                        cred.Exclude(credId);
                    }

                    cred.SetType(FromKeyType(Type));
                    cred.SetClientData(Cd);
                    cred.Rp = new FidoCredentialRp
                    {
                        Id   = "localhost",
                        Name = "sweet home localhost"
                    };

                    cred.SetUser(new FidoCredentialUser
                    {
                        Id          = UserId,
                        DisplayName = "john smith",
                        Name        = "jsmith"
                    });

                    cred.SetExtensions(ext);

                    if (ResidentKey)
                    {
                        cred.SetResidentKeyRequired(true);
                    }

                    if (UserVerificationRequired)
                    {
                        cred.SetUserVerificationRequried(true);
                    }

                    if (Timeout > 0)
                    {
                        dev.SetTimeout(TimeSpan.FromSeconds(Timeout));
                    }

                    dev.MakeCredential(cred, Pin);
                    dev.Close();
                }

                if (Pin != null)
                {
                    UserVerificationRequired = true;
                }

                VerifyCred(cred.Format, cred.AuthData, cred.X5C, cred.Signature);
            }
        }