-
Notifications
You must be signed in to change notification settings - Fork 129
Update webauthn-rs 6.0 to use crypto-glue 2.0 #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Firstyear
wants to merge
5
commits into
kanidm:6.0-dev-drop-openssl
Choose a base branch
from
Firstyear:20260825-update-glue
base: 6.0-dev-drop-openssl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -3,14 +3,14 @@ | |||
| use crate::stubs::*; | ||||
|
|
||||
| use crypto_glue::{ | ||||
| block_padding::generic_array::{ | ||||
| sequence::Split, | ||||
| block_padding::array::{ | ||||
| // sequence::Split, | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| typenum::{U32, U64}, | ||||
| GenericArray, | ||||
| Array, | ||||
| }, | ||||
| ecdh_p256::{self, EcdhP256EphemeralSecret}, | ||||
| hmac_s256::{self, HmacSha256Key}, | ||||
| rand::{rngs::ThreadRng, RngCore}, | ||||
| rand::{self, Rng}, | ||||
| traits::Zeroizing, | ||||
| }; | ||||
| use num_traits::ToPrimitive; | ||||
|
|
@@ -30,11 +30,11 @@ type QrSecret = [u8; 16]; | |||
|
|
||||
| /// Two concatenated [`Aes256Key`s][crypto_glue::aes256::Aes256Key], the encryption key and signing | ||||
| /// key. | ||||
| type EidKey = Zeroizing<GenericArray<u8, U64>>; | ||||
| type EidKey = Zeroizing<Array<u8, U64>>; | ||||
|
|
||||
| /// Alias for a non-[`Zeroizing`][] form of [`Aes256Key`][crypto_glue::aes256::Aes256Key], used to | ||||
| /// reassure Rust's type checker. | ||||
| type NonZeroingAes256Key = GenericArray<u8, U32>; | ||||
| type NonZeroingAes256Key = Array<u8, U32>; | ||||
|
|
||||
| type CableEid = [u8; 16]; | ||||
| type TunnelId = [u8; 16]; | ||||
|
|
@@ -77,8 +77,8 @@ impl Discovery { | |||
| pub fn new(request_type: CableRequestType) -> Result<Self, WebauthnCError> { | ||||
| // chrome_authenticator_request_delegate.cc ChromeAuthenticatorRequestDelegate::ConfigureCable | ||||
| let mut qr_secret: QrSecret = [0; size_of::<QrSecret>()]; | ||||
| let mut rng = ThreadRng::default(); | ||||
| rng.try_fill_bytes(&mut qr_secret)?; | ||||
| let mut rng = rand::rng(); | ||||
| rng.fill_bytes(&mut qr_secret); | ||||
| Self::new_with_qr_secret(request_type, qr_secret) | ||||
| } | ||||
|
|
||||
|
|
@@ -214,9 +214,9 @@ pub struct Eid { | |||
| impl Eid { | ||||
| /// Creates a new [Eid] using a random nonce. | ||||
| pub fn new(tunnel_server_id: u16, routing_id: RoutingId) -> Result<Self, WebauthnCError> { | ||||
| let mut rng = ThreadRng::default(); | ||||
| let mut rng = rand::rng(); | ||||
| let mut nonce: BleNonce = [0; size_of::<BleNonce>()]; | ||||
| rng.try_fill_bytes(&mut nonce)?; | ||||
| rng.fill_bytes(&mut nonce); | ||||
|
|
||||
| Ok(Self { | ||||
| tunnel_server_id, | ||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -11,14 +11,14 @@ use crate::stubs::*; | |||
| use crypto_glue::{ | ||||
| aes256::Aes256Key, | ||||
| aes256gcm::{Aes256Gcm, Aes256GcmNonce}, | ||||
| block_padding::generic_array::{ | ||||
| sequence::Split, | ||||
| block_padding::array::{ | ||||
| // sequence::Split, | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| typenum::{U16, U32, U64, U96}, | ||||
| GenericArray, | ||||
| Array, | ||||
| }, | ||||
| ecdh_p256::{self, EcdhP256EphemeralSecret, EcdhP256PublicKey}, | ||||
| s256::Sha256Output, | ||||
| traits::{AeadInPlace, KeyInit, ToEncodedPoint as _, Zeroizing}, | ||||
| traits::{AeadInOut, KeyInit, ToSec1Point as _, Zeroizing}, | ||||
| }; | ||||
| use std::mem::size_of; | ||||
|
|
||||
|
|
@@ -121,8 +121,10 @@ impl CipherState { | |||
|
|
||||
| let cipher = Aes256Gcm::new(key); | ||||
| // trace!("encrypting: {:?}", hex::encode(&buf[..padded_len])); | ||||
|
|
||||
| let work = &mut buf[..padded_len]; | ||||
| let tag = cipher | ||||
| .encrypt_in_place_detached(&nonce, aad, &mut buf[..padded_len]) | ||||
| .encrypt_inout_detached(&nonce, aad, work.into()) | ||||
| .map_err(|_| WebauthnCError::CryptographyAeadError)?; | ||||
| // trace!( | ||||
| // "encrypted: {:?}, tag: {:?}, nonce: {:?}, aad: {:?}, key: {:?}", | ||||
|
|
@@ -158,14 +160,16 @@ impl CipherState { | |||
|
|
||||
| let msg_len = buf.len() - 16; | ||||
| let (ct, tag) = buf.split_at_mut(msg_len); | ||||
| let tag: &mut GenericArray<u8, U16> = tag.into(); | ||||
| let tag: &mut Array<u8, U16> = tag | ||||
| .try_into() | ||||
| .map_err(|_| WebauthnCError::CryptographyAeadError)?; | ||||
|
|
||||
| let nonce = self.construct_nonce(); | ||||
|
|
||||
| let cipher = Aes256Gcm::new(key); | ||||
|
|
||||
| if cipher | ||||
| .decrypt_in_place_detached(&nonce, aad, ct, tag) | ||||
| .decrypt_inout_detached(&nonce, aad, ct.into(), tag) | ||||
| .is_err() | ||||
| { | ||||
| // error!( | ||||
|
|
@@ -233,7 +237,7 @@ impl CipherState { | |||
| /// | ||||
| /// [SymmetricState]: https://noiseprotocol.org/noise.html#the-symmetricstate-object | ||||
| pub struct CableNoise { | ||||
| ck: Zeroizing<GenericArray<u8, U32>>, | ||||
| ck: Zeroizing<Array<u8, U32>>, | ||||
| h: Sha256Output, | ||||
|
|
||||
| cipher_state: CipherState, | ||||
|
|
@@ -269,23 +273,23 @@ impl CableNoise { | |||
| } | ||||
|
|
||||
| fn mix_hash_point(&mut self, point: &EcdhP256PublicKey) -> Result<(), WebauthnCError> { | ||||
| let point = point.to_encoded_point(false); | ||||
| let point = point.to_sec1_point(false); | ||||
| // trace!("mix_hash_point(point={:?})", hex::encode(point.as_bytes())); | ||||
| self.mix_hash(point.as_bytes()); | ||||
| Ok(()) | ||||
| } | ||||
|
|
||||
| /// `SymmetricState.MixKey(input_key_material)` | ||||
| fn mix_key(&mut self, ikm: &[u8]) -> Result<(), WebauthnCError> { | ||||
| let mut o: Zeroizing<GenericArray<u8, U64>> = Default::default(); | ||||
| let mut o: Zeroizing<Array<u8, U64>> = Default::default(); | ||||
| hkdf_sha_256(&self.ck, ikm, None, &mut o)?; | ||||
| // trace!( | ||||
| // "mix_key(ikm={:?}) => hkdf(salt={:?}, output={:?})", | ||||
| // hex::encode(&ikm), | ||||
| // hex::encode(&self.ck), | ||||
| // hex::encode(&o), | ||||
| // ); | ||||
| let (ck, temp_k): (GenericArray<u8, U32>, _) = o.split(); | ||||
| let (ck, temp_k): (Array<u8, U32>, _) = o.split(); | ||||
| self.ck.copy_from_slice(&ck); | ||||
| self.cipher_state.init_key(temp_k.into()); | ||||
| Ok(()) | ||||
|
|
@@ -294,16 +298,16 @@ impl CableNoise { | |||
| /// `SymmetricState.MixKeyAndHash(input_key_material)` | ||||
| fn mix_key_and_hash(&mut self, ikm: &[u8]) -> Result<(), WebauthnCError> { | ||||
| // https://source.chromium.org/chromium/chromium/src/+/main:device/fido/cable/noise.cc;l=90;drc=38321ee39cd73ac2d9d4400c56b90613dee5fe29 | ||||
| let mut o: Zeroizing<GenericArray<u8, U96>> = Default::default(); | ||||
| let mut o: Zeroizing<Array<u8, U96>> = Default::default(); | ||||
| hkdf_sha_256(&self.ck, ikm, None, &mut o)?; | ||||
| // trace!( | ||||
| // "mix_key_and_hash(ikm={:?}) => hkdf(salt={:?}, output={:?})", | ||||
| // hex::encode(&ikm), | ||||
| // hex::encode(&self.ck), | ||||
| // hex::encode(&o), | ||||
| // ); | ||||
| let (ck, temp): (GenericArray<u8, U32>, _) = o.split(); | ||||
| let (temp_h, temp_k): (GenericArray<u8, U32>, GenericArray<u8, U32>) = temp.split(); | ||||
| let (ck, temp): (Array<u8, U32>, _) = o.split(); | ||||
| let (temp_h, temp_k): (Array<u8, U32>, Array<u8, U32>) = temp.split(); | ||||
|
|
||||
| self.ck.copy_from_slice(&ck); | ||||
| self.mix_hash(&temp_h); | ||||
|
|
@@ -333,7 +337,7 @@ impl CableNoise { | |||
| /// further transport messages. `write_key` is for messages sent by the | ||||
| /// initiator, `read_key` is for messages sent by the authenticator. | ||||
| fn traffic_keys(&self) -> Result<(EncryptionKey, EncryptionKey), WebauthnCError> { | ||||
| let mut o: Zeroizing<GenericArray<u8, U64>> = Default::default(); | ||||
| let mut o: Zeroizing<Array<u8, U64>> = Default::default(); | ||||
| hkdf_sha_256(&self.ck, &[], None, &mut o)?; | ||||
|
|
||||
| let (a, b) = o.split(); | ||||
|
|
@@ -342,7 +346,7 @@ impl CableNoise { | |||
|
|
||||
| fn get_ephemeral_key_public_bytes(&self) -> Result<[u8; 65], WebauthnCError> { | ||||
| let mut o = [0; 65]; | ||||
| let point = self.ephemeral_key.public_key().to_encoded_point(false); | ||||
| let point = self.ephemeral_key.public_key().to_sec1_point(false); | ||||
| if point.len() != o.len() { | ||||
| error!( | ||||
| "unexpected public key length {} != {}", | ||||
|
|
@@ -641,7 +645,7 @@ mod test { | |||
| let cipher = Aes256Gcm::new(&Default::default()); | ||||
| let mut buf = vec![]; | ||||
| let tag = cipher | ||||
| .encrypt_in_place_detached(&[0u8; 12].into(), &[0], &mut buf) | ||||
| .encrypt_inout_detached(&[0u8; 12].into(), &[0], buf.as_mut_slice().into()) | ||||
| .unwrap(); | ||||
|
|
||||
| warn!("our empty tag was: {}", hex::encode(tag)); | ||||
|
|
@@ -650,7 +654,7 @@ mod test { | |||
| let cipher = Aes256Gcm::new(&Default::default()); | ||||
| let mut buf = vec![]; | ||||
| cipher | ||||
| .decrypt_in_place_detached(&[0u8; 12].into(), &[0], &mut buf, &tag) | ||||
| .decrypt_inout_detached(&[0u8; 12].into(), &[0], buf.as_mut_slice().into(), &tag) | ||||
| .unwrap(); | ||||
| } | ||||
|
|
||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.