This is an automated email from the ASF dual-hosted git repository.
mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git
The following commit(s) were added to refs/heads/master by this push:
new 51e7ee8 [docs] Add document on defining customized function (#318)
51e7ee8 is described below
commit 51e7ee830dea022b87a758284d3ffb74cd63dadc
Author: Mingshen Sun <[email protected]>
AuthorDate: Tue May 26 16:52:01 2020 -0700
[docs] Add document on defining customized function (#318)
---
config/README.md | 8 +++++---
docs/README.md | 1 +
docs/my-first-function.md | 33 +++++++++++++++++++++++++++++++--
examples/python/mesapy_echo.py | 16 ++++++++--------
examples/python/mesapy_echo_payload.py | 4 ++++
5 files changed, 49 insertions(+), 13 deletions(-)
diff --git a/config/README.md b/config/README.md
index 7ab0591..71fb128 100644
--- a/config/README.md
+++ b/config/README.md
@@ -17,8 +17,10 @@ certificate of attestation service used for verifying
attestation report,
auditors' public keys for verification of enclave information, and topological
graph of connections between services for mutual attestation. More detailed
explanation of configurations can be seen in the
-[`build.config.toml`](build.config.toml) file. We also implement a
-[`config_gen`](config_gen) tool to generate hard-coded configurations in Rust
+[`build.config.toml`](https://github.com/apache/incubator-teaclave/blob/master/config/build.config.toml)
+file. We also implement a
+[`config_gen`](https://github.com/apache/incubator-teaclave/tree/master/config/config_gen)
+tool to generate hard-coded configurations in Rust
from the user-defined config in TOML at compilation time.
Note that it is very *important* to define these configurations in build time,
@@ -36,7 +38,7 @@ Teaclave, the enclave information and auditor's signatures
files loaded at
runtime, algorithm/id/key used for connecting attestation services, etc.
Some configurations can be overridden by environment variables. Detailed
explanation of configurations can be found in the
-[`runtime.config.toml`](runtime.config.toml) file.
+[`runtime.config.toml`](https://github.com/apache/incubator-teaclave/blob/master/config/runtime.config.toml)
file.
Note that the runtime config will be loaded when launching the services. We
diff --git a/docs/README.md b/docs/README.md
index 96d9fbb..64196ba 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -8,3 +8,4 @@ permalink: /docs/
- [Threat Model](threat-model.md)
- [Rust Development Guideline](rust-guideline.md)
- [Mutual Attestation: Why and How](mutual-attestation.md)
+- [Access Control in Teaclave](access-control.md)
diff --git a/docs/my-first-function.md b/docs/my-first-function.md
index e141bb1..615cb55 100644
--- a/docs/my-first-function.md
+++ b/docs/my-first-function.md
@@ -103,6 +103,8 @@ remote attestation. They can be installed with `pip`:
$ pip3 install pyopenssl toml cryptography
```
+### Built-in function
+
Then, run the echo example:
```
@@ -119,8 +121,35 @@ $ PYTHONPATH=../../sdk/python python3 builtin_echo.py
'Hello, Teaclave!'
[+] function return: b'Hello, Teaclave!'
```
-If you see above log, this means that the function is successfully invoked in
-Teaclave.
+If you see above log, this means that the function is successfully invoked in
Teaclave.
+
+### Define my own function
+
+The previous example is to demonstrate invoking the built-in echo function. In
+Teaclave, you can also register and invoke a function written by yourself.
+For example, we can implement a echo function in Python like this:
+
+```
+$ cat mesapy_echo_payload.py
+def entrypoint(argv):
+ assert argv[0] == 'message'
+ assert argv[1] is not None
+ return argv[1]
+```
+
+Then run the mesapy echo example:
+```
+$ PYTHONPATH=../../sdk/python python3 mesapy_echo.py mesapy_echo_payload.py
'Hello, Teaclave!'
+[+] registering user
+[+] login
+[+] registering function
+[+] creating task
+[+] approving task
+[+] invoking task
+[+] getting result
+[+] done
+[+] function return: b'Hello, Teaclave!'
+```
## Simulation Mode
To try Teaclave in SGX simulation mode, please install Intel SGX SDK first
with instructions in
diff --git a/examples/python/mesapy_echo.py b/examples/python/mesapy_echo.py
index 6e6d1d8..6536f94 100644
--- a/examples/python/mesapy_echo.py
+++ b/examples/python/mesapy_echo.py
@@ -23,7 +23,7 @@ class MesaPyEchoExample:
self.user_id = user_id
self.user_password = user_password
- def echo(self, message="Hello, Teaclave!"):
+ def echo(self, payload_file="mesapy_echo_payload.py", message="Hello,
Teaclave!"):
channel = AuthenticationService(AUTHENTICATION_SERVICE_ADDRESS,
AS_ROOT_CA_CERT_PATH,
ENCLAVE_INFO_PATH).connect()
@@ -43,12 +43,8 @@ class MesaPyEchoExample:
print("[+] registering function")
- payload = b"""
-def entrypoint(argv):
- assert argv[0] == 'message'
- assert argv[1] is not None
- return argv[1]
- """
+ with open(payload_file, "rb") as f:
+ payload = f.read()
function_id = client.register_function(
name="mesapy-echo",
description="An echo function implemented in Python",
@@ -73,9 +69,13 @@ def entrypoint(argv):
def main():
example = MesaPyEchoExample(USER_ID, USER_PASSWORD)
- if len(sys.argv) > 1:
+ if len(sys.argv) == 2:
message = sys.argv[1]
rt = example.echo(message)
+ elif len(sys.argv) == 3:
+ payload = sys.argv[1]
+ message = sys.argv[2]
+ rt = example.echo(payload, message)
else:
rt = example.echo()
diff --git a/examples/python/mesapy_echo_payload.py
b/examples/python/mesapy_echo_payload.py
new file mode 100644
index 0000000..04b4844
--- /dev/null
+++ b/examples/python/mesapy_echo_payload.py
@@ -0,0 +1,4 @@
+def entrypoint(argv):
+ assert argv[0] == 'message'
+ assert argv[1] is not None
+ return argv[1]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]