Skip to content

Commit

Permalink
WIP: update RSA traits after updating to 0.6.0
Browse files Browse the repository at this point in the history
Signed-off-by: alt3r 3go <[email protected]>
  • Loading branch information
alt3r-3go committed Jul 17, 2022
1 parent 921b5b7 commit ecc399e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 9 additions & 5 deletions src/mechanisms/rsa2kpkcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rsa::{
RsaPrivateKey,
RsaPublicKey,
PublicKey,
pkcs8::{FromPrivateKey, ToPrivateKey, ToPublicKey}
pkcs8::{EncodePrivateKey, DecodePrivateKey, EncodePublicKey}
};

use crate::api::*;
Expand All @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ecc399e

Please sign in to comment.