Skip to content

Commit

Permalink
Add conformance binary support for providing custom trust roots.
Browse files Browse the repository at this point in the history
This allows us to have additional test cases that weren't previously
possible when assuming the public-good trust root.

See also sigstore/sigstore-conformance#101.
  • Loading branch information
steiza committed Sep 27, 2023
1 parent cd2b598 commit bca1ce3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ jobs:
with:
entrypoint: ${{ github.workspace }}/conformance
skip-signing: true
supports-trusted-root: true
65 changes: 45 additions & 20 deletions cmd/conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ var certPath *string
var certOIDC *string
var certSAN *string
var signaturePath *string
var trustedRootPath *string

func usage() {
fmt.Println("Usage:")
fmt.Printf("\t%s verify --signature FILE --certificate FILE --certificate-identity IDENTITY --certificate-oidc-issuer URL FILE\n", os.Args[0])
fmt.Printf("\t%s verify-bundle --bundle FILE --certificate-identity IDENTITY --certificate-oidc-issuer URL FILE\n", os.Args[0])
fmt.Printf("\t%s verify --signature FILE --certificate FILE --certificate-identity IDENTITY --certificate-oidc-issuer URL [--trusted-root FILE] FILE\n", os.Args[0])
fmt.Printf("\t%s verify-bundle --bundle FILE --certificate-identity IDENTITY --certificate-oidc-issuer URL [--trusted-root FILE] FILE\n", os.Args[0])
}

func main() {
Expand All @@ -49,6 +50,8 @@ func main() {
certSAN = &os.Args[i+1]
case "--signature":
signaturePath = &os.Args[i+1]
case "--trusted-root":
trustedRootPath = &os.Args[i+1]
}
}

Expand Down Expand Up @@ -116,20 +119,31 @@ func main() {
policyConfig = append(policyConfig, verify.WithCertificateIdentity(certID))
}

policyConfig = append(policyConfig, verify.WithArtifactDigest("sha256", fileDigest[:]))

// Load trust root
_, filename, _, ok := runtime.Caller(1)
if !ok {
log.Fatal("unable to get path")
}
var trustedRootJSON []byte

if trustedRootPath != nil {
trustedRootJSON, err = os.ReadFile(*trustedRootPath)
if err != nil {
log.Fatal(err)
}
} else {
_, filename, _, ok := runtime.Caller(1)
if !ok {
log.Fatal("unable to get path")
}

tufDir := path.Join(path.Dir(filename), "tufdata")
tufDir := path.Join(path.Dir(filename), "tufdata")

trustedrootJSON, err := tuf.GetTrustedrootJSON("tuf-repo-cdn.sigstore.dev", tufDir)
if err != nil {
log.Fatal(err)
trustedRootJSON, err = tuf.GetTrustedrootJSON("tuf-repo-cdn.sigstore.dev", tufDir)
if err != nil {
log.Fatal(err)
}
}

tr, err := root.NewTrustedRootFromJSON(trustedrootJSON)
tr, err := root.NewTrustedRootFromJSON(trustedRootJSON)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -158,6 +172,8 @@ func main() {
certOIDC = &os.Args[i+1]
case "--certificate-identity":
certSAN = &os.Args[i+1]
case "--trusted-root":
trustedRootPath = &os.Args[i+1]
}
}

Expand Down Expand Up @@ -186,19 +202,28 @@ func main() {
}

// Load trust root
_, filename, _, ok := runtime.Caller(1)
if !ok {
log.Fatal("unable to get path")
}
var trustedRootJSON []byte

tufDir := path.Join(path.Dir(filename), "tufdata")
if trustedRootPath != nil {
trustedRootJSON, err = os.ReadFile(*trustedRootPath)
if err != nil {
log.Fatal(err)
}
} else {
_, filename, _, ok := runtime.Caller(1)
if !ok {
log.Fatal("unable to get path")
}

trustedrootJSON, err := tuf.GetTrustedrootJSON("tuf-repo-cdn.sigstore.dev", tufDir)
if err != nil {
log.Fatal(err)
tufDir := path.Join(path.Dir(filename), "tufdata")

trustedRootJSON, err = tuf.GetTrustedrootJSON("tuf-repo-cdn.sigstore.dev", tufDir)
if err != nil {
log.Fatal(err)
}
}

tr, err := root.NewTrustedRootFromJSON(trustedrootJSON)
tr, err := root.NewTrustedRootFromJSON(trustedRootJSON)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit bca1ce3

Please sign in to comment.