Skip to content

Commit 90c1c23

Browse files
Merge pull request #16 from mbrandenburger/fab-1.4
Add Fabric 1.4 support; also update SGX SDK and nanopb deps
2 parents e1182f1 + 41c4e6c commit 90c1c23

File tree

14 files changed

+368
-383
lines changed

14 files changed

+368
-383
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ deploying and running an example chaincode.
9595
## Requirements
9696

9797
* CMake 3.5.1 or higher
98-
* Go 1.10 or higher
99-
* Install Fabric v1.2 https://github.com/hyperledger/fabric
100-
* Install the Linux SGX SDK v2.1.3 https://github.com/intel/linux-sgx
98+
* Go 1.11 or higher
99+
* Install Fabric v1.4 https://github.com/hyperledger/fabric
100+
* Install the Linux SGX SDK v2.4 https://github.com/intel/linux-sgx
101101
* You also need to install Intel SGX SSL https://github.com/intel/intel-sgx-ssl
102102

103103
### SGX SDK and SSL

ecc/vscc/ecc_validation_plugin.go

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import (
2222

2323
commonerrors "github.com/hyperledger/fabric/common/errors"
2424
"github.com/hyperledger/fabric/core/handlers/validation/api"
25-
. "github.com/hyperledger/fabric/core/handlers/validation/api/capabilities"
26-
. "github.com/hyperledger/fabric/core/handlers/validation/api/identities"
2725
. "github.com/hyperledger/fabric/core/handlers/validation/api/policies"
2826
. "github.com/hyperledger/fabric/core/handlers/validation/api/state"
29-
default_vscc "github.com/hyperledger/fabric/core/handlers/validation/builtin"
27+
defaultvscc "github.com/hyperledger/fabric/core/handlers/validation/builtin"
3028
"github.com/hyperledger/fabric/protos/common"
3129
"github.com/pkg/errors"
3230
)
@@ -43,7 +41,7 @@ func (*ECCValidationFactory) New() validation.Plugin {
4341
}
4442

4543
type ECCValidation struct {
46-
DefaultTxValidator TransactionValidator
44+
DefaultTxValidator validation.Plugin
4745
ECCTxValidator TransactionValidator
4846
}
4947

@@ -72,7 +70,7 @@ func (v *ECCValidation) Validate(block *common.Block, namespace string, txPositi
7270
}
7371

