Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to verify-blob from urls #646

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions cmd/cosign/cli/verify_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/peterbourgon/ff/v3/ffcli"
"github.com/pkg/errors"
Expand Down Expand Up @@ -161,32 +160,26 @@ func VerifyBlobCmd(ctx context.Context, ko KeyOpts, certRef, sigRef, blobRef str
}

var b64sig string
// This can be the base64-encoded bytes or a path to the signature
if _, err = os.Stat(sigRef); err != nil {
if os.IsNotExist(err) {
b64sig = sigRef
} else {
return err
}
} else {
targetSig, err := loadFileOrURL(sigRef)
if err != nil {
targetSig, err := loadFileOrURL(sigRef)
if err != nil {
if !os.IsNotExist(err) {
// ignore if file does not exist, it can be a base64 encoded string as well
return err
}
targetSig = []byte(sigRef)
}

if isb64(targetSig) {
b64sig = string(targetSig)
} else {
b64sig = base64.StdEncoding.EncodeToString(targetSig)
}

if isb64(targetSig) {
b64sig = string(targetSig)
} else {
b64sig = base64.StdEncoding.EncodeToString(targetSig)
}

var blobBytes []byte
if blobRef == "-" {
blobBytes, err = ioutil.ReadAll(os.Stdin)
} else {
blobBytes, err = ioutil.ReadFile(filepath.Clean(blobRef))
blobBytes, err = loadFileOrURL(blobRef)
}
if err != nil {
return err
Expand Down