Skip to content

Commit

Permalink
Private base64 field (#433)
Browse files Browse the repository at this point in the history
* Remove usage of the inner fields of Base64UrlSafeData, in favour of using Deref/Borrow/etc.

* fix formatting

* fixup win10

* Remove dependency on base64urlsafedata string formatting, fixup some mozilla issues

* Base64UrlSafeData: remove FromStr and Display impl

* fixup win10

* Updated

* Wrap up

* key manager

* CI

---------

Co-authored-by: Michael Farrell <micolous+git@gmail.com>
  • Loading branch information
Firstyear and micolous authored Apr 25, 2024
1 parent e7cf209 commit e7d7cef
Show file tree
Hide file tree
Showing 48 changed files with 533 additions and 537 deletions.
4 changes: 2 additions & 2 deletions attestation-ca/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct AttestationCa {
impl Into<SerialisableAttestationCa> for AttestationCa {
fn into(self) -> SerialisableAttestationCa {
SerialisableAttestationCa {
ca: Base64UrlSafeData(self.ca.to_der().expect("Invalid DER")),
ca: Base64UrlSafeData::from(self.ca.to_der().expect("Invalid DER")),
aaguids: self.aaguids,
blanket_allow: self.blanket_allow,
}
Expand All @@ -69,7 +69,7 @@ impl TryFrom<SerialisableAttestationCa> for AttestationCa {

fn try_from(data: SerialisableAttestationCa) -> Result<Self, Self::Error> {
Ok(AttestationCa {
ca: x509::X509::from_der(&data.ca.0)?,
ca: x509::X509::from_der(data.ca.as_slice())?,
aaguids: data.aaguids,
blanket_allow: data.blanket_allow,
})
Expand Down
2 changes: 1 addition & 1 deletion base64urlsafedata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "base64urlsafedata"
version = "0.1.3"
version = "0.2.0"
authors = ["William Brown <william@blackhats.net.au>"]
edition = "2021"
rust-version = "1.70.0"
Expand Down
6 changes: 6 additions & 0 deletions base64urlsafedata/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ macro_rules! common_impls {
}
}

impl AsMut<[u8]> for $type {
fn as_mut(&mut self) -> &mut [u8] {
&mut self.0
}
}

macro_rules! partial_eq_impl {
($other:ty) => {
impl PartialEq<$other> for $type {
Expand Down
21 changes: 1 addition & 20 deletions base64urlsafedata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static ALLOWED_DECODING_FORMATS: &[GeneralPurpose] =
/// [0]: https://docs.rs/serde/latest/serde/trait.Serializer.html#method.is_human_readable
/// [sec5]: https://datatracker.ietf.org/doc/html/rfc4648#section-5
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub struct Base64UrlSafeData(pub Vec<u8>);
pub struct Base64UrlSafeData(Vec<u8>);

common_impls!(Base64UrlSafeData);

Expand All @@ -141,25 +141,6 @@ impl PartialEq<HumanBinaryData> for Base64UrlSafeData {
}
}

impl fmt::Display for Base64UrlSafeData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", URL_SAFE_NO_PAD.encode(self))
}
}

impl TryFrom<&str> for Base64UrlSafeData {
type Error = ();

fn try_from(v: &str) -> Result<Self, Self::Error> {
for config in ALLOWED_DECODING_FORMATS {
if let Ok(data) = config.decode(v) {
return Ok(Base64UrlSafeData(data));
}
}
Err(())
}
}

impl Serialize for Base64UrlSafeData {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
6 changes: 0 additions & 6 deletions base64urlsafedata/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use super::*;

#[test]
fn test_try_from() {
assert!(Base64UrlSafeData::try_from("aGVsbG8=").is_ok());
assert!(Base64UrlSafeData::try_from("abcdefghij").is_err());
}

macro_rules! from_json_test {
($($name:ident: $value:expr,)*) => {
$(
Expand Down
9 changes: 5 additions & 4 deletions compat_tester/webauthn-rs-demo-shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "core")]
use webauthn_rs_core::error::WebauthnError;

pub use webauthn_rs_core::proto::CredentialID;
pub use webauthn_rs_proto::{
AttestationConveyancePreference, AuthenticationExtensions, AuthenticatorAttachment,
COSEAlgorithm, CreationChallengeResponse, CredProtect, CredentialID,
CredentialProtectionPolicy, ExtnState, Mediation, PublicKeyCredential,
RegisterPublicKeyCredential, RegisteredExtensions, RequestAuthenticationExtensions,
RequestChallengeResponse, RequestRegistrationExtensions, UserVerificationPolicy,
COSEAlgorithm, CreationChallengeResponse, CredProtect, CredentialProtectionPolicy, ExtnState,
Mediation, PublicKeyCredential, RegisterPublicKeyCredential, RegisteredExtensions,
RequestAuthenticationExtensions, RequestChallengeResponse, RequestRegistrationExtensions,
UserVerificationPolicy,
};

#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
Expand Down
6 changes: 3 additions & 3 deletions compat_tester/webauthn-rs-demo/pkg/webauthn_rs_demo_wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export interface InitOutput {
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly wasm_bindgen__convert__closures__invoke1_mut_ref__hfc527fb71bcc8311: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hc2ee46a1a9a1b672: (a: number, b: number, c: number) => void;
readonly wasm_bindgen__convert__closures__invoke1_mut__h94a0c3ab6366c6f7: (a: number, b: number, c: number) => void;
readonly wasm_bindgen__convert__closures__invoke1_mut_ref__h015a6d4beac911b9: (a: number, b: number, c: number) => void;
readonly wasm_bindgen__convert__closures__invoke1__h9385f9b96e74d99b: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hcb3dcc208685cd98: (a: number, b: number, c: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_exn_store: (a: number) => void;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
Expand Down
Loading

0 comments on commit e7d7cef

Please sign in to comment.