@@ -131,6 +131,64 @@ func TestSignVerify(t *testing.T) {
131
131
mustErr (verify (pubKeyPath , imgName , true , map [string ]interface {}{"foo" : "bar" , "baz" : "bat" }, "" , false ), t )
132
132
}
133
133
134
+ func TestSignVerifyCertBundle (t * testing.T ) {
135
+ td := t .TempDir ()
136
+ err := downloadAndSetEnv (t , rekorURL + "/api/v1/log/publicKey" , env .VariableSigstoreRekorPublicKey .String (), td )
137
+ if err != nil {
138
+ t .Fatal (err )
139
+ }
140
+
141
+ repo , stop := reg (t )
142
+ defer stop ()
143
+
144
+ imgName := path .Join (repo , "cosign-e2e" )
145
+
146
+ _ , _ , cleanup := mkimage (t , imgName )
147
+ defer cleanup ()
148
+
149
+ caCertFile , _ /* caPrivKeyFile */ , caIntermediateCertFile , _ /* caIntermediatePrivKeyFile */ , certFile , privKeyFile , pubkeyFile , certChainFile , err := generateCertificateBundleFiles (td , true , "foobar" )
150
+
151
+ ctx := context .Background ()
152
+ // Verify should fail at first
153
+ must (verifyCertBundle (pubkeyFile , caCertFile , caIntermediateCertFile , certFile , imgName , true , nil , "" , false ), t )
154
+ // So should download
155
+ mustErr (download .SignatureCmd (ctx , options.RegistryOptions {}, imgName ), t )
156
+
157
+ // Now sign the image
158
+ ko := options.KeyOpts {
159
+ KeyRef : privKeyFile ,
160
+ PassFunc : passFunc ,
161
+ RekorURL : rekorURL ,
162
+ SkipConfirmation : true ,
163
+ }
164
+ so := options.SignOptions {
165
+ Upload : true ,
166
+ TlogUpload : true ,
167
+ }
168
+ must (sign .SignCmd (ro , ko , so , []string {imgName }), t )
169
+
170
+ // Now verify and download should work!
171
+ must (verifyCertBundle (pubkeyFile , caCertFile , caIntermediateCertFile , certFile , imgName , true , nil , "" , false ), t )
172
+ // verification with certificate chain instead of root/intermediate files should work as well
173
+ must (verifyCertChain (pubkeyFile , certChainFile , certFile , imgName , true , nil , "" , false ), t )
174
+ must (download .SignatureCmd (ctx , options.RegistryOptions {}, imgName ), t )
175
+
176
+ // Look for a specific annotation
177
+ mustErr (verifyCertBundle (pubkeyFile , caCertFile , caIntermediateCertFile , certFile , imgName , true , map [string ]interface {}{"foo" : "bar" }, "" , false ), t )
178
+
179
+ so .AnnotationOptions = options.AnnotationOptions {
180
+ Annotations : []string {"foo=bar" },
181
+ }
182
+ // Sign the image with an annotation
183
+ must (sign .SignCmd (ro , ko , so , []string {imgName }), t )
184
+
185
+ // It should match this time.
186
+ must (verifyCertBundle (pubkeyFile , caCertFile , caIntermediateCertFile , certFile , imgName , true , map [string ]interface {}{"foo" : "bar" }, "" , false ), t )
187
+
188
+ // But two doesn't work
189
+ mustErr (verifyCertBundle (pubkeyFile , caCertFile , caIntermediateCertFile , certFile , imgName , true , map [string ]interface {}{"foo" : "bar" , "baz" : "bat" }, "" , false ), t )
190
+ }
191
+
134
192
func TestSignVerifyClean (t * testing.T ) {
135
193
td := t .TempDir ()
136
194
err := downloadAndSetEnv (t , rekorURL + "/api/v1/log/publicKey" , env .VariableSigstoreRekorPublicKey .String (), td )
0 commit comments