From 7d4ad69e64ad308944c012aef5b9cfd7654d9be8 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 28 Nov 2023 20:19:39 +0100 Subject: [PATCH] Configure large-blobs buffer size with feature flag 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). --- CHANGELOG.md | 1 + Cargo.toml | 3 +++ src/sizes.rs | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b30bfa2..e262809 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 66fae2d..525536b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [] diff --git a/src/sizes.rs b/src/sizes.rs index 06b1419..8b440ff 100644 --- a/src/sizes.rs +++ b/src/sizes.rs @@ -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;