-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a319c0a
commit bd995c8
Showing
18 changed files
with
200 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
|
||
* Basic | ||
|
||
Build: | ||
`./basic/build` | ||
|
||
Run locally: | ||
`./basic/run` | ||
`./basic/run Alice` | ||
|
||
|
||
* Tee | ||
|
||
Build: | ||
`./tee/build` | ||
|
||
Run locally: | ||
`./tee/run` | ||
`./tee/run Alice` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM python:3.7.3 | ||
|
||
### install some python3 dependencies | ||
RUN pip3 install eth_abi | ||
|
||
COPY ./src /app | ||
|
||
ENTRYPOINT ["python", "/app/app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
|
||
docker image build -f ../basic/Dockerfile -t offchain-python-hello-world:1.0.0 .. $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
|
||
IEXEC_OUT=/tmp/iexec_out | ||
|
||
rm -rf $IEXEC_OUT | ||
mkdir -p $IEXEC_OUT | ||
|
||
docker run --rm -e IEXEC_OUT=/iexec_out -e IEXEC_IN=/iexec_in -v $IEXEC_OUT:/iexec_out offchain-python-hello-world:1.0.0 $@ | ||
|
||
echo | ||
find $IEXEC_OUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import sys | ||
import json | ||
import eth_abi | ||
|
||
iexec_out = os.environ['IEXEC_OUT'] | ||
iexec_in = os.environ['IEXEC_IN'] | ||
|
||
# Do whatever you want | ||
data = "Hello, World!" | ||
if len(sys.argv) > 1: | ||
data = 'Hello, {}!'.format(sys.argv[1]) | ||
|
||
# Eventually use some confidential assets | ||
if os.path.exists(iexec_in + '/dataset.txt'): | ||
with open(iexec_in + '/dataset.txt', 'r') as dataset: | ||
print('Confidential dataset: ' + dataset.read()) | ||
|
||
# Send callback data to smart-contract | ||
callback_data = eth_abi.encode_abi([ 'string'], [ data ]).hex() | ||
print('Offchain computing for Smart-Contracts [data:{}, callback_data:{}]'.format(data, callback_data)) | ||
with open(iexec_out + '/computed.json', 'w+') as f: | ||
json.dump({ "callback-data" : callback_data}, f) | ||
|
||
|
||
## Try: | ||
# Basic: | ||
# mkdir -p /tmp/iexec_out && IEXEC_OUT=/tmp/iexec_out IEXEC_IN=/tmp/iexec_in python3 app.py Alice | ||
# | ||
# Tee: | ||
# mkdir -p /tmp/iexec_out && IEXEC_OUT=/tmp/iexec_out IEXEC_IN=../tee/confidential-assets python3 app.py Alice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM sconecuratedimages/apps:python-3.7.3-alpine3.10-scone3.0 | ||
|
||
### install some python3 dependencies | ||
RUN apk add gcc | ||
RUN SCONE_MODE=sim pip3 install eth_abi | ||
|
||
### copy the code inside the image | ||
COPY ./src /app | ||
|
||
### protect file system with Scone | ||
COPY ./tee/protect-fs.sh ./tee/Dockerfile /build/ | ||
RUN sh /build/protect-fs.sh /app | ||
|
||
ENTRYPOINT ["python", "/app/app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
docker image build -f ../tee/Dockerfile -t offchain-tee-python-hello-world:1.0.0 .. $@ |
1 change: 1 addition & 0 deletions
1
v5/offchain-python-hello-world/tee/confidential-assets/dataset.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy dataset file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/sh | ||
|
||
cd $(dirname $0) | ||
|
||
if [ ! -e Dockerfile ] | ||
then | ||
printf "\nFailed to parse Dockerfile ENTRYPOINT\n" | ||
printf "Did you forget to add your Dockerfile in your build?\n" | ||
printf "COPY ./tee/Dockerfile /build/\n\n" | ||
exit 1 | ||
fi | ||
|
||
ENTRYPOINT_ARSG=$(grep ENTRYPOINT ./Dockerfile | tail -1 | grep -o '"[^"]\+"' | tr -d '"') | ||
echo $ENTRYPOINT_ARSG > ./entrypoint | ||
|
||
if [ -z "$ENTRYPOINT_ARSG" ] | ||
then | ||
printf "\nFailed to parse Dockerfile ENTRYPOINT\n" | ||
printf "Did you forget to add an ENTRYPOINT to your Dockerfile?\n" | ||
printf "ENTRYPOINT [\"executable\", \"param1\", \"param2\"]\n\n" | ||
exit 1 | ||
fi | ||
|
||
INTERPRETER=$(awk '{print $1}' ./entrypoint) # python | ||
ENTRYPOINT=$(cat ./entrypoint) # /python /app/app.py | ||
|
||
export SCONE_MODE=sim | ||
export SCONE_HEAP=1G | ||
|
||
APP_FOLDER=$1 | ||
|
||
printf "\n### Starting file system protection ...\n\n" | ||
|
||
scone fspf create /fspf.pb | ||
scone fspf addr /fspf.pb / --not-protected --kernel / | ||
scone fspf addr /fspf.pb /usr --authenticated --kernel /usr | ||
scone fspf addf /fspf.pb /usr /usr | ||
scone fspf addr /fspf.pb /bin --authenticated --kernel /bin | ||
scone fspf addf /fspf.pb /bin /bin | ||
scone fspf addr /fspf.pb /lib --authenticated --kernel /lib | ||
scone fspf addf /fspf.pb /lib /lib | ||
scone fspf addr /fspf.pb /etc/ssl --authenticated --kernel /etc/ssl | ||
scone fspf addf /fspf.pb /etc/ssl /etc/ssl | ||
scone fspf addr /fspf.pb /sbin --authenticated --kernel /sbin | ||
scone fspf addf /fspf.pb /sbin /sbin | ||
printf "\n### Protecting code found in folder \"$APP_FOLDER\"\n\n" | ||
scone fspf addr /fspf.pb $APP_FOLDER --authenticated --kernel $APP_FOLDER | ||
scone fspf addf /fspf.pb $APP_FOLDER $APP_FOLDER | ||
|
||
scone fspf encrypt /fspf.pb > ./keytag | ||
|
||
MRENCLAVE="$(SCONE_HASH=1 $INTERPRETER)" | ||
FSPF_TAG=$(cat ./keytag | awk '{print $9}') | ||
FSPF_KEY=$(cat ./keytag | awk '{print $11}') | ||
FINGERPRINT="$FSPF_KEY|$FSPF_TAG|$MRENCLAVE|$ENTRYPOINT" | ||
echo $FINGERPRINT > ./fingerprint | ||
|
||
printf "\n\n" | ||
printf "Your application fingerprint (mrenclave) is ready:\n" | ||
printf "#####################################################################\n" | ||
printf "iexec.json:\n\n" | ||
printf "%s\n" "\"app\": { " " \"owner\" : ... " " \"name\": ... " " ..." " \"mrenclave\": \"$FINGERPRINT\"" "}" | ||
printf "#####################################################################\n" | ||
printf "Hint: Replace 'mrenclave' before doing 'iexec app deploy' step.\n" | ||
printf "\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
|
||
IEXEC_OUT=/tmp/iexec_out | ||
|
||
rm -rf $IEXEC_OUT | ||
mkdir -p $IEXEC_OUT | ||
|
||
docker run --rm -e IEXEC_OUT=/iexec_out -e IEXEC_IN=/iexec_in -v $IEXEC_OUT:/iexec_out -v $(pwd)/confidential-assets:/iexec_in --device /dev/isgx offchain-tee-python-hello-world:1.0.0 $@ | ||
|
||
echo | ||
find $IEXEC_OUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
|
||
docker image build -f ../basic/Dockerfile -t python-hello-world:4.0.0 .. $@ | ||
docker image build -f ../basic/Dockerfile -t python-hello-world:1.0.0 .. $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
|
||
rm -rf /tmp/iexec_out | ||
mkdir -p /tmp/iexec_out | ||
IEXEC_OUT=/tmp/iexec_out | ||
|
||
docker run --rm -e IEXEC_OUT=/iexec_out -v /tmp/iexec_out:/iexec_out python-hello-world:4.0.0 $@ | ||
rm -rf $IEXEC_OUT | ||
mkdir -p $IEXEC_OUT | ||
|
||
docker run --rm -e IEXEC_OUT=/iexec_out -e IEXEC_IN=/iexec_in -v /tmp/iexec_out:/iexec_out python-hello-world:1.0.0 $@ | ||
|
||
echo | ||
find /tmp/iexec_out/ | ||
find $IEXEC_OUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
docker image build -f ../tee/Dockerfile -t tee-python-hello-world:4.0.0 .. $@ | ||
docker image build -f ../tee/Dockerfile -t tee-python-hello-world:1.0.0 .. $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dummy dataset file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
#!/bin/sh | ||
cd $(dirname $0) | ||
|
||
rm -rf /tmp/iexec_out | ||
mkdir -p /tmp/iexec_out | ||
IEXEC_OUT=/tmp/iexec_out | ||
|
||
docker run --rm -e IEXEC_OUT=/iexec_out -v /tmp/iexec_out:/iexec_out --device /dev/isgx tee-python-hello-world:4.0.0 $@ | ||
rm -rf $IEXEC_OUT | ||
mkdir -p $IEXEC_OUT | ||
|
||
docker run --rm -e IEXEC_OUT=/iexec_out -e IEXEC_IN=/iexec_in -v $IEXEC_OUT:/iexec_out -v $(pwd)/confidential-assets:/iexec_in --device /dev/isgx tee-python-hello-world:1.0.0 $@ | ||
|
||
echo | ||
find /tmp/iexec_out/ | ||
find $IEXEC_OUT |