44 "context"
55 "crypto"
66 "fmt"
7+ "log/slog"
78 "os"
89 "strings"
910 "time"
@@ -13,7 +14,12 @@ import (
1314 "github.com/sigstore/cosign/v2/cmd/cosign/cli/verify"
1415)
1516
16- const timeout = 45 * time .Second
17+ const (
18+ timeout = 45 * time .Second
19+ maxWorkers = 5
20+ hashAlgo = crypto .SHA256
21+ obsKey = "https://ftp.suse.com/pub/projects/security/keys/container-key.pem"
22+ )
1723
1824var archSuffixes = []string {
1925 "-linux-amd64" ,
@@ -30,11 +36,38 @@ var archSuffixes = []string{
3036//
3137// Upstream documentation:
3238// https://github.com/sigstore/cosign/blob/main/specs/SIGNATURE_SPEC.md
33- func Verify (imageName string ) error {
39+ func Verify (image string ) error {
3440 ctx , cancel := context .WithTimeout (context .Background (), timeout )
3541 defer cancel ()
3642
37- certIdentity , err := certIdentity (imageName )
43+ if obsSigned (image ) {
44+ return verifyObs (ctx , image )
45+ }
46+
47+ return verifyKeyless (ctx , image )
48+ }
49+
50+ func verifyObs (ctx context.Context , image string ) error {
51+ slog .Debug ("OBS verification" )
52+ v := & verify.VerifyCommand {
53+ KeyRef : obsKey ,
54+ RekorURL : options .DefaultRekorURL ,
55+ CertRef : obsKey ,
56+ CheckClaims : true ,
57+ HashAlgorithm : hashAlgo ,
58+ MaxWorkers : maxWorkers ,
59+ }
60+
61+ if strings .EqualFold (os .Getenv ("DEBUG" ), "true" ) {
62+ logs .Debug .SetOutput (os .Stderr )
63+ }
64+
65+ return v .Exec (ctx , []string {image })
66+ }
67+
68+ func verifyKeyless (ctx context.Context , image string ) error {
69+ slog .Info ("GHA keyless verification" )
70+ certIdentity , err := certIdentity (image )
3871 if err != nil {
3972 return err
4073 }
@@ -47,15 +80,15 @@ func Verify(imageName string) error {
4780 CertOidcIssuer : "https://token.actions.githubusercontent.com" ,
4881 },
4982 CheckClaims : true ,
50- HashAlgorithm : crypto . SHA256 ,
51- MaxWorkers : 5 ,
83+ HashAlgorithm : hashAlgo ,
84+ MaxWorkers : maxWorkers ,
5285 }
5386
5487 if strings .EqualFold (os .Getenv ("DEBUG" ), "true" ) {
5588 logs .Debug .SetOutput (os .Stderr )
5689 }
5790
58- return v .Exec (ctx , []string {imageName })
91+ return v .Exec (ctx , []string {image })
5992}
6093
6194func certIdentity (imageName string ) (string , error ) {
0 commit comments