Skip to content

Commit f2de95f

Browse files
Enable FPC simulation mode using pure Go
Allows to build ercc and FPC go chaincode without SGX deps. This allows developer to fiddle around with FPC, in particular, prototyping FPC chaincode, without SGX required on their development machines. While our FPC Dev container works fine in most cases, developers with Apple M1 machines cannot use our dockerized environment. This commit overcomes this issue. Signed-off-by: Marcus Brandenburger <[email protected]>
1 parent 9c6a377 commit f2de95f

File tree

11 files changed

+123
-23
lines changed

11 files changed

+123
-23
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,47 @@ echo 'YOUR_SPID' > $FPC_PATH/config/ias/spid.txt
423423
```
424424
where `YOUR_SPID_TYPE` must be `epid-linkable` or `epid-unlinkable`, depending on the type of your subscription.
425425

426-
### Trouble shooting
426+
427+
### FPC Playground for non-SGX environments
428+
429+
FPC leverages Intel SGX as the Confidential Computing technology to guard Fabric chaincodes.
430+
Even though the Intel SGX SDK supports a simulation mode, where you can run applications in a simulated enclave, it still requires an x86-based platform to run and compile the enclave code.
431+
Another limitation comes from the fact that the Intel SGX SDK is only available for Linux and Windows.
432+
433+
To overcome these limitations and allow developers to toy around with the FPC API, we provide two ways to getting started with FPC.
434+
435+
1) Using the [Docker-based FPC Development Environment](#setup-your-development-environment) (works well on x86-based platforms on Linux and Mac).
436+
2) FPC builds without SGX SDK dependencies (targets x86/arm-based platforms on Linux and Mac).
437+
438+
We now elaborate on how to build the FPC components without the SGX SDK.
439+
Note that this is indented for developing purpose only and does not provide any protection at all.
440+
441+
In your `config.override.mk` set the following to variables:
442+
```Makefile
443+
FPC_CCENV_IMAGE=ubuntu:20.04
444+
ERCC_GOTAGS=
445+
```
446+
This configuration sets a standard Ubuntu image as alternative to our `fabric-private-chaincode-ccenv` image and overrides the default build tags we use to build `ercc`.
447+
448+
Next you can build `ercc` using the following command:
449+
```bash
450+
GOOS=linux make -C $FPC_PATH/ercc build docker
451+
```
452+
453+
For building a chaincode, for instance `$FPC_PATH/samples/chaincode/kv-test-go`, just run:
454+
```bash
455+
GOOS=linux make -C $FPC_PATH/samples/chaincode/kv-test-go with_go docker
456+
```
457+
458+
You can test your FPC chaincode easily with one of the [sample deployments](samples/deployment) tutorials.
459+
We recommend to start with [the-simple-testing-network](samples/deployment/fabric-smart-client/the-simple-testing-network).
460+
461+
Notes:
462+
- On Mac use a recent version of bash (`brew install bash`).
463+
- TODO more to come
464+
465+
466+
### Troubleshooting
427467

428468
This section elaborate on common issues with building Fabric Private Chaincode.
429469

config.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ PROJECT_NAME=fabric-private-chaincode
6969
export FABRIC_VERSION ?= 2.3.3
7070

7171
export FPC_VERSION := go-support
72+
export FPC_CCENV_IMAGE ?= hyperledger/fabric-private-chaincode-ccenv:$(FPC_VERSION)
7273

7374
export FABRIC_PATH ?= ${GOPATH}/src/github.com/hyperledger/fabric
7475

ecc_go/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
# - sgxmode: SGX_MODE
1212
# - Chaincode as a Server Port: CAAS_PORT
1313

14-
ARG FPC_VERSION=main
14+
ARG FPC_CCENV_IMAGE=hyperledger/fabric-private-chaincode-ccenv:main
1515

16-
FROM hyperledger/fabric-private-chaincode-ccenv:${FPC_VERSION}
16+
FROM ${FPC_CCENV_IMAGE}
1717

1818
ARG SGX_MODE
1919
ENV SGX_MODE=${SGX_MODE}

ecc_go/build.mk

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ endif
5353
ifdef DOCKER_FORCE_REBUILD
5454
DOCKER_BUILD_OPTS += --no-cache
5555
endif
56-
DOCKER_BUILD_OPTS += --build-arg FPC_VERSION=$(FPC_VERSION)
56+
DOCKER_BUILD_OPTS += --build-arg FPC_CCENV_IMAGE=$(FPC_CCENV_IMAGE)
5757
DOCKER_BUILD_OPTS += --build-arg SGX_MODE=$(SGX_MODE)
5858
DOCKER_BUILD_OPTS += --build-arg CAAS_PORT=$(CAAS_PORT)
5959

60-
61-
6260
docker:
63-
$(DOCKER) build $(DOCKER_BUILD_OPTS) -t $(DOCKER_IMAGE):$(FPC_VERSION) -f $(DOCKER_FILE)\
64-
$(shell if [ "${SGX_MODE}" = "SIM" ]; then echo "--build-arg OE_SIMULATION=1"; fi)\
65-
. &&\
66-
$(DOCKER) tag $(DOCKER_IMAGE):$(FPC_VERSION) $(DOCKER_IMAGE):latest
61+
$(DOCKER) build $(DOCKER_BUILD_OPTS) \
62+
$(shell if [ "${SGX_MODE}" = "SIM" ]; then echo "--build-arg OE_SIMULATION=1"; fi) \
63+
-t $(DOCKER_IMAGE):$(FPC_VERSION) \
64+
-f $(DOCKER_FILE) \
65+
. \
66+
&& $(DOCKER) tag $(DOCKER_IMAGE):$(FPC_VERSION) $(DOCKER_IMAGE):latest
6767

6868
clean:
6969
$(GO) clean

ercc/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55

6-
ARG FPC_VERSION=main
6+
ARG FPC_CCENV_IMAGE=hyperledger/fabric-private-chaincode-ccenv:main
77

8-
FROM hyperledger/fabric-private-chaincode-ccenv:${FPC_VERSION}
8+
FROM ${FPC_CCENV_IMAGE}
99

1010
ENV PATH=/opt/ercc:$PATH
1111

ercc/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
TOP = ..
77
include $(TOP)/build.mk
88

9-
GOTAGS += -tags WITH_PDO_CRYPTO
9+
ERCC_GOTAGS ?= -tags WITH_PDO_CRYPTO
10+
GOTAGS += $(ERCC_GOTAGS)
1011

1112
build: ercc
1213

@@ -34,7 +35,7 @@ DOCKER_IMAGE?=fpc/ercc
3435

3536
docker: ercc
3637
$(DOCKER) build $(DOCKER_BUILD_OPTS) \
37-
--build-arg FPC_VERSION=$(FPC_VERSION) \
38+
--build-arg FPC_CCENV_IMAGE=$(FPC_CCENV_IMAGE) \
3839
-t $(DOCKER_IMAGE):$(FPC_VERSION) \
3940
. \
4041
&& $(DOCKER) tag $(DOCKER_IMAGE):$(FPC_VERSION) $(DOCKER_IMAGE):latest

ercc/attestation/pdo.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build WITH_PDO_CRYPTO
2+
3+
/*
4+
Copyright IBM Corp. All Rights Reserved.
5+
6+
SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
package attestation
10+
11+
import (
12+
"github.com/hyperledger/fabric-private-chaincode/internal/attestation/epid/pdo"
13+
)
14+
15+
func init() {
16+
registry.add(pdo.NewEpidLinkableVerifier())
17+
registry.add(pdo.NewEpidUnlinkableVerifier())
18+
}

ercc/attestation/simulation.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package attestation
8+
9+
import "github.com/hyperledger/fabric-private-chaincode/internal/attestation/simulation"
10+
11+
func init() {
12+
registry.add(simulation.NewSimulationVerifier())
13+
}

ercc/attestation/verifier.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package attestation
8+
9+
import (
10+
"github.com/hyperledger/fabric-private-chaincode/internal/attestation"
11+
"github.com/hyperledger/fabric-private-chaincode/internal/attestation/types"
12+
"github.com/pkg/errors"
13+
)
14+
15+
var registry verifierRegistry
16+
17+
type verifierRegistry struct {
18+
verifiers []*types.Verifier
19+
}
20+
21+
func (vr *verifierRegistry) add(verifier *types.Verifier) {
22+
for _, v := range vr.verifiers {
23+
if v.Type == verifier.Type {
24+
// this type of verifier is already registered
25+
panic(errors.Errorf("credential verifier of type '%v' already registered!", verifier.Type))
26+
}
27+
}
28+
29+
vr.verifiers = append(vr.verifiers, verifier)
30+
}
31+
32+
func GetAvailableVerifier() *attestation.CredentialVerifier {
33+
return attestation.NewCredentialVerifier(registry.verifiers...)
34+
}

ercc/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import (
1111

1212
"github.com/hyperledger/fabric-chaincode-go/shim"
1313
"github.com/hyperledger/fabric-contract-api-go/contractapi"
14+
"github.com/hyperledger/fabric-private-chaincode/ercc/attestation"
1415
"github.com/hyperledger/fabric-private-chaincode/ercc/registry"
15-
"github.com/hyperledger/fabric-private-chaincode/internal/attestation"
16-
"github.com/hyperledger/fabric-private-chaincode/internal/attestation/epid/pdo"
17-
"github.com/hyperledger/fabric-private-chaincode/internal/attestation/simulation"
1816
"github.com/hyperledger/fabric-private-chaincode/internal/utils"
1917
"github.com/hyperledger/fabric/common/flogging"
2018
)
@@ -28,11 +26,7 @@ func main() {
2826
// For example: FABRIC_LOGGING_SPEC=ecc=DEBUG:ecc_enclave=ERROR
2927

3028
c := &registry.Contract{}
31-
c.Verifier = attestation.NewCredentialVerifier(
32-
simulation.NewSimulationVerifier(),
33-
pdo.NewEpidLinkableVerifier(),
34-
pdo.NewEpidUnlinkableVerifier(),
35-
)
29+
c.Verifier = attestation.GetAvailableVerifier()
3630
c.IEvaluator = &utils.IdentityEvaluator{}
3731
c.BeforeTransaction = registry.MyBeforeTransaction
3832

internal/crypto/crypto_go.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ SPDX-License-Identifier: Apache-2.0
66

77
package crypto
88

9-
import "C"
109
import (
1110
"crypto/aes"
1211
"crypto/cipher"

0 commit comments

Comments
 (0)