This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Refactor package common #226
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2b11be1
Move everything related to verification to internal/verification package
rbehjati 5bc42e1
Rename package common to model
rbehjati a92704a
Update README
rbehjati 3819e09
Update license file
rbehjati 1fa5122
Fixes after review
rbehjati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\");"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 specify expected values to verify provenances against. | ||
type ReferenceValues struct { | ||
// Allow list of binary digests. | ||
BinarySHA256Digests []string `toml:"binary_sha256_digests"` | ||
// If true, expect that the provenance has a non-empty build command. | ||
WantBuildCmds bool `toml:"want_build_cmds"` | ||
// Allow list of builder image digests that are trusted for building 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"` | ||
// Allow list of builders trusted 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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.