7472
// do defalt vscc
75-
err := v.DefaultTxValidator.Validate(block.Data.Data[txPosition], serializedPolicy.Bytes())
73+
err := v.DefaultTxValidator.Validate(block, namespace, txPosition, actionPosition, contextData...)
7674
if err != nil {
7775
logger.Debugf("block %d, namespace: %s, tx %d validation results is: %v", block.Header.Number, namespace, txPosition, err)
7876
return convertErrorTypeOrPanic(err)
@@ -102,41 +100,25 @@ func convertErrorTypeOrPanic(err error) error {
102100
}
103101

104102
func (v *ECCValidation) Init(dependencies ...validation.Dependency) error {
105-
var (
106-
d IdentityDeserializer
107-
c Capabilities
108-
sf StateFetcher
109-
pe PolicyEvaluator
110-
)
103+
var sf StateFetcher
111104
for _, dep := range dependencies {
112-
if deserializer, isIdentityDeserializer := dep.(IdentityDeserializer); isIdentityDeserializer {
113-
d = deserializer
114-
}
115-
if capabilities, isCapabilities := dep.(Capabilities); isCapabilities {
116-
c = capabilities
117-
}
118105
if stateFetcher, isStateFetcher := dep.(StateFetcher); isStateFetcher {
119106
sf = stateFetcher
120107
}
121-
if policyEvaluator, isPolicyFetcher := dep.(PolicyEvaluator); isPolicyFetcher {
122-
pe = policyEvaluator
123-
}
124108
}
125109
if sf == nil {
126-
return errors.New("stateFetcher not passed in init")
127-
}
128-
if d == nil {
129-
return errors.New("identityDeserializer not passed in init")
130-
}
131-
if c == nil {
132-
return errors.New("capabilities not passed in init")
110+
return errors.New("ECC-VSCC: stateFetcher not passed in init")
133111
}
134-
if pe == nil {
135-
return errors.New("policy fetcher not passed in init")
136-
}
137-
// use default vscc and our custom ercc vscc
138-
v.DefaultTxValidator = default_vscc.New(c, sf, d, pe)
112+
139113
v.ECCTxValidator = New(sf)
140114

115+
// use default vscc and our custom ecc vscc
116+
factory := &defaultvscc.DefaultValidationFactory{}
117+
v.DefaultTxValidator = factory.New()
118+
err := v.DefaultTxValidator.Init(dependencies...)
119+
if err != nil {
120+
return errors.Errorf("Error while creating default vscc: %s", err)
121+
}
122+
141123
return nil
142124
}

ercc/vscc/ercc_validation_plugin.go

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import (
2222

2323
commonerrors "github.com/hyperledger/fabric/common/errors"
2424
"github.com/hyperledger/fabric/core/handlers/validation/api"
25-
. "github.com/hyperledger/fabric/core/handlers/validation/api/capabilities"
26-
. "github.com/hyperledger/fabric/core/handlers/validation/api/identities"
2725
. "github.com/hyperledger/fabric/core/handlers/validation/api/policies"
2826
. "github.com/hyperledger/fabric/core/handlers/validation/api/state"
29-
default_vscc "github.com/hyperledger/fabric/core/handlers/validation/builtin"
27+
defaultvscc "github.com/hyperledger/fabric/core/handlers/validation/builtin"
3028
"github.com/hyperledger/fabric/protos/common"
3129
"github.com/pkg/errors"
3230
)
@@ -43,7 +41,7 @@ func (*ERCCValidationFactory) New() validation.Plugin {
4341
}
4442

4543
type ERCCValidation struct {
46-
DefaultTxValidator TransactionValidator
44+
DefaultTxValidator validation.Plugin
4745
ERCCTxValidator TransactionValidator
4846
}
4947

@@ -72,7 +70,7 @@ func (v *ERCCValidation) Validate(block *common.Block, namespace string, txPosit
7270
}
7371

7472
// do defalt vscc
75-
err := v.DefaultTxValidator.Validate(block.Data.Data[txPosition], serializedPolicy.Bytes())
73+
err := v.DefaultTxValidator.Validate(block, namespace, txPosition, actionPosition, contextData...)
7674
if err != nil {
7775
logger.Debugf("block %d, namespace: %s, tx %d validation results is: %v", block.Header.Number, namespace, txPosition, err)
7876
return convertErrorTypeOrPanic(err)
@@ -102,41 +100,25 @@ func convertErrorTypeOrPanic(err error) error {
102100
}
103101

104102
func (v *ERCCValidation) Init(dependencies ...validation.Dependency) error {
105-
var (
106-
d IdentityDeserializer
107-
c Capabilities
108-
sf StateFetcher
109-
pe PolicyEvaluator
110-
)
103+
var sf StateFetcher
111104
for _, dep := range dependencies {
112-
if deserializer, isIdentityDeserializer := dep.(IdentityDeserializer); isIdentityDeserializer {
113-
d = deserializer
114-
}
115-
if capabilities, isCapabilities := dep.(Capabilities); isCapabilities {
116-
c = capabilities
117-
}
118105
if stateFetcher, isStateFetcher := dep.(StateFetcher); isStateFetcher {
119106
sf = stateFetcher
120107
}
121-
if policyEvaluator, isPolicyFetcher := dep.(PolicyEvaluator); isPolicyFetcher {
122-
pe = policyEvaluator
123-
}
124108
}
125109
if sf == nil {
126-
return errors.New("stateFetcher not passed in init")
127-
}
128-
if d == nil {
129-
return errors.New("identityDeserializer not passed in init")
130-
}
131-
if c == nil {
132-
return errors.New("capabilities not passed in init")
133-
}
134-
if pe == nil {
135-
return errors.New("policy fetcher not passed in init")
110+
return errors.New("ERCC-VSCC: stateFetcher not passed in init")
136111
}
137-
// use default vscc and our custom ercc vscc
138-
v.DefaultTxValidator = default_vscc.New(c, sf, d, pe)
112+
139113
v.ERCCTxValidator = New(sf)
140114

115+
// use default vscc and our custom ercc vscc
116+
factory := &defaultvscc.DefaultValidationFactory{}
117+
v.DefaultTxValidator = factory.New()
118+
err := v.DefaultTxValidator.Init(dependencies...)
119+
if err != nil {
120+
return errors.Errorf("Error while creating default vscc: %s", err)
121+
}
122+
141123
return nil
142124
}

fabric/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
To enable SGX support for a Fabric peer start with a fresh copy of Fabric and
44
apply our patch. https://github.com/hyperledger/fabric
55

6-
We assume that you are familiar with build Fabric manually otherwise we
6+
We assume that you are familiar with building Fabric manually; otherwise we highly
77
recommend to spend some time to build Fabric and run a simple network with a
88
few peers and a ordering service.
99

1010
## Patch and Build
1111

12-
Clone fabric and checkout the 1.2 release.
12+
Clone fabric and checkout the 1.4 release.
1313

1414
$ git clone https://github.com/hyperledger/fabric.git
15-
$ git checkout release-1.2
15+
$ git checkout release-1.4
1616
$ git apply path-to-this-patch/sgx_support.patch
1717

1818
When building the peer make sure fabric is your ``GOPATH`` and you enable the
1919
plugin feature. Otherwise our custom validation plugins can not be loaded.
2020

21-
$ GO_TAGS=pluginsenabled EXPERIMENTAL=false DOCKER_DYNAMIC_LINK=true make peer
21+
$ GO_TAGS=pluginsenabled make peer
2222

2323
To make your life easier we have prepared an example configuration and an
2424
auction demo. You can copy ``sgxconfig`` to your fabric directory and modify
@@ -40,6 +40,9 @@ Place your client certificate and your SPID in the ``ias`` folder.
4040
cp client.key /path-to/fabric/sgxconfig/ias/client.key
4141
echo 'YOURSPID' | xxd -r -p > /path-to/fabric/sgxconfig/ias/spid.txt
4242

43+
We currently make use of `unlinkable signatures` for the attestation, thus, when registering with the IAS please choose
44+
unlinkable signatures.
45+
4346
## Run the Auction
4447

4548
Before you continue here build the other components, such as the chaincode

fabric/sgx_support.patch

Lines changed: 14 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,27 @@
1-
diff --git a/core/chaincode/shim/mockstub.go b/core/chaincode/shim/mockstub.go
2-
index acc8200..e808052 100644
3-
--- a/core/chaincode/shim/mockstub.go
4-
+++ b/core/chaincode/shim/mockstub.go
5-
@@ -12,6 +12,7 @@ import (
6-
"container/list"
7-
"fmt"
8-
"strings"
9-
+ "sync"
10-
11-
"github.com/golang/protobuf/ptypes/timestamp"
12-
"github.com/hyperledger/fabric/common/util"
13-
@@ -62,6 +63,10 @@ type MockStub struct {
14-
15-
// channel to store ChaincodeEvents
16-
ChaincodeEventsChannel chan *pb.ChaincodeEvent
17-
+
18-
+ Decorations map[string][]byte
19-
+
20-
+ sync.RWMutex
21-
}
22-
23-
func (stub *MockStub) GetTxID() string {
24-
@@ -137,7 +142,7 @@ func (stub *MockStub) MockInvoke(uuid string, args [][]byte) pb.Response {
25-
}
26-
27-
func (stub *MockStub) GetDecorations() map[string][]byte {
28-
- return nil
29-
+ return stub.Decorations
30-
}
31-
32-
// Invoke this chaincode, also starts and ends a transaction.
33-
@@ -193,6 +198,8 @@ func (stub *MockStub) GetPrivateDataQueryResult(collection, query string) (State
34-
35-
// GetState retrieves the value for a given key from the ledger
36-
func (stub *MockStub) GetState(key string) ([]byte, error) {
37-
+ stub.RLock()
38-
+ defer stub.RUnlock()
39-
value := stub.State[key]
40-
mockLogger.Debug("MockStub", stub.Name, "Getting", key, value)
41-
return value, nil
42-
@@ -200,11 +207,13 @@ func (stub *MockStub) GetState(key string) ([]byte, error) {
43-
44-
// PutState writes the specified `value` and `key` into the ledger.
45-
func (stub *MockStub) PutState(key string, value []byte) error {
46-
- if stub.TxID == "" {
47-
- err := errors.New("cannot PutState without a transactions - call stub.MockTransactionStart()?")
48-
- mockLogger.Errorf("%+v", err)
49-
- return err
50-
- }
51-
+ stub.Lock()
52-
+ defer stub.Unlock()
53-
+ // if stub.TxID == "" {
54-
+ // err := errors.New("cannot PutState without a transactions - call stub.MockTransactionStart()?")
55-
+ // mockLogger.Errorf("%+v", err)
56-
+ // return err
57-
+ // }
58-
59-
mockLogger.Debug("MockStub", stub.Name, "Putting", key, value)
60-
stub.State[key] = value
61-
@@ -244,6 +253,8 @@ func (stub *MockStub) PutState(key string, value []byte) error {
62-
63-
// DelState removes the specified `key` and its value from the ledger.
64-
func (stub *MockStub) DelState(key string) error {
65-
+ stub.Lock()
66-
+ defer stub.Unlock()
67-
mockLogger.Debug("MockStub", stub.Name, "Deleting", key, stub.State[key])
68-
delete(stub.State, key)
69-
70-
@@ -257,6 +268,8 @@ func (stub *MockStub) DelState(key string) error {
71-
}
72-
73-
func (stub *MockStub) GetStateByRange(startKey, endKey string) (StateQueryIteratorInterface, error) {
74-
+ stub.RLock()
75-
+ defer stub.RUnlock()
76-
if err := validateSimpleKeys(startKey, endKey); err != nil {
77-
return nil, err
78-
}
79-
@@ -288,6 +301,8 @@ func (stub *MockStub) GetHistoryForKey(key string) (HistoryQueryIteratorInterfac
80-
//a partial composite key. For a full composite key, an iter with empty response
81-
//would be returned.
82-
func (stub *MockStub) GetStateByPartialCompositeKey(objectType string, attributes []string) (StateQueryIteratorInterface, error) {
83-
+ stub.RLock()
84-
+ defer stub.RUnlock()
85-
partialCompositeKey, err := stub.CreateCompositeKey(objectType, attributes)
86-
if err != nil {
87-
return nil, err
88-
@@ -381,6 +396,7 @@ func NewMockStub(name string, cc Chaincode) *MockStub {
89-
s.Invokables = make(map[string]*MockStub)
90-
s.Keys = list.New()
91-
s.ChaincodeEventsChannel = make(chan *pb.ChaincodeEvent, 100) //define large capacity for non-blocking setEvent calls.
92-
+ s.Decorations = make(map[string][]byte)
93-
94-
return s
95-
}
96-
diff --git a/core/container/dockercontroller/dockercontroller.go b/core/container/dockercontroller/dockercontroller.go
97-
index a6ec99e..e5c1f69 100644
98-
--- a/core/container/dockercontroller/dockercontroller.go
99-
+++ b/core/container/dockercontroller/dockercontroller.go
1+
diff --git i/core/container/dockercontroller/dockercontroller.go w/core/container/dockercontroller/dockercontroller.go
2+
index 2a709ed0b..51df8f7ff 100644
3+
--- i/core/container/dockercontroller/dockercontroller.go
4+
+++ w/core/container/dockercontroller/dockercontroller.go
1005
@@ -168,6 +168,14 @@ func getDockerHostConfig() *docker.HostConfig {
1016
CPUQuota: getInt64("CpuQuota"),
1027
CPUPeriod: getInt64("CpuPeriod"),
1038
BlkioWeight: getInt64("BlkioWeight"),
1049
+ Binds: []string{"/var/run/aesmd:/var/run/aesmd"},
10510
+ Devices: []docker.Device{
106-
+ docker.Device{
11+
+ {
10712
+ PathOnHost: "/dev/isgx",
10813
+ PathInContainer: "/dev/isgx",
10914
+ CgroupPermissions: "rwm",
11015
+ },
11116
+ },
11217
}
18+
}
11319

114-
return hostConfig
115-
@@ -176,7 +184,8 @@ func getDockerHostConfig() *docker.HostConfig {
116-
func (vm *DockerVM) createContainer(ctxt context.Context, client dockerClient,
117-
imageID string, containerID string, args []string,
118-
env []string, attachStdout bool) error {
119-
- config := docker.Config{Cmd: args, Image: imageID, Env: env, AttachStdout: attachStdout, AttachStderr: attachStdout}
120-
+ v := map[string]struct{}{"/var/run/aesmd": {}}
121-
+ config := docker.Config{Cmd: args, Image: imageID, Env: env, AttachStdout: attachStdout, AttachStderr: attachStdout, Volumes: v}
122-
copts := docker.CreateContainerOptions{Name: containerID, Config: &config, HostConfig: getDockerHostConfig()}
123-
dockerLogger.Debugf("Create container: %s", containerID)
124-
_, err := client.CreateContainer(copts)
20+
@@ -182,6 +190,7 @@ func (vm *DockerVM) createContainer(client dockerClient, imageID, containerID st
21+
Env: env,
22+
AttachStdout: attachStdout,
23+
AttachStderr: attachStdout,
24+
+ Volumes: map[string]struct{}{"/var/run/aesmd": {}},
25+
},
26+
HostConfig: getDockerHostConfig(),
27+
})

0 commit comments

Comments
 (0)