Skip to content

Commit f64a4f1

Browse files
[WIP] More progress
1 parent fce8da2 commit f64a4f1

File tree

15 files changed

+132
-95
lines changed

15 files changed

+132
-95
lines changed

libwebauthn/examples/prf_test.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ use std::time::Duration;
77
use libwebauthn::transport::hid::channel::HidChannel;
88
use libwebauthn::UvUpdate;
99
use rand::{thread_rng, Rng};
10-
use serde_bytes::ByteBuf;
1110
use text_io::read;
1211
use tokio::sync::broadcast::Receiver;
1312
use tracing_subscriber::{self, EnvFilter};
1413

1514
use libwebauthn::ops::webauthn::{
16-
GetAssertionHmacOrPrfInput, GetAssertionRequest, GetAssertionRequestExtensions, PRFValue,
17-
UserVerificationRequirement,
15+
Base64UrlString, GetAssertionHmacOrPrfInput, GetAssertionRequest,
16+
GetAssertionRequestExtensions, PRFValue, UserVerificationRequirement,
1817
};
1918
use libwebauthn::pin::PinRequestReason;
2019
use libwebauthn::proto::ctap2::{Ctap2PublicKeyCredentialDescriptor, Ctap2PublicKeyCredentialType};
@@ -115,7 +114,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
115114

116115
let credential = Ctap2PublicKeyCredentialDescriptor {
117116
r#type: Ctap2PublicKeyCredentialType::PublicKey,
118-
id: ByteBuf::from(credential_id.as_slice()),
117+
id: Base64UrlString::from(credential_id.as_slice()),
119118
transports: None,
120119
};
121120

libwebauthn/examples/webauthn_extensions_hid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use tracing_subscriber::{self, EnvFilter};
1111

1212
use libwebauthn::ops::webauthn::{
1313
CredentialProtectionExtension, CredentialProtectionPolicy, GetAssertionHmacOrPrfInput,
14-
GetAssertionRequest, GetAssertionRequestExtensions, HMACGetSecretInput,
15-
MakeCredentialHmacOrPrfInput, MakeCredentialLargeBlobExtension, MakeCredentialRequest,
14+
GetAssertionRequest, GetAssertionRequestExtensions, HMACGetSecretInput, MakeCredentialRequest,
1615
MakeCredentialsRequestExtensions, ResidentKeyRequirement, UserVerificationRequirement,
1716
};
1817
use libwebauthn::pin::PinRequestReason;
@@ -88,10 +87,11 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
8887
policy: CredentialProtectionPolicy::UserVerificationRequired,
8988
enforce_policy: true,
9089
}),
91-
cred_blob: Some(r"My own little blob".into()),
92-
large_blob: MakeCredentialLargeBlobExtension::None,
90+
cred_blob: Some("My own little blob".as_bytes().into()),
91+
large_blob: None,
9392
min_pin_length: Some(true),
94-
hmac_or_prf: MakeCredentialHmacOrPrfInput::HmacGetSecret,
93+
hmac_create_secret: Some(true),
94+
prf: None,
9595
cred_props: Some(true),
9696
};
9797

libwebauthn/examples/webauthn_preflight_hid.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use std::time::Duration;
66
use libwebauthn::transport::hid::channel::HidChannel;
77
use libwebauthn::UvUpdate;
88
use rand::{thread_rng, Rng};
9-
use serde_bytes::ByteBuf;
109
use text_io::read;
1110
use tokio::sync::broadcast::Receiver;
1211
use tracing_subscriber::{self, EnvFilter};
1312

