Skip to content

Commit

Permalink
digest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pranayv27 committed Sep 29, 2023
1 parent e5dca32 commit 43082cd
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 24 deletions.
43 changes: 40 additions & 3 deletions verification/certifyKey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func TestCertifyKey(t *testing.T) {
log.Fatal(err)
}
}
testCertifyKey(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testCertifyKey384(instance, t)
} else {
testCertifyKey256(instance, t)
}
}

func TestCertifyKey_SimulationMode(t *testing.T) {
Expand All @@ -41,7 +45,11 @@ func TestCertifyKey_SimulationMode(t *testing.T) {
log.Fatal(err)
}
}
testCertifyKey(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testCertifyKey384(instance, t)
} else {
testCertifyKey256(instance, t)
}
}

func checkCertificateStructure(t *testing.T, certData []byte) {
Expand Down Expand Up @@ -108,7 +116,7 @@ func checkCertificateStructure(t *testing.T, certData []byte) {
}
}

func testCertifyKey(d TestDPEInstance, t *testing.T) {
func testCertifyKey384(d TestDPEInstance, t *testing.T) {
if d.HasPowerControl() {
err := d.PowerOn()
if err != nil {
Expand Down Expand Up @@ -136,3 +144,32 @@ func testCertifyKey(d TestDPEInstance, t *testing.T) {

// TODO: When DeriveChild is implemented, call it here to add more TCIs and call CertifyKey again.
}

func testCertifyKey256(d TestDPEInstance, t *testing.T) {
if d.HasPowerControl() {
err := d.PowerOn()
if err != nil {
log.Fatal(err)
}
defer d.PowerOff()
}
client, 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,
}

certifyKeyResp, err := client.CertifyKey(&certifyKeyReq)
if err != nil {
t.Fatalf("Could not certify key: %v", err)
}
checkCertificateStructure(t, certifyKeyResp.Certificate)

// TODO: When DeriveChild is implemented, call it here to add more TCIs and call CertifyKey again.
}
139 changes: 123 additions & 16 deletions verification/getProfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func TestGetProfile(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_SimulationMode(t *testing.T) {
Expand All @@ -36,7 +40,11 @@ func TestGetProfile_SimulationMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_ExtendTciMode(t *testing.T) {
Expand All @@ -51,7 +59,11 @@ func TestGetProfile_ExtendTciMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_AutoInitMode(t *testing.T) {
Expand All @@ -66,7 +78,11 @@ func TestGetProfile_AutoInitMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_TaggingMode(t *testing.T) {
Expand All @@ -81,7 +97,11 @@ func TestGetProfile_TaggingMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_RotateContextMode(t *testing.T) {
Expand All @@ -96,7 +116,11 @@ func TestGetProfile_RotateContextMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_X509Mode(t *testing.T) {
Expand All @@ -111,7 +135,11 @@ func TestGetProfile_X509Mode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_CsrMode(t *testing.T) {
Expand All @@ -126,7 +154,11 @@ func TestGetProfile_CsrMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_IsSymmetricMode(t *testing.T) {
Expand All @@ -141,7 +173,11 @@ func TestGetProfile_IsSymmetricMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_InternalInfoMode(t *testing.T) {
Expand All @@ -156,7 +192,11 @@ func TestGetProfile_InternalInfoMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_InternalDiceMode(t *testing.T) {
Expand All @@ -171,7 +211,11 @@ func TestGetProfile_InternalDiceMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_IsCAMode(t *testing.T) {
Expand All @@ -186,7 +230,11 @@ func TestGetProfile_IsCAMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_SupportMode_01(t *testing.T) {
Expand All @@ -201,7 +249,11 @@ func TestGetProfile_SupportMode_01(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_SupportMode_02(t *testing.T) {
Expand All @@ -216,7 +268,11 @@ func TestGetProfile_SupportMode_02(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func TestGetProfile_AllSupportMode(t *testing.T) {
Expand All @@ -231,10 +287,14 @@ func TestGetProfile_AllSupportMode(t *testing.T) {
}
}

testGetProfile(instance, t)
if instance.GetProfile() == DPE_EMULATOR_PROFILE {
testGetProfile384(instance, t)
} else {
testGetProfile256(instance, t)
}
}

func testGetProfile(d TestDPEInstance, t *testing.T) {
func testGetProfile384(d TestDPEInstance, t *testing.T) {
const MIN_TCI_NODES uint32 = 8
if d.HasPowerControl() {
err := d.PowerOn()
Expand Down Expand Up @@ -280,3 +340,50 @@ func testGetProfile(d TestDPEInstance, t *testing.T) {
}
}
}

func testGetProfile256(d TestDPEInstance, t *testing.T) {
const MIN_TCI_NODES uint32 = 8
if d.HasPowerControl() {
err := d.PowerOn()
if err != nil {
log.Fatal(err)
}
defer d.PowerOff()
}
client, err := NewClient256(d)
if err != nil {
t.Fatalf("Could not initialize client: %v", err)
}

for _, locality := range d.GetSupportedLocalities() {
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 rsp.MajorVersion != d.GetProfileMajorVersion() {
t.Fatalf("Incorrect version. 0x%08x != 0x%08x", d.GetProfileMajorVersion(), rsp.MajorVersion)
}
if rsp.MinorVersion != d.GetProfileMinorVersion() {
t.Fatalf("Incorrect version. 0x%08x != 0x%08x", d.GetProfileMinorVersion(), rsp.MinorVersion)
}
if rsp.VendorId != d.GetProfileVendorId() {
t.Fatalf("Incorrect version. 0x%08x != 0x%08x", d.GetProfileVendorId(), rsp.VendorId)
}
if rsp.VendorSku != d.GetProfileVendorSku() {
t.Fatalf("Incorrect version. 0x%08x != 0x%08x", d.GetProfileVendorSku(), rsp.VendorSku)
}
if rsp.MaxTciNodes != d.GetMaxTciNodes() {
t.Fatalf("Incorrect max TCI nodes. 0x%08x != 0x%08x", d.GetMaxTciNodes(), rsp.MaxTciNodes)
}
if rsp.MaxTciNodes < MIN_TCI_NODES {
t.Fatalf("DPE instances must be able to support at least %d TCI nodes.", MIN_TCI_NODES)
}
if rsp.Flags != d.GetSupport().ToFlags() {
t.Fatalf("Incorrect support flags. 0x%08x != 0x%08x", d.GetSupport().ToFlags(), rsp.Flags)
}
}
}
Loading

0 comments on commit 43082cd

Please sign in to comment.