-
Notifications
You must be signed in to change notification settings - Fork 22
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
Multi tcb info fields validation with derived context #269
base: main
Are you sure you want to change the base?
Conversation
@@ -3,11 +3,116 @@ | |||
package verification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions that validate various fields are moved here from certifyKey.go. This is an effort to keep helper functions that are independent of DPEClient instance in certs.go
This was done to reduce the bloating in CertifyKey.go
@@ -455,6 +54,7 @@ func testCertifyKey(d TestDPEInstance, c DPEClient, t *testing.T, simulation boo | |||
|
|||
certifyKeyParams := []CertifyKeyParams{ | |||
{Label: make([]byte, digestLen), Flags: CertifyKeyFlags(0)}, | |||
{Label: make([]byte, digestLen), Flags: CertifyKeyFlags(CertifyAddIsCA)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new test case to check if IS_CA is set.
verification/certifyKey.go
Outdated
checkWithDerivedChildContextSimulation(d, c, t, handle) | ||
} else { | ||
checkWithDerivedChildContext(d, c, t, handle) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommended to have two separate methods to test derived child contexts as clubbing together lead to confusing if-elses.
The simulation mode varies in locality, Derivechild flags, not needing restoration of parent handle etc...
verification/certifyKey.go
Outdated
// - the "fwid" field must contain cumulative TCI measurement. | ||
func checkWithDerivedChildContext(d TestDPEInstance, c DPEClient, t *testing.T, handle *ContextHandle) { | ||
profile, err := GetTransportProfile(d) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New method after adding DeriveContext support.
Derives child contexzt, preserves & rotates back default handle, focusses on multi tcb info fields validation.
verification/certifyKey.go
Outdated
keyUsageNames := []string{} | ||
// Checks Multi Tcb Info for context derived from simulation mode | ||
func checkWithDerivedChildContextSimulation(d TestDPEInstance, c DPEClient, t *testing.T, handle *ContextHandle) { | ||
profile, err := GetTransportProfile(d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New method after adding DeriveContext support.
Derives child context from simulated context, there is no need to preserve & rotate back parent handle, focusses on multi tcb info fields validation.
verification/certs.go
Outdated
// FWID at index 1 has the TCI_CUMULATIVE as digest | ||
// The length of FWID array in each DICE TCB information block is 2. | ||
func validateDiceTcbFwids(leafCertBytes []byte, expectedCurrentTci []byte) error { | ||
var leafCert *x509.Certificate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function cycles through all multi TCB info blocks and validates cumulative measurement, it gets the current TCI values from caller - the most recend node's current TCI value will be added first in this input list.
verification/certs.go
Outdated
@@ -18,12 +123,12 @@ func getMultiTcbInfo(c *x509.Certificate) (TcgMultiTcbInfo, error) { | |||
for _, ext := range c.Extensions { | |||
if ext.Id.Equal(OidExtensionTcgDiceMultiTcbInfo) { // OID for Tcg Dice MultiTcbInfo | |||
if !ext.Critical { | |||
return multiTcbInfo, fmt.Errorf("[ERROR]: TCG DICE MultiTcbInfo extension is not marked as CRITICAL") | |||
return multiTcbInfo, fmt.Errorf("multiTcbInfo extension is not marked as CRITICAL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to smallcase as IDE kept complaining that error message should not start with Upper case, have new lines and have punctuation at the end.
) | ||
|
||
type TcgMultiTcbInfo = []DiceTcbInfo | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some required structs and constants
verification/certifyKey.go
Outdated
binary.Write(flagsBuf, binary.LittleEndian, flags) | ||
// Checks whether FWID array omits index-1 when extend TCI is not supported in DPE profile. | ||
func TestCertifyKeyWithoutExtendTciSupport(d TestDPEInstance, c DPEClient, t *testing.T) { | ||
simulation := false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test case to check if FWID[1] is omitted when no extendTCI support in DPE profile
verification/certs.go
Outdated
for i, tcbinfo := range multiTcbInfo { | ||
currentTci := tcbinfo.Fwids[0].Digest | ||
cumulativeTci := tcbinfo.Fwids[1].Digest | ||
hasher.Reset() | ||
hasher.Write(lastCumulativeTCI) | ||
hasher.Write(currentTci) | ||
expectedCumulativeValue := hasher.Sum(nil) | ||
if !bytes.Equal(cumulativeTci, expectedCumulativeValue) { | ||
return fmt.Errorf("cumulative TCI value for TCB block-%d, want %v but got %v", i, expectedCumulativeValue, cumulativeTci) | ||
} | ||
lastCumulativeTCI = cumulativeTci | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TCI_CUMULATIVE isn't a hash of all the currents from TcbInfos in the cert. TCI_CUMULATIVE gets extended whenever the ExtendTCI command is called on a node so for a given TCI Node X, TCI_CUMULATIVE is calculated using all the values input
for each call to ExtendTCI(handle=X, input_data=input)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rectified the issue
if !d.GetSupport().ExtendTci { | ||
t.Errorf("ExtendTCI is unsupported by profile, unable to run tests to verify TCI_CUMULATIVE measurement") | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because extendTCI when not supported cumulative hash will be omitted from FWID array
verification/certifyKey.go
Outdated
for i := range childTCI2 { | ||
childTCI2[i] = byte(i + 2) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to try TCB validation for multiple TCI nodes with different TCI inputs
return opts | ||
childHandle = &certifiedKey.Handle | ||
leafCertBytes := certifiedKey.Certificate | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update child handle for cleanup.
|
||
// Build list of tci_current for validation and use it for validating TCI measurements | ||
currentTCIs := [][]byte{childTCI2, childTCI1} | ||
if err = validateDiceTcbFwids(leafCertBytes, currentTCIs, digestLen); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rectified the issue pointed out.
// Check cumulative, current TCI of other indices if any | ||
lastCumulativeTCI := defaultTci | ||
multiTcbInfo = multiTcbInfo[:lastIndex] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate validation for the last index as the TCI_CURRENT = TCI_CUMULATIVE = Default TCI.
wantCurrentTci := currentTcis[i] | ||
verifyDiceTcbDigest(tcbinfo, wantCurrentTci, lastCumulativeTCI) | ||
} | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cross verify the TCI_CUMULATIVE with TCI_CURRENT value passed.
681f410
to
d849694
Compare
"CertifyKey_TcbValidation", | ||
getTestTarget([]string{"AutoInit", "Simulation", "X509", "Csr", "IsCA", "RotateContext", "ExtendTci"}), | ||
[]TestCase{DiceTcbValidationTestCase, DiceTcbValidationSimulationTestCase}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have added this as separate test target.
As per a comment in #PR250, it was mentioned to move tests that modify DPE tree out of basic testcases.
I addressed it in this PR because it is relevant to CertifyKey command.
If i had to include these tests in "AllTestCases" list, I had to use RetainParent, ChangeLocality(for Sim mode), so that the parent context wouyld be available for further tests.
"CheckDiceTcbInfo", TestDiceTcbInfo, []string{"AutoInit", "X509", "IsCA", "RotateContext", "ExtendTci"}, | ||
} | ||
var DiceTcbValidationSimulationTestCase = TestCase{ | ||
"CheckDiceTcbInfoInSimulationMode", TestDiceTcbInfoSimulation, []string{"AutoInit", "Simulation", "X509", "IsCA", "RotateContext", "ExtendTci"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having DiceTcb Validation as separate test from CertifyKey as it uses DeriveChild command and due to aforementioned reason.
) | ||
|
||
type TcgMultiTcbInfo = []DiceTcbInfo | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to certs.go
func TestDiceTcbInfoSimulation(d TestDPEInstance, c DPEClient, t *testing.T) { | ||
testDiceTcbInfo(d, c, t, true) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate test case to validate DiceTcb with derived contexts in normal mode and Sim mode.
// unknownExtnMap collects extensions unknown to both x509 and the DICE certificate profiles spec. | ||
// positive case expects the unknownExtnMap to be empty. | ||
func removeTcgDiceCriticalExtensions(t *testing.T, certs []*x509.Certificate) { | ||
t.Helper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the utility function to certs.go
// unknownKeyUsagesMap collects keyusages unknown to both x509 and the DICE certificate profiles spec. | ||
// positive case expects the unknownKeyUsagesMap to be empty. | ||
func removeTcgDiceExtendedKeyUsages(t *testing.T, certs []*x509.Certificate) { | ||
t.Helper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the utility function to certs.go
Hi @jhand2
This commit has :
MultiTcb information has field-wise validation (apart from checking structure)
Verify by deriving more child contexts in non-simulation mode and simulation mode.
Aside from above checks, have moved helper functions that operate of certificate and cert extensions to certs.go for better readabilty of certifyKey.go. The helper functions will just return errors and caller must handle/log errors using t.Error()
Check if multitcb info fwidarray length is 1 when extendtci is not supported by DPE profile.
Specification contents