From 92fef529c0d695400958daffa7ed645a0b62bf8e Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Fri, 7 Jul 2023 19:12:47 +0200 Subject: [PATCH] Send empty response to clientPin instead of empty map For the SetPin and ChangePin subcommands, the clientPin command does not return any parameters. Previously, we sent an empty map for these cases. With this patch, we sent an empty response instead. Fixes: https://github.com/solokeys/ctap-types/issues/13 --- CHANGELOG.md | 2 ++ src/ctap2.rs | 8 +++++++- src/ctap2/client_pin.rs | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1877372..ccca22b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rename `url` to `icon` in `PublicKeyCredentialRpEntity` and ignore its content ([#9][]) - Truncate overlong `name` and `displayName` values for `PublicKeyCredentialEntity` instances ([#30][]) +- Send empty response to clientPin instead of empty map ([#13][]) [#9]: https://github.com/solokeys/ctap-types/issues/9 [#30]: https://github.com/solokeys/fido-authenticator/issues/30 +[#13]: https://github.com/solokeys/ctap-types/issues/13 ## [0.1.2] - 2022-03-07 diff --git a/src/ctap2.rs b/src/ctap2.rs index 0301bac..87a98c5 100644 --- a/src/ctap2.rs +++ b/src/ctap2.rs @@ -148,7 +148,13 @@ impl Response { let outcome = match self { GetInfo(response) => cbor_serialize(response, data), MakeCredential(response) => cbor_serialize(response, data), - ClientPin(response) => cbor_serialize(response, data), + ClientPin(response) => { + if response.is_empty() { + Ok([].as_slice()) + } else { + cbor_serialize(response, data) + } + }, GetAssertion(response) | GetNextAssertion(response) => cbor_serialize(response, data), CredentialManagement(response) => cbor_serialize(response, data), Reset | Selection | Vendor => Ok([].as_slice()), diff --git a/src/ctap2/client_pin.rs b/src/ctap2/client_pin.rs index b74c3b4..22bdf3a 100644 --- a/src/ctap2/client_pin.rs +++ b/src/ctap2/client_pin.rs @@ -73,6 +73,12 @@ pub struct Response { pub retries: Option, } +impl Response { + pub fn is_empty(&self) -> bool { + self.key_agreement.is_none() && self.pin_token.is_none() && self.retries.is_none() + } +} + #[cfg(test)] mod tests {