Example #1
0
 public static async Task <CreateCommandStatus> Create(DevParam devParam, string publickeyJson, string pin = "")
 {
     try {
         var publickey = JsonConvert.DeserializeObject <PublicKeyforCreate>(publickeyJson);
         publickey.pin = pin;
         return(await Create(devParam, publickey));
     } catch (Exception ex) {
         var status = new CreateCommandStatus();
         status.msg = ex.Message.ToString();
         return(status);
     }
 }
Example #2
0
 public static bool Verify(CreateCommandStatus status)
 {
     foreach (var command in status.commands)
     {
         if (command.cmd.GetType() == typeof(CTAPauthenticatorMakeCredential))
         {
             var make = ((CTAPauthenticatorMakeCredential)(command.cmd));
             return(Verify(make.RpId, make.ClientDataHash, status.attestation));
         }
     }
     return(false);
 }
Example #3
0
        public static async Task <CreateCommandStatus> Create(DevParam devParam, PublicKeyforCreate publickey)
        {
            var status = new CreateCommandStatus();

            try {
                if (publickey.rp == null || publickey.user == null || publickey.challenge == null)
                {
                    throw (new Exception("Param Error"));
                }

                var ctap = new CTAPauthenticatorMakeCredential();

                ctap.RpId             = publickey.rp.id;
                ctap.RpName           = publickey.rp.name;
                ctap.UserId           = publickey.user.id;
                ctap.UserId_bytearray = publickey.user.id_bytearray;
                ctap.UserName         = publickey.user.name;
                ctap.UserDisplayName  = publickey.user.displayName;
                ctap.ClientDataHash   = CTAPauthenticator.CreateClientDataHash(publickey.challenge);
                ctap.TimeoutMs        = publickey.timeout;

                ctap.Option_rk = publickey.authenticatorSelection.requireResidentKey;
                if (publickey.authenticatorSelection.userVerification == UserVerificationRequirement.discouraged)
                {
                    ctap.Option_uv = false;
                }
                else
                {
                    ctap.Option_uv = true;
                }

                if (publickey.pin.Length > 0)
                {
                    string pin = publickey.pin;

                    var ctap2 = new CTAPauthenticatorClientPIN();

                    var st1 = await ctap2.GetKeyAgreement(devParam);

                    status.commands.Add(new CommandStatus.CommandInfo(ctap2, st1));
                    if (st1.Status != 0)
                    {
                        throw (new Exception("GetKeyAgreement"));
                    }

                    var sharedSecret = ctap2.createSharedSecret(ctap2.Authenticator_KeyAgreement);

                    var pinHashEnc = ctap2.createPinHashEnc(pin, sharedSecret);

                    var token = await ctap2.GetPINToken(devParam, pinHashEnc);

                    status.commands.Add(new CommandStatus.CommandInfo(ctap2, token));
                    if (token.Status != 0)
                    {
                        throw (new Exception("GetPINToken"));
                    }

                    ctap.PinAuth = ctap2.createPinAuth(sharedSecret, ctap.ClientDataHash, token.PinTokenEnc);
                }

                var att = await ctap.SendAndResponse(devParam);

                status.commands.Add(new CommandStatus.CommandInfo(ctap, att));
                if (att.Status != 0)
                {
                    throw (new Exception("MakeCredential"));
                }

                status.attestation = att;
                status.isSuccess   = true;
            } catch (Exception ex) {
                status.setErrorMsg(ex);
            }
            return(status);
        }