Skip to content

Commit 2171305

Browse files
authored
Merge pull request #428 from dodok8/dodok8-issue-399
2 parents d804914 + aacec75 commit 2171305

6 files changed

Lines changed: 17 additions & 8 deletions

File tree

deno.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,10 @@
107107
"check-all"
108108
]
109109
}
110+
},
111+
"test": {
112+
"include": [
113+
"./packages"
114+
]
110115
}
111116
}

packages/fedify/src/runtime/key.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const algorithms: Record<
2727
*/
2828
export async function importSpki(pem: string): Promise<CryptoKey> {
2929
pem = pem.replace(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "");
30-
let spki: Uint8Array;
30+
let spki: Uint8Array<ArrayBuffer>;
3131
try {
3232
spki = decodeBase64(pem);
3333
} catch (_) {
@@ -110,7 +110,11 @@ export async function importMultibaseKey(key: string): Promise<CryptoKey> {
110110
format: "der",
111111
type: "pkcs1",
112112
});
113-
const spki = keyObject.export({ type: "spki", format: "der" }).buffer;
113+
const exported = keyObject.export({ type: "spki", format: "der" });
114+
const spki = exported instanceof Uint8Array
115+
? exported
116+
: new Uint8Array(exported);
117+
114118
return await crypto.subtle.importKey(
115119
"spki",
116120
new Uint8Array(spki),
@@ -121,7 +125,7 @@ export async function importMultibaseKey(key: string): Promise<CryptoKey> {
121125
} else if (code === 0xed) { // ed25519-pub
122126
return await crypto.subtle.importKey(
123127
"raw",
124-
content,
128+
content.slice(),
125129
"Ed25519",
126130
true,
127131
["verify"],

packages/fedify/src/sig/http.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ test("verifyRequest() [rfc9421] manual POST verification", async () => {
671671
const signatureVerified = await crypto.subtle.verify(
672672
"RSASSA-PKCS1-v1_5",
673673
rsaPublicKey2.publicKey,
674-
parsedSignature.sig1,
674+
parsedSignature.sig1.slice(),
675675
new TextEncoder().encode(signatureBase),
676676
);
677677

packages/fedify/src/sig/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ async function verifyRequestRfc9421(
11961196
const verified = await crypto.subtle.verify(
11971197
algorithm,
11981198
key.publicKey,
1199-
sigBytes,
1199+
sigBytes.slice(),
12001200
signatureBaseBytes,
12011201
);
12021202

packages/fedify/src/sig/ld.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export async function verifySignature(
313313
const verified = await crypto.subtle.verify(
314314
"RSASSA-PKCS1-v1_5",
315315
key.publicKey,
316-
signature,
316+
signature.slice(),
317317
messageBytes,
318318
);
319319
if (verified) return key;
@@ -339,7 +339,7 @@ export async function verifySignature(
339339
const verified = await crypto.subtle.verify(
340340
"RSASSA-PKCS1-v1_5",
341341
key.publicKey,
342-
signature,
342+
signature.slice(),
343343
messageBytes,
344344
);
345345
return verified ? key : null;

packages/fedify/src/sig/proof.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ async function verifyProofInternal(
352352
const verified = await crypto.subtle.verify(
353353
"Ed25519",
354354
publicKey.publicKey,
355-
proof.proofValue,
355+
proof.proofValue.slice(),
356356
digest,
357357
);
358358
if (!verified) {

0 commit comments

Comments
 (0)