@@ -14,6 +14,10 @@ const sigstore = require('sigstore')
14
14
const corgiDoc = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
15
15
const fullDoc = 'application/json'
16
16
17
+ // Some really old packages have no time field in their packument so we need a
18
+ // cutoff date.
19
+ const MISSING_TIME_CUTOFF = '2015-01-01T00:00:00.000Z'
20
+
17
21
const fetch = require ( 'npm-registry-fetch' )
18
22
19
23
const _headers = Symbol ( '_headers' )
@@ -115,6 +119,13 @@ class RegistryFetcher extends Fetcher {
115
119
return this . package
116
120
}
117
121
122
+ // When verifying signatures, we need to fetch the full/uncompressed
123
+ // packument to get publish time as this is not included in the
124
+ // corgi/compressed packument.
125
+ if ( this . opts . verifySignatures ) {
126
+ this . fullMetadata = true
127
+ }
128
+
118
129
const packument = await this . packument ( )
119
130
let mani = await pickManifest ( packument , this . spec . fetchSpec , {
120
131
...this . opts ,
@@ -124,6 +135,12 @@ class RegistryFetcher extends Fetcher {
124
135
mani = rpj . normalize ( mani )
125
136
/* XXX add ETARGET and E403 revalidation of cached packuments here */
126
137
138
+ // add _time from packument if fetched with fullMetadata
139
+ const time = packument . time ?. [ mani . version ]
140
+ if ( time ) {
141
+ mani . _time = time
142
+ }
143
+
127
144
// add _resolved and _integrity from dist object
128
145
const { dist } = mani
129
146
if ( dist ) {
@@ -171,8 +188,10 @@ class RegistryFetcher extends Fetcher {
171
188
'but no corresponding public key can be found'
172
189
) , { code : 'EMISSINGSIGNATUREKEY' } )
173
190
}
174
- const validPublicKey =
175
- ! publicKey . expires || ( Date . parse ( publicKey . expires ) > Date . now ( ) )
191
+
192
+ const publishedTime = Date . parse ( mani . _time || MISSING_TIME_CUTOFF )
193
+ const validPublicKey = ! publicKey . expires ||
194
+ publishedTime < Date . parse ( publicKey . expires )
176
195
if ( ! validPublicKey ) {
177
196
throw Object . assign ( new Error (
178
197
`${ mani . _id } has a registry signature with keyid: ${ signature . keyid } ` +
@@ -254,8 +273,13 @@ class RegistryFetcher extends Fetcher {
254
273
) , { code : 'EMISSINGSIGNATUREKEY' } )
255
274
}
256
275
257
- const validPublicKey =
258
- ! publicKey . expires || ( Date . parse ( publicKey . expires ) > Date . now ( ) )
276
+ const integratedTime = new Date (
277
+ Number (
278
+ bundle . verificationMaterial . tlogEntries [ 0 ] . integratedTime
279
+ ) * 1000
280
+ )
281
+ const validPublicKey = ! publicKey . expires ||
282
+ ( integratedTime < Date . parse ( publicKey . expires ) )
259
283
if ( ! validPublicKey ) {
260
284
throw Object . assign ( new Error (
261
285
`${ mani . _id } has attestations with keyid: ${ keyid } ` +
0 commit comments