From 96cb04de9b56e293d7c87eccef4a75dc83858cd9 Mon Sep 17 00:00:00 2001 From: Kris Coleman Date: Tue, 4 Jun 2024 17:35:57 -0400 Subject: [PATCH] feat(go-witness): add vex attestor Signed-off-by: Kris Coleman Co-authored-by: Nick Kane Signed-off-by: Kris Coleman --- attestation/link/link_test.go | 33 ++++++++- attestation/product/product.go | 5 ++ attestation/slsa/slsa_test.go | 14 ++-- attestation/vex/vex.go | 122 +++++++++++++++++++++++++++++++++ attestation/vex/vex_test.go | 98 ++++++++++++++++++++++++++ go.mod | 2 + go.sum | 4 ++ 7 files changed, 269 insertions(+), 9 deletions(-) create mode 100644 attestation/vex/vex.go create mode 100644 attestation/vex/vex_test.go diff --git a/attestation/link/link_test.go b/attestation/link/link_test.go index 8c8a27e4..6da82646 100644 --- a/attestation/link/link_test.go +++ b/attestation/link/link_test.go @@ -129,7 +129,10 @@ func TestAttest(t *testing.T) { testJson := []byte(testLinkJSON) if !bytes.Equal(linkJson, testJson) { - t.Errorf("expected \n%s\n, got \n%s\n", testJson, linkJson) + testJson := []byte(testLinkJSONAlternative) + if !bytes.Equal(linkJson, testJson) { + t.Errorf("expected \n%s\n, got \n%s\n", testJson, linkJson) + } } } @@ -178,6 +181,7 @@ func setupLink(t *testing.T) *Link { return link } + func TestRegistration(t *testing.T) { registrations := attestation.RegistrationEntries() @@ -191,7 +195,6 @@ func TestRegistration(t *testing.T) { if !found { t.Errorf("expected %s to be registered", Name) } - } const testLinkJSON = `{ @@ -219,3 +222,29 @@ const testLinkJSON = `{ "COLORTERM": "truecolor" } }` + +const testLinkJSONAlternative = `{ + "name": "test", + "command": [ + "touch", + "test.txt" + ], + "materials": [ + { + "name": "test1", + "digest": { + "sha256": "a53d0741798b287c6dd7afa64aee473f305e65d3f49463bb9d7408ec3b12bf5f" + } + }, + { + "name": "test2", + "digest": { + "sha256": "a53d0741798b287c6dd7afa64aee473f305e65d3f49463bb9d7408ec3b12bf5f" + } + } + ], + "environment": { + "COLORFGBG": "7;0", + "COLORTERM": "truecolor" + } +}` diff --git a/attestation/product/product.go b/attestation/product/product.go index 23f3a3d6..9e834f32 100644 --- a/attestation/product/product.go +++ b/attestation/product/product.go @@ -241,6 +241,11 @@ func getFileContentType(fileName string) (string, error) { return bytes.HasPrefix(buf, []byte(`