From ecc399e1386aae1f3ee77e692e50cfc942acf971 Mon Sep 17 00:00:00 2001 From: alt3r 3go Date: Sun, 17 Jul 2022 13:59:07 +0200 Subject: [PATCH] WIP: update RSA traits after updating to 0.6.0 Signed-off-by: alt3r 3go --- Cargo.toml | 2 +- src/mechanisms/rsa2kpkcs.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a5baea242f6..5ca772a6078 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ des = { version = "0.7", optional = true } hmac = "0.11" sha-1 = { version = "0.9", default-features = false, optional = true } sha2 = { version = "0.9", default-features = false } -rsa = { version = "0.5.0", optional = true } +rsa = { version = "0.6.0", optional = true } # ours cosey = "0.3" diff --git a/src/mechanisms/rsa2kpkcs.rs b/src/mechanisms/rsa2kpkcs.rs index 8ee765382c9..9c4ab6b6e47 100644 --- a/src/mechanisms/rsa2kpkcs.rs +++ b/src/mechanisms/rsa2kpkcs.rs @@ -2,7 +2,7 @@ use rsa::{ RsaPrivateKey, RsaPublicKey, PublicKey, - pkcs8::{FromPrivateKey, ToPrivateKey, ToPublicKey} + pkcs8::{EncodePrivateKey, DecodePrivateKey, EncodePublicKey} }; use crate::api::*; @@ -12,6 +12,10 @@ use crate::error::Error; use crate::service::*; use crate::types::*; +//TODO:alt3r-3go: sign() and verify() are the only two methods that are actually different between -pkcs and -pss. +// Moreover, the key::Kind::Rsa2K could also probably be parametrized, instead of having a dedicated kind +// for each. Overall this means the class structure can probably be simplified - need to decide. + #[cfg(feature = "rsa2k-pkcs")] impl DeriveKey for super::Rsa2kPkcs { @@ -31,7 +35,7 @@ impl DeriveKey for super::Rsa2kPkcs // std::println!("Loaded key material: {}", delog::hex_str!(&priv_key_der)); // std::println!("Key material length is {}", priv_key_der.len()); - let priv_key = FromPrivateKey::from_pkcs8_der(&priv_key_der) + let priv_key = DecodePrivateKey::from_pkcs8_der(&priv_key_der) .expect("Failed to deserialize an RSA 2K private key from PKCS#8 DER"); // Derive and store public key @@ -66,7 +70,7 @@ impl DeserializeKey for super::Rsa2kPkcs return Err(Error::InternalError); } - let private_key: RsaPrivateKey = FromPrivateKey::from_pkcs8_der(&request.serialized_key) + let private_key: RsaPrivateKey = DecodePrivateKey::from_pkcs8_der(&request.serialized_key) .map_err(|_| Error::InvalidSerializedKey)?; // We store our keys in PKCS#8 DER format as well @@ -180,7 +184,7 @@ impl Sign for super::Rsa2kPkcs .expect("Failed to load an RSA 2K private key with the given ID") .material; - let priv_key: RsaPrivateKey = FromPrivateKey::from_pkcs8_der(&priv_key_der) + let priv_key: RsaPrivateKey = DecodePrivateKey::from_pkcs8_der(&priv_key_der) .expect("Failed to deserialize an RSA 2K private key from PKCS#8 DER"); // RSA lib takes in a hash value to sign, not raw data. @@ -230,7 +234,7 @@ impl Verify for super::Rsa2kPkcs .expect("Failed to load an RSA 2K private key with the given ID") .material; - let priv_key = FromPrivateKey::from_pkcs8_der(&priv_key_der) + let priv_key = DecodePrivateKey::from_pkcs8_der(&priv_key_der) .expect("Failed to deserialize an RSA 2K private key from PKCS#8 DER"); // Get the public key