Skip to content

Commit 070f50f

Browse files
committed
Add verification tests for the "export-cdi" DeriveContext feature
1 parent b39178f commit 070f50f

File tree

8 files changed

+584
-475
lines changed

8 files changed

+584
-475
lines changed

simulator/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ struct Args {
112112
/// Supports the RETAIN_PARENT_CONTEXT extension to DeriveContext
113113
#[arg(long)]
114114
supports_retain_parent_context: bool,
115+
116+
/// Supports the CDI_EXPORT extension to DeriveContext
117+
#[arg(long)]
118+
supports_cdi_export: bool,
115119
}
116120

117121
struct SimTypes {}
@@ -156,6 +160,7 @@ fn main() -> std::io::Result<()> {
156160
Support::RETAIN_PARENT_CONTEXT,
157161
args.supports_retain_parent_context,
158162
);
163+
support.set(Support::CDI_EXPORT, args.supports_cdi_export);
159164

160165
let mut env = DpeEnv::<SimTypes> {
161166
crypto: <SimTypes as DpeTypes>::Crypto::new(),

verification/client/abi.go

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Support struct {
3535
InternalDice bool
3636
IsCA bool
3737
RetainParentContext bool
38+
CdiExport bool
3839
}
3940

4041
// profileCommandCodes holds command codes for a specific revision of the
@@ -125,6 +126,9 @@ const (
125126
// ContextHandle is a DPE context handle
126127
type ContextHandle [16]byte
127128

129+
// ExportedCdi is a handle to an exported CDI
130+
type ExportedCdi [32]byte
131+
128132
// DestroyCtxCmd is input parameters to DestroyContext
129133
type DestroyCtxCmd struct {
130134
handle ContextHandle
@@ -218,6 +222,8 @@ const (
218222
InputAllowCA DeriveContextFlags = 1 << 26
219223
InputAllowX509 DeriveContextFlags = 1 << 25
220224
Recursive DeriveContextFlags = 1 << 24
225+
CdiExport DeriveContextFlags = 1 << 23
226+
CreateCertificate DeriveContextFlags = 1 << 22
221227
)
222228

223229
// DeriveContextReq is the input request to DeriveContext
@@ -233,16 +239,14 @@ type DeriveContextReq[Digest DigestAlgorithm] struct {
233239
type DeriveContextResp struct {
234240
NewContextHandle ContextHandle
235241
ParentContextHandle ContextHandle
242+
ExportedCdi ExportedCdi
243+
CertificateSize uint32
244+
NewCertificate []byte
236245
}
237246

238247
// SignFlags is the input flags to Sign
239248
type SignFlags uint32
240249

241-
// Supported Sign flags
242-
const (
243-
IsSymmetric SignFlags = 1 << 30
244-
)
245-
246250
// SignReq is the input request to Sign
247251
type SignReq[Digest DigestAlgorithm] struct {
248252
ContextHandle ContextHandle
@@ -512,15 +516,43 @@ func (c *DPEABI[_, _, _]) GetCertificateChainABI() (*GetCertificateChainResp, er
512516
}
513517

514518
// DeriveContextABI calls DPE DeriveContext command.
515-
func (c *DPEABI[_, Digest, _]) DeriveContextABI(cmd *DeriveContextReq[Digest]) (*DeriveContextResp, error) {
516-
var respStruct DeriveContextResp
519+
func (c *DPEABI[_, Digest, DPECertificate]) DeriveContextABI(cmd *DeriveContextReq[Digest]) (*DeriveContextResp, error) {
520+
// Define an anonymous struct for the response, because the shape changes if exportCdi is set.
521+
if cmd.Flags&CdiExport == CdiExport {
522+
respStruct := struct {
523+
NewContextHandle [16]byte
524+
ParentContextHandle [16]byte
525+
ExportedCdi [32]byte
526+
CertificateSize uint32
527+
Certificate DPECertificate
528+
}{}
529+
_, err := execCommand(c.transport, c.constants.Codes.DeriveContext, c.Profile, cmd, &respStruct)
530+
if err != nil {
531+
return nil, err
532+
}
517533

518-
_, err := execCommand(c.transport, c.constants.Codes.DeriveContext, c.Profile, cmd, &respStruct)
519-
if err != nil {
520-
return nil, err
521-
}
534+
return &DeriveContextResp{
535+
NewContextHandle: respStruct.NewContextHandle,
536+
ParentContextHandle: respStruct.ParentContextHandle,
537+
ExportedCdi: respStruct.ExportedCdi,
538+
CertificateSize: respStruct.CertificateSize,
539+
NewCertificate: respStruct.Certificate.Bytes()[:respStruct.CertificateSize],
540+
}, nil
541+
} else {
542+
respStruct := struct {
543+
NewContextHandle [16]byte
544+
ParentContextHandle [16]byte
545+
}{}
546+
_, err := execCommand(c.transport, c.constants.Codes.DeriveContext, c.Profile, cmd, &respStruct)
547+
if err != nil {
548+
return nil, err
549+
}
522550

523-
return &respStruct, err
551+
return &DeriveContextResp{
552+
NewContextHandle: respStruct.NewContextHandle,
553+
ParentContextHandle: respStruct.ParentContextHandle,
554+
}, nil
555+
}
524556
}
525557

526558
// RotateContextHandleABI calls DPE RotateContextHandle command.
@@ -733,5 +765,8 @@ func (s *Support) ToFlags() uint32 {
733765
if s.RetainParentContext {
734766
flags |= (1 << 19)
735767
}
768+
if s.CdiExport {
769+
flags |= (1 << 18)
770+
}
736771
return flags
737772
}

verification/sim/transport.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func (s *DpeSimulator) PowerOn() error {
8282
if s.supports.RetainParentContext {
8383
args = append(args, "--supports-retain-parent-context")
8484
}
85+
if s.supports.CdiExport {
86+
args = append(args, "--supports-cdi-export")
87+
}
8588

8689
s.cmd = exec.Command(s.exePath, args...)
8790
s.cmd.Stdout = os.Stdout

0 commit comments

Comments
 (0)