-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Asra Ali <asraa@google.com>
- Loading branch information
Showing
3 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
] | ||
} |