Skip to content
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

go/runtime/bundle: Verify SGX signature if present #4542

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/4542.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/bundle: Verify SGX signature if present
27 changes: 27 additions & 0 deletions go/runtime/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/sgx"
"github.com/oasisprotocol/oasis-core/go/common/sgx/sigstruct"
)

// Bundle is a runtime bundle instance.
Expand Down Expand Up @@ -80,6 +81,11 @@ func (bnd *Bundle) Validate() error {
}
}

// Make sure the SGX signature is valid if it exists.
if err := bnd.verifySgxSignature(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -120,6 +126,27 @@ func (bnd *Bundle) MrEnclave() (*sgx.MrEnclave, error) {
return &mrEnclave, nil
}

func (bnd *Bundle) verifySgxSignature() error {
if bnd.Manifest.SGX == nil || bnd.Manifest.SGX.Signature == "" {
return nil
}

mrEnclave, err := bnd.MrEnclave()
if err != nil {
return err
}
_, sigStruct, err := sigstruct.Verify(bnd.Data[bnd.Manifest.SGX.Signature])
if err != nil {
return fmt.Errorf("runtime/bundle: failed to verify sigstruct: %w", err)
}

if sigStruct.EnclaveHash != *mrEnclave {
return fmt.Errorf("runtime/bundle: sigstruct does not match SGXS (got: %s expected: %s)", sigStruct.EnclaveHash, *mrEnclave)
}

return nil
}

// Write serializes a runtime bundle to the on-disk representation.
func (bnd *Bundle) Write(fn string) error {
// Ensure the bundle is well-formed.
Expand Down