Skip to content

Commit

Permalink
Configure large-blobs buffer size with feature flag
Browse files Browse the repository at this point in the history
The buffer size used in the response to the large-blobs command should
match the maximum message size of the FIDO2 implementation (minus 64).
At the same time, the buffer size must be hardcoded because
serde-indexed does not support const generics.  As a temporary
workaround, this patch changes the default buffer size to zero (to
reduce stack usage if the extension is not used) and sets the buffer
size to 3008 if the large-blobs feature is activated (matching the max
message size declared by usbd-ctaphid that is used in solo2 and
nitrokey-3-firmware).
  • Loading branch information
robin-nitrokey committed Nov 28, 2023
1 parent 02e8949 commit bc6a6cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for the `largeBlobKey` extension ([#18][])
- Remove `AuthenticatorDataFlags::EMPTY` (use `AuthenticatorDataFlags::empty()` instead)
- Allow missing algorithms in COSE keys ([#8][])
- Remove unused `REALISTIC_MAX_MESSAGE_SIZE` constant

[#8]: https://github.com/trussed-dev/ctap-types/pull/8
[#9]: https://github.com/solokeys/ctap-types/issues/9
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ quickcheck = "1.0.3"
serde = { version = "1" }

[features]
# enables support for implementing the large-blobs extension, see src/sizes.rs
large-blobs = []

log-all = ["cbor-smol/log-all"]
log-none = []

Expand Down
11 changes: 10 additions & 1 deletion src/sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ pub const THEORETICAL_MAX_MESSAGE_SIZE: usize = PACKET_SIZE - 7 + 128 * (PACKET_

/// Max length for a large blob fragment, according to
/// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#largeBlobsRW
pub const LARGE_BLOB_MAX_FRAGMENT_LENGTH: usize = 1200 - 64;
///
/// This constant determines the buffer size in [`ctap2::large_blobs::Response`][]. Ideally, this
/// would be configurable. Currently, this is not possible. To keep the stack usage low if the
/// extension is not used, this constant defaults to zero. For compatibility with the max message
/// size in usbd-ctaphid (used by solo2 and nitrokey-3-firmware), it is set to 3072 - 64 =
/// 3008 if the `large-blobs` feature is enabled.
#[cfg(not(feature = "large-blobs"))]
pub const LARGE_BLOB_MAX_FRAGMENT_LENGTH: usize = 0;
#[cfg(feature = "large-blobs")]
pub const LARGE_BLOB_MAX_FRAGMENT_LENGTH: usize = 3008;

0 comments on commit bc6a6cd

Please sign in to comment.