Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Remove the Amber provenance format #225

Merged
merged 6 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions cmd/verifier/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
# Verifying provenances

The [`verifier`](/internal/verifier/) package provides functionality for verifying an input
provenance file. The provenance file should follow the
[Amber provenance](./../pkg/amber/schema/v1/provenance.json) format and provide a list of materials
(including the source code and the build toolchain), and steps for building a binary from the listed
materials. The verification logic uses the provenance file to build a binary, and checks that the
binary has a SHA256 hash equal to the expected digest given in the provenance file.
The [`verifier`](/internal/verifier/) package provides functionality for verifying an input SLSA
provenance file. Currently the provenance verifier only parses the provenance files, and verifies
that it contains exactly one subject, containing a SHA256 digest and a binary name.

Note that the Amber provenance format will soon be deprecated (see
[issue #224](https://github.com/project-oak/transparent-release/issues/224)), and replaced with
[SLSA v1.0 format](https://slsa.dev/provenance/v1).

To verify a SLSA provenance of the Amber build type run:

```console
$ go run cmd/verifier/main.go -provenance_path schema/provenance/v1/example.json
```

This fetches the sources from the Git repository specified in the SLSA statement file, re-runs the
build, and verifies that it yields the expected hash.

Check the [`development guidelines`](./../docs/development-guidelines.md) for a quick start to
[`verifying provenances`](./../docs/development-guidelines.md#verifying-provenances).

To use a local repository you can specify `-git_root_dir`. In this case, the binary will be built
from the repo, only if the latest commit matches the one specified in the config file fail with an
error otherwise.
To verify a SLSA v0.2 provenance, run:

```console
$ go run cmd/verifier/main.go \
-provenance_path schema/provenance/v1/example.json \
-git_root_dir <path-to-git-repo-root>
$ go run cmd/verifier/main.go -provenance_path testdata/slsa_v02_provenance.json
2023/04/21 14:33:47 Verification was successful.
```
33 changes: 22 additions & 11 deletions cmd/verifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,47 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package main contains a command-line tool for building binaries.
// Package main contains a command-line tool for verifying SLSA provenances.
package main

import (
"flag"
"log"
"os"

"github.com/project-oak/transparent-release/internal/common"
"github.com/project-oak/transparent-release/internal/verifier"
"github.com/project-oak/transparent-release/pkg/amber"
"github.com/project-oak/transparent-release/pkg/types"
)

func main() {
provenancePath := flag.String("provenance_path", "",
"Required - Path to SLSA provenance file of the Amber build type.")
gitRootDirPtr := flag.String("git_root_dir", "",
"Optional - Root of the Git repository. If not specified, sources are fetched from the repo specified in the config file.")
"Required - Path to a SLSA provenance file.")
flag.Parse()

provenance, err := amber.ParseProvenanceFile(*provenancePath)
provenanceBytes, err := os.ReadFile(*provenancePath)
if err != nil {
log.Fatalf("couldn't load the provenance file from %s: %v", *provenancePath, err)
return
log.Fatalf("couldn't load the provenance bytes from %s: %v", *provenancePath, err)
}
// Parse into a validated provenance to get the predicate/build type of the provenance.
validatedProvenance, err := types.ParseStatementData(provenanceBytes)
if err != nil {
log.Fatalf("couldn't parse bytes from %s into a validated provenance: %v", *provenancePath, err)
}
// Map to internal provenance representation based on the predicate/build type.
provenanceIR, err := common.FromValidatedProvenance(validatedProvenance)
if err != nil {
log.Fatalf("couldn't map from %s to internal representation: %v", validatedProvenance, err)
}

provenanceVerifier := verifier.ReproducibleProvenanceVerifier{
Provenance: provenance,
GitRootDir: *gitRootDirPtr,
provenanceVerifier := verifier.ProvenanceIRVerifier{
Got: provenanceIR,
Want: &common.ReferenceValues{},
}

if err := provenanceVerifier.Verify(); err != nil {
log.Fatalf("error when verifying the provenance: %v", err)
}

log.Print("Verification was successful.")
}
Loading