Skip to content

Commit db10011

Browse files
committed
fixup! Get NPM signing keys from @sigstore/tuf
1 parent 975fb2c commit db10011

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ index f966ce1bb0cdc6c785ce1263f1faea15d3fe764c..3b50fa0c24fd5f6e9e29cf398a3d3bf1
1919
- timeout: this.timeout,
2020
- retry: this.retry,
2121
+ const response = await globalThis.fetch(url, {
22-
+ timeout: this.timeout && AbortSignal.timeout(this.timeout)
22+
+ signal: this.timeout && AbortSignal.timeout(this.timeout)
2323
});
2424
if (!response.ok || !response?.body) {
2525
throw new error_1.DownloadHTTPError('Failed to download', response.status);

sources/npmRegistryUtils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export async function fetchAsJson(packageName: string, version?: string) {
3939

4040
interface KeyInfo {
4141
keyid: string;
42-
key: crypto.KeyObject;
42+
// base64 encoded DER SPKI
43+
keyData: string;
4344
}
4445

4546
async function fetchSigstoreTufKeys(): Promise<Array<KeyInfo> | null> {
@@ -68,7 +69,7 @@ async function fetchSigstoreTufKeys(): Promise<Array<KeyInfo> | null> {
6869
}
6970
}).map(k => ({
7071
keyid: k.keyId,
71-
key: crypto.createPublicKey({key: Buffer.from(k.publicKey.rawBytes, `base64`), format: `der`, type: `spki`}),
72+
keyData: k.publicKey.rawBytes,
7273
}));
7374
}
7475

@@ -83,8 +84,7 @@ async function getVerificationKeys(): Promise<Array<KeyInfo>> {
8384
debugUtils.log(`Using COREPACK_INTEGRITY_KEYS to verify signatures: ${keys.map(k => k.keyid).join(`, `)}`);
8485
return keys.map(k => ({
8586
keyid: k.keyid,
86-
key: crypto.createPublicKey(`-----BEGIN PUBLIC KEY-----\n${k.key}\n-----END PUBLIC KEY-----`,
87-
),
87+
keyData: k.key,
8888
}));
8989
}
9090

@@ -98,12 +98,11 @@ async function getVerificationKeys(): Promise<Array<KeyInfo>> {
9898
debugUtils.log(`Falling back to built-in npm verification keys`);
9999
return defaultConfig.keys.npm.map(k => ({
100100
keyid: k.keyid,
101-
key: crypto.createPublicKey(`-----BEGIN PUBLIC KEY-----\n${k.key}\n-----END PUBLIC KEY-----`,
102-
),
101+
keyData: k.key,
103102
}));
104103
}
105104

106-
let verificationKeysCache: Promise<Array<{ keyid: string, key: crypto.KeyObject }>> | null = null;
105+
let verificationKeysCache: Promise<Array<KeyInfo>> | null = null;
107106

108107
export async function verifySignature({signatures, integrity, packageName, version}: {
109108
signatures: Array<{keyid: string, sig: string}>;
@@ -115,21 +114,22 @@ export async function verifySignature({signatures, integrity, packageName, versi
115114
verificationKeysCache = getVerificationKeys();
116115

117116
const keys = await verificationKeysCache;
118-
const key = keys.find(({keyid}) => signatures.some(s => s.keyid === keyid));
119-
if (key == null)
117+
const keyInfo = keys.find(({keyid}) => signatures.some(s => s.keyid === keyid));
118+
if (keyInfo == null)
120119
throw new Error(`Cannot find key to verify signature. signature keys: ${signatures.map(s => s.keyid)}, verification keys: ${keys.map(k => k.keyid)}`);
121120

122-
const signature = signatures.find(({keyid}) => keyid === key.keyid);
121+
const signature = signatures.find(({keyid}) => keyid === keyInfo.keyid);
123122
assert(signature);
124123

125124
const verifier = crypto.createVerify(`SHA256`);
126125
const payload = `${packageName}@${version}:${integrity}`;
127126
verifier.end(payload);
127+
const key = crypto.createPublicKey({key: Buffer.from(keyInfo.keyData, `base64`), format: `der`, type: `spki`});
128128
const valid = verifier.verify(key, signature.sig, `base64`);
129129

130130
if (!valid) {
131131
throw new Error(
132-
`Signature verification failed for ${payload} with key ${key.keyid}\n` +
132+
`Signature verification failed for ${payload} with key ${keyInfo.keyid}\n` +
133133
`If you are using a custom registry you can set COREPACK_INTEGRITY_KEYS.`,
134134
);
135135
}

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,12 +4703,12 @@ __metadata:
47034703

47044704
"tuf-js@patch:tuf-js@npm%3A3.0.1#~/.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch":
47054705
version: 3.0.1
4706-
resolution: "tuf-js@patch:tuf-js@npm%3A3.0.1#~/.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch::version=3.0.1&hash=a7966e"
4706+
resolution: "tuf-js@patch:tuf-js@npm%3A3.0.1#~/.yarn/patches/tuf-js-npm-3.0.1-9135d15fbd.patch::version=3.0.1&hash=05f694"
47074707
dependencies:
47084708
"@tufjs/models": "npm:3.0.1"
47094709
debug: "npm:^4.3.6"
47104710
make-fetch-happen: "npm:^14.0.1"
4711-
checksum: 10c0/d7374bf8db935947bd50e9436e4c8b3a7244fb70c876821d91bffe9f3d0e6448fab4ddccc93867f68cfe892d776fac7c988c0bbbfe9ac052b2f83482f55ea50e
4711+
checksum: 10c0/8f50e885865555112d5ffc5fe7803c9270a611462300b53fd0b528914eb6b9f849b7a4782c07f356f4f0aeb6b752cbb3f7e1c5f2b068bfb574fca3990d1675d5
47124712
languageName: node
47134713
linkType: hard
47144714

0 commit comments

Comments
 (0)