1413
use libwebauthn::ops::webauthn::{
15-
GetAssertionRequest, GetAssertionResponse, MakeCredentialRequest, ResidentKeyRequirement,
16-
UserVerificationRequirement,
14+
Base64UrlString, GetAssertionRequest, GetAssertionResponse, MakeCredentialRequest,
15+
ResidentKeyRequirement, UserVerificationRequirement,
1716
};
1817
use libwebauthn::pin::PinRequestReason;
1918
use libwebauthn::proto::ctap2::{
@@ -226,7 +225,7 @@ async fn get_assertion_call(
226225
fn create_credential(id: &[u8]) -> Ctap2PublicKeyCredentialDescriptor {
227226
Ctap2PublicKeyCredentialDescriptor {
228227
r#type: Ctap2PublicKeyCredentialType::PublicKey,
229-
id: ByteBuf::from(id),
228+
id: Base64UrlString::from(id),
230229
transports: None,
231230
}
232231
}

libwebauthn/examples/webauthn_prf_hid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use tracing_subscriber::{self, EnvFilter};
1313

1414
use libwebauthn::ops::webauthn::{
1515
GetAssertionHmacOrPrfInput, GetAssertionRequest, GetAssertionRequestExtensions,
16-
MakeCredentialHmacOrPrfInput, MakeCredentialRequest, MakeCredentialsRequestExtensions,
17-
PRFValue, ResidentKeyRequirement, UserVerificationRequirement,
16+
MakeCredentialPrfInput, MakeCredentialRequest, MakeCredentialsRequestExtensions, PRFValue,
17+
ResidentKeyRequirement, UserVerificationRequirement,
1818
};
1919
use libwebauthn::pin::PinRequestReason;
2020
use libwebauthn::proto::ctap2::{
@@ -85,7 +85,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
8585
let challenge: [u8; 32] = thread_rng().gen();
8686

8787
let extensions = MakeCredentialsRequestExtensions {
88-
hmac_or_prf: MakeCredentialHmacOrPrfInput::Prf,
88+
prf: Some(MakeCredentialPrfInput { _eval: None }),
8989
..Default::default()
9090
};
9191

libwebauthn/src/fido.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ use serde::{
44
de::{DeserializeOwned, Error as DesError, Visitor},
55
Deserialize, Deserializer, Serialize,
66
};
7-
use serde_bytes::ByteBuf;
87
use std::{
98
fmt,
109
io::{Cursor, Read},
1110
marker::PhantomData,
1211
};
1312
use tracing::{error, warn};
1413

15-
use crate::proto::ctap2::cbor;
14+
use crate::{ops::webauthn::idl::Base64UrlString, proto::ctap2::cbor};
1615
use crate::{
1716
proto::{
1817
ctap2::{Ctap2PublicKeyCredentialDescriptor, Ctap2PublicKeyCredentialType},
@@ -69,7 +68,7 @@ impl From<&AttestedCredentialData> for Ctap2PublicKeyCredentialDescriptor {
6968
fn from(data: &AttestedCredentialData) -> Self {
7069
Self {
7170
r#type: Ctap2PublicKeyCredentialType::PublicKey,
72-
id: ByteBuf::from(data.credential_id.clone()),
71+
id: Base64UrlString::from(data.credential_id.clone()),
7372
transports: None,
7473
}
7574
}

libwebauthn/src/ops/u2f.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use x509_parser::nom::AsBytes;
88

99
use super::webauthn::MakeCredentialRequest;
1010
use crate::fido::{AttestedCredentialData, AuthenticatorData, AuthenticatorDataFlags};
11+
use crate::ops::webauthn::idl::Base64UrlString;
1112
use crate::ops::webauthn::{
1213
GetAssertionRequest, GetAssertionResponse, MakeCredentialResponse, UserVerificationRequirement,
1314
};
@@ -183,7 +184,7 @@ impl UpgradableResponse<GetAssertionResponse, SignRequest> for SignResponse {
183184
let response = Ctap2GetAssertionResponse {
184185
credential_id: Some(Ctap2PublicKeyCredentialDescriptor {
185186
r#type: Ctap2PublicKeyCredentialType::PublicKey,
186-
id: ByteBuf::from(request.key_handle.clone()),
187+
id: Base64UrlString::from(request.key_handle.clone()),
187188
transports: None,
188189
}),
189190
authenticator_data,

libwebauthn/src/ops/webauthn/create.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use super::idl::Base64UrlString;
22
use crate::{
3-
ops::webauthn::{ResidentKeyRequirement, UserVerificationRequirement},
3+
ops::webauthn::{
4+
MakeCredentialsRequestExtensions, ResidentKeyRequirement, UserVerificationRequirement,
5+
},
46
proto::ctap2::{
57
Ctap2CredentialType, Ctap2PublicKeyCredentialDescriptor, Ctap2PublicKeyCredentialRpEntity,
68
Ctap2PublicKeyCredentialUserEntity,
@@ -63,5 +65,5 @@ pub struct PublicKeyCredentialCreationOptionsJSON {
6365
pub attestation: String,
6466
#[serde(rename = "attestationFormats")]
6567
pub attestation_formats: Vec<String>,
66-
pub extensions: JsonObject,
68+
pub extensions: MakeCredentialsRequestExtensions,
6769
}

libwebauthn/src/ops/webauthn/get_assertion.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use super::idl::WebAuthnIDL;
2-
31
use std::{collections::HashMap, time::Duration};
42

53
use serde::{Deserialize, Serialize};
@@ -8,11 +6,6 @@ use tracing::{debug, error, trace};
86

97
use crate::{
108
fido::AuthenticatorData,
11-
ops::webauthn::{
12-
create::PublicKeyCredentialCreationOptionsJSON,
13-
idl::{FromInnerModel, JsonError},
14-
rpid::RelyingPartyId,
15-
},
169
pin::PinUvAuthProtocol,
1710
proto::ctap2::{
1811
Ctap2AttestationStatement, Ctap2GetAssertionResponseExtensions,

libwebauthn/src/ops/webauthn/idl.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::Deref;
2+
13
use base64_url;
24
use serde::{de::DeserializeOwned, Deserialize, Serialize};
35
use serde_json;
@@ -33,9 +35,29 @@ where
3335
}
3436

3537
// TODO(afresta): Move to ctap2 module.
36-
#[derive(Debug, Clone)]
38+
#[derive(Debug, Clone, PartialEq)]
3739
pub struct Base64UrlString(pub Vec<u8>);
3840

41+
impl From<Vec<u8>> for Base64UrlString {
42+
fn from(bytes: Vec<u8>) -> Self {
43+
Base64UrlString(bytes)
44+
}
45+
}
46+
47+
impl From<&[u8]> for Base64UrlString {
48+
fn from(bytes: &[u8]) -> Self {
49+
Base64UrlString(bytes.to_vec())
50+
}
51+
}
52+
53+
impl Deref for Base64UrlString {
54+
type Target = [u8];
55+
56+
fn deref(&self) -> &[u8] {
57+
&self.0
58+
}
59+
}
60+
3961
impl<'de> Deserialize<'de> for Base64UrlString {
4062
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
4163
where

0 commit comments

Comments
 (0)