()
| 64 | } |
| 65 | |
| 66 | func main() { |
| 67 | flag.Parse() |
| 68 | if *artifactDigest == "" { |
| 69 | fmt.Fprintln(os.Stderr, "artifact-digest is required.") |
| 70 | usage() |
| 71 | os.Exit(1) |
| 72 | } |
| 73 | |
| 74 | token := os.Getenv("GITHUB_AUTH_TOKEN") |
| 75 | |
| 76 | if token == "" { |
| 77 | log.Fatal("Unauthorized: No token present. Please set the GITHUB_AUTH_TOKEN environment variable to a valid token with `attestations:read` permission.") |
| 78 | } |
| 79 | |
| 80 | ctx := context.Background() |
| 81 | client, err := github.NewClient(github.WithAuthToken(token)) |
| 82 | if err != nil { |
| 83 | log.Fatalf("Error creating GitHub client: %v", err) |
| 84 | } |
| 85 | |
| 86 | // Fetch attestations from the GitHub API. |
| 87 | // The attestations API doesn't differentiate between users and orgs, |
| 88 | // so we can use the OrganizationsService to fetch attestations for both. |
| 89 | attestations, _, err := client.Organizations.ListAttestations(ctx, *owner, fmt.Sprintf("%v:%v", *artifactDigestAlgorithm, *artifactDigest), nil) |
| 90 | if err != nil { |
| 91 | log.Fatal(err) |
| 92 | } |
| 93 | |
| 94 | if len(attestations.Attestations) == 0 { |
| 95 | log.Fatal("No attestations found.") |
| 96 | } |
| 97 | |
| 98 | sev, err := getSignedEntityVerifier() |
| 99 | if err != nil { |
| 100 | log.Fatal(err) |
| 101 | } |
| 102 | |
| 103 | pb, err := getPolicyBuilder() |
| 104 | if err != nil { |
| 105 | log.Fatal(err) |
| 106 | } |
| 107 | |
| 108 | var b *bundle.Bundle |
| 109 | for _, attestation := range attestations.Attestations { |
| 110 | if err := json.Unmarshal(attestation.Bundle, &b); err != nil { |
| 111 | log.Fatal(err) |
| 112 | } |
| 113 | |
| 114 | err := runVerification(sev, pb, b) |
| 115 | if err != nil { |
| 116 | log.Fatal(err) |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func getTrustedMaterial() (root.TrustedMaterialCollection, error) { |
| 122 | trustedRootJSON, err := os.ReadFile(*trustedRootJSONPath) |
nothing calls this directly
no test coverage detected
searching dependent graphs…