Skip to content

Commit

Permalink
Merge pull request #24 from jrjatin/validate-changes
Browse files Browse the repository at this point in the history
Rename check.proto to checkconfig.proto
  • Loading branch information
jrjatin authored Sep 29, 2023
2 parents 7b2d9d9 + ce37260 commit 46c1339
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 146 deletions.
6 changes: 3 additions & 3 deletions proto/check.proto → proto/checkconfig.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

syntax = "proto3";

// Package check represents an attestation validation policy.
package check;
// Package checkconfig represents an attestation validation policy.
package checkconfig;

option go_package = "github.com/google/go-tdx-guest/proto/check";
option go_package = "github.com/google/go-tdx-guest/proto/checkconfig";

// Policy is a representation of an attestation quote validation policy.
// Each field corresponds to a field on validate.Options. This format
Expand Down
236 changes: 119 additions & 117 deletions proto/check/check.pb.go → proto/checkconfig/checkconfig.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions proto/check/doc.go → proto/checkconfig/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// 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
// 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 check defines the message type for the check CLI tool's options.
package check
// Package checkconfig defines the message type for the check CLI tool's options.
package checkconfig
2 changes: 1 addition & 1 deletion proto/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
package proto

//go:generate protoc -I$PROTOC_INSTALL_DIR/include -I=. --go_out=. --go_opt=module=github.com/google/go-tdx-guest/proto tdx.proto
//go:generate protoc -I$PROTOC_INSTALL_DIR/include -I=. --go_out=. --go_opt=module=github.com/google/go-tdx-guest/proto check.proto
//go:generate protoc -I$PROTOC_INSTALL_DIR/include -I=. --go_out=. --go_opt=module=github.com/google/go-tdx-guest/proto checkconfig.proto
12 changes: 6 additions & 6 deletions tools/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

"github.com/google/go-sev-guest/tools/lib/cmdline"
"github.com/google/go-tdx-guest/abi"
checkpb "github.com/google/go-tdx-guest/proto/check"
ccpb "github.com/google/go-tdx-guest/proto/checkconfig"
pb "github.com/google/go-tdx-guest/proto/tdx"
testcases "github.com/google/go-tdx-guest/testing"
"github.com/google/go-tdx-guest/validate"
Expand Down Expand Up @@ -108,9 +108,9 @@ var (
testLocalGetter = flag.Bool("test_local_getter", false, "Use this flag only to test this CLI tool when network access is not available")

// Assign the values of the flags to the corresponding proto fields
config = &checkpb.Config{
RootOfTrust: &checkpb.RootOfTrust{},
Policy: &checkpb.Policy{HeaderPolicy: &checkpb.HeaderPolicy{}, TdQuoteBodyPolicy: &checkpb.TDQuoteBodyPolicy{}},
config = &ccpb.Config{
RootOfTrust: &ccpb.RootOfTrust{},
Policy: &ccpb.Policy{HeaderPolicy: &ccpb.HeaderPolicy{}, TdQuoteBodyPolicy: &ccpb.TDQuoteBodyPolicy{}},
}
)

Expand Down Expand Up @@ -220,10 +220,10 @@ func parseConfig(path string) error {
}
// Populate fields that should not be nil
if config.RootOfTrust == nil {
config.RootOfTrust = &checkpb.RootOfTrust{}
config.RootOfTrust = &ccpb.RootOfTrust{}
}
if config.Policy == nil {
config.Policy = &checkpb.Policy{HeaderPolicy: &checkpb.HeaderPolicy{}, TdQuoteBodyPolicy: &checkpb.TDQuoteBodyPolicy{}}
config.Policy = &ccpb.Policy{HeaderPolicy: &ccpb.HeaderPolicy{}, TdQuoteBodyPolicy: &ccpb.TDQuoteBodyPolicy{}}
}
return nil
}
Expand Down
22 changes: 11 additions & 11 deletions tools/check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
"strconv"
"testing"

checkpb "github.com/google/go-tdx-guest/proto/check"
ccpb "github.com/google/go-tdx-guest/proto/checkconfig"
"github.com/google/logger"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
)

// Returns true if the test should be skipped for the protobuf case since the field
// can't be set to the expected value.
type setterFn func(p *checkpb.Policy, value string, t *testing.T) bool
type setterFn func(p *ccpb.Policy, value string, t *testing.T) bool

// Represents a test case that will set a flag or config field to a good or bad value.
// We use this data to check that
Expand Down Expand Up @@ -75,7 +75,7 @@ func withBaseArgs(config string, args ...string) []string {
return result
}

