Skip to content

Commit

Permalink
fix: fix blob verification output
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa committed Aug 12, 2022
1 parent 7d80bc0 commit 15f4d30
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/cosign/cli/verify/verify_blob.go
Expand Up @@ -362,7 +362,7 @@ func verifyRekorEntry(ctx context.Context, ko options.KeyOpts, e *models.LogEntr
return err
}

fmt.Fprintf(os.Stderr, "tlog entry verified with uuid: %s index: %d\n", hex.EncodeToString(uuid), *e.Verification.InclusionProof.LogIndex)
fmt.Fprintf(os.Stderr, "tlog entry verified with uuid: %s index: %d\n", hex.EncodeToString(uuid), *e.LogIndex)
if cert == nil {
return nil
}
Expand Down
117 changes: 117 additions & 0 deletions cmd/test/main.go
@@ -0,0 +1,117 @@
package main

import (
"bytes"
"context"
"crypto"
"encoding/json"
"fmt"
"log"
"os"
"strings"

"github.com/sigstore/cosign/cmd/cosign/cli/rekor"
"github.com/sigstore/cosign/pkg/cosign"
"github.com/sigstore/cosign/pkg/cosign/attestation"
"github.com/sigstore/cosign/pkg/types"
"github.com/sigstore/rekor/pkg/generated/client/entries"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"github.com/sigstore/sigstore/pkg/signature"
"github.com/sigstore/sigstore/pkg/signature/dsse"
)

func main() {
/*
leafHash, _ := hex.DecodeString("71b798262fcef0c46b6516ac372f3e9cfe4d7dcbeff980b8c90670f9d9fc2e81")
rootHash, _ := hex.DecodeString("542F2EEBA553152D7423BAB993E84563355FE74B6E4729CF4AA90C642FCD5A86")
hashes := [][]byte{}
loadedHashes := []string{
"ecbed6e3645732b327770fcaebb8cb8b77f3dbe6823bd638e48b78a25144aa5b",
"daf09a97cf09589cd97b4e85ecf87649e75d34ee9e176e04f594dea7359faea6",
"83cae05a2978c0242bb2493e88a83605660a92df1ba8c5b7ea67b3858e9e038f",
}
for _, h := range loadedHashes {
hb, _ := hex.DecodeString(h)
hashes = append(hashes, hb)
}
if err := proof.VerifyInclusion(rfc6962.DefaultHasher, uint64(25), uint64(26),
leafHash, hashes, rootHash); err != nil {
log.Fatal(fmt.Sprintf("verifying inclusion proof: %s", err.Error()))
}
fmt.Printf("sucess")
*/

ctx := context.Background()
rekorClient, err := rekor.NewClient("http://localhost:3000")
if err != nil {
log.Fatal("creating rekor client: %w", err)
}

f, err := os.ReadFile("./cmd/test/pred.json")
if err != nil {
log.Fatal("creating rekor client: %w", err)
}

// create a signed attestation
for i := 1; i < 200; i++ {
priv, err := cosign.GeneratePrivateKey()
if err != nil {
log.Fatal(err)
}
sv, err := signature.LoadECDSASignerVerifier(priv, crypto.SHA256)
if err != nil {
log.Fatal(err)
}
wrapped := dsse.WrapSigner(sv, types.IntotoPayloadType)
sh, err := attestation.GenerateStatement(attestation.GenerateOpts{
Predicate: bytes.NewReader(f),
Type: "slsaprovenance",
Digest: "",
Repo: "",
})
if err != nil {
log.Fatal(err)
}

payload, err := json.Marshal(sh)
if err != nil {
log.Fatal(err)
}
att, err := wrapped.SignMessage(bytes.NewReader(payload))
if err != nil {
log.Fatal(err)
}

// upload
rekorBytes, err := cryptoutils.MarshalPublicKeyToPEM(sv.Public())
if err != nil {
log.Fatal(err)
}
logEntry, err := cosign.TLogUploadInTotoAttestation(ctx, rekorClient, att, rekorBytes)
if err != nil {
log.Fatal("uploading attestation: %w", err)
}

// get the log entry proof from 2 ago
params := entries.NewGetLogEntryByIndexParamsWithContext(ctx)
params.SetLogIndex(*logEntry.LogIndex)
resp, err := rekorClient.Entries.GetLogEntryByIndex(params)
if err != nil {
log.Fatal("retrieving log uuid by index: %w", err)
}
for uuid, entry := range resp.Payload {
err := cosign.VerifyTLogEntry(ctx, rekorClient, &entry)
if err != nil {
fmt.Println(fmt.Sprintf("log index: %d", *entry.LogIndex))
fmt.Println(fmt.Sprintf("tree size: %d", *entry.Verification.InclusionProof.TreeSize))
fmt.Println(fmt.Sprintf("root hash: %s", *entry.Verification.InclusionProof.RootHash))
fmt.Println(fmt.Sprintf("uuid: %s", uuid))
fmt.Printf(strings.Join(entry.Verification.InclusionProof.Hashes, "\n "))
log.Fatal(fmt.Sprintf("validating log entry %d: %s", *logEntry.LogIndex, err))
}
log.Print(fmt.Sprintf("verified %d", *logEntry.LogIndex))
}
}

}
26 changes: 26 additions & 0 deletions cmd/test/pred.json
@@ -0,0 +1,26 @@
{
"builder": {
"id": "https://github.com/slsa-framework/slsa-github-generator-go/.github/workflows/builder.yml@refs/heads/main"
},
"buildType": "https://github.com/slsa-framework/slsa-github-generator-go@v1",
"invocation": {
"configSource": {
"uri": "git+https://github.comlaurentsimon/slsa-on-github-test@refs/heads/main.git",
"digest": {
"sha1": "d3fd9482e68d276e69c0a8b3f7eaabb3b9e56695"
},
"entryPoint": "SLSA Release"
},
"parameters": {},
"environment": {}
},
"buildConfig": {},
"materials": [
{
"uri": "git+laurentsimon/slsa-on-github-test.git",
"digest": {
"sha1": "d3fd9482e68d276e69c0a8b3f7eaabb3b9e56695"
}
}
]
}

0 comments on commit 15f4d30

Please sign in to comment.