Skip to content

Commit dd53292

Browse files
author
Jake Sanders
authored
return error when rekor pub cannot be retrieved, fix file path construction (#1157)
Signed-off-by: Jake Sanders <[email protected]>
1 parent a684c45 commit dd53292

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

pkg/cosign/tlog.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ import (
4343
// This is the rekor public key target name
4444
var rekorTargetStr = `rekor.pub`
4545

46-
func GetRekorPub(ctx context.Context) string {
46+
// GetRekorPub retrieves the rekor public key from the embedded or cached TUF root. If expired, makes a
47+
// network call to retrieve the updated target.
48+
func GetRekorPub(ctx context.Context) ([]byte, error) {
4749
buf := tuf.ByteDestination{Buffer: &bytes.Buffer{}}
48-
// Retrieves the rekor public key from the embedded or cached TUF root. If expired, makes a
49-
// network call to retrieve the updated target.
5050
if err := tuf.GetTarget(ctx, rekorTargetStr, &buf); err != nil {
51-
panic("error retrieving rekor public key")
51+
return nil, err
5252
}
53-
return buf.String()
53+
return buf.Bytes(), nil
5454
}
5555

5656
// TLogUpload will upload the signature, public key and payload to the transparency log.

pkg/cosign/tuf/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
const (
4242
TufRootEnv = "TUF_ROOT"
4343
SigstoreNoCache = "SIGSTORE_NO_CACHE"
44-
defaultLocalStore = ".sigstore/root/"
4544
DefaultRemoteRoot = "sigstore-tuf-root"
4645
)
4746

@@ -68,7 +67,7 @@ func CosignCachedRoot() string {
6867
if err != nil {
6968
home = ""
7069
}
71-
return path.Join(home, defaultLocalStore)
70+
return path.Join(home, ".sigstore", "root")
7271
}
7372
return rootDir
7473
}
@@ -102,7 +101,7 @@ func getLocalTarget(name string) (fs.File, error) {
102101
// Return local cached target
103102
return os.Open(path.Join(CosignCachedTargets(), name))
104103
}
105-
return root.Open(path.Join("repository/targets", name))
104+
return root.Open(path.Join("repository", "targets", name))
106105
}
107106

108107
type signedMeta struct {

pkg/cosign/verify.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,12 @@ func VerifyBundle(ctx context.Context, sig oci.Signature) (bool, error) {
446446
return false, nil
447447
}
448448

449-
rekorPubKey, err := PemToECDSAKey([]byte(GetRekorPub(ctx)))
449+
pub, err := GetRekorPub(ctx)
450+
if err != nil {
451+
return false, errors.Wrap(err, "retrieving rekor public key")
452+
}
453+
454+
rekorPubKey, err := PemToECDSAKey(pub)
450455
if err != nil {
451456
return false, errors.Wrap(err, "pem to ecdsa")
452457
}

0 commit comments

Comments
 (0)