@@ -11,6 +11,7 @@ import (
1111
1212 beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
1313 "github.com/oasisprotocol/oasis-core/go/common"
14+ "github.com/oasisprotocol/oasis-core/go/common/cbor"
1415 "github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
1516 "github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
1617 "github.com/oasisprotocol/oasis-core/go/common/entity"
@@ -497,6 +498,7 @@ func VerifyRegisterNodeArgs( // nolint: gocyclo
497498 epoch beacon.EpochTime ,
498499 runtimeLookup RuntimeLookup ,
499500 nodeLookup NodeLookup ,
501+ isFeatureVersion242 bool ,
500502) (* node.Node , []* Runtime , error ) {
501503 var n node.Node
502504 if sigNode == nil {
@@ -621,6 +623,11 @@ func VerifyRegisterNodeArgs( // nolint: gocyclo
621623 if err := VerifyNodeRuntimeEnclaveIDs (logger , n .ID , rt , regRt , params .TEEFeatures , now , height ); err != nil && ! isSanityCheck && ! isGenesis {
622624 return nil , nil , err
623625 }
626+ if ! isFeatureVersion242 {
627+ if err := VerifyNodeRuntimeCapabilities (rt , regRt ); err != nil {
628+ return nil , nil , err
629+ }
630+ }
624631
625632 // Enforce what kinds of runtimes are allowed.
626633 if regRt .Kind == KindKeyManager && ! n .HasRoles (KeyManagerRuntimeAllowedRoles ) {
@@ -849,6 +856,44 @@ func VerifyNodeRuntimeEnclaveIDs(
849856 return fmt .Errorf ("%w: node running unknown runtime enclave version" , ErrInvalidArgument )
850857}
851858
859+ // VerifyNodeRuntimeCapabilities verifies that the node's runtimes' capabilities
860+ // have valid FMSPC whitelists.
861+ func VerifyNodeRuntimeCapabilities (rt * node.Runtime , regRt * Runtime ) error {
862+ if rt .Capabilities .TEE == nil {
863+ return nil
864+ }
865+
866+ for _ , rtVersionInfo := range regRt .Deployments {
867+ if rtVersionInfo .Version != rt .Version {
868+ continue
869+ }
870+ if err := VerifyNodeRuntimeCapability (rt .Capabilities .TEE , rtVersionInfo .TEE ); err != nil {
871+ return err
872+ }
873+ }
874+ return nil
875+ }
876+
877+ // VerifyNodeRuntimeCapability verifies that the node's runtime capabilities
878+ // have valid FMSPC whitelist.
879+ func VerifyNodeRuntimeCapability (c * node.CapabilityTEE , constraints []byte ) error {
880+ switch c .Hardware {
881+ case node .TEEHardwareIntelSGX :
882+ var sc node.SGXConstraints
883+ if err := cbor .Unmarshal (constraints , & sc ); err != nil {
884+ return fmt .Errorf ("node: malformed SGX constraints: %w" , err )
885+ }
886+ if sc .Policy == nil {
887+ return nil
888+ }
889+ if err := sc .Policy .VerifyFMSPCWhitelist (); err != nil {
890+ return fmt .Errorf ("node: malformed SGX constraints: %w" , err )
891+ }
892+ default :
893+ return nil
894+ }
895+ }
896+
852897// VerifyAddress verifies a node address.
853898func VerifyAddress (addr node.Address , allowUnroutable bool ) error {
854899 if ! allowUnroutable {
@@ -1097,6 +1142,7 @@ func VerifyRuntime( // nolint: gocyclo
10971142 isGenesis bool ,
10981143 isSanityCheck bool ,
10991144 now beacon.EpochTime ,
1145+ isFeatureVersion242 bool ,
11001146) error {
11011147 if rt == nil {
11021148 return fmt .Errorf ("%w: no runtime given" , ErrInvalidArgument )
@@ -1141,7 +1187,7 @@ func VerifyRuntime( // nolint: gocyclo
11411187
11421188 // Validate the deployments. This also handles validating that the
11431189 // appropriate TEE configuration is present in each deployment.
1144- if err := rt .ValidateDeployments (now , params ); err != nil {
1190+ if err := rt .ValidateDeployments (now , params , isFeatureVersion242 ); err != nil {
11451191 logger .Error ("RegisterRuntime: invalid deployments" ,
11461192 "runtime_id" , rt .ID ,
11471193 "err" , err ,
@@ -1215,6 +1261,7 @@ func VerifyRuntimeUpdate(
12151261 currentRt , newRt * Runtime ,
12161262 now beacon.EpochTime ,
12171263 params * ConsensusParameters ,
1264+ isFeatureVersion242 bool ,
12181265) error {
12191266 if ! currentRt .ID .Equal (& newRt .ID ) {
12201267 logger .Error ("RegisterRuntime: trying to update runtime ID" ,
@@ -1270,7 +1317,7 @@ func VerifyRuntimeUpdate(
12701317
12711318 // Validate the deployments.
12721319 activeDeployment := currentRt .ActiveDeployment (now )
1273- if err := currentRt .ValidateDeployments (now , params ); err != nil {
1320+ if err := currentRt .ValidateDeployments (now , params , isFeatureVersion242 ); err != nil {
12741321 // Invariant violation, this should NEVER happen.
12751322 logger .Error ("RegisterRuntime: malformed deployments present in state" ,
12761323 "runtime_id" , currentRt .ID ,
@@ -1284,7 +1331,7 @@ func VerifyRuntimeUpdate(
12841331 }
12851332
12861333 newActiveDeployment := newRt .ActiveDeployment (now )
1287- if err := newRt .ValidateDeployments (now , params ); err != nil {
1334+ if err := newRt .ValidateDeployments (now , params , isFeatureVersion242 ); err != nil {
12881335 logger .Error ("RegisterRuntime: malformed deployments" ,
12891336 "runtime_id" , currentRt .ID ,
12901337 "err" , err ,
0 commit comments