Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial profile changes #180

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
6 changes: 3 additions & 3 deletions verification/certifyKey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ func testCertifyKey(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)
}

certifyKeyReq := CertifyKeyReq[SHA256Digest]{
certifyKeyReq := CertifyKeyReq[SHA384Digest]{
ContextHandle: [16]byte{0},
Flags: 0,
Label: [32]byte{0},
Label: [48]byte{0},
Format: CertifyKeyX509,
}

Expand Down
37 changes: 37 additions & 0 deletions verification/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
29 changes: 20 additions & 9 deletions verification/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"net"
"os"
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -126,11 +127,17 @@ 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
}

var i int
for i = 0; i < len(buf); i++ {
fmt.Print(buf[i])
fmt.Print(",")
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should be removed

// Prepend the command with the locality.
prepended := bytes.NewBuffer(make([]byte, 0, 4+len(buf)))
if err := binary.Write(prepended, binary.LittleEndian, s.currentLocality); err != nil {
Expand All @@ -157,8 +164,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 {
Expand Down
2 changes: 1 addition & 1 deletion verification/getProfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func testGetProfile(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)
}
Expand Down
2 changes: 1 addition & 1 deletion verification/go.mod
jhand2 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
2 changes: 1 addition & 1 deletion verification/go.sum
jhand2 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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=
6 changes: 3 additions & 3 deletions verification/initializeContext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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} {
Expand Down
4 changes: 4 additions & 0 deletions verification/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 27 additions & 3 deletions verification/verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package verification
import (
"errors"
"flag"
"log"
"os"
"reflect"
"testing"
Expand All @@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -98,15 +101,36 @@ 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}
instance.SetSupport(support)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support cannot be set on the emulator. Either the target supports what is needed or it doesn't. So I think this line can be removed and then the SetSupport target API can be removed.

return instance, nil
}

Expand Down
Loading