Skip to content

[RFC] Add an initial Open DICE profile implementation. - #15

Merged
setrofim merged 2 commits into
mainfrom
setrofim
Jun 29, 2023
Merged

[RFC] Add an initial Open DICE profile implementation.#15
setrofim merged 2 commits into
mainfrom
setrofim

Conversation

@setrofim

@setrofim setrofim commented Jun 9, 2023

Copy link
Copy Markdown
Contributor

Add an innitial implmentation of validaiton and evidence extraction of Open DICE profile certificate chains.

@setrofim

setrofim commented Jun 9, 2023

Copy link
Copy Markdown
Contributor Author

NOTE: This depends on COSE_Key implemented by veraison/go-cose#146 and cannot be merged until that has been integated into main and the dependencies have been adjusted accordingly.

@thomas-fossati
thomas-fossati force-pushed the setrofim branch 5 times, most recently from cb18e25 to 559d045 Compare June 14, 2023 21:14
@SampoSovio

Copy link
Copy Markdown

Hi Sergei,

This looks good i have suggestion related to ExtractOpenDiceChainFromX509

You have following loop there:

for i, cert := range certs {
		var odCert OpenDiceX509CdiCert

		if err = odCert.PopulateFromX509Cert(cert); err != nil {
			return nil, fmt.Errorf(
				"cert at index %d does appear to match Open DICE profile: %w",
				i, err,
			)
		}
		if verify {
			if _, err = odCert.Verify(verifOpts); err != nil {
				return nil, fmt.Errorf(
					"failed to verify cert at index %d: %w",
					i, err,
				)
			}
			verifOpts.Intermediates.AddCert(&odCert.Certificate)
		}
		result = append(result, odCert.GetEntry())
	}
}

If i undestand this code properly you are validating beginning of chain again and again. I would suggest following optimization:

var leaf x509.Certificate
for i, cert := range certs {
	var odCert OpenDiceX509CdiCert

	if err = odCert.PopulateFromX509Cert(cert); err != nil {
		return nil, fmt.Errorf(
			"cert at index %d does appear to match Open DICE profile: %w",
			i, err,
		)
	}
	if verify {
		verifOpts.Intermediates.AddCert(&odCert.Certificate)
		if len(certs) > 0 && i == len(certs)-1 {
			leaf = odCert.Certificate
		}
	}
	result = append(result, odCert.GetEntry())
}
if verify {
	if _, err = leaf.Verify(verifOpts); err != nil {
		return nil, fmt.Errorf(
			"failed to verify cert: %w",
			err,
		)
	}
}

Following test passes: func Test_ExtractOpenDiceChainFromX509(t *testing.T)

If you change line 278 to be:

assert.EqualError(t, err, "failed to verify cert: x509: certificate signed by unknown authority")

@setrofim

Copy link
Copy Markdown
Contributor Author

Hi Sampo,

You're absolutely right, this was re-verifying the chain at each "segment". I've implemented your suggestion with a minor tweak. Thank you!

Rename the source files for the TCG DICE extension in preparation to
adding non-TCG related stuff.

Signed-off-by: Sergei Trofimov <sergei.trofimov@arm.com>

@thomas-fossati thomas-fossati left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

- Add validation and claim extraction for Open DICE X.509 and CBOR
  certificate chains.
- Add TCB into claim extension definition.

Signed-off-by: Sergei Trofimov <sergei.trofimov@arm.com>
@setrofim
setrofim merged commit 767bbd6 into main Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants