From 4a12b458c9368712f360eece84b6ffcc8230ef0a Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 7 Jun 2022 18:55:59 +0800 Subject: [PATCH] seems like the DH key exchange is broken somehow? needs more digging. i've extracted the key parameters from the test suite and confirmed that that the hash value is computed correctly on their side. i've also confirmed that the hash value is computed correctly from the locally computed key. so what's gone wrong is the devired secret key doesn't match what's on the other side. possible issues could be either a PK serialization issue, or something wrong in the DH exchange itself. --- Cargo.lock | 1 + apps/vault/src/ctap/pin_protocol_v1.rs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 335ee9369..9038db236 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -728,6 +728,7 @@ dependencies = [ "cbc", "cbor", "hex 0.3.2", + "log", "p256", "rand 0.8.5", "rand_chacha 0.3.1", diff --git a/apps/vault/src/ctap/pin_protocol_v1.rs b/apps/vault/src/ctap/pin_protocol_v1.rs index e8f23a91b..e7256814d 100644 --- a/apps/vault/src/ctap/pin_protocol_v1.rs +++ b/apps/vault/src/ctap/pin_protocol_v1.rs @@ -249,9 +249,9 @@ impl PinProtocolV1 { pin_auth: &[u8], authenticated_message: &[u8], ) -> Result<[u8; 32], Ctap2StatusCode> { - log::info!("cosekey: {:?}", key_agreement); let pk: ctap_crypto::ecdh::PubKey = CoseKey::try_into(key_agreement)?; - log::info!("pk: {:?}", pk); + log::info!("CONS pk: {:?}", pk); + log::info!("CHECK pk: {:?}", self.key_agreement_key.genpk()); let shared_secret = self.key_agreement_key.exchange_x_sha256(&pk); log::info!("shared_secret: {:?}", shared_secret); @@ -278,6 +278,7 @@ impl PinProtocolV1 { fn process_get_key_agreement(&self) -> Result { let pk = self.key_agreement_key.genpk(); + log::info!("GEN pk: {:?}", pk); Ok(AuthenticatorClientPinResponse { key_agreement: Some(CoseKey::from(pk)), pin_token: None, @@ -293,7 +294,7 @@ impl PinProtocolV1 { new_pin_enc: Vec, ) -> Result<(), Ctap2StatusCode> { if persistent_store.pin_hash()?.is_some() { - log::info!("pin_hash() is_some()"); + log::debug!("pin_hash() is_some()"); return Err(Ctap2StatusCode::CTAP2_ERR_PIN_AUTH_INVALID); } let pin_decryption_key =