这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all 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
32 changes: 29 additions & 3 deletions testing/fakekds.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,34 @@ import (
"google.golang.org/protobuf/proto"
)

var testUseKDS = flag.Bool("test_use_kds", false, "If true, tests will attempt to retrieve certificates from AMD KDS")
var testUseKDS = flag.Bool("test_use_kds", false, "Deprecated: If true, tests will attempt to retrieve certificates from AMD KDS")

type testKdsType struct {
value string
}

func (t *testKdsType) String() string { return t.value }
func (t *testKdsType) Set(value string) error {
if value != "amd" && value != "cache" && value != "none" {
return fmt.Errorf("--test_kds must be one of amd, cache, or none. Got %q", value)
}
t.value = value
return nil
}

var testKds = testKdsType{value: "cache"}

func init() {
flag.Var(&testKds, "test_kds", "One of amd, cache, none. If amd, tests will "+
"attempt to retrieve certificates from AMD KDS. If cache, only piper-submitted certificates "+
"will be available given a hostname and TCB version. If none, then no VCEK certificates will "+
"be retrieved.")
}

// TestUseKDS returns whether tests should use the network to connect the live AMD Key Distribution
// service.
func TestUseKDS() bool {
return *testUseKDS
return *testUseKDS || testKds.value == "amd"
}

// The Milan product certificate bundle is only embedded for tests rather than in the main library
Expand Down Expand Up @@ -144,13 +166,17 @@ func (f *FakeKDS) Get(url string) ([]byte, error) {
// GetKDS returns an HTTPSGetter that can produce the expected certificates for a given URL in the
// test environment.
func GetKDS(t testing.TB) trust.HTTPSGetter {
if *testUseKDS {
if TestUseKDS() {
return trust.DefaultHTTPSGetter()
}
fakeKds := &FakeKDS{
Certs: &kpb.Certificates{},
RootBundles: map[string]string{"Milan": string(milanCerts)},
}
// Provide nothing if --test_kds=none.
if testKds.value == "none" {
return fakeKds
}
if err := proto.Unmarshal(internalKDSCache, fakeKds.Certs); err != nil {
t.Fatalf("could not unmarshal embedded FakeKDS file: %v", err)
}
Expand Down