1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore: Upgrade RSA to 0.5.0 (#11589)

This commit is contained in:
Divy Srivastava 2021-08-06 13:40:50 +05:30 committed by GitHub
parent 728d205d9d
commit b6b71c3d59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 86 additions and 61 deletions

116
Cargo.lock generated
View file

@ -377,6 +377,12 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "const-oid"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c32f031ea41b4291d695026c023b95d59db2d8a2c7640800ed56bc8f510f22"
[[package]]
name = "convert_case"
version = "0.4.0"
@ -464,6 +470,17 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "crypto-bigint"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b32a398eb1ccfbe7e4f452bc749c44d38dd732e9a253f19da224c416f00ee7f4"
dependencies = [
"generic-array",
"rand_core 0.6.3",
"subtle",
]
[[package]]
name = "d3d12"
version = "0.4.0"
@ -884,6 +901,16 @@ dependencies = [
"serde",
]
[[package]]
name = "der"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f215f706081a44cb702c71c39a52c05da637822e9c1645a50b7202689e982d"
dependencies = [
"const-oid",
"crypto-bigint",
]
[[package]]
name = "derive_more"
version = "0.99.16"
@ -991,7 +1018,7 @@ checksum = "9a9591846b69e7c62879e3f9dc02d5ebd0fcc2868a96ba9bbb9b6bc304e02dee"
dependencies = [
"bumpalo",
"fnv",
"num-bigint 0.2.6",
"num-bigint",
"swc_atoms",
"swc_common",
"swc_ecmascript",
@ -2241,17 +2268,6 @@ dependencies = [
"serde",
]
[[package]]
name = "num-bigint"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e0d047c1062aa51e256408c560894e5251f08925980e53cf1aa5bd00eec6512"
dependencies = [
"autocfg 1.0.1",
"num-integer",
"num-traits",
]
[[package]]
name = "num-bigint-dig"
version = "0.7.0"
@ -2386,17 +2402,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "pem"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb"
dependencies = [
"base64 0.13.0",
"once_cell",
"regex",
]
[[package]]
name = "percent-encoding"
version = "2.1.0"
@ -2498,6 +2503,28 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkcs1"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "359e7852310174a810f078124edb73c66e88a1a731b2fd586dba34ee32dbe416"
dependencies = [
"der",
"zeroize",
]
[[package]]
name = "pkcs8"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbee84ed13e44dd82689fa18348a49934fa79cc774a344c42fc9b301c71b140a"
dependencies = [
"der",
"pkcs1",
"spki",
"zeroize",
]
[[package]]
name = "pkg-config"
version = "0.3.19"
@ -2892,9 +2919,9 @@ dependencies = [
[[package]]
name = "rsa"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ef841a26fc5d040ced0417c6c6a64ee851f42489df11cdf0218e545b6f8d28"
checksum = "e05c2603e2823634ab331437001b411b9ed11660fbc4066f3908c84a9439260d"
dependencies = [
"byteorder",
"digest",
@ -2903,9 +2930,9 @@ dependencies = [
"num-integer",
"num-iter",
"num-traits",
"pem",
"pkcs1",
"pkcs8",
"rand 0.8.4",
"simple_asn1",
"subtle",
"zeroize",
]
@ -3139,9 +3166,9 @@ dependencies = [
[[package]]
name = "sha-1"
version = "0.9.6"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c4cfa741c5832d0ef7fab46cabed29c2aae926db0b11bb2069edd8db5e64e16"
checksum = "1a0c8611594e2ab4ebbf06ec7cbbf0a99450b8570e96cbf5188b5d5f6ef18d81"
dependencies = [
"block-buffer",
"cfg-if 1.0.0",
@ -3178,18 +3205,6 @@ dependencies = [
"libc",
]
[[package]]
name = "simple_asn1"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eb4ea60fb301dc81dfc113df680571045d375ab7345d171c5dc7d7e13107a80"
dependencies = [
"chrono",
"num-bigint 0.4.0",
"num-traits",
"thiserror",
]
[[package]]
name = "siphasher"
version = "0.3.5"
@ -3278,6 +3293,15 @@ dependencies = [
"num-traits",
]
[[package]]
name = "spki"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "987637c5ae6b3121aba9d513f869bd2bff11c4cc086c22473befd6649c0bd521"
dependencies = [
"der",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
@ -3412,7 +3436,7 @@ dependencies = [
"from_variant",
"fxhash",
"log",
"num-bigint 0.2.6",
"num-bigint",
"once_cell",
"owning_ref",
"scoped-tls",
@ -3431,7 +3455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "033da686d95b9663e6732c4021e002bc23173bef251db87857e1c3c8bfbfe8cb"
dependencies = [
"is-macro",
"num-bigint 0.2.6",
"num-bigint",
"serde",
"string_enum",
"swc_atoms",
@ -3445,7 +3469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f377629e04d7e4c6b17167421072a51015ced9e8cb4d0022a90470d4779c637"
dependencies = [
"bitflags",
"num-bigint 0.2.6",
"num-bigint",
"sourcemap",
"swc_atoms",
"swc_common",
@ -3503,7 +3527,7 @@ dependencies = [
"fxhash",
"lexical",
"log",
"num-bigint 0.2.6",
"num-bigint",
"serde",
"smallvec",
"swc_atoms",
@ -3669,7 +3693,7 @@ version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b06818a3a50e6de46a81d3d9f51a46d08624ff0f9eb2b3f30de717b15133858d"
dependencies = [
"num-bigint 0.2.6",
"num-bigint",
"swc_atoms",
"swc_common",
"swc_ecma_ast",

View file

@ -20,9 +20,9 @@ lazy_static = "1.4.0"
num-traits = "0.2.14"
rand = "0.8.4"
ring = { version = "0.16.20", features = ["std"] }
rsa = "0.4.0" # TODO: remove "pem" feature when next release is on crates.io
rsa = { version = "0.5.0", default-features = false, features = ["std"] }
serde = { version = "1.0.126", features = ["derive"] }
sha-1 = "0.9.6"
sha-1 = "0.9.7"
sha2 = "0.9.5"
tokio = { version = "1.8.1", features = ["full"] }
uuid = { version = "0.8.2", features = ["v4"] }

View file

@ -32,11 +32,12 @@ use ring::rand::SecureRandom;
use ring::signature::EcdsaKeyPair;
use ring::signature::EcdsaSigningAlgorithm;
use rsa::padding::PaddingScheme;
use rsa::pkcs8::FromPrivateKey;
use rsa::pkcs8::ToPrivateKey;
use rsa::BigUint;
use rsa::PrivateKeyEncoding;
use rsa::PublicKey;
use rsa::RSAPrivateKey;
use rsa::RSAPublicKey;
use rsa::RsaPrivateKey;
use rsa::RsaPublicKey;
use sha1::Sha1;
use sha2::Digest;
use sha2::Sha256;
@ -141,9 +142,9 @@ pub async fn op_crypto_generate_key(
let mut rng = OsRng;
let private_key: RSAPrivateKey = tokio::task::spawn_blocking(
move || -> Result<RSAPrivateKey, rsa::errors::Error> {
RSAPrivateKey::new_with_exp(
let private_key: RsaPrivateKey = tokio::task::spawn_blocking(
move || -> Result<RsaPrivateKey, rsa::errors::Error> {
RsaPrivateKey::new_with_exp(
&mut rng,
modulus_length as usize,
&exponent,
@ -154,7 +155,7 @@ pub async fn op_crypto_generate_key(
.unwrap()
.map_err(|e| custom_error("DOMExceptionOperationError", e.to_string()))?;
private_key.to_pkcs8()?
private_key.to_pkcs8_der()?.as_ref().to_vec()
}
Algorithm::Ecdsa => {
let curve: &EcdsaSigningAlgorithm =
@ -248,7 +249,7 @@ pub async fn op_crypto_sign_key(
let signature = match algorithm {
Algorithm::RsassaPkcs1v15 => {
let private_key = RSAPrivateKey::from_pkcs8(&*args.key.data)?;
let private_key = RsaPrivateKey::from_pkcs8_der(&*args.key.data)?;
let (padding, hashed) = match args
.hash
.ok_or_else(|| type_error("Missing argument hash".to_string()))?
@ -298,7 +299,7 @@ pub async fn op_crypto_sign_key(
private_key.sign(padding, &hashed)?
}
Algorithm::RsaPss => {
let private_key = RSAPrivateKey::from_pkcs8(&*args.key.data)?;
let private_key = RsaPrivateKey::from_pkcs8_der(&*args.key.data)?;
let salt_len = args
.salt_length
@ -402,8 +403,8 @@ pub async fn op_crypto_verify_key(
let verification = match algorithm {
Algorithm::RsassaPkcs1v15 => {
let public_key: RSAPublicKey =
RSAPrivateKey::from_pkcs8(&*args.key.data)?.to_public_key();
let public_key: RsaPublicKey =
RsaPrivateKey::from_pkcs8_der(&*args.key.data)?.to_public_key();
let (padding, hashed) = match args
.hash
.ok_or_else(|| type_error("Missing argument hash".to_string()))?
@ -459,8 +460,8 @@ pub async fn op_crypto_verify_key(
.salt_length
.ok_or_else(|| type_error("Missing argument saltLength".to_string()))?
as usize;
let public_key: RSAPublicKey =
RSAPrivateKey::from_pkcs8(&*args.key.data)?.to_public_key();
let public_key: RsaPublicKey =
RsaPrivateKey::from_pkcs8_der(&*args.key.data)?.to_public_key();
let rng = OsRng;
let (padding, hashed) = match args