Esempio n. 1
0
        private async void button2_Click(object sender, RoutedEventArgs e)
        {
            log("【MakeCredential - Start】");

            byte[] challenge = System.Text.Encoding.ASCII.GetBytes("this is challenge");
            string rpid      = textBox_rpid.Text;
            string user      = textBoxUser.Text;
            string pin       = textBoxPIN.Text;

            if ((bool)checkMakeCredentialPIN.IsChecked == false)
            {
                pin = "";
            }

            string requireResidentKey = "false";

            if ((bool)checkMakeCredentialRK.IsChecked == true)
            {
                requireResidentKey = "true";
            }

            string userVerification = "discouraged";

            if ((bool)checkMakeCredentialUV.IsChecked == true)
            {
                userVerification = "preferred";
            }

            string json =
                "{" +
                @"rp : {" +
                string.Format($"id : '{rpid}',") +
                string.Format($"name :'GEBO_{rpid}',") +
                @"}," +
                @"user : {" +
                string.Format($"id : '{user}',") +
                string.Format($"name :'GEBO_{user}',") +
                string.Format($"displayName :'my name is {user}',") +
                @"}," +
                @"pubKeyCredParams: [{type: 'public-key',alg: -7}]," +
                @"attestation: 'direct'," +
                @"timeout: 10000," +
                @"authenticatorSelection : {" +
                string.Format($"requireResidentKey : {requireResidentKey},") +
                @"authenticatorAttachment : 'cross-platform'," +
                string.Format($"userVerification : '{userVerification}'") +
                @"}," +
                string.Format($"challenge:[{string.Join(",", challenge)}],") +
                "}";

            var ret = await Credentials.Create(devParam, json, pin);

            setResponse(ret);

            if (ret.isSuccess == true)
            {
                // Verify
                if (CTAPVerify.Verify(ret))
                {
                    log("Verify - OK!");

                    // Export_File
                    Credentials.SerializeAttestationToFile(ret.attestation, string.Format($".\\credentials\\credential_{rpid}_attestation.json"));

                    // Certificate
                    var certpem = CTAPVerify.ConvertCertificateDERtoPEM(ret.attestation.AttStmtX5c);
                    System.IO.File.WriteAllText(string.Format($".\\credentials\\credential_{rpid}_attestation_cert.pem"), certpem);

                    // PublicKey
                    var pubkeypem = CTAPVerify.ConvertCOSEtoPEM(ret.attestation.CredentialPublicKeyByte);
                    System.IO.File.WriteAllText(string.Format($".\\credentials\\credential_{rpid}_pubkey.pem"), pubkeypem);
                }
                else
                {
                    log("Error --- Verify - NG!");
                }
            }

            log("【MakeCredential - End】");
        }
Esempio n. 2
0
        private async void button3_Click(object sender, RoutedEventArgs e)
        {
            log("【GetAssertion - Start】");

            byte[] challenge = System.Text.Encoding.ASCII.GetBytes("this is challenge");
            string rpid      = textBox_rpid.Text;
            string pin       = textBoxPIN.Text;

            if ((bool)checkGetAssertionPIN.IsChecked == false)
            {
                pin = "";
            }

            var att = Credentials.DeSerializeAttestationFromFile(string.Format($".\\credentials\\credential_{rpid}_attestation.json"));

            // credential-id
            var credentialid = new byte[0];

            if ((bool)checkGetAssertionCredentialId.IsChecked)
            {
                if (att == null)
                {
                    log("Error deSerializeAttestationFromFile");
                    return;
                }
                credentialid = att.CredentialId;
            }

            string requireUserPresence = "false";

            if ((bool)checkGetAssertionUP.IsChecked == true)
            {
                requireUserPresence = "true";
            }

            string userVerification = "discouraged";

            if ((bool)checkGetAssertionUV.IsChecked == true)
            {
                userVerification = "preferred";
            }

            string json =
                "{" +
                string.Format($"timeout : 10000,") +
                string.Format($"challenge:[{string.Join(",", challenge)}],") +
                string.Format($"rpId : '{rpid}',") +
                @"allowCredentials : [{" +
                string.Format($"id : [{string.Join(",", credentialid)}],") +
                string.Format($"type : 'public-key',") +
                @"}]," +
                string.Format($"requireUserPresence : '{requireUserPresence}',") +
                string.Format($"userVerification : '{userVerification}',") +
                "}";

            var ret = await Credentials.Get(devParam, json, pin);

            setResponse(ret);

            if (ret.isSuccess == true)
            {
                if (att == null)
                {
                    log("Error --- Verify - NG!(deSerializeAttestationFromFile)");
                    return;
                }

                // Verify - check index=0 only
                if (CTAPVerify.Verify(ret, att.CredentialPublicKeyByte, 0))
                {
                    log("Verify - OK!");
                }
                else
                {
                    log("Error --- Verify - NG!");
                }
            }

            log("【GetAssertion - End】");
        }