From 683bd6a170f4a09cf626535a6ff009cdab969d72 Mon Sep 17 00:00:00 2001 From: Jordan Santell Date: Mon, 5 Jun 2023 12:00:43 -0700 Subject: [PATCH] chore: Update rsa to 0.9. --- ucan-key-support/Cargo.toml | 2 +- ucan-key-support/src/rsa.rs | 9 ++++----- ucan-key-support/src/web_crypto.rs | 9 ++------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/ucan-key-support/Cargo.toml b/ucan-key-support/Cargo.toml index 6074364e..9fb437c9 100644 --- a/ucan-key-support/Cargo.toml +++ b/ucan-key-support/Cargo.toml @@ -25,7 +25,7 @@ async-trait = "0.1" bs58 = "0.5" ed25519-zebra = "3.1" log = "0.4" -rsa = "0.8" +rsa = "0.9" p256 = "0.13" sha2 = { version = "0.10", features = ["oid"] } ucan = { path = "../ucan", version = "0.3.2" } diff --git a/ucan-key-support/src/rsa.rs b/ucan-key-support/src/rsa.rs index 914e066d..29219115 100644 --- a/ucan-key-support/src/rsa.rs +++ b/ucan-key-support/src/rsa.rs @@ -2,8 +2,8 @@ use anyhow::{anyhow, Result}; use async_trait::async_trait; use rsa::{ - pkcs1::{der::Encode, DecodeRsaPublicKey, EncodeRsaPublicKey}, - Pkcs1v15Sign, PublicKey, RsaPrivateKey, RsaPublicKey, + pkcs1::{DecodeRsaPublicKey, EncodeRsaPublicKey}, + Pkcs1v15Sign, RsaPrivateKey, RsaPublicKey, }; use sha2::{Digest, Sha256}; @@ -12,10 +12,9 @@ use ucan::crypto::{JwtSignatureAlgorithm, KeyMaterial}; pub use ucan::crypto::did::RSA_MAGIC_BYTES; pub fn bytes_to_rsa_key(bytes: Vec) -> Result> { - // NOTE: DID bytes are PKCS1, but we are using PKCS8, so do the conversion here.. println!("Trying to parse RSA key..."); - let public_key = rsa::pkcs1::RsaPublicKey::try_from(bytes.as_slice())?; - let public_key = RsaPublicKey::from_pkcs1_der(&public_key.to_vec()?)?; + // NOTE: DID bytes are PKCS1, but we store RSA keys as PKCS8 + let public_key = RsaPublicKey::from_pkcs1_der(&bytes)?; Ok(Box::new(RsaKeyMaterial(public_key, None))) } diff --git a/ucan-key-support/src/web_crypto.rs b/ucan-key-support/src/web_crypto.rs index c9d54ba3..4d1ea625 100644 --- a/ucan-key-support/src/web_crypto.rs +++ b/ucan-key-support/src/web_crypto.rs @@ -2,10 +2,7 @@ use crate::rsa::RsaKeyMaterial; use anyhow::{anyhow, Result}; use async_trait::async_trait; use js_sys::{Array, ArrayBuffer, Boolean, Object, Reflect, Uint8Array}; -use rsa::{ - pkcs1::{der::Encode, DecodeRsaPublicKey}, - RsaPublicKey, -}; +use rsa::{pkcs1::DecodeRsaPublicKey, RsaPublicKey}; use ucan::crypto::{JwtSignatureAlgorithm, KeyMaterial}; use wasm_bindgen::{JsCast, JsValue}; use wasm_bindgen_futures::JsFuture; @@ -129,9 +126,7 @@ impl KeyMaterial for WebCryptoRsaKeyMaterial { let public_key_bytes = public_key_bytes.to_vec(); let public_key_bytes = convert_spki_to_rsa_public_key(public_key_bytes.as_slice())?; - - let public_key = rsa::pkcs1::RsaPublicKey::try_from(public_key_bytes.as_slice())?; - let public_key = RsaPublicKey::from_pkcs1_der(&public_key.to_vec()?)?; + let public_key = RsaPublicKey::from_pkcs1_der(&public_key_bytes)?; Ok(RsaKeyMaterial(public_key, None).get_did().await?) }