1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(ext/node): compute pem length (upper bound) for key exports (#26231)

Fixes https://github.com/denoland/deno/issues/26188
This commit is contained in:
Divy Srivastava 2024-10-14 14:24:26 +05:30 committed by GitHub
parent 68b388a93a
commit bbad7c5922
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View file

@ -2024,7 +2024,9 @@ pub fn op_node_export_public_key_pem(
_ => unreachable!("export_der would have errored"),
};
let mut out = vec![0; 2048];
let pem_len = der::pem::encapsulated_len(label, LineEnding::LF, data.len())
.map_err(|_| type_error("very large data"))?;
let mut out = vec![0; pem_len];
let mut writer = PemWriter::new(label, LineEnding::LF, &mut out)?;
writer.write(&data)?;
let len = writer.finish()?;
@ -2063,7 +2065,9 @@ pub fn op_node_export_private_key_pem(
_ => unreachable!("export_der would have errored"),
};
let mut out = vec![0; 2048];
let pem_len = der::pem::encapsulated_len(label, LineEnding::LF, data.len())
.map_err(|_| type_error("very large data"))?;
let mut out = vec![0; pem_len];
let mut writer = PemWriter::new(label, LineEnding::LF, &mut out)?;
writer.write(&data)?;
let len = writer.finish()?;

View file

@ -656,3 +656,24 @@ z6TExWlQMjt66nV7R8cRAkzmABrG+NW3e8Zpac7Lkuv+zu0S+K7c
assertEquals(publicKey.type, "public");
assertEquals(publicKey.asymmetricKeyType, "rsa");
});
// https://github.com/denoland/deno/issues/26188
Deno.test("generateKeyPair large pem", function () {
const passphrase = "mypassphrase";
const cipher = "aes-256-cbc";
const modulusLength = 4096;
generateKeyPairSync("rsa", {
modulusLength,
publicKeyEncoding: {
type: "spki",
format: "pem",
},
privateKeyEncoding: {
type: "pkcs8",
format: "pem",
cipher,
passphrase,
},
});
});