|
1 | | -use std::convert::TryInto; |
2 | 1 | use std::error::Error; |
3 | 2 | use std::io::{self, Write}; |
4 | 3 | use std::time::Duration; |
5 | 4 |
|
6 | 5 | use libwebauthn::UvUpdate; |
7 | | -use rand::{thread_rng, Rng}; |
8 | 6 | use text_io::read; |
9 | 7 | use tokio::sync::broadcast::Receiver; |
10 | 8 | use tracing_subscriber::{self, EnvFilter}; |
11 | 9 |
|
12 | 10 | use libwebauthn::ops::webauthn::{ |
13 | | - GetAssertionRequest, GetAssertionRequestExtensions, MakeCredentialRequest, RelyingPartyId, |
14 | | - UserVerificationRequirement, WebAuthnIDL as _, |
| 11 | + GetAssertionRequest, MakeCredentialRequest, RelyingPartyId, WebAuthnIDL as _, |
15 | 12 | }; |
16 | 13 | use libwebauthn::pin::PinRequestReason; |
17 | | -use libwebauthn::proto::ctap2::Ctap2PublicKeyCredentialDescriptor; |
18 | 14 | use libwebauthn::transport::hid::list_devices; |
19 | 15 | use libwebauthn::transport::{Channel as _, Device}; |
20 | 16 | use libwebauthn::webauthn::{Error as WebAuthnError, WebAuthn}; |
@@ -136,17 +132,18 @@ pub async fn main() -> Result<(), Box<dyn Error>> { |
136 | 132 | .unwrap(); |
137 | 133 | println!("WebAuthn MakeCredential response: {:?}", response); |
138 | 134 |
|
139 | | - let challenge: [u8; 32] = thread_rng().gen(); |
140 | | - let credential: Ctap2PublicKeyCredentialDescriptor = |
141 | | - (&response.authenticator_data).try_into().unwrap(); |
142 | | - let get_assertion = GetAssertionRequest { |
143 | | - relying_party_id: "example.org".to_owned(), |
144 | | - hash: Vec::from(challenge), |
145 | | - allow: vec![credential], |
146 | | - user_verification: UserVerificationRequirement::Discouraged, |
147 | | - extensions: GetAssertionRequestExtensions::default(), |
148 | | - timeout: TIMEOUT, |
149 | | - }; |
| 135 | + let request_json = r#" |
| 136 | + { |
| 137 | + "challenge": "Y3JlZGVudGlhbHMtZm9yLWxpbnV4L2xpYndlYmF1dGhu", |
| 138 | + "timeout": 30000, |
| 139 | + "rpId": "example.org", |
| 140 | + "userVerification": "discouraged" |
| 141 | + } |
| 142 | + "#; |
| 143 | + let get_assertion: GetAssertionRequest = |
| 144 | + GetAssertionRequest::from_json(&rpid, request_json) |
| 145 | + .expect("Failed to parse request JSON"); |
| 146 | + println!("WebAuthn GetAssertion request: {:?}", get_assertion); |
150 | 147 |
|
151 | 148 | let response = loop { |
152 | 149 | match channel.webauthn_get_assertion(&get_assertion).await { |
|
0 commit comments