diff --git a/verification/certifyKey_test.go b/verification/certifyKey_test.go index e8d1ebe3..81c9c6fc 100644 --- a/verification/certifyKey_test.go +++ b/verification/certifyKey_test.go @@ -116,23 +116,46 @@ func testCertifyKey(d TestDPEInstance, t *testing.T) { } defer d.PowerOff() } - client, err := NewClient256(d) + var client256 *Client256 + var client384 *Client384 + var err error + + if d.GetProfile() == DPE_EMULATOR_PROFILE { + client384, err = NewClient384(d) + } else { + client256, err = NewClient256(d) + } if err != nil { t.Fatalf("Could not initialize client: %v", err) } - certifyKeyReq := CertifyKeyReq[SHA256Digest]{ - ContextHandle: [16]byte{0}, - Flags: 0, - Label: [32]byte{0}, - Format: CertifyKeyX509, - } + if d.GetProfile() == DPE_EMULATOR_PROFILE { + certifyKeyReq := CertifyKeyReq[SHA384Digest]{ + ContextHandle: [16]byte{0}, + Flags: 0, + Label: [48]byte{0}, + Format: CertifyKeyX509, + } - certifyKeyResp, err := client.CertifyKey(&certifyKeyReq) - if err != nil { - t.Fatalf("Could not certify key: %v", err) + certifyKeyResp, err := client384.CertifyKey(&certifyKeyReq) + if err != nil { + t.Fatalf("Could not certify key: %v", err) + } + checkCertificateStructure(t, certifyKeyResp.Certificate) + } else { + certifyKeyReq := CertifyKeyReq[SHA256Digest]{ + ContextHandle: [16]byte{0}, + Flags: 0, + Label: [32]byte{0}, + Format: CertifyKeyX509, + } + + certifyKeyResp, err := client256.CertifyKey(&certifyKeyReq) + if err != nil { + t.Fatalf("Could not certify key: %v", err) + } + checkCertificateStructure(t, certifyKeyResp.Certificate) } - checkCertificateStructure(t, certifyKeyResp.Certificate) // TODO: When DeriveChild is implemented, call it here to add more TCIs and call CertifyKey again. } diff --git a/verification/client.go b/verification/client.go index ad589dc7..30139e78 100644 --- a/verification/client.go +++ b/verification/client.go @@ -253,3 +253,40 @@ func (s *Support) ToFlags() uint32 { } return flags } + +func (s *Support) ToSupport(flag uint32) *Support { + if flag&(1<<31) != 0 { + s.Simulation = true + } + if flag&(1<<30) != 0 { + s.ExtendTci = true + } + if flag&(1<<29) != 0 { + s.AutoInit = true + } + if flag&(1<<28) != 0 { + s.Tagging = true + } + if flag&(1<<27) != 0 { + s.RotateContext = true + } + if flag&(1<<26) != 0 { + s.X509 = true + } + if flag&(1<<25) != 0 { + s.Csr = true + } + if flag&(1<<24) != 0 { + s.IsSymmetric = true + } + if flag&(1<<23) != 0 { + s.InternalInfo = true + } + if flag&(1<<22) != 0 { + s.InternalDice = true + } + if flag&(1<<21) != 0 { + s.IsCA = true + } + return s +} diff --git a/verification/emulator.go b/verification/emulator.go index 5a12f285..2c2187a7 100644 --- a/verification/emulator.go +++ b/verification/emulator.go @@ -6,6 +6,7 @@ import ( "bytes" "encoding/binary" "errors" + "fmt" "io" "net" "os" @@ -20,16 +21,16 @@ const ( DPE_EMULATOR_AUTO_INIT_LOCALITY uint32 = 0 DPE_EMULATOR_OTHER_LOCALITY uint32 = 0 - DPE_EMULATOR_PROFILE Profile = 0 - DPE_EMULATOR_MAX_TCI_NODES uint32 = 0 + DPE_EMULATOR_PROFILE Profile = ProfileP384SHA384 + DPE_EMULATOR_MAX_TCI_NODES uint32 = 0x00000018 DPE_EMULATOR_MAJOR_PROFILE_VERSION uint16 = 0 - DPE_EMULATOR_MINOR_PROFILE_VERSION uint16 = 0 - DPE_EMULATOR_VENDOR_ID uint32 = 0 - DPE_EMULATOR_VENDOR_SKU uint32 = 0 + DPE_EMULATOR_MINOR_PROFILE_VERSION uint16 = 8 + DPE_EMULATOR_VENDOR_ID uint32 = 0x43545241 + DPE_EMULATOR_VENDOR_SKU uint32 = 0x43545241 ) // Added dummy support for emulator .This is to verify against the support_needed list -var emulator_supports = []string{"AutoInit", "X509"} +var emulator_supports = []string{"AutoInit", "X509", "Simulation", "Tagging"} //TODO code for emulator to start, stop, getsupport @@ -116,7 +117,7 @@ func (s *DpeEmulator) waitForPower(on bool) bool { for i := 0; i < checks_per_sec*timeout_seconds; i++ { // Check if the socket file has been created. - if fileExists(simulatorSocketPath) == on { + if fileExists(emulatorSocketPath) == on { return true } time.Sleep(time.Duration(1000/checks_per_sec) * time.Millisecond) @@ -126,7 +127,7 @@ func (s *DpeEmulator) waitForPower(on bool) bool { func (s *DpeEmulator) SendCmd(buf []byte) ([]byte, error) { // Connect to DPE instance. - conn, err := net.Dial("unix", simulatorSocketPath) + conn, err := net.Dial("unix", emulatorSocketPath) if err != nil { return nil, err } @@ -157,8 +158,12 @@ func (s *DpeEmulator) GetSupport() *Support { return &s.supports } +func (s *DpeEmulator) SetSupport(support Support) { + s.supports = support +} + func (s *DpeEmulator) GetProfile() Profile { - return DPE_SIMULATOR_PROFILE + return DPE_EMULATOR_PROFILE } func (s *DpeEmulator) GetSupportedLocalities() []uint32 { diff --git a/verification/getProfile_test.go b/verification/getProfile_test.go index 39afc6f5..ed6bd0b0 100644 --- a/verification/getProfile_test.go +++ b/verification/getProfile_test.go @@ -243,19 +243,25 @@ func testGetProfile(d TestDPEInstance, t *testing.T) { } defer d.PowerOff() } - client, err := NewClient256(d) + var client256 *Client256 + var client384 *Client384 + var err error + + if d.GetProfile() == DPE_EMULATOR_PROFILE { + client384, err = NewClient384(d) + } else { + client256, err = NewClient256(d) + } if err != nil { t.Fatalf("Could not initialize client: %v", err) } - for _, locality := range d.GetSupportedLocalities() { + var rsp *GetProfileResp d.SetLocality(locality) - rsp, err := client.GetProfile() - if err != nil { - t.Fatalf("Unable to get profile: %v", err) - } - if rsp.Profile != d.GetProfile() { - t.Fatalf("Incorrect profile. 0x%08x != 0x%08x", d.GetProfile(), rsp.Profile) + if d.GetProfile() == DPE_EMULATOR_PROFILE { + rsp, err = client384.GetProfile() + } else { + rsp, err = client256.GetProfile() } if rsp.MajorVersion != d.GetProfileMajorVersion() { t.Fatalf("Incorrect version. 0x%08x != 0x%08x", d.GetProfileMajorVersion(), rsp.MajorVersion) diff --git a/verification/go.mod b/verification/go.mod index 5c3c9374..790a27ae 100644 --- a/verification/go.mod +++ b/verification/go.mod @@ -14,4 +14,4 @@ require ( golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect golang.org/x/net v0.8.0 // indirect golang.org/x/text v0.8.0 // indirect -) +) \ No newline at end of file diff --git a/verification/go.sum b/verification/go.sum index 59288fa6..89920016 100644 --- a/verification/go.sum +++ b/verification/go.sum @@ -120,4 +120,4 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= \ No newline at end of file diff --git a/verification/initializeContext_test.go b/verification/initializeContext_test.go index 759a3a1f..50f4c9a5 100644 --- a/verification/initializeContext_test.go +++ b/verification/initializeContext_test.go @@ -55,7 +55,7 @@ func testInitContext(d TestDPEInstance, t *testing.T) { defer d.PowerOff() } - client, err := NewClient256(d) + client, err := NewClient384(d) if err != nil { t.Fatalf("Could not initialize client: %v", err) } @@ -104,10 +104,10 @@ func testInitContext(d TestDPEInstance, t *testing.T) { // Try to get the correct error for overflowing the contexts. Fill up the // rest of the contexts (-1 for default). - for i := uint32(0); i < getProfileRsp.MaxTciNodes-1; i++ { + for i := uint32(0); i < getProfileRsp.MaxTciNodes-2; i++ { initCtxResp, err := client.InitializeContext(NewInitCtxIsSimulation()) if err != nil { - t.Fatal("The instance should be able to create a simulation context.") + t.Fatal("The instance should be able to create a simulation context.", err) } // Could prove difficult to prove it is a cryptographically secure random. if initCtxResp.Handle == [16]byte{0} { diff --git a/verification/simulator.go b/verification/simulator.go index 555f5d02..b0890e96 100644 --- a/verification/simulator.go +++ b/verification/simulator.go @@ -159,6 +159,10 @@ func (s *DpeSimulator) GetSupport() *Support { return &s.supports } +func (s *DpeSimulator) SetSupport(support Support) { + s.supports = support +} + func (s *DpeSimulator) GetProfile() Profile { return DPE_SIMULATOR_PROFILE } diff --git a/verification/verification_test.go b/verification/verification_test.go index c5b88742..04cc6ed7 100644 --- a/verification/verification_test.go +++ b/verification/verification_test.go @@ -5,6 +5,7 @@ package verification import ( "errors" "flag" + "log" "os" "reflect" "testing" @@ -28,7 +29,7 @@ func TestMain(m *testing.M) { if testTargetType == SIMULATOR { target_exe = flag.String("sim", "../simulator/target/debug/simulator", "path to simulator executable") } else if testTargetType == EMULATOR { - target_exe = flag.String("emu", "../simulator/target/debug/emulator", "path to emulator executable") + target_exe = flag.String("emu", "../emulator/target/debug/emulator", "path to emulator executable") } exitVal := m.Run() @@ -51,6 +52,8 @@ type TestDPEInstance interface { // it supports, but this function is used by tests to know how to test the DPE // instance. GetSupport() *Support + //Set the Support + SetSupport(support Support) // Returns the profile the transport supports. GetProfile() Profile // Returns a slice of all the localities the instance supports. @@ -98,15 +101,35 @@ func GetTestTarget(support_needed []string) (TestDPEInstance, error) { // Get the emulator target func GetEmulatorTarget(support_needed []string) (TestDPEInstance, error) { + // TODO : Get the supported modes from emulator and then check. + var instance TestDPEInstance = &DpeEmulator{exe_path: *target_exe} + if instance.HasPowerControl() { + err := instance.PowerOn() + if err != nil { + log.Fatal(err) + } + defer instance.PowerOff() + } + + client, err := NewClient384(instance) + if err != nil { + return nil, errors.New("Error in getting client") + } + + rsp, err := client.GetProfile() + if err != nil { + return nil, errors.New("Unable to get profile") + } - value := reflect.ValueOf(DpeEmulator{}.supports) + support := Support{} + + value := reflect.ValueOf(support.ToSupport(rsp.Flags)) for i := 0; i < len(support_needed); i++ { support := reflect.Indirect(value).FieldByName(support_needed[i]) if !support.Bool() { return nil, errors.New("Error in creating dpe instances - supported feature is not enabled in emulator") } } - var instance TestDPEInstance = &DpeEmulator{exe_path: *target_exe} return instance, nil }