-
Notifications
You must be signed in to change notification settings - Fork 19
Hybrid transport: Add state-assisted transactions #100
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aa45a26
Hybrid transport: Add state-assisted transactions (WiP)
AlfioEmanueleFresta a46798d
Decouple CableChannel from CableDevice implementations
AlfioEmanueleFresta f860475
Known device advertisement
AlfioEmanueleFresta dcd7ad2
Fix ClientPayload serialization; Add ClientPayloadHint
AlfioEmanueleFresta 1003628
Fix typo
AlfioEmanueleFresta 8c68e66
Keep track of noise handshake hash
AlfioEmanueleFresta 64d5b9a
Verify signature on linking info
AlfioEmanueleFresta 6625f7b
Address review comments
AlfioEmanueleFresta 3cff871
Update README.md
AlfioEmanueleFresta 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| use ::btleplug::api::Central; | ||
| use futures::StreamExt; | ||
| use std::pin::pin; | ||
| use tracing::{debug, trace, warn}; | ||
| use uuid::Uuid; | ||
|
|
||
| use crate::transport::ble::btleplug::{self, FidoDevice}; | ||
| use crate::transport::cable::crypto::trial_decrypt_advert; | ||
| use crate::webauthn::{Error, TransportError}; | ||
|
|
||
| const CABLE_UUID_FIDO: &str = "0000fff9-0000-1000-8000-00805f9b34fb"; | ||
| const CABLE_UUID_GOOGLE: &str = "0000fde2-0000-1000-8000-00805f9b34fb"; | ||
|
|
||
| #[derive(Debug)] | ||
| pub(crate) struct DecryptedAdvert { | ||
| pub plaintext: [u8; 16], | ||
| pub nonce: [u8; 10], | ||
| pub routing_id: [u8; 3], | ||
| pub encoded_tunnel_server_domain: u16, | ||
| } | ||
|
|
||
| impl From<[u8; 16]> for DecryptedAdvert { | ||
| fn from(plaintext: [u8; 16]) -> Self { | ||
| let mut nonce = [0u8; 10]; | ||
| nonce.copy_from_slice(&plaintext[1..11]); | ||
AlfioEmanueleFresta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let mut routing_id = [0u8; 3]; | ||
| routing_id.copy_from_slice(&plaintext[11..14]); | ||
| let encoded_tunnel_server_domain = u16::from_le_bytes([plaintext[14], plaintext[15]]); | ||
| let mut plaintext_fixed = [0u8; 16]; | ||
| plaintext_fixed.copy_from_slice(&plaintext[..16]); | ||
| Self { | ||
| plaintext: plaintext_fixed, | ||
| nonce, | ||
| routing_id, | ||
| encoded_tunnel_server_domain, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub(crate) async fn await_advertisement( | ||
| eid_key: &[u8], | ||
| ) -> Result<(FidoDevice, DecryptedAdvert), Error> { | ||
| let uuids = &[ | ||
| Uuid::parse_str(CABLE_UUID_FIDO).unwrap(), | ||
| Uuid::parse_str(CABLE_UUID_GOOGLE).unwrap(), // Deprecated, but may still be in use. | ||
| ]; | ||
| let stream = btleplug::manager::start_discovery_for_service_data(uuids) | ||
| .await | ||
| .or(Err(Error::Transport(TransportError::TransportUnavailable)))?; | ||
|
|
||
| let mut stream = pin!(stream); | ||
| while let Some((adapter, peripheral, data)) = stream.as_mut().next().await { | ||
| debug!({ ?peripheral, ?data }, "Found device with service data"); | ||
|
|
||
| let Some(device) = btleplug::manager::get_device(peripheral.clone()) | ||
| .await | ||
| .or(Err(Error::Transport(TransportError::TransportUnavailable)))? | ||
| else { | ||
| warn!( | ||
| ?peripheral, | ||
| "Unable to fetch peripheral properties, ignoring" | ||
| ); | ||
| continue; | ||
| }; | ||
|
|
||
| trace!(?device, ?data, ?eid_key); | ||
| let Some(decrypted) = trial_decrypt_advert(&eid_key, &data) else { | ||
| warn!(?device, "Trial decrypt failed, ignoring"); | ||
| continue; | ||
| }; | ||
| trace!(?decrypted); | ||
|
|
||
| let advert = DecryptedAdvert::from(decrypted); | ||
| debug!( | ||
| ?device, | ||
| ?decrypted, | ||
| "Successfully decrypted advertisement from device" | ||
| ); | ||
|
|
||
| adapter | ||
| .stop_scan() | ||
| .await | ||
| .or(Err(Error::Transport(TransportError::TransportUnavailable)))?; | ||
|
|
||
| return Ok((device, advert)); | ||
| } | ||
|
|
||
| warn!("BLE advertisement discovery stream terminated"); | ||
| Err(Error::Transport(TransportError::TransportUnavailable)) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.