-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor package common #226
Changes from 4 commits
2b11be1
5bc42e1
a92704a
3819e09
1fa5122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
{ | ||
"**/*.go": "// Copyright 2022 The Project Oak Authors", | ||
"**/BUILD": "# Copyright 2022 The Project Oak Authors" | ||
"**/*.go": ["// Licensed under the Apache License, Version 2.0 (the \"License\");"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The Project Oak Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package verification | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pelletier/go-toml" | ||
) | ||
|
||
// ReferenceValues given by the product team to verify provenances against. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't particularly like the "product team" terminology. How about "verifier" or "client"? I don't really like those either, but I think we should keep thinking about a better alternative (after this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't care so much where these values come from, at least in this documentation. Updated the comments. |
||
type ReferenceValues struct { | ||
// The digests of the binaries whose provenance the product team wants to verify. | ||
BinarySHA256Digests []string `toml:"binary_sha256_digests"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why these are only sha256? Could they not be arbitrary digests, as long as they have the appropriate prefix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general they could, but we use SHA256. We can relax this restriction in the future if needed. |
||
// If true the product team wants the provenance to have a non-empty build command. | ||
WantBuildCmds bool `toml:"want_build_cmds"` | ||
// The digests of the builder images the product team trusts to build the binary. | ||
BuilderImageSHA256Digests []string `toml:"builder_image_sha256_digests"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For slice fields, I assume that means that any of those values is sufficient? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Updated the comment to better reflect this. |
||
// The URI of the repo holding the resources the binary is built from. | ||
RepoURI string `toml:"repo_uri"` | ||
// The builders a product team trusts to build the binary. | ||
TrustedBuilders []string `toml:"trusted_builders"` | ||
} | ||
|
||
// LoadReferenceValuesFromFile loads reference values from a toml file in the given path and returns an instance of ReferenceValues. | ||
func LoadReferenceValuesFromFile(path string) (*ReferenceValues, error) { | ||
tomlTree, err := toml.LoadFile(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("couldn't load toml file: %v", err) | ||
} | ||
|
||
referenceValues := ReferenceValues{} | ||
if err := tomlTree.Unmarshal(&referenceValues); err != nil { | ||
return nil, fmt.Errorf("couldn't unmarshal toml file: %v", err) | ||
} | ||
|
||
return &referenceValues, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 The Project Oak Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package verification | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/project-oak/transparent-release/internal/testutil" | ||
) | ||
|
||
const ( | ||
testdataPath = "../../testdata/" | ||
) | ||
|
||
func TestParseReferenceValues(t *testing.T) { | ||
path := filepath.Join(testdataPath, "reference_values.toml") | ||
referenceValues, err := LoadReferenceValuesFromFile(path) | ||
if err != nil { | ||
t.Fatalf("couldn't load reference values file: %v", err) | ||
} | ||
|
||
testutil.AssertEq(t, "binary digests[0]", referenceValues.BinarySHA256Digests[0], "d059c38cea82047ad316a1c6c6fbd13ecf7a0abdcc375463920bd25bf5c142cc") | ||
testutil.AssertEq(t, "want build cmd", referenceValues.WantBuildCmds, false) | ||
testutil.AssertEq(t, "builder image digests[0]", referenceValues.BuilderImageSHA256Digests[0], "9e2ba52487d945504d250de186cb4fe2e3ba023ed2921dd6ac8b97ed43e76af9") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong package name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed.