Skip to content

Commit acba596

Browse files
author
dlorenc
authored
Add the URIs subject to our outputting. (#721)
GitHub certificates in Fulcio use the URIs field, while others use email. Let's add both to the output formatting. Signed-off-by: Dan Lorenc <[email protected]>
1 parent 419af55 commit acba596

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmd/cosign/cli/verify.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cli
1717

1818
import (
1919
"context"
20+
"crypto/x509"
2021
"encoding/json"
2122
"flag"
2223
"fmt"
@@ -207,13 +208,23 @@ func PrintVerificationHeader(imgRef string, co *cosign.CheckOpts) {
207208
fmt.Fprintln(os.Stderr, " - Any certificates were verified against the Fulcio roots.")
208209
}
209210

211+
func certSubject(c *x509.Certificate) string {
212+
switch {
213+
case c.EmailAddresses != nil:
214+
return c.EmailAddresses[0]
215+
case c.URIs != nil:
216+
return c.URIs[0].String()
217+
}
218+
return ""
219+
}
220+
210221
// PrintVerification logs details about the verification to stdout
211222
func PrintVerification(imgRef string, verified []cosign.SignedPayload, output string) {
212223
switch output {
213224
case "text":
214225
for _, vp := range verified {
215226
if vp.Cert != nil {
216-
fmt.Println("Certificate subject: ", vp.Cert.EmailAddresses)
227+
fmt.Println("Certificate subject: ", certSubject(vp.Cert))
217228
}
218229

219230
fmt.Println(string(vp.Payload))
@@ -232,7 +243,7 @@ func PrintVerification(imgRef string, verified []cosign.SignedPayload, output st
232243
if ss.Optional == nil {
233244
ss.Optional = make(map[string]interface{})
234245
}
235-
ss.Optional["Subject"] = vp.Cert.EmailAddresses
246+
ss.Optional["Subject"] = certSubject(vp.Cert)
236247
}
237248
if vp.Bundle != nil {
238249
if ss.Optional == nil {

0 commit comments

Comments
 (0)