Debian Codegraph @

verifier/timestamp_test.go

raw ◀ ▶
1 Debian patch touch this file
1 // Copyright The Notary Project Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package verifier
15
16 import (
17 "context"
18 "crypto/x509"
19 "net/http"
20 "os"
•21 "strings"
22 "testing"
23 "time"
24
25 "github.com/notaryproject/notation-core-go/revocation"
26 "github.com/notaryproject/notation-core-go/revocation/purpose"
27 "github.com/notaryproject/notation-core-go/signature"
28 "github.com/notaryproject/notation-core-go/signature/cose"
29 "github.com/notaryproject/notation-core-go/signature/jws"
30 "github.com/notaryproject/notation-go"
31 "github.com/notaryproject/notation-go/dir"
32 "github.com/notaryproject/notation-go/verifier/trustpolicy"
33 "github.com/notaryproject/notation-go/verifier/truststore"
34 )
35
36 func TestAuthenticTimestamp(t *testing.T) {
37 dir.UserConfigDir = "testdata"
38 trustStore := truststore.NewX509TrustStore(dir.ConfigFS())
39 dummyTrustPolicy := &trustpolicy.TrustPolicy{
40 Name: "test-timestamp",
41 RegistryScopes: []string{"*"},
42 SignatureVerification: trustpolicy.SignatureVerification{
43 VerificationLevel: trustpolicy.LevelStrict.Name,
44 VerifyTimestamp: trustpolicy.OptionAlways,
45 },
46 TrustStores: []string{"ca:valid-trust-store", "tsa:test-timestamp"},
47 TrustedIdentities: []string{"*"},
48 }
49 revocationTimestampingValidator, err := revocation.NewWithOptions(revocation.Options{
50 OCSPHTTPClient: &http.Client{Timeout: 2 * time.Second},
51 CertChainPurpose: purpose.Timestamping,
52 })
53 if err != nil {
54 t.Fatalf("failed to get revocation timestamp client: %v", err)
55 }
56 // valid JWS signature envelope with timestamp countersignature
57 jwsEnvContent, err := parseEnvContent("testdata/timestamp/sigEnv/jwsWithTimestamp.sig", jws.MediaTypeEnvelope)
58 if err != nil {
59 t.Fatalf("failed to get signature envelope content: %v", err)
60 }
61
62 // valid COSE signature envelope with timestamp countersignature
63 coseEnvContent, err := parseEnvContent("testdata/timestamp/sigEnv/coseWithTimestamp.sig", cose.MediaTypeEnvelope)
64 if err != nil {
65 t.Fatalf("failed to get signature envelope content: %v", err)
66 }
67
68 t.Run("verify Authentic Timestamp with jws format", func(t *testing.T) {
69 outcome := &notation.VerificationOutcome{
70 EnvelopeContent: jwsEnvContent,
71 VerificationLevel: trustpolicy.LevelStrict,
72 }
73 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
74 if err := authenticTimestampResult.Error; err != nil {
•75 if strings.Contains(err.Error(), "revocation status is unknown") {
76 t.Skipf("Skipping test: %v", err)
77 }
78 t.Fatalf("expected nil error, but got %s", err)
79 }
80 })
81
82 t.Run("verify Authentic Timestamp with cose format", func(t *testing.T) {
83 outcome := &notation.VerificationOutcome{
84 EnvelopeContent: coseEnvContent,
85 VerificationLevel: trustpolicy.LevelStrict,
86 }
87 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
88 if err := authenticTimestampResult.Error; err != nil {
•89 if strings.Contains(err.Error(), "revocation status is unknown") {
90 t.Skipf("Skipping test: %v", err)
91 }
92 t.Fatalf("expected nil error, but got %s", err)
93 }
94 })
95
96 t.Run("verify Authentic Timestamp jws with expired codeSigning cert", func(t *testing.T) {
97 jwsEnvContent, err := parseEnvContent("testdata/timestamp/sigEnv/jwsExpiredWithTimestamp.sig", jws.MediaTypeEnvelope)
98 if err != nil {
•99 if strings.Contains(err.Error(), "revocation status is unknown") {
100 t.Skipf("Skipping test: %v", err)
101 }
102 t.Fatalf("failed to get signature envelope content: %v", err)
103 }
104 outcome := &notation.VerificationOutcome{
105 EnvelopeContent: jwsEnvContent,
106 VerificationLevel: trustpolicy.LevelStrict,
107 }
108 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
109 if err := authenticTimestampResult.Error; err != nil {
•110 if strings.Contains(err.Error(), "revocation status is unknown") {
111 t.Skipf("Skipping test: %v", err)
112 }
113 t.Fatalf("expected nil error, but got %s", err)
114 }
115 })
116
117 t.Run("verify Authentic Timestamp cose with expired codeSigning cert", func(t *testing.T) {
118 coseEnvContent, err := parseEnvContent("testdata/timestamp/sigEnv/coseExpiredWithTimestamp.sig", cose.MediaTypeEnvelope)
119 if err != nil {
120 t.Fatalf("failed to get signature envelope content: %v", err)
121 }
122 outcome := &notation.VerificationOutcome{
123 EnvelopeContent: coseEnvContent,
124 VerificationLevel: trustpolicy.LevelStrict,
125 }
126 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
127 if err := authenticTimestampResult.Error; err != nil {
•128 if strings.Contains(err.Error(), "revocation status is unknown") {
129 t.Skipf("Skipping test: %v", err)
130 }
131 t.Fatalf("expected nil error, but got %s", err)
132 }
133 })
134
135 t.Run("verify Authentic Timestamp with afterCertExpiry set", func(t *testing.T) {
136 dummyTrustPolicy := &trustpolicy.TrustPolicy{
137 Name: "test-timestamp",
138 RegistryScopes: []string{"*"},
139 SignatureVerification: trustpolicy.SignatureVerification{
140 VerificationLevel: trustpolicy.LevelStrict.Name,
141 VerifyTimestamp: trustpolicy.OptionAfterCertExpiry,
142 },
143 TrustStores: []string{"ca:valid-trust-store", "tsa:test-timestamp"},
144 TrustedIdentities: []string{"*"},
145 }
146 outcome := &notation.VerificationOutcome{
147 EnvelopeContent: coseEnvContent,
148 VerificationLevel: trustpolicy.LevelStrict,
149 }
150 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
151 if err := authenticTimestampResult.Error; err != nil {
152 t.Fatalf("expected nil error, but got %s", err)
153 }
154 })
155
156 t.Run("verify Authentic Timestamp failed due to invalid trust policy", func(t *testing.T) {
157 dummyTrustPolicy := &trustpolicy.TrustPolicy{
158 Name: "test-timestamp",
159 RegistryScopes: []string{"*"},
160 SignatureVerification: trustpolicy.SignatureVerification{
161 VerificationLevel: trustpolicy.LevelStrict.Name,
162 VerifyTimestamp: trustpolicy.OptionAlways,
163 },
164 TrustStores: []string{"ca:valid-trust-store", "tsa"},
165 TrustedIdentities: []string{"*"},
166 }
167 outcome := &notation.VerificationOutcome{
168 EnvelopeContent: jwsEnvContent,
169 VerificationLevel: trustpolicy.LevelStrict,
170 }
171 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
172 expectedErrMsg := "failed to check tsa trust store configuration in turst policy with error: invalid trust policy statement: \"test-timestamp\" is missing separator in trust store value \"tsa\". The required format is <TrustStoreType>:<TrustStoreName>"
173 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
174 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
175 }
176 })
177
178 t.Run("verify Authentic Timestamp failed due to missing tsa in trust policy and expired codeSigning cert", func(t *testing.T) {
179 dummyTrustPolicy := &trustpolicy.TrustPolicy{
180 Name: "test-timestamp",
181 RegistryScopes: []string{"*"},
182 SignatureVerification: trustpolicy.SignatureVerification{
183 VerificationLevel: trustpolicy.LevelStrict.Name,
184 VerifyTimestamp: trustpolicy.OptionAlways,
185 },
186 TrustStores: []string{"ca:valid-trust-store"},
187 TrustedIdentities: []string{"*"},
188 }
189 coseEnvContent, err := parseEnvContent("testdata/timestamp/sigEnv/coseExpiredWithTimestamp.sig", cose.MediaTypeEnvelope)
190 if err != nil {
191 t.Fatalf("failed to get signature envelope content: %v", err)
192 }
193 outcome := &notation.VerificationOutcome{
194 EnvelopeContent: coseEnvContent,
195 VerificationLevel: trustpolicy.LevelStrict,
196 }
197 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
198 expectedErrMsg := "verification time is after certificate \"CN=testTSA,O=Notary,L=Seattle,ST=WA,C=US\" validity period, it was expired at \"Tue, 18 Jun 2024 07:30:31 +0000\""
199 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
200 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
201 }
202 })
203
204 t.Run("verify Authentic Timestamp failed due to missing timestamp countersignature", func(t *testing.T) {
205 envContent, err := parseEnvContent("testdata/timestamp/sigEnv/withoutTimestamp.sig", jws.MediaTypeEnvelope)
206 if err != nil {
207 t.Fatalf("failed to get signature envelope content: %v", err)
208 }
209 outcome := &notation.VerificationOutcome{
210 EnvelopeContent: envContent,
211 VerificationLevel: trustpolicy.LevelStrict,
212 }
213 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
214 expectedErrMsg := "no timestamp countersignature was found in the signature envelope"
215 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
216 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
217 }
218 })
219
220 t.Run("verify Authentic Timestamp failed due to invalid timestamp countersignature content type", func(t *testing.T) {
221 signedToken, err := os.ReadFile("testdata/timestamp/countersignature/TimeStampTokenWithInvalideContentType.p7s")
222 if err != nil {
223 t.Fatalf("failed to get signedToken: %v", err)
224 }
225 envContent, err := parseEnvContent("testdata/timestamp/sigEnv/withoutTimestamp.sig", jws.MediaTypeEnvelope)
226 if err != nil {
227 t.Fatalf("failed to get signature envelope content: %v", err)
228 }
229 envContent.SignerInfo.UnsignedAttributes.TimestampSignature = signedToken
230 outcome := &notation.VerificationOutcome{
231 EnvelopeContent: envContent,
232 VerificationLevel: trustpolicy.LevelStrict,
233 }
234 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
235 expectedErrMsg := "failed to parse timestamp countersignature with error: unexpected content type: 1.2.840.113549.1.7.1. Expected to be id-ct-TSTInfo (1.2.840.113549.1.9.16.1.4)"
236 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
237 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
238 }
239 })
240
241 t.Run("verify Authentic Timestamp failed due to invalid TSTInfo", func(t *testing.T) {
242 signedToken, err := os.ReadFile("testdata/timestamp/countersignature/TimeStampTokenWithInvalidTSTInfo.p7s")
243 if err != nil {
244 t.Fatalf("failed to get signedToken: %v", err)
245 }
246 envContent, err := parseEnvContent("testdata/timestamp/sigEnv/withoutTimestamp.sig", jws.MediaTypeEnvelope)
247 if err != nil {
248 t.Fatalf("failed to get signature envelope content: %v", err)
249 }
250 envContent.SignerInfo.UnsignedAttributes.TimestampSignature = signedToken
251 outcome := &notation.VerificationOutcome{
252 EnvelopeContent: envContent,
253 VerificationLevel: trustpolicy.LevelStrict,
254 }
255 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
256 expectedErrMsg := "failed to get the timestamp TSTInfo with error: cannot unmarshal TSTInfo from timestamp token: asn1: structure error: tags don't match (23 vs {class:0 tag:16 length:3 isCompound:true}) {optional:false explicit:false application:false private:false defaultValue:<nil> tag:<nil> stringType:0 timeType:24 set:false omitEmpty:false} Time @89"
257 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
258 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
259 }
260 })
261
262 t.Run("verify Authentic Timestamp failed due to failed to validate TSTInfo", func(t *testing.T) {
263 signedToken, err := os.ReadFile("testdata/timestamp/countersignature/TimeStampToken.p7s")
264 if err != nil {
265 t.Fatalf("failed to get signedToken: %v", err)
266 }
267 envContent, err := parseEnvContent("testdata/timestamp/sigEnv/withoutTimestamp.sig", jws.MediaTypeEnvelope)
268 if err != nil {
269 t.Fatalf("failed to get signature envelope content: %v", err)
270 }
271 envContent.SignerInfo.UnsignedAttributes.TimestampSignature = signedToken
272 envContent.SignerInfo.Signature = []byte("mismatch")
273 outcome := &notation.VerificationOutcome{
274 EnvelopeContent: envContent,
275 VerificationLevel: trustpolicy.LevelStrict,
276 }
277 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
278 expectedErrMsg := "failed to get timestamp from timestamp countersignature with error: invalid TSTInfo: mismatched message"
279 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
280 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
281 }
282 })
283
284 t.Run("verify Authentic Timestamp failed due to failed to verify timestamp countersignature", func(t *testing.T) {
285 signedToken, err := os.ReadFile("testdata/timestamp/countersignature/TimeStampTokenWithoutCertificate.p7s")
286 if err != nil {
287 t.Fatalf("failed to get signedToken: %v", err)
288 }
289 envContent, err := parseEnvContent("testdata/timestamp/sigEnv/withoutTimestamp.sig", jws.MediaTypeEnvelope)
290 if err != nil {
291 t.Fatalf("failed to get signature envelope content: %v", err)
292 }
293 envContent.SignerInfo.UnsignedAttributes.TimestampSignature = signedToken
294 envContent.SignerInfo.Signature = []byte("notation")
295 outcome := &notation.VerificationOutcome{
296 EnvelopeContent: envContent,
297 VerificationLevel: trustpolicy.LevelStrict,
298 }
299 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
300 expectedErrMsg := "failed to verify the timestamp countersignature with error: failed to verify signed token: signing certificate not found in the timestamp token"
301 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
302 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
303 }
304 })
305
306 t.Run("verify Authentic Timestamp failed due to trust store does not exist", func(t *testing.T) {
307 dummyTrustPolicy := &trustpolicy.TrustPolicy{
308 Name: "test-timestamp",
309 RegistryScopes: []string{"*"},
310 SignatureVerification: trustpolicy.SignatureVerification{
311 VerificationLevel: trustpolicy.LevelStrict.Name,
312 VerifyTimestamp: trustpolicy.OptionAlways,
313 },
314 TrustStores: []string{"ca:valid-trust-store", "tsa:does-not-exist"},
315 TrustedIdentities: []string{"*"},
316 }
317 outcome := &notation.VerificationOutcome{
318 EnvelopeContent: coseEnvContent,
319 VerificationLevel: trustpolicy.LevelStrict,
320 }
321 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
322 expectedErrMsg := "failed to load tsa trust store with error: the trust store \"does-not-exist\" of type \"tsa\" does not exist"
323 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
324 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
325 }
326 })
327
328 t.Run("verify Authentic Timestamp failed due to empty trust store", func(t *testing.T) {
329 dummyTrustPolicy := &trustpolicy.TrustPolicy{
330 Name: "test-timestamp",
331 RegistryScopes: []string{"*"},
332 SignatureVerification: trustpolicy.SignatureVerification{
333 VerificationLevel: trustpolicy.LevelStrict.Name,
334 VerifyTimestamp: trustpolicy.OptionAlways,
335 },
336 TrustStores: []string{"ca:valid-trust-store", "tsa:test-empty"},
337 TrustedIdentities: []string{"*"},
338 }
339 outcome := &notation.VerificationOutcome{
340 EnvelopeContent: coseEnvContent,
341 VerificationLevel: trustpolicy.LevelStrict,
342 }
343 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, dummyTrustStore{}, revocationTimestampingValidator, outcome)
344 expectedErrMsg := "no trusted TSA certificate found in trust store"
345 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
346 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
347 }
348 })
349
350 t.Run("verify Authentic Timestamp failed due to tsa not trust", func(t *testing.T) {
351 dummyTrustPolicy := &trustpolicy.TrustPolicy{
352 Name: "test-timestamp",
353 RegistryScopes: []string{"*"},
354 SignatureVerification: trustpolicy.SignatureVerification{
355 VerificationLevel: trustpolicy.LevelStrict.Name,
356 VerifyTimestamp: trustpolicy.OptionAlways,
357 },
358 TrustStores: []string{"ca:valid-trust-store", "tsa:test-mismatch"},
359 TrustedIdentities: []string{"*"},
360 }
361 outcome := &notation.VerificationOutcome{
362 EnvelopeContent: coseEnvContent,
363 VerificationLevel: trustpolicy.LevelStrict,
364 }
365 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
366 expectedErrMsg := "failed to verify the timestamp countersignature with error: failed to verify signed token: cms verification failure: x509: certificate signed by unknown authority"
367 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
368 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
369 }
370 })
371
372 t.Run("verify Authentic Timestamp failed due to timestamp before signing cert not before", func(t *testing.T) {
373 dummyTrustPolicy := &trustpolicy.TrustPolicy{
374 Name: "test-timestamp",
375 RegistryScopes: []string{"*"},
376 SignatureVerification: trustpolicy.SignatureVerification{
377 VerificationLevel: trustpolicy.LevelStrict.Name,
378 VerifyTimestamp: trustpolicy.OptionAlways,
379 },
380 TrustStores: []string{"ca:valid-trust-store", "tsa:test-timestamp"},
381 TrustedIdentities: []string{"*"},
382 }
383 envContent, err := parseEnvContent("testdata/timestamp/sigEnv/timestampBeforeNotBefore.sig", jws.MediaTypeEnvelope)
384 if err != nil {
385 t.Fatalf("failed to get signature envelope content: %v", err)
386 }
387 outcome := &notation.VerificationOutcome{
388 EnvelopeContent: envContent,
389 VerificationLevel: trustpolicy.LevelStrict,
390 }
391 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
392 expectedErrMsg := "timestamp can be before certificate \"CN=testTSA,O=Notary,L=Seattle,ST=WA,C=US\" validity period, it will be valid from \"Fri, 18 Sep 2099 11:54:34 +0000\""
393 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
394 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
395 }
396 })
397
398 t.Run("verify Authentic Timestamp failed due to timestamp after signing cert not after", func(t *testing.T) {
399 dummyTrustPolicy := &trustpolicy.TrustPolicy{
400 Name: "test-timestamp",
401 RegistryScopes: []string{"*"},
402 SignatureVerification: trustpolicy.SignatureVerification{
403 VerificationLevel: trustpolicy.LevelStrict.Name,
404 VerifyTimestamp: trustpolicy.OptionAlways,
405 },
406 TrustStores: []string{"ca:valid-trust-store", "tsa:test-timestamp"},
407 TrustedIdentities: []string{"*"},
408 }
409 envContent, err := parseEnvContent("testdata/timestamp/sigEnv/timestampAfterNotAfter.sig", cose.MediaTypeEnvelope)
410 if err != nil {
411 t.Fatalf("failed to get signature envelope content: %v", err)
412 }
413 outcome := &notation.VerificationOutcome{
414 EnvelopeContent: envContent,
415 VerificationLevel: trustpolicy.LevelStrict,
416 }
417 authenticTimestampResult := verifyAuthenticTimestamp(context.Background(), dummyTrustPolicy.Name, dummyTrustPolicy.TrustStores, dummyTrustPolicy.SignatureVerification, trustStore, revocationTimestampingValidator, outcome)
418 expectedErrMsg := "timestamp can be after certificate \"CN=testTSA,O=Notary,L=Seattle,ST=WA,C=US\" validity period, it was expired at \"Tue, 18 Sep 2001 11:54:34 +0000\""
419 if err := authenticTimestampResult.Error; err == nil || err.Error() != expectedErrMsg {
420 t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
421 }
422 })
423 }
424
425 func parseEnvContent(filepath, format string) (*signature.EnvelopeContent, error) {
426 sigEnvBytes, err := os.ReadFile(filepath)
427 if err != nil {
428 return nil, err
429 }
430 sigEnv, err := signature.ParseEnvelope(format, sigEnvBytes)
431 if err != nil {
432 return nil, err
433 }
434 return sigEnv.Content()
435 }
436
437 type dummyTrustStore struct{}
438
439 func (ts dummyTrustStore) GetCertificates(ctx context.Context, storeType truststore.Type, namedStore string) ([]*x509.Certificate, error) {
440 return nil, nil
441 }