func setField(p *checkpb.Policy, policy string, name string, value any) {
func setField(p *ccpb.Policy, policy string, name string, value any) {
if policy == "header_policy" {
s := p.HeaderPolicy
r := s.ProtoReflect()
Expand All @@ -90,7 +90,7 @@ func setField(p *checkpb.Policy, policy string, name string, value any) {
}

func bytesSetter(name string, policy string) setterFn {
return func(p *checkpb.Policy, value string, t *testing.T) bool {
return func(p *ccpb.Policy, value string, t *testing.T) bool {
v, err := hex.DecodeString(value)
if err != nil {
return true
Expand All @@ -101,7 +101,7 @@ func bytesSetter(name string, policy string) setterFn {
}

func uint32setter(name string, policy string) setterFn {
return func(p *checkpb.Policy, value string, t *testing.T) bool {
return func(p *ccpb.Policy, value string, t *testing.T) bool {
u, err := strconv.ParseUint(value, 10, 32)
if err != nil {
return true
Expand Down Expand Up @@ -217,8 +217,8 @@ func withTempFile(contents []byte, t *testing.T, runner func(path string)) {
runner(file.Name())
}

func withTestConfig(p *checkpb.Policy, t *testing.T, runner func(path string)) {
config := &checkpb.Config{Policy: p}
func withTestConfig(p *ccpb.Policy, t *testing.T, runner func(path string)) {
config := &ccpb.Config{Policy: p}

out, err := proto.Marshal(config)
if err != nil {
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestRtmrs(t *testing.T) {
func TestCheckGoodFields(t *testing.T) {
for _, tc := range testCases() {
t.Run(tc.flag, func(t *testing.T) {
p := &checkpb.Policy{HeaderPolicy: &checkpb.HeaderPolicy{}, TdQuoteBodyPolicy: &checkpb.TDQuoteBodyPolicy{}}
p := &ccpb.Policy{HeaderPolicy: &ccpb.HeaderPolicy{}, TdQuoteBodyPolicy: &ccpb.TDQuoteBodyPolicy{}}
if tc.setter(p, tc.good, t) {
t.Fatal("unexpected parse failure")
}
Expand All @@ -302,7 +302,7 @@ func TestCheckBadFields(t *testing.T) {
for _, tc := range testCases() {
for i, bad := range tc.bad {
t.Run(fmt.Sprintf("%s_bad[%d]", tc.flag, i+1), func(t *testing.T) {
p := &checkpb.Policy{HeaderPolicy: &checkpb.HeaderPolicy{}, TdQuoteBodyPolicy: &checkpb.TDQuoteBodyPolicy{}}
p := &ccpb.Policy{HeaderPolicy: &ccpb.HeaderPolicy{}, TdQuoteBodyPolicy: &ccpb.TDQuoteBodyPolicy{}}
if tc.setter(p, bad, t) {
return
}
Expand All @@ -321,7 +321,7 @@ func TestCheckGoodFlagOverridesBadField(t *testing.T) {
for _, tc := range testCases() {
for i, bad := range tc.bad {
t.Run(fmt.Sprintf("%s_bad[%d]", tc.flag, i+1), func(t *testing.T) {
p := &checkpb.Policy{HeaderPolicy: &checkpb.HeaderPolicy{}, TdQuoteBodyPolicy: &checkpb.TDQuoteBodyPolicy{}}
p := &ccpb.Policy{HeaderPolicy: &ccpb.HeaderPolicy{}, TdQuoteBodyPolicy: &ccpb.TDQuoteBodyPolicy{}}
if tc.setter(p, bad, t) {
return
}
Expand All @@ -340,7 +340,7 @@ func TestCheckBadFlagOverridesGoodField(t *testing.T) {
for _, tc := range testCases() {
for i, bad := range tc.bad {
t.Run(fmt.Sprintf("%s_bad[%d]", tc.flag, i+1), func(t *testing.T) {
p := &checkpb.Policy{HeaderPolicy: &checkpb.HeaderPolicy{}, TdQuoteBodyPolicy: &checkpb.TDQuoteBodyPolicy{}}
p := &ccpb.Policy{HeaderPolicy: &ccpb.HeaderPolicy{}, TdQuoteBodyPolicy: &ccpb.TDQuoteBodyPolicy{}}
if tc.setter(p, tc.good, t) {
t.Fatal("unexpected parse failure")
}
Expand Down
4 changes: 2 additions & 2 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"

"github.com/google/go-tdx-guest/abi"
cpb "github.com/google/go-tdx-guest/proto/check"
ccpb "github.com/google/go-tdx-guest/proto/checkconfig"
pb "github.com/google/go-tdx-guest/proto/tdx"
vr "github.com/google/go-tdx-guest/verify"
"go.uber.org/multierr"
Expand Down Expand Up @@ -124,7 +124,7 @@ func checkOptionsLengths(opts *Options) error {
}

// PolicyToOptions returns an Options object that is represented by a Policy message.
func PolicyToOptions(policy *cpb.Policy) (*Options, error) {
func PolicyToOptions(policy *ccpb.Policy) (*Options, error) {
if policy.GetHeaderPolicy().GetMinimumQeSvn() > 65535 {
return nil, fmt.Errorf("minimum_qe_svn is %d. Expect 0-65535", policy.GetHeaderPolicy().GetMinimumQeSvn())
}
Expand Down
6 changes: 3 additions & 3 deletions verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

"github.com/google/go-tdx-guest/abi"
"github.com/google/go-tdx-guest/pcs"
cpb "github.com/google/go-tdx-guest/proto/check"
ccpb "github.com/google/go-tdx-guest/proto/checkconfig"
pb "github.com/google/go-tdx-guest/proto/tdx"
"github.com/google/go-tdx-guest/verify/trust"
"github.com/google/logger"
Expand Down Expand Up @@ -1214,7 +1214,7 @@ func RawTdxQuote(raw []byte, options *Options) error {
return TdxQuote(quote, options)
}

func getTrustedRoots(rot *cpb.RootOfTrust) (*x509.CertPool, error) {
func getTrustedRoots(rot *ccpb.RootOfTrust) (*x509.CertPool, error) {
if len(rot.CabundlePaths) == 0 && len(rot.Cabundles) == 0 {
return nil, nil
}
Expand All @@ -1239,7 +1239,7 @@ func getTrustedRoots(rot *cpb.RootOfTrust) (*x509.CertPool, error) {

// RootOfTrustToOptions translates the RootOfTrust message into the Options type needed
// for driving an attestation verification.
func RootOfTrustToOptions(rot *cpb.RootOfTrust) (*Options, error) {
func RootOfTrustToOptions(rot *ccpb.RootOfTrust) (*Options, error) {
trustedRoots, err := getTrustedRoots(rot)
if err != nil {
return nil, err
Expand Down

0 comments on commit 46c1339

Please sign in to comment.