Skip to content

Commit c39c0be

Browse files
authored
helpful error message for hashedrekord types (sigstore#605)
* helpful error message for hashedrekord types Signed-off-by: Bob Callaway <bob.callaway@gmail.com>
1 parent 3dc5e1f commit c39c0be

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

cmd/rekor-cli/app/upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var uploadCmd = &cobra.Command{
113113

114114
entry, err = types.NewProposedEntry(context.Background(), typeStr, versionStr, *props)
115115
if err != nil {
116-
return nil, err
116+
return nil, fmt.Errorf("error: %w", err)
117117
}
118118
}
119119
params.SetProposedEntry(entry)

cmd/rekor-cli/app/verify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ var verifyCmd = &cobra.Command{
117117

118118
entry, err := types.NewProposedEntry(context.Background(), typeStr, versionStr, *props)
119119
if err != nil {
120-
return nil, err
120+
return nil, fmt.Errorf("error: %w", err)
121121
}
122122

123123
entries := []models.ProposedEntry{entry}

pkg/types/hashedrekord/v0.0.1/entry.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
196196

197197
var err error
198198

199+
if props.PKIFormat != string(pki.X509) {
200+
return nil, errors.New("hashedrekord entries can only be created for artifacts signed with x509-based PKI")
201+
}
202+
199203
re.HashedRekordObj.Signature = &models.HashedrekordV001SchemaSignature{}
200204
sigBytes := props.SignatureBytes
201205
if sigBytes == nil {

tests/e2e_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ func TestUploadVerifyHashedRekord(t *testing.T) {
155155
}
156156

157157
// Verify should fail initially
158-
runCliErr(t, "verify", "--type=hashedrekord", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
158+
runCliErr(t, "verify", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
159159

160160
// It should upload successfully.
161-
out := runCli(t, "upload", "--type=hashedrekord", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
161+
out := runCli(t, "upload", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
162162
outputContains(t, out, "Created entry at")
163163

164164
// Now we should be able to verify it.
165-
out = runCli(t, "verify", "--type=hashedrekord", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
165+
out = runCli(t, "verify", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
166166
outputContains(t, out, "Inclusion Proof:")
167167
}
168168

0 commit comments

Comments
 (0)