Skip to content

Commit

Permalink
serializer: force serialization as array (iqlusioninc#546)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
baloo committed Jan 23, 2025
1 parent 12b25dd commit 6b7d726
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/wrap/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ impl Plaintext {

/// Return the rsa key of this [`Plaintext`] if it was an RSA key.
pub fn rsa(&self) -> Option<RsaPrivateKey> {
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,
};

Expand All @@ -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");

Expand Down

0 comments on commit 6b7d726

Please sign in to comment.