Skip to content
Snippets Groups Projects
Unverified Commit c39c0beb authored by Bob Callaway's avatar Bob Callaway Committed by GitHub
Browse files

helpful error message for hashedrekord types (#605)


* helpful error message for hashedrekord types

Signed-off-by: default avatarBob Callaway <bob.callaway@gmail.com>
parent 3dc5e1fc
No related branches found
No related tags found
No related merge requests found
......@@ -113,7 +113,7 @@ var uploadCmd = &cobra.Command{
entry, err = types.NewProposedEntry(context.Background(), typeStr, versionStr, *props)
if err != nil {
return nil, err
return nil, fmt.Errorf("error: %w", err)
}
}
params.SetProposedEntry(entry)
......
......@@ -117,7 +117,7 @@ var verifyCmd = &cobra.Command{
entry, err := types.NewProposedEntry(context.Background(), typeStr, versionStr, *props)
if err != nil {
return nil, err
return nil, fmt.Errorf("error: %w", err)
}
entries := []models.ProposedEntry{entry}
......
......@@ -196,6 +196,10 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
var err error
if props.PKIFormat != string(pki.X509) {
return nil, errors.New("hashedrekord entries can only be created for artifacts signed with x509-based PKI")
}
re.HashedRekordObj.Signature = &models.HashedrekordV001SchemaSignature{}
sigBytes := props.SignatureBytes
if sigBytes == nil {
......
......@@ -155,14 +155,14 @@ func TestUploadVerifyHashedRekord(t *testing.T) {
}
// Verify should fail initially
runCliErr(t, "verify", "--type=hashedrekord", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
runCliErr(t, "verify", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
// It should upload successfully.
out := runCli(t, "upload", "--type=hashedrekord", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
out := runCli(t, "upload", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
outputContains(t, out, "Created entry at")
// Now we should be able to verify it.
out = runCli(t, "verify", "--type=hashedrekord", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
out = runCli(t, "verify", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath)
outputContains(t, out, "Inclusion Proof:")
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment