Skip to content

Commit

Permalink
go/runtime/bundle: Add expected enclave identity to manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Nov 6, 2024
1 parent 8f2032a commit 9227c3f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelog/5931.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/bundle: Add expected enclave identity to manifest
8 changes: 8 additions & 0 deletions go/common/sgx/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,11 @@ func (id *EnclaveIdentity) UnmarshalHex(text string) error {
func (id EnclaveIdentity) String() string {
return hex.EncodeToString(id.MrEnclave[:]) + hex.EncodeToString(id.MrSigner[:])
}

// Clone returns a copy of the enclave identity.
func (id *EnclaveIdentity) Clone() *EnclaveIdentity {
return &EnclaveIdentity{
MrEnclave: id.MrEnclave,
MrSigner: id.MrSigner,
}
}
10 changes: 10 additions & 0 deletions go/runtime/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ func (bnd *Bundle) MrSigner(id component.ID) (*sgx.MrSigner, error) {

// EnclaveIdentity returns the SGX enclave identity of the given component.
func (bnd *Bundle) EnclaveIdentity(id component.ID) (*sgx.EnclaveIdentity, error) {
// If the component has a build-time known expected identity, use it.
comp := bnd.Manifest.GetComponentByID(id)
if comp == nil {
return nil, fmt.Errorf("runtime/bundle: component '%s' not available", id)
}
if comp.Identity != nil {
return comp.Identity.Clone(), nil
}

// When not available, recompute at runtime (only supported for SGX).
mrEnclave, err := bnd.MrEnclave(id)
if err != nil {
return nil, err
Expand Down
11 changes: 11 additions & 0 deletions go/runtime/bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/sgx"
"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
)

Expand Down Expand Up @@ -40,6 +41,10 @@ func TestBundle(t *testing.T) {
SGX: &SGXMetadata{
Executable: "runtime.sgx",
},
Identity: &sgx.EnclaveIdentity{
MrSigner: sgx.MrSigner{0x01},
MrEnclave: sgx.MrEnclave{0x02},
},
},
},
}
Expand Down Expand Up @@ -77,6 +82,12 @@ func TestBundle(t *testing.T) {
delete(bundle2.Data, manifestName)

ensureBundlesEqual(t, bundle, bundle2, "opened bundle mismatch")

// Test enclave identity is correct.
eid, err := bundle2.EnclaveIdentity(component.ID_RONL)
require.NoError(t, err, "EnclaveIdentity")
require.Equal(t, "0100000000000000000000000000000000000000000000000000000000000000", eid.MrSigner.String())
require.Equal(t, "0200000000000000000000000000000000000000000000000000000000000000", eid.MrEnclave.String())
})

t.Run("ResetManifest", func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions go/runtime/bundle/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/sgx"
"github.com/oasisprotocol/oasis-core/go/common/version"
"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
)
Expand Down Expand Up @@ -232,6 +233,10 @@ type Component struct {
// TDX is the TDX specific manifest metadata if any.
TDX *TDXMetadata `json:"tdx,omitempty"`

// Identity is the (optional) expected enclave identity. When it is not provided, it must be
// computed at runtime. In the future, this field will become required.
Identity *sgx.EnclaveIdentity `json:"identity,omitempty"`

// Disabled specifies whether the component is disabled by default and needs to be explicitly
// enabled via node configuration to be used.
Disabled bool `json:"disabled,omitempty"`
Expand Down

0 comments on commit 9227c3f

Please sign in to comment.