Skip to content
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

Serialize credential with fields names using only 1 bytes #59

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

sosthene-nitrokey
Copy link

This saves space when serializing credentials.

We cannot use #[serde(remote)] because that would require supporting #[serde(with)] in serde_indexed, already used for CredentialData

This replaces #58 it should be 1 bytes larger per serialized fields, but is better than serde-indexed as it has les risks to break accidentally when adding/removing a field.

Copy link
Member

@robin-nitrokey robin-nitrokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some artifacts from the previous implementation using serde-indexed to be removed/updated.

Cargo.toml Outdated
@@ -76,9 +77,11 @@ ctap-types = { git = "https://github.com/trussed-dev/ctap-types.git", rev = "72e
ctaphid-dispatch = { git = "https://github.com/trussed-dev/ctaphid-dispatch.git", rev = "57cb3317878a8593847595319aa03ef17c29ec5b" }
apdu-dispatch = { git = "https://github.com/trussed-dev/apdu-dispatch.git", rev = "915fc237103fcecc29d0f0b73391f19abf6576de" }
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "2b45a7559ff44260c6dd693e4cb61f54ae5efc53" }
serde-indexed = { git = "https://github.com/sosthene-nitrokey/serde-indexed.git", rev = "5005d23cb4ee8622e62188ea0f9466146f851f0d" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this PR does not use serde-indexed (anymore). Can we remove the patch?

@@ -205,15 +205,105 @@ impl Credential {
}
}

/// Copy of [`ctap_types::webauthn::PublicKeyCredentialUserEntity`] but with `serde_indexed` serialization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Copy of [`ctap_types::webauthn::PublicKeyCredentialUserEntity`] but with `serde_indexed` serialization
/// Copy of [`ctap_types::webauthn::PublicKeyCredentialUserEntity`] but with shorter field names for serialization

}
}

/// Copy of [`ctap_types::webauthn::PublicKeyCredentialUserEntity`] but with `serde_indexed` serialization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Copy of [`ctap_types::webauthn::PublicKeyCredentialUserEntity`] but with `serde_indexed` serialization
/// Copy of [`ctap_types::webauthn::PublicKeyCredentialUserEntity`] but with shorter field names for serialization


/// Copy of [`ctap_types::webauthn::PublicKeyCredentialUserEntity`] but with `serde_indexed` serialization
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct LocalPublicKeyCredentialUserEntity {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move struct definition above the impls

@@ -724,6 +810,308 @@ mod test {
});
}

#[test]
fn indexed_derive_rp_name_none() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/indexed_derive/local/, also for the other tests

CHANGELOG.md Outdated
@@ -37,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#61]: https://github.com/Nitrokey/fido-authenticator/pull/61
[#62]: https://github.com/Nitrokey/fido-authenticator/pull/62
[#63]: https://github.com/Nitrokey/fido-authenticator/pull/63
[#59]: ttps://github.com/Nitrokey/fido-authenticator/issues/59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ttps/https/

@sosthene-nitrokey sosthene-nitrokey merged commit 0fdecc9 into main Aug 1, 2024
3 checks passed
robin-nitrokey added a commit that referenced this pull request Dec 2, 2024
In #59, we changed the format for serialized credentials to use shorter
field names for the RP and user entities.  This has an unintended side
effect:  For non-discoverable credentials that were generated with older
crate versions, the stripped data embedded into the credential ID
includes the RP and user.  If we change their serialization format, we
also change these credential IDs.

We already supported deserializing both formats using a serde alias.
This patch introduces helper enums that deserialize both formats using a
custom Deserialize implementation and keep track of the used format.
This format is then also used for serialization (using serde’s untagged
mechanism that is not available for deserialization in no-std contexts).

#59

Fixes: #111
robin-nitrokey added a commit that referenced this pull request Dec 2, 2024
In #59, we changed the format for serialized credentials to use shorter
field names for the RP and user entities.  This has an unintended side
effect:  For non-discoverable credentials that were generated with older
crate versions, the stripped data embedded into the credential ID
includes the RP and user.  If we change their serialization format, we
also change these credential IDs.

We already supported deserializing both formats using a serde alias.
This patch introduces helper enums that deserialize both formats using a
custom Deserialize implementation and keep track of the used format.
This format is then also used for serialization (using serde’s untagged
mechanism that is not available for deserialization in no-std contexts).

#59

Fixes: #111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants