mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(ext/node): handle KeyObject in prepareAsymmetricKey
(#23026)
Fixes https://github.com/denoland/deno/issues/20938
This commit is contained in:
parent
22eec2b3cf
commit
43be97923f
2 changed files with 54 additions and 0 deletions
|
@ -215,6 +215,12 @@ export interface JsonWebKeyInput {
|
|||
export function prepareAsymmetricKey(key) {
|
||||
if (isStringOrBuffer(key)) {
|
||||
return { format: "pem", data: getArrayBufferOrView(key, "key") };
|
||||
} else if (isKeyObject(key)) {
|
||||
return {
|
||||
// Assumes that assymetric keys are stored as PEM.
|
||||
format: "pem",
|
||||
data: getKeyMaterial(key),
|
||||
};
|
||||
} else if (typeof key == "object") {
|
||||
const { key: data, encoding, format, type } = key;
|
||||
if (!isStringOrBuffer(data)) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
createPrivateKey,
|
||||
createPublicKey,
|
||||
createSecretKey,
|
||||
createSign,
|
||||
generateKeyPair,
|
||||
generateKeyPairSync,
|
||||
KeyObject,
|
||||
|
@ -354,3 +355,50 @@ Deno.test("ECDH getPublicKey compressed", function () {
|
|||
assertEquals(uncompressedKey.length, 65);
|
||||
}
|
||||
});
|
||||
|
||||
// https://github.com/denoland/deno/issues/20938
|
||||
Deno.test("rsa jwt signer", function () {
|
||||
const token = `-----BEGIN PRIVATE KEY-----
|
||||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCVoKHiWLQKlnCG
|
||||
oR4d8g+OSGXoJ3yY+BFubB+1TSaCvWGLkqHjYAA0UCgOoaazE2YnXhVlO4tLDLn/
|
||||
5R6PJrsxksnup+AWnEbur+CuaeQqizGTQXA0nUrsza/QJxb05GSMW9kupzI5BXBi
|
||||
1R8Tmo5I0CpmXDi1yF+nL2NeDXHB999tXcRSrN/Ai11G1HFoYVs36+cm/Jw71BB1
|
||||
KsokwFuzvxTFL9bOXDy8/8MlF8QSBFaWBN1tNZ40+oLf/rYeNXp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rcWCO/PCp4l/9gN+5Ql24eaZLOpuCzDRuZfI5Y8DBgCKfEFtjEEwWQKcuuIx
|
||||
I7cNvJ3A1M+C6wfgoTpPP/2R/e3mFvjXqGlNuxUlWseK95+EuUntdZxNEaqQMdOX
|
||||
Kw0YrQBHjUJ3XeMAFxfwptN5TjRJSTA73OGjI7kCgYBtw1LmjFd6wJFyqLEsBnqO
|
||||
gnVnpxf1DMeMUFpNr+M14P3ETa5UaqiMvCD6VGOzCYv1F7JhnS9TFsYY+FV+L3Nh
|
||||
1+bZIPY4D4seyPgH0cCycBSVfqdAHJlfxf/Pm7lHCNxTGEfBWri4Ga1bW+zQpWY7
|
||||
SogaIHQjE81ZkmNtU5gM5Q==
|
||||
-----END PRIVATE KEY-----`;
|
||||
|
||||
const key = createPrivateKey(token);
|
||||
assertEquals(key.type, "private");
|
||||
assertEquals(key.asymmetricKeyType, "rsa");
|
||||
assertEquals(key.asymmetricKeyDetails?.modulusLength, 2048);
|
||||
assertEquals(key.asymmetricKeyDetails?.publicExponent, 65537n);
|
||||
|
||||
const signer = createSign("RSA-SHA256");
|
||||
signer.update("hello");
|
||||
const signature = signer.sign(key, "base64");
|
||||
|
||||
assertEquals(
|
||||
signature,
|
||||
`jEwckJ/d5GkF/8TTm+wllq2JNghG/m2JYJIW7vS8Vms53zCTTNSSegTSoIVoxWymwTPw2dTtZi41Lg0O271/WvEmQhiWD2dnjz6D/0F4eyn+QUhcmGCadDFyfp7+8x1XOppSw2YB8vL5WCL0QDdp3TAa/rWI0Hn4OftHMa6HPvatkGs+8XlQOGCCfd3TLg+t1UROgpgmetjoAM67mlwxXMGGu/Tr/EbXnnINKeB0iuSmD1FCxlrgFuYWDKxd79n2jZ74FrS/zto+bqWSI5uUa4Ar7yvXtek1Cu1OFM6vgdN9Y6Po2UD9+IT04EhU03LUDY5paYOO8yohz7p7kqHvpA==`,
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue