diff --git a/libjose/Cargo.toml b/libjose/Cargo.toml index c9f98eba65..2585c4b939 100644 --- a/libjose/Cargo.toml +++ b/libjose/Cargo.toml @@ -21,7 +21,7 @@ zeroize = { version = "1.2", default-features = false, features = ["zeroize_deri curve25519-dalek = { version = "3.0", default-features = false } num-bigint-dig = { version = "0.7", default-features = false } rand = { version = "0.8", default-features = false, features = ["getrandom"] } -rsa = { version = "0.4", default-features = false, features = ["pem", "std"] } +rsa = { version = "0.5", default-features = false, features = ["pem", "std"] } sha-1 = { version = "0.9", default-features = false } subtle = { version = "2.4", default-features = false } diff --git a/libjose/src/utils/crypto/key_repr.rs b/libjose/src/utils/crypto/key_repr.rs index 7fd765aa8c..b3f94c944e 100644 --- a/libjose/src/utils/crypto/key_repr.rs +++ b/libjose/src/utils/crypto/key_repr.rs @@ -15,9 +15,13 @@ use crate::jwk::JwkParamsOkp; use crate::jwk::JwkParamsRsa; use crate::lib::*; use crate::utils::decode_b64; +use rsa::pkcs1::FromRsaPrivateKey; +use rsa::pkcs1::FromRsaPublicKey; +use rsa::pkcs8::FromPrivateKey; +use rsa::pkcs8::FromPublicKey; -pub type RsaPublicKey = rsa::RSAPublicKey; -pub type RsaSecretKey = rsa::RSAPrivateKey; +pub type RsaPublicKey = rsa::RsaPublicKey; +pub type RsaSecretKey = rsa::RsaPrivateKey; pub type RsaUint = rsa::BigUint; pub type RsaPadding = rsa::PaddingScheme; @@ -104,9 +108,9 @@ impl<'a> Secret<'a> { pub fn to_rsa_public(self) -> Result { match self { - Secret::Arr(arr) => RsaPublicKey::from_pkcs1(arr) - .or_else(|_| RsaPublicKey::from_pkcs8(arr)) - .map_err(Into::into), + Secret::Arr(arr) => RsaPublicKey::from_pkcs1_der(arr) + .or_else(|_| RsaPublicKey::from_public_key_der(arr)) + .map_err(|err| rsa::errors::Error::from(err).into()), Secret::Jwk(jwk) => { let params: &JwkParamsRsa = jwk.try_rsa_params()?; let n: RsaUint = decode_rsa_uint(¶ms.n)?; @@ -120,9 +124,9 @@ impl<'a> Secret<'a> { #[allow(clippy::many_single_char_names)] pub fn to_rsa_secret(self) -> Result { match self { - Secret::Arr(arr) => RsaSecretKey::from_pkcs1(arr) - .or_else(|_| RsaSecretKey::from_pkcs8(arr)) - .map_err(Into::into), + Secret::Arr(arr) => RsaSecretKey::from_pkcs1_der(arr) + .or_else(|_| RsaSecretKey::from_pkcs8_der(arr)) + .map_err(|err| rsa::errors::Error::from(err).into()), Secret::Jwk(jwk) => { let params: &JwkParamsRsa = jwk.try_rsa_params()?;