From 6b7d726249d05dd5a9d03ad0adc9ac4a21ee7a5c Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Fri, 28 Jun 2024 17:51:28 +0000 Subject: [PATCH] serializer: force serialization as array (#546) The implementation of array deserializer expects the payload to be serialized as array. Sadly the serializer left the door open for the underlying serializer to choice either bytes or array, if available. This would only occur when the objects are used outside yubihsm.rs. This change was tested on both mockhsm and yubihsm on usb. rsa: when wrapped, the private does not carry the modulus --- src/wrap/message.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/wrap/message.rs b/src/wrap/message.rs index 9005acc0..6f6f5466 100644 --- a/src/wrap/message.rs +++ b/src/wrap/message.rs @@ -149,10 +149,10 @@ impl Plaintext { /// Return the rsa key of this [`Plaintext`] if it was an RSA key. pub fn rsa(&self) -> Option { - let (component_size, modulus_size) = match self.object_info.algorithm { - algorithm::Algorithm::Asymmetric(asymmetric::Algorithm::Rsa2048) => (128, 256), - algorithm::Algorithm::Asymmetric(asymmetric::Algorithm::Rsa3072) => (192, 384), - algorithm::Algorithm::Asymmetric(asymmetric::Algorithm::Rsa4096) => (256, 512), + let component_size = match self.object_info.algorithm { + algorithm::Algorithm::Asymmetric(asymmetric::Algorithm::Rsa2048) => 128, + algorithm::Algorithm::Asymmetric(asymmetric::Algorithm::Rsa3072) => 192, + algorithm::Algorithm::Asymmetric(asymmetric::Algorithm::Rsa4096) => 256, _ => return None, }; @@ -163,7 +163,6 @@ impl Plaintext { let _dp = BigUint::from_bytes_be(reader.read(component_size)?); let _dq = BigUint::from_bytes_be(reader.read(component_size)?); let _qinv = BigUint::from_bytes_be(reader.read(component_size)?); - let _n = BigUint::from_bytes_be(reader.read(modulus_size)?); const EXP: u64 = 65537; let e = BigUint::from_u64(EXP).expect("invalid static exponent");