You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2022/05/31 21:01:07 UTC

[incubator-teaclave] 01/01: Prototyping

This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch cleanroom
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git

commit 0069cd2dec0e93bfa6ebd4289be7b04d9811440a
Author: Mingshen Sun <ms...@apache.org>
AuthorDate: Tue May 31 14:00:58 2022 -0700

    Prototyping
---
 cleanroom/cleanroom.diff | 15583 +++++++++++++++++++++++++++++++++++++++++++++
 cleanroom/wamr.diff      |  2928 +++++++++
 2 files changed, 18511 insertions(+)

diff --git a/cleanroom/cleanroom.diff b/cleanroom/cleanroom.diff
new file mode 100644
index 00000000..07999077
--- /dev/null
+++ b/cleanroom/cleanroom.diff
@@ -0,0 +1,15583 @@
+diff --git a/.drone.yml b/.drone.yml
+index fa2e4c7..19b7350 100644
+--- a/.drone.yml
++++ b/.drone.yml
+@@ -12,41 +12,59 @@
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+-
+-x-isgx-1804-image: &isgx-1804-image
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-
+ kind: pipeline
+-name: sgx-debug-ubuntu-1804
++name: sgx-debug-ubuntu-2004
+ 
+ steps:
+ - name: prepare
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
+   commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - mkdir -p build
+   - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_MODE=ON ..
+ - name: check
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: compile
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  <<: *isgx-1804-image
++- name: package-cli
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
++  - . /root/.cargo/env
++  - . /opt/sgxsdk/environment
++  - apt update
++  - apt install -y clang
++  - pip3 install pyoxidizer 
++  - cd cleanroom-cli
+   - make
++# - name: tvm example
++#   image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++#   commands:
++#   - . ~/.cargo/env
++#   - cd examples/python/wasm_tvm_mnist_payload
++#   - make
+ - name: test
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   environment:
+     AS_ALGO: sgx_epid
+     AS_URL: https://api.trustedservices.intel.com:443
+@@ -65,6 +83,8 @@ steps:
+   - . /opt/sgxsdk/environment
+   - (cd release/tool && ./teaclave_sgx_tool status)
+   - (cd release/tool && ./teaclave_sgx_tool attestation --key $AS_KEY --spid $AS_SPID)
++  - export TEACLAVE_LOG=warn
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - cd build && make run-tests
+ 
+ volumes:
+@@ -75,46 +95,65 @@ volumes:
+   host:
+     path: /var/run/aesmd/aesm.socket
+ 
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
++
+ node:
+   instance: mesatee-sgx
+ 
+----
+ 
+-x-dcap-1804-image: &dcap-1804-image
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-dcap-1.11:0.1.5
++---
+ 
+ kind: pipeline
+-name: sgx-dcap-debug-ubuntu-1804
++name: sgx-dcap-release-ubuntu-2004
+ 
+ steps:
+ - name: prepare
+-  <<: *dcap-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
+   commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - mkdir -p build
+-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_MODE=ON -DDCAP=ON ..
++  - cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTEST_MODE=ON -DDCAP=ON ..
+ - name: check
+-  <<: *dcap-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: compile
+-  <<: *dcap-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - sed -i 's/ias_root_ca_cert/dcap_root_ca_cert/' config/build.config.toml
+   - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  <<: *dcap-1804-image
++- name: package-cli
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
++  - . /root/.cargo/env
++  - . /opt/sgxsdk/environment
++  - pip3 install pyoxidizer 
++  - apt update
++  - apt install -y clang
++  - cd cleanroom-cli
+   - make
+ - name: test
+-  <<: *dcap-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
+   environment:
+     AS_ALGO: sgx_ecdsa
+     AS_URL: https://localhost:8080
+@@ -141,6 +180,7 @@ steps:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - (cd release/dcap && ./teaclave_dcap_ref_as &)
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - cd build && make run-tests
+ 
+ volumes:
+@@ -163,440 +203,393 @@ volumes:
+   host:
+     path: /etc/sgx_default_qcnl.conf
+ 
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
++
+ node:
+   instance: mesatee-sgx-dcap
+ 
+----
+ 
+-x-isgx-2004-image: &isgx-2004-image
+-  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.3
++---
+ 
+ kind: pipeline
+-name: sgx-debug-ubuntu-2004
++name: sgx-dcap-release-tag-publish-ubuntu-2004
+ 
+ steps:
+ - name: prepare
+-  <<: *isgx-2004-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
++    DCAP_ROOT_CA_CERT:
++      from_secret: DCAP_ROOT_CA_CERT
++    DCAP_SERVER_CERT:
++      from_secret: DCAP_SERVER_CERT
++    DCAP_SERVER_KEY:
++      from_secret: DCAP_SERVER_KEY
++  commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - echo $DCAP_ROOT_CA_CERT | base64 -d > keys/dcap_root_ca_cert.pem
++  - echo $DCAP_SERVER_CERT | base64 -d > keys/dcap_server_cert.pem
++  - echo $DCAP_SERVER_KEY | base64 -d > keys/dcap_server_key.pem
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
++  - . /root/.cargo/env
++  - . /opt/sgxsdk/environment
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - mkdir -p build
+-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_MODE=ON ..
++  - cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTEST_MODE=OFF -DDCAP=ON ..
+ - name: check
+-  <<: *isgx-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: compile
+-  <<: *isgx-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
++  - sed -i 's/ias_root_ca_cert/dcap_root_ca_cert/' config/build.config.toml
+   - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  <<: *isgx-2004-image
+-  commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
+-  - make
+-- name: test
+-  <<: *isgx-2004-image
++- name: publish
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1
+   environment:
+-    AS_ALGO: sgx_epid
+-    AS_URL: https://api.trustedservices.intel.com:443
+-    AS_KEY:
+-      from_secret: V5_KEY
+-    AS_SPID:
+-      from_secret: V5_SPID
+-  privileged: true
+-  volumes:
+-  - name: isgx
+-    path: /dev/isgx
+-  - name: aesmd
+-    path: /var/run/aesmd/aesm.socket
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - (cd release/tool && ./teaclave_sgx_tool status)
+-  - (cd release/tool && ./teaclave_sgx_tool attestation --key $AS_KEY --spid $AS_SPID)
+-  - cd build && make run-tests
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
++    PUBLISH_DIR:
++      from_secret: PUBLISH_DIR
++  commands:
++  - release_id=${DRONE_TAG}_$(git rev-parse --short HEAD)
++  - out_service="dcap_service_release_$release_id"
++  - mkdir $out_service
++  - cp -r ./release $out_service/release
++  - cp -r ./dcap_deployment/docker $out_service/docker
++  - cp -r ./monitoring/prometheus.py $out_service
++
++  - out_sdk="dcap_sdk_release_$release_id"
++  - mkdir $out_sdk
++  - cp -r ./sdk/python $out_sdk/python
++  - cp ./release/services/enclave_info.toml $out_sdk/enclave_info.toml
++  - cp ./release/cli/teaclave_cli $out_sdk/teaclave_cli
++  - cp ./keys/dcap_root_ca_cert.pem $out_sdk/dcap_root_cert.pem
++
++  - tar czvf $out_sdk.tgz $out_sdk
++  - tar czvf $out_service.tgz $out_service
++  - scp -i id_rsa -oStrictHostKeyChecking=no $out_sdk.tgz $SSH_USERNAME@$SSH_SERVER_IP:$PUBLISH_DIR
++  - scp -i id_rsa -oStrictHostKeyChecking=no $out_service.tgz $SSH_USERNAME@$SSH_SERVER_IP:$PUBLISH_DIR
+ 
+-volumes:
+-- name: isgx
+-  host:
+-    path: /dev/isgx
+-- name: aesmd
+-  host:
+-    path: /var/run/aesmd/aesm.socket
++
++trigger:
++  ref:
++    include:
++    - refs/tags/service-**
++
++depends_on:
++  - sgx-dcap-release-ubuntu-2004
+ 
+ node:
+   instance: mesatee-sgx
+ 
+ ---
+ 
+-x-dcap-2004-image: &dcap-2004-image
+-  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.3
+-
+ kind: pipeline
+-name: sgx-dcap-debug-ubuntu-2004
++name: sgx-release-ubuntu-2004
+ 
+ steps:
+ - name: prepare
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
+   commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - mkdir -p build
+-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_MODE=ON -DDCAP=ON ..
++  - cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTEST_MODE=OFF ..
+ - name: check
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: compile
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+-  - sed -i 's/ias_root_ca_cert/dcap_root_ca_cert/' config/build.config.toml
+   - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
++- name: package-cli
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
+-  - make
+-- name: test
+-  <<: *dcap-2004-image
+-  environment:
+-    AS_ALGO: sgx_ecdsa
+-    AS_URL: https://localhost:8080
+-    AS_KEY:
+-      from_secret: V5_KEY
+-    AS_SPID:
+-      from_secret: V5_SPID
+-  privileged: true
+-  volumes:
+-  - name: sgx
+-    path: /dev/sgx
+-  - name: sgx_enclave
+-    path: /dev/sgx_enclave
+-  - name: sgx_provision
+-    path: /dev/sgx_provision
+-  - name: aesmd
+-    path: /var/run/aesmd/aesm.socket
+-  - name: aesmd-conf
+-    path: /etc/aesmd.conf
+-  - name: qcnl
+-    path: /etc/sgx_default_qcnl.conf
+-  commands:
+-  - echo "$(ip route | awk 'NR==1 {print $3}') pccs-server" >> /etc/hosts
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+-  - (cd release/dcap && ./teaclave_dcap_ref_as &)
+-  - cd build && make run-tests
+-
+-volumes:
+-- name: sgx
+-  host:
+-    path: /dev/sgx
+-- name: sgx_enclave
+-  host:
+-    path: /dev/sgx_enclave
+-- name: sgx_provision
+-  host:
+-    path: /dev/sgx_provision
+-- name: aesmd
+-  host:
+-    path: /var/run/aesmd/aesm.socket
+-- name: aesmd-conf
+-  host:
+-    path: /etc/aesmd.conf
+-- name: qcnl
+-  host:
+-    path: /etc/sgx_default_qcnl.conf
+-
+-node:
+-  instance: mesatee-sgx-dcap
+-
+----
+-
+-x-dcap-2004-image: &dcap-2004-image
+-  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.3
+-
+-kind: pipeline
+-name: sgx-dcap-coverage-ubuntu-2004
+-
+-steps:
+-- name: prepare
+-  <<: *dcap-2004-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - mkdir -p build
+-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_MODE=ON -DDCAP=ON -DCOV=ON ..
+-- name: check
+-  <<: *dcap-2004-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - cd build && make check
+-- name: compile
+-  <<: *dcap-2004-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - sed -i 's/ias_root_ca_cert/dcap_root_ca_cert/' config/build.config.toml
+-  - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-  commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
++  - pip3 install pyoxidizer 
++  - apt update
++  - apt install -y clang
++  - cd cleanroom-cli
+   - make
++# - name: tvm example
++#   image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++#   commands:
++#   - . ~/.cargo/env
++#   - cd examples/python/wasm_tvm_mnist_payload
++#   - make
+ - name: test
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  privileged: true
+   environment:
+-    AS_ALGO: sgx_ecdsa
+-    AS_URL: https://localhost:8080
++    AS_ALGO: sgx_epid
++    AS_URL: https://api.trustedservices.intel.com:443
+     AS_KEY:
+       from_secret: V5_KEY
+     AS_SPID:
+       from_secret: V5_SPID
+-  privileged: true
+   volumes:
+-  - name: sgx
+-    path: /dev/sgx
+-  - name: sgx_enclave
+-    path: /dev/sgx_enclave
+-  - name: sgx_provision
+-    path: /dev/sgx_provision
++  - name: isgx
++    path: /dev/isgx
+   - name: aesmd
+     path: /var/run/aesmd/aesm.socket
+-  - name: aesmd-conf
+-    path: /etc/aesmd.conf
+-  - name: qcnl
+-    path: /etc/sgx_default_qcnl.conf
+   commands:
+-  - echo "$(ip route | awk 'NR==1 {print $3}') pccs-server" >> /etc/hosts
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+-  - (cd release/dcap && ./teaclave_dcap_ref_as &)
+-  - cd build && make run-tests && make cov
++  - cd build && make run-examples
+ 
+ volumes:
+-- name: sgx
+-  host:
+-    path: /dev/sgx
+-- name: sgx_enclave
+-  host:
+-    path: /dev/sgx_enclave
+-- name: sgx_provision
++- name: isgx
+   host:
+-    path: /dev/sgx_provision
++    path: /dev/isgx
+ - name: aesmd
+   host:
+     path: /var/run/aesmd/aesm.socket
+-- name: aesmd-conf
+-  host:
+-    path: /etc/aesmd.conf
+-- name: qcnl
+-  host:
+-    path: /etc/sgx_default_qcnl.conf
++
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
+ 
+ node:
+-  instance: mesatee-sgx-dcap
+----
++  instance: mesatee-sgx
+ 
+-x-dcap-2004-image: &dcap-2004-image
+-  image: teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.3
++---
+ 
+ kind: pipeline
+-name: sgx-dcap-release-ubuntu-2004
++name: sim-debug-ubuntu-2004
+ 
+ steps:
+ - name: prepare
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
+   commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - mkdir -p build
+-  - cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTEST_MODE=OFF -DDCAP=ON ..
++  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DSGX_SIM_MODE=ON -DTEST_MODE=ON ..
+ - name: check
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: compile
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+-  - sed -i 's/ias_root_ca_cert/dcap_root_ca_cert/' config/build.config.toml
+   - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  <<: *dcap-2004-image
+-  commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
+-  - make
++- name: package-cli
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  commands:
++  - . /root/.cargo/env
++  - . /opt/sgxsdk/environment
++  - pip3 install pyoxidizer
++  - apt update
++  - apt install -y clang
++  - cd cleanroom-cli
++  - make 
++# - name: tvm example
++#   image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++#   commands:
++#   - . ~/.cargo/env
++#   - cd examples/python/wasm_tvm_mnist_payload
++#   - make
+ - name: test
+-  <<: *dcap-2004-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   environment:
+-    AS_ALGO: sgx_ecdsa
+-    AS_URL: https://localhost:8080
++    AS_ALGO: sgx_epid
++    AS_URL: https://api.trustedservices.intel.com:443
+     AS_KEY:
+       from_secret: V5_KEY
+     AS_SPID:
+       from_secret: V5_SPID
+-  privileged: true
+-  volumes:
+-  - name: sgx
+-    path: /dev/sgx
+-  - name: sgx_enclave
+-    path: /dev/sgx_enclave
+-  - name: sgx_provision
+-    path: /dev/sgx_provision
+-  - name: aesmd
+-    path: /var/run/aesmd/aesm.socket
+-  - name: aesmd-conf
+-    path: /etc/aesmd.conf
+-  - name: qcnl
+-    path: /etc/sgx_default_qcnl.conf
+   commands:
+-  - echo "$(ip route | awk 'NR==1 {print $3}') pccs-server" >> /etc/hosts
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+-  - (cd release/dcap && ./teaclave_dcap_ref_as &)
+-  - cd build && make run-examples
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
++  - cd build && make run-tests
+ 
+-volumes:
+-- name: sgx
+-  host:
+-    path: /dev/sgx
+-- name: sgx_enclave
+-  host:
+-    path: /dev/sgx_enclave
+-- name: sgx_provision
+-  host:
+-    path: /dev/sgx_provision
+-- name: aesmd
+-  host:
+-    path: /var/run/aesmd/aesm.socket
+-- name: aesmd-conf
+-  host:
+-    path: /etc/aesmd.conf
+-- name: qcnl
+-  host:
+-    path: /etc/sgx_default_qcnl.conf
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
+ 
+ node:
+-  instance: mesatee-sgx-dcap
++  instance: mesatee-sgx
+ 
+ ---
+ 
+-x-isgx-1804-image: &isgx-1804-image
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-
+ kind: pipeline
+-name: sgx-release-ubuntu-1804
++name: sim-release-ubuntu-2004
+ 
+ steps:
+ - name: prepare
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
+   commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - mkdir -p build
+-  - cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTEST_MODE=OFF ..
++  - cd build && cmake -DCMAKE_BUILD_TYPE=Release -DSGX_SIM_MODE=ON -DTEST_MODE=OFF ..
+ - name: check
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: compile
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  <<: *isgx-1804-image
++- name: package-cli
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
++  - . /root/.cargo/env
++  - . /opt/sgxsdk/environment
++  - pip3 install pyoxidizer 
++  - apt update
++  - apt install -y clang
++  - cd cleanroom-cli
+   - make
++# - name: tvm example
++#   image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++#   commands:
++#   - . ~/.cargo/env
++#   - cd examples/python/wasm_tvm_mnist_payload
++#   - make
+ - name: test
+-  <<: *isgx-1804-image
+-  privileged: true
+-  environment:
+-    AS_ALGO: sgx_epid
+-    AS_URL: https://api.trustedservices.intel.com:443
+-    AS_KEY:
+-      from_secret: V5_KEY
+-    AS_SPID:
+-      from_secret: V5_SPID
+-  volumes:
+-  - name: isgx
+-    path: /dev/isgx
+-  - name: aesmd
+-    path: /var/run/aesmd/aesm.socket
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make run-examples
+ 
+-volumes:
+-- name: isgx
+-  host:
+-    path: /dev/isgx
+-- name: aesmd
+-  host:
+-    path: /var/run/aesmd/aesm.socket
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
+ 
+ node:
+   instance: mesatee-sgx
+ 
+ ---
+ 
+-x-isgx-1804-image: &isgx-1804-image
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-
+ kind: pipeline
+-name: sim-debug-ubuntu-1804
++name: sim-debug-ubuntu-2004-test-log
+ 
+ steps:
+ - name: prepare
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
+   commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
++  - echo "127.0.0.1       teaclave-file-service" >> /etc/hosts
+   - mkdir -p build
+   - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DSGX_SIM_MODE=ON -DTEST_MODE=ON ..
+ - name: check
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: compile
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  <<: *isgx-1804-image
++- name: package-cli
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
++  - . /root/.cargo/env
++  - . /opt/sgxsdk/environment
++  - pip3 install pyoxidizer
++  - apt update
++  - apt install -y clang 
++  - cd cleanroom-cli
+   - make
++# - name: tvm example
++#   image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++#   commands:
++#   - . ~/.cargo/env
++#   - cd examples/python/wasm_tvm_mnist_payload
++#   - make
+ - name: test
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   environment:
+     AS_ALGO: sgx_epid
+     AS_URL: https://api.trustedservices.intel.com:443
+@@ -607,84 +600,59 @@ steps:
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+-  - cd build && make run-tests
+-
+-node:
+-  instance: mesatee-sgx
+-
+----
++  - cd build 
++  - export TEACLAVE_LOG=warn && make run-examples
+ 
+-x-isgx-1804-image: &isgx-1804-image
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-
+-kind: pipeline
+-name: sim-release-ubuntu-1804
+-
+-steps:
+-- name: prepare
+-  <<: *isgx-1804-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - mkdir -p build
+-  - cd build && cmake -DCMAKE_BUILD_TYPE=Release -DSGX_SIM_MODE=ON -DTEST_MODE=OFF ..
+-- name: check
+-  <<: *isgx-1804-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - cd build && make check
+-- name: compile
+-  <<: *isgx-1804-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - cd build && make VERBOSE=1 -j2
+-- name: tvm example
+-  <<: *isgx-1804-image
+-  commands:
+-  - . ~/.cargo/env
+-  - cd examples/python/wasm_tvm_mnist_payload
+-  - make
+-- name: test
+-  <<: *isgx-1804-image
+-  commands:
+-  - . /root/.cargo/env
+-  - . /opt/sgxsdk/environment
+-  - cd build && make run-examples
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
+ 
+ node:
+   instance: mesatee-sgx
+ 
+ ---
+ 
+-x-isgx-1804-image: &isgx-1804-image
+-  image: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-
+ kind: pipeline
+ name: lint
+ 
+ steps:
+ - name: prepare
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
++  environment:
++    SSH_USERNAME:
++      from_secret: SSH_USERNAME
++    SSH_PRIVATE_KEY:
++      from_secret: SSH_PRIVATE_KEY
++    SSH_SERVER_IP:
++      from_secret: SSH_SERVER_IP
+   commands:
++  - mkdir -p algorithm2_hash_sgx 
++  - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
++  - chmod 400 id_rsa
++  - scp -i id_rsa -oStrictHostKeyChecking=no $SSH_USERNAME@$SSH_SERVER_IP:/xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - mkdir -p build
+   - cd build && cmake -DRUSTFLAGS="-D warnings" -DTEST_MODE=ON ..
+ - name: check
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make check
+ - name: clippy
+-  <<: *isgx-1804-image
++  image: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.1
+   commands:
+   - . /root/.cargo/env
+   - . /opt/sgxsdk/environment
+   - cd build && make CLP=1
+ 
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
++
+ node:
+   instance: mesatee-sgx
+ 
+@@ -723,15 +691,17 @@ trigger:
+       - hourly
+ 
+ depends_on:
+-  - sgx-debug-ubuntu-1804
+-  - sgx-dcap-debug-ubuntu-1804
+   - sgx-debug-ubuntu-2004
+-  - sgx-dcap-debug-ubuntu-2004
+-  - sgx-dcap-coverage-ubuntu-2004
+-  - sgx-release-ubuntu-1804
+-  - sim-debug-ubuntu-1804
+-  - sim-release-ubuntu-1804
++  - sgx-dcap-release-ubuntu-2004
++  - sgx-release-ubuntu-2004
++  - sim-debug-ubuntu-2004
++  - sim-release-ubuntu-2004
+   - lint
+ 
++trigger:
++  ref:
++    exclude:
++    - refs/tags/cli-**
++
+ node:
+-  instance: mesatee-sgx
++  instance: mesatee-sgx
+\ No newline at end of file
+diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
+deleted file mode 100644
+index 2ca637a..0000000
+--- a/.github/workflows/ci.yml
++++ /dev/null
+@@ -1,170 +0,0 @@
+-# Licensed to the Apache Software Foundation (ASF) under one
+-# or more contributor license agreements.  See the NOTICE file
+-# distributed with this work for additional information
+-# regarding copyright ownership.  The ASF licenses this file
+-# to you under the Apache License, Version 2.0 (the
+-# "License"); you may not use this file except in compliance
+-# with the License.  You may obtain a copy of the License at
+-#
+-#   http://www.apache.org/licenses/LICENSE-2.0
+-#
+-# Unless required by applicable law or agreed to in writing,
+-# software distributed under the License is distributed on an
+-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-# KIND, either express or implied.  See the License for the
+-# specific language governing permissions and limitations
+-# under the License.
+-
+-name: CI
+-on: [push, pull_request]
+-defaults:
+-  run:
+-    shell: bash
+-
+-jobs:
+-  teaclave-client-sdk-macos:
+-    runs-on: macos-latest
+-    steps:
+-      - uses: actions/checkout@v2
+-        with:
+-          submodules: 'true'
+-      - name: Install dependencies
+-        run: |
+-          brew install cmake openssl@1.1
+-          curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
+-          export PATH=~/.cargo/bin:$PATH
+-          rustup default nightly-2020-10-25 && rustup target add aarch64-apple-ios x86_64-apple-ios
+-      - name: Building Teaclave Client SDK
+-        run: |
+-          export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig:/usr/local/opt/libssh2/lib/pkgconfig/"
+-          export PATH=~/.cargo/bin:$PATH
+-          cargo +stable install cargo-lipo
+-          cargo build --manifest-path sdk/rust/Cargo.toml
+-          cargo build --manifest-path sdk/rust/Cargo.toml --target aarch64-apple-ios
+-          cargo lipo --manifest-path sdk/rust/Cargo.toml
+-          cd sdk/swift/TeaclaveClientSDK && xcodebuild -scheme TeaclaveClientSDK
+-  sim-debug-ubuntu-1804:
+-    runs-on: ubuntu-18.04
+-    container: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-    steps:
+-      - uses: actions/checkout@v2
+-      - name: Setting up $HOME
+-        run: |
+-          cp /root/.bashrc $HOME/.bashrc &&
+-          ln -sf /root/.rustup ~/.rustup &&
+-          ln -sf /root/.cargo ~/.cargo
+-      - name: Preparing build system
+-        run: |
+-          . ~/.cargo/env &&
+-          . /opt/sgxsdk/environment &&
+-          mkdir -p build &&
+-          cd build &&
+-          cmake -DCMAKE_BUILD_TYPE=Debug -DSGX_SIM_MODE=ON -DTEST_MODE=ON ..
+-      - name: Building
+-        run: |
+-          . /opt/sgxsdk/environment &&
+-          . ~/.cargo/env &&
+-          cd build &&
+-          make VERBOSE=1
+-      - name: Build TVM example
+-        run: |
+-          . ~/.cargo/env &&
+-          cd ${GITHUB_WORKSPACE}/examples/python/wasm_tvm_mnist_payload &&
+-          make
+-      - name: Run tests and examples
+-        run: |
+-          export AS_SPID="00000000000000000000000000000000" &&
+-          export AS_KEY="00000000000000000000000000000000" &&
+-          export AS_ALGO="sgx_epid" &&
+-          export AS_URL="https://api.trustedservices.intel.com:443" &&
+-          . ~/.cargo/env &&
+-          cd build &&
+-          make run-tests
+-
+-  sim-debug-ubuntu-2004:
+-    runs-on: ubuntu-20.04
+-    container: teaclave/teaclave-build-ubuntu-2004-sgx-2.15.1:0.1.3
+-    steps:
+-      - uses: actions/checkout@v2
+-      - name: Setting up $HOME
+-        run: |
+-          cp /root/.bashrc $HOME/.bashrc &&
+-          ln -sf /root/.rustup ~/.rustup &&
+-          ln -sf /root/.cargo ~/.cargo
+-      - name: Preparing build system
+-        run: |
+-          . ~/.cargo/env &&
+-          . /opt/sgxsdk/environment &&
+-          mkdir -p build &&
+-          cd build &&
+-          cmake -DCMAKE_BUILD_TYPE=Debug -DSGX_SIM_MODE=ON -DTEST_MODE=ON ..
+-      - name: Building
+-        run: |
+-          . /opt/sgxsdk/environment &&
+-          . ~/.cargo/env &&
+-          cd build &&
+-          make VERBOSE=1
+-      - name: Build TVM example
+-        run: |
+-          . ~/.cargo/env &&
+-          cd ${GITHUB_WORKSPACE}/examples/python/wasm_tvm_mnist_payload &&
+-          make
+-      - name: Run tests and examples
+-        run: |
+-          export AS_SPID="00000000000000000000000000000000" &&
+-          export AS_KEY="00000000000000000000000000000000" &&
+-          export AS_ALGO="sgx_epid" &&
+-          export AS_URL="https://api.trustedservices.intel.com:443" &&
+-          . ~/.cargo/env &&
+-          cd build &&
+-          make run-tests
+-
+-  format:
+-    runs-on: ubuntu-18.04
+-    container: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-    steps:
+-      - uses: actions/checkout@v2
+-      - name: Setting up $HOME
+-        run: |
+-          cp /root/.bashrc $HOME/.bashrc &&
+-          ln -sf /root/.rustup ~/.rustup &&
+-          ln -sf /root/.cargo ~/.cargo
+-      - name: Preparing build system
+-        run: |
+-          . ~/.cargo/env &&
+-          . /opt/sgxsdk/environment &&
+-          mkdir -p build &&
+-          cd build &&
+-          cmake -DRUSTFLAGS="-D warnings" -DTEST_MODE=ON ..
+-      - name: Checking code format
+-        run: |
+-          . /root/.cargo/env &&
+-          cd build && make check
+-  lint:
+-    runs-on: ubuntu-18.04
+-    container: teaclave/teaclave-build-ubuntu-1804-sgx-2.14:0.1.5
+-    steps:
+-      - uses: actions/checkout@v2
+-      - name: Setting up $HOME
+-        run: |
+-          cp /root/.bashrc $HOME/.bashrc &&
+-          ln -sf /root/.rustup ~/.rustup &&
+-          ln -sf /root/.cargo ~/.cargo
+-      - name: Preparing build system
+-        run: |
+-          . ~/.cargo/env &&
+-          . /opt/sgxsdk/environment &&
+-          mkdir -p build &&
+-          cd build &&
+-          cmake -DRUSTFLAGS="-D warnings" -DTEST_MODE=ON ..
+-      - name: Code linting with Clippy
+-        run: |
+-          . /opt/sgxsdk/environment &&
+-          . /root/.cargo/env &&
+-          cd build && make CLP=1
+-  license:
+-    runs-on: ubuntu-18.04
+-    steps:
+-      - uses: actions/checkout@v2
+-      - name: Check License Header
+-        uses: apache/skywalking-eyes@main 
+diff --git a/.github/workflows/cli-packaging.yml b/.github/workflows/cli-packaging.yml
+new file mode 100644
+index 0000000..9f42d95
+--- /dev/null
++++ b/.github/workflows/cli-packaging.yml
+@@ -0,0 +1,122 @@
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++name: cli-packaging
++on:
++  push:
++    tags:
++      - 'cli-**'
++defaults:
++  run:
++    shell: bash
++
++
++jobs:
++  matrix-packaging:
++    runs-on: ${{ matrix.label }}
++    strategy:
++      matrix:
++        label: [ci-mac-x86_64, ci-linux-x64]
++    steps:
++      - uses: actions/checkout@v2
++      - name: Set env
++        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
++      - name: Test
++        run: |
++          echo $RELEASE_VERSION
++          echo $(uname) $(uname -m)
++      - name: Building Cleanroom CLI
++        run: |
++          CommitID=$(git rev-parse --short HEAD)
++          UniqID=$RELEASE_VERSION-$CommitID
++          DestBase=/xlabfs/shared/teaclave-release/tmp
++          DestDir=$DestBase/$UniqID
++          echo $DestDir
++
++          ssh node5 "mkdir -p $DestDir -m775"
++
++          cd cleanroom-cli
++          make azure > make_azure.log
++
++          os=$(uname)
++          arch=$(uname -m)
++          package_name=cleanroom-cli-$os-$arch
++
++          ls $package_name.tgz
++
++          scp $package_name.tgz node5:"$DestDir"
++
++  mac-arm64-packaging:
++    runs-on: ci-mac-arm64
++    steps:
++      - uses: actions/checkout@v2
++      - name: Set env
++        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
++      - name: Test
++        run: |
++          echo $RELEASE_VERSION
++          echo $(uname) $(uname -m)
++      - name: Building Cleanroom CLI
++        run: |
++          CommitID=$(git rev-parse --short HEAD)
++          UniqID=$RELEASE_VERSION-$CommitID
++          DestBase=/xlabfs/shared/teaclave-release/tmp
++          DestDir=$DestBase/$UniqID
++          echo $DestDir
++
++          ssh node5 "mkdir -p $DestDir -m775"
++
++          cd cleanroom-cli
++
++          arch -arm64 make azure > make_azure.log
++          package_name=cleanroom-cli-Darwin-arm64
++
++          ls $package_name.tgz
++
++          scp $package_name.tgz node5:"$DestDir"
++
++  archive-packages:
++    needs: [matrix-packaging, mac-arm64-packaging]
++    runs-on: ci-linux-x64
++    steps:
++      - uses: actions/checkout@v2
++      - name: Set ENV
++        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
++      - name: Test ENV
++        run: |
++          echo $RELEASE_VERSION
++      - name: Building Cleanroom CLI
++        run: |
++          CommitID=$(git rev-parse --short HEAD)
++          UniqID=$RELEASE_VERSION-$CommitID
++          ReleaseDir=/xlabfs/shared/teaclave-release
++          DestBase=/xlabfs/shared/teaclave-release/tmp
++          DestDir=$DestBase/$UniqID
++          echo $DestDir
++
++          cd cleanroom-cli/
++          cli_version=$(cat cleanroom-cli.py | sed -n 's/^__version__ = "\(.*\)"/\1/p')
++          echo $cli_version
++
++          echo $RELEASE_VERSION | grep -qE "$cli_version$"
++
++          echo $cli_version > version
++          cp version $DestDir
++          cp install.sh $DestDir
++
++          tar czvf cleanroom-$UniqID.tgz -C $DestBase $UniqID
++          cp cleanroom-$UniqID.tgz $ReleaseDir
+diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
+deleted file mode 100644
+index b9c5ff0..0000000
+--- a/.github/workflows/codeql-analysis.yml
++++ /dev/null
+@@ -1,62 +0,0 @@
+-# Licensed to the Apache Software Foundation (ASF) under one
+-# or more contributor license agreements.  See the NOTICE file
+-# distributed with this work for additional information
+-# regarding copyright ownership.  The ASF licenses this file
+-# to you under the Apache License, Version 2.0 (the
+-# "License"); you may not use this file except in compliance
+-# with the License.  You may obtain a copy of the License at
+-#
+-#   http://www.apache.org/licenses/LICENSE-2.0
+-#
+-# Unless required by applicable law or agreed to in writing,
+-# software distributed under the License is distributed on an
+-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-# KIND, either express or implied.  See the License for the
+-# specific language governing permissions and limitations
+-# under the License.
+-
+-name: "Code scanning"
+-
+-on:
+-  push:
+-  pull_request:
+-  schedule:
+-    - cron: '36 22 * * 3'
+-
+-jobs:
+-  analyze-cpp:
+-    name: Analyze cpp
+-    runs-on: ubuntu-latest
+-
+-    steps:
+-    - name: Checkout repository
+-      uses: actions/checkout@v2
+-      with:
+-        submodules: 'true'
+-
+-    - name: Initialize CodeQL
+-      uses: github/codeql-action/init@v1
+-      with:
+-        languages: cpp
+-
+-    - name: Build C projects
+-      run: cd examples/c && make
+-
+-    - name: Perform CodeQL Analysis
+-      uses: github/codeql-action/analyze@v1
+-
+-  analyze-python:
+-    name: Analyze python
+-    runs-on: ubuntu-latest
+-
+-    steps:
+-    - name: Checkout repository
+-      uses: actions/checkout@v2
+-
+-    - name: Initialize CodeQL
+-      uses: github/codeql-action/init@v1
+-      with:
+-        languages: python
+-
+-    - name: Perform CodeQL Analysis
+-      uses: github/codeql-action/analyze@v1
+diff --git a/.gitmodules b/.gitmodules
+index b2955f0..d861c3f 100644
+--- a/.gitmodules
++++ b/.gitmodules
+@@ -15,5 +15,6 @@
+ 	ignore = dirty
+ [submodule "third_party/wasm-micro-runtime"]
+ 	path = third_party/wasm-micro-runtime
+-	url = https://github.com/bytecodealliance/wasm-micro-runtime
++	url = https://github.com/organization/wasm-micro-runtime
++	branch = cleanroom
+ 	ignore = dirty
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index ff7b657..3d46b38 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -110,8 +110,12 @@ parse_cargo_packages(
+ if(NOT TEST_MODE)
+   list(FILTER SGX_APPS EXCLUDE REGEX "_tests$")
+   list(FILTER SGX_APP_CATEGORIES EXCLUDE REGEX "tests")
++  list(FILTER SGX_APPS EXCLUDE REGEX "_profiling$")
++  list(FILTER SGX_APP_CATEGORIES EXCLUDE REGEX "profiling")
+   list(FILTER SGX_LIBS EXCLUDE REGEX "_tests_enclave$")
+   list(FILTER SGX_LIB_CATEGORIES EXCLUDE REGEX "tests")
++  list(FILTER SGX_LIBS EXCLUDE REGEX "_profiling_enclave$")
++  list(FILTER SGX_LIB_CATEGORIES EXCLUDE REGEX "profiling")
+ endif()
+ 
+ if(NOT DCAP)
+@@ -189,6 +193,7 @@ set(WAMR_OUTPUTS
+   ${TEACLAVE_OUT_DIR}/libvmlib.a
+ )
+ 
++
+ if(USE_PREBUILT_MESAPY)
+ add_custom_command(
+   OUTPUT ${MESAPY_OUTPUTS}
+@@ -220,22 +225,27 @@ ExternalProject_Add(wamr_teaclave
+   LOG_BUILD 1
+ )
+ 
++
+ add_custom_command(
+   OUTPUT ${WAMR_OUTPUTS}
+   DEPENDS wamr_teaclave
+   COMMAND
+-    cp ${WAMR_TEACLAVE_ROOT_DIR}/build/libvmlib.a ${TEACLAVE_OUT_DIR}
++    cp ${WAMR_TEACLAVE_ROOT_DIR}/build/libvmlib.a ${TEACLAVE_OUT_DIR} &&
++    cp ${ALGORITHM2_ROOT_DIR}/libalgorithm2.a ${TEACLAVE_OUT_DIR}
+   WORKING_DIRECTORY ${WAMR_TEACLAVE_ROOT_DIR}/build
+   )
+ 
++
+ add_custom_target(mesapy
+   DEPENDS ${MESAPY_OUTPUTS}
+   )
+ 
++
+ add_custom_target(wamr
+   DEPENDS ${WAMR_TEACLAVE_ROOT_DIR}/CMakeLists.txt ${WAMR_OUTPUTS}
+   )
+ 
++
+ # mesapy components
+ add_custom_command(
+   OUTPUT ${TEACLAVE_OUT_DIR}/acs_py_enclave.c
+@@ -303,3 +313,4 @@ add_cargo_build_dylib_staticlib_target(teaclave_client_sdk
+ # ${TEACLAVE_EXAMPLE_INSTALL_DIR}/quickstart_c )
+ 
+ add_enclave_sig_target_n_hooks()
++
+diff --git a/NOTICE b/NOTICE
+index 8d84f50..22629d1 100644
+--- a/NOTICE
++++ b/NOTICE
+@@ -1,5 +1,5 @@
+ Apache Teaclave (incubating)
+-Copyright 2019-2022 The Apache Software Foundation
++Copyright 2019-2021 The Apache Software Foundation
+ 
+ This product includes software developed at
+ The Apache Software Foundation (http://www.apache.org/).
+diff --git a/README.md b/README.md
+index fe59a6f..4c0cbbf 100644
+--- a/README.md
++++ b/README.md
+@@ -55,7 +55,6 @@ platform, making computation on privacy-sensitive data safe and simple.
+ 
+ ### Contribute to Teaclave
+ 
+-- [Release Guide](docs/release-guide.md)
+ - [Rust Development Guideline](docs/rust-guideline.md)
+ - [Development Tips](docs/development-tips.md)
+ 
+diff --git a/attestation/Cargo.toml b/attestation/Cargo.toml
+index 35bc104..85e6cc2 100644
+--- a/attestation/Cargo.toml
++++ b/attestation/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_attestation"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Provides TLS-based remote attestation mechanism in Teaclave."
+ license = "Apache-2.0"
+@@ -44,7 +44,7 @@ cfg-if           = { version = "0.1.9" }
+ chrono           = { version = "0.4.6" }
+ hex              = { version = "0.4.0" }
+ httparse         = { version = "1.3.2", default-features = false }
+-log              = { version = "0.4.6", features = ["release_max_level_info"] }
++log              = { version = "0.4.6", features = ["release_max_level_debug"] }
+ num-bigint       = { version = "0.2.2" }
+ percent-encoding = { version = "2.1.0" }
+ rustls           = { version = "0.16.0", features = ["dangerous_configuration"] }
+diff --git a/binder/Cargo.toml b/binder/Cargo.toml
+index a427e2f..eb5b869 100644
+--- a/binder/Cargo.toml
++++ b/binder/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_binder"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Abstract communication interfaces between TEE untrusted/trusted worlds."
+ license = "Apache-2.0"
+@@ -39,7 +39,7 @@ app_unit_test = []
+ cfg-if     = { version = "0.1.9" }
+ anyhow       = { version = "1.0.26" }
+ env_logger   = { version = "0.7.1" }
+-log          = { version = "0.4.6", features = ["release_max_level_info"] }
++log          = { version = "0.4.6", features = ["release_max_level_debug"] }
+ serde        = { version = "1.0.92", features = ["derive"] }
+ serde_json   = { version = "1.0.39" }
+ thiserror    = { version = "1.0.9" }
+diff --git a/binder/attribute/Cargo.toml b/binder/attribute/Cargo.toml
+index a4162de..538af15 100644
+--- a/binder/attribute/Cargo.toml
++++ b/binder/attribute/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_binder_attribute"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Macros for binder"
+ license = "Apache-2.0"
+diff --git a/binder/src/proto.rs b/binder/src/proto.rs
+index b3e7fa7..aab5c5f 100644
+--- a/binder/src/proto.rs
++++ b/binder/src/proto.rs
+@@ -96,14 +96,22 @@ impl RunTestInput {
+ #[derive(Serialize, Deserialize, Debug)]
+ pub struct RunTestOutput;
+ 
+-#[derive(Default, Serialize, Deserialize, Debug)]
++#[derive(Serialize, Deserialize, Debug)]
++pub enum SubCmd {
++    Attestation,
++    BackupDb,
++}
++
++#[derive(Serialize, Deserialize, Debug)]
+ pub struct RawJsonInput {
++    pub sub_cmd: SubCmd,
+     pub json: String,
+ }
+ 
+ impl RawJsonInput {
+-    pub fn new(json: impl ToString) -> Self {
++    pub fn new(sub_cmd: SubCmd, json: impl ToString) -> Self {
+         Self {
++            sub_cmd,
+             json: json.to_string(),
+         }
+     }
+diff --git a/cli/Cargo.toml b/cli/Cargo.toml
+index ff36216..aa0bcf6 100644
+--- a/cli/Cargo.toml
++++ b/cli/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_cli"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave command line tool"
+ license = "Apache-2.0"
+diff --git a/cmake/TeaclaveGenVars.cmake b/cmake/TeaclaveGenVars.cmake
+index 347ed06..966bcba 100644
+--- a/cmake/TeaclaveGenVars.cmake
++++ b/cmake/TeaclaveGenVars.cmake
+@@ -17,6 +17,7 @@
+ 
+ set(TEACLAVE_PROJECT_ROOT ${PROJECT_SOURCE_DIR})
+ set(TEACLAVE_BUILD_ROOT ${PROJECT_BINARY_DIR})
++set(TEACLAVE_CLEANROOMCLI_ROOT ${PROJECT_SOURCE_DIR}/cleanroom-cli)
+ set(TEACLAVE_OUT_DIR ${PROJECT_BINARY_DIR}/intermediate)
+ set(TEACLAVE_INSTALL_DIR ${PROJECT_SOURCE_DIR}/release)
+ set(TEACLAVE_EDL_DIR ${PROJECT_SOURCE_DIR}/edl)
+@@ -45,6 +46,9 @@ set(TRUSTED_TARGET_DIR ${TEACLAVE_TARGET_DIR}/trusted)
+ set(WAMR_TEACLAVE_ROOT_DIR
+   ${PROJECT_SOURCE_DIR}/third_party/wasm-micro-runtime/product-mini/platforms/teaclave-sgx
+ )
++set(ALGORITHM2_ROOT_DIR
++  ${PROJECT_SOURCE_DIR}/algorithm2_hash_sgx
++)
+ # build.rs will read ENV{ENCLAVE_OUT_DIR} for linking
+ set(ENCLAVE_OUT_DIR ${TEACLAVE_OUT_DIR})
+ set(RUST_SGX_SDK ${PROJECT_SOURCE_DIR}/third_party/rust-sgx-sdk)
+@@ -123,6 +127,7 @@ set(TEACLAVE_COMMON_ENVS
+     TEACLAVE_EXAMPLE_INSTALL_DIR=${TEACLAVE_EXAMPLE_INSTALL_DIR}
+     TEACLAVE_BIN_INSTALL_DIR=${TEACLAVE_BIN_INSTALL_DIR}
+     TEACLAVE_CLI_INSTALL_DIR=${TEACLAVE_CLI_INSTALL_DIR}
++    TEACLAVE_CLEANROOMCLI_ROOT=${TEACLAVE_CLEANROOMCLI_ROOT}
+     TEACLAVE_TOOL_INSTALL_DIR=${TEACLAVE_TOOL_INSTALL_DIR}
+     TEACLAVE_DCAP_INSTALL_DIR=${TEACLAVE_DCAP_INSTALL_DIR}
+     TEACLAVE_LIB_INSTALL_DIR=${TEACLAVE_LIB_INSTALL_DIR}
+diff --git a/cmake/TeaclaveUtils.cmake b/cmake/TeaclaveUtils.cmake
+index 144a0f7..877a525 100644
+--- a/cmake/TeaclaveUtils.cmake
++++ b/cmake/TeaclaveUtils.cmake
+@@ -58,17 +58,8 @@ function(init_submodules)
+         )
+       endif()
+       # Patch WAMR after pulling
+-      if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third_party/wasm-micro-runtime/product-mini/platforms/teaclave-sgx/CMakeLists.txt")
+-        execute_process(
+-          COMMAND 
+-            patch -N -p1
+-          INPUT_FILE "../wamr.patch"
+-          WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/wasm-micro-runtime
+-          )
+-      endif()
+     endif()
+   endif()
+-
+   if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third_party/crates-io"
+      OR NOT EXISTS "${PROJECT_SOURCE_DIR}/third_party/crates-sgx"
+      OR NOT EXISTS "${PROJECT_SOURCE_DIR}/third_party/mesapy"
+diff --git a/cmake/UtilTargets.cmake b/cmake/UtilTargets.cmake
+index 5c6cf1c..d707b95 100644
+--- a/cmake/UtilTargets.cmake
++++ b/cmake/UtilTargets.cmake
+@@ -74,8 +74,12 @@ if(TEST_MODE)
+     run-sdk-tests COMMAND ${TEACLAVE_COMMON_ENVS}
+                           ${MT_SCRIPT_DIR}/test.sh sdk)
+   add_custom_target(
+-    run-cancel-test COMMAND ${TEACLAVE_COMMON_ENVS}
++    run-cancel-tests COMMAND ${TEACLAVE_COMMON_ENVS}
+                           ${MT_SCRIPT_DIR}/test.sh cancel)
++
++  add_custom_target(
++    run-cleanroomcli-tests COMMAND ${TEACLAVE_COMMON_ENVS}
++                          ${MT_SCRIPT_DIR}/test.sh cleanroomcli)
+ else()
+   add_custom_target(
+     run-tests
+diff --git a/cmake/scripts/parse_cargo_packages.py b/cmake/scripts/parse_cargo_packages.py
+index 457b9c7..3412191 100644
+--- a/cmake/scripts/parse_cargo_packages.py
++++ b/cmake/scripts/parse_cargo_packages.py
+@@ -95,6 +95,7 @@ def pkg_path_2_category(pkg_path):
+ DEFAULT_EDL_LIB = "Enclave_common_t"
+ PKG_NAME_TO_EDL_LIB = {
+     "teaclave_unit_tests_enclave": "Enclave_fa_t",
++    "teaclave_profiling_enclave": "Enclave_fa_t",
+     "teaclave_execution_service_enclave": "Enclave_fa_t",
+ }
+ 
+diff --git a/cmake/scripts/prep.sh b/cmake/scripts/prep.sh
+index dc87812..6fa4b21 100755
+--- a/cmake/scripts/prep.sh
++++ b/cmake/scripts/prep.sh
+@@ -26,7 +26,7 @@ REQUIRED_ENVS=("CMAKE_SOURCE_DIR" "CMAKE_BINARY_DIR"
+ "TEACLAVE_CLI_INSTALL_DIR" "TEACLAVE_TOOL_INSTALL_DIR" "TEACLAVE_DCAP_INSTALL_DIR"
+ "TEACLAVE_LIB_INSTALL_DIR" "TEACLAVE_TEST_INSTALL_DIR"
+ "TEACLAVE_AUDITORS_DIR" "TEACLAVE_EXAMPLE_AUDITORS_DIR" "DCAP" "TEACLAVE_SYMLINKS"
+-"TEACLAVE_PROJECT_ROOT"
++"TEACLAVE_PROJECT_ROOT" "TEACLAVE_CLEANROOMCLI_ROOT"
+ )
+ 
+ for var in "${REQUIRED_ENVS[@]}"; do
+diff --git a/cmake/scripts/sgx_link_sign.sh b/cmake/scripts/sgx_link_sign.sh
+index b2e4de7..dd9a44e 100755
+--- a/cmake/scripts/sgx_link_sign.sh
++++ b/cmake/scripts/sgx_link_sign.sh
+@@ -46,7 +46,7 @@ fi
+ 
+ TEACLAVE_LINK_FLAGS="-L${TEACLAVE_OUT_DIR} -lpycomponent ffi.o -lpypy-c -lsgx_tlibc_ext -lffi"
+ if [ "$TEACLAVE_EXECUTOR_WAMR" == "ON" ]; then
+-    TEACLAVE_LINK_FLAGS+=" -lvmlib"
++    TEACLAVE_LINK_FLAGS+=" -lvmlib -lalgorithm2"
+ fi
+ 
+ # Enable the security flags
+diff --git a/cmake/scripts/test.sh b/cmake/scripts/test.sh
+index a8a5747..1f79e61 100755
+--- a/cmake/scripts/test.sh
++++ b/cmake/scripts/test.sh
+@@ -18,7 +18,6 @@
+ # under the License.
+ 
+ set -eE
+-export TEACLAVE_LOG=teaclave=info
+ 
+ if [ -z "${TEACLAVE_PROJECT_ROOT}" ] \
+ || [ -z "${SGX_SDK}" ] || [ -z "${SGX_MODE}" ]; then
+@@ -69,7 +68,7 @@ cleanup() {
+ wait_port() {
+   for port in "$@"
+   do
+-    timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' localhost "$port"
++    timeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' localhost "$port"
+   done
+ }
+ 
+@@ -227,16 +226,17 @@ run_examples() {
+ 
+   # Run tests of execution service separately
+   ./teaclave_execution_service &
+-  sleep 3    # wait for execution services
++  sleep 6    # wait for execution services
+   popd
+ 
+   # Generate WASM file for WAMR Rust example
+-  pushd ${TEACLAVE_PROJECT_ROOT}/examples/python/wasm_rust_psi_payload
+-  make
+-  popd
++  # pushd ${TEACLAVE_PROJECT_ROOT}/examples/python/wasm_rust_psi_payload
++  # make
++  # popd
+ 
+   pushd ${TEACLAVE_PROJECT_ROOT}/examples/python
+   export PYTHONPATH=${TEACLAVE_PROJECT_ROOT}/sdk/python
++  python3 test_default_arguments.py
+   python3 builtin_echo.py
+   python3 mesapy_echo.py
+   python3 mesapy_logistic_reg.py
+@@ -248,24 +248,29 @@ run_examples() {
+   python3 builtin_rsa_sign.py
+   python3 builtin_face_detection.py
+   python3 builtin_password_check.py
+-  python3 wasm_c_simple_add.py
+-  python3 wasm_rust_psi.py
+-  python3 wasm_tvm_mnist.py
++  python3 cleanroom_algorithm1.py
++  python3 cleanroom_stderr.py
++  python3 builtin_cleanroom_algorithm2.py
++  # python3 cleanroom_algorithm1_repeat.py 
++  # python3 cleanroom_algorithm2.py
++  # python3 wasm_c_simple_add.py
++  # python3 wasm_rust_psi.py
++  # python3 wasm_tvm_mnist.py
+   python3 test_disable_function.py
+   popd
+ 
+-  pushd ${TEACLAVE_PROJECT_ROOT}/examples/c
+-  make run
+-  popd
+-
+-  pushd ${TEACLAVE_PROJECT_ROOT}/examples/rust
+-  pushd ./builtin_echo
+-  RUSTFLAGS=${RUSTFLAGS} cargo run
+-  popd
+-  pushd ./builtin_ordered_set_intersect
+-  RUSTFLAGS=${RUSTFLAGS} cargo run
+-  popd
+-  popd
++  # pushd ${TEACLAVE_PROJECT_ROOT}/examples/c
++  # make run
++  # popd
++
++  # pushd ${TEACLAVE_PROJECT_ROOT}/examples/rust
++  # pushd ./builtin_echo
++  # RUSTFLAGS=${RUSTFLAGS} cargo run
++  # popd
++  # pushd ./builtin_ordered_set_intersect
++  # RUSTFLAGS=${RUSTFLAGS} cargo run
++  # popd
++  # popd
+   
+   # kill all background services
+   cleanup
+@@ -301,7 +306,7 @@ run_cancel_test() {
+   # Run of execution services separately
+   ./teaclave_execution_service & exe_pid1=$!
+   ./teaclave_execution_service & exe_pid2=$!
+-  sleep 10    # wait for execution services
++  sleep 25    # wait for execution services
+   popd
+ 
+   echo "executor 1 pid: $exe_pid1"
+@@ -312,7 +317,7 @@ run_cancel_test() {
+   python3 mesapy_deadloop_cancel.py
+   popd
+ 
+-  sleep 10 # Wait for executor exit
++  sleep 15 # Wait for executor exit
+ 
+   live_pids=0
+   if ps -p $exe_pid1 > /dev/null
+@@ -325,6 +330,7 @@ run_cancel_test() {
+     live_pids=$((live_pids+1))
+   fi
+ 
++  echo "Current Executor: ${live_pids}"
+   if [ $live_pids -eq 1 ]
+   then
+     echo "only one executor is killed, test passed"
+@@ -336,6 +342,46 @@ run_cancel_test() {
+   cleanup
+ }
+ 
++run_cleanroomcli_tests() {
++  trap cleanup INT TERM ERR
++
++  echo_title "cleanroom cli"
++  mkdir -p /tmp/fusion_data
++  pushd ${TEACLAVE_CLI_INSTALL_DIR}
++  ./teaclave_cli verify \
++                 --enclave-info ../examples/enclave_info.toml \
++                 --public-keys $(find ../examples -name "*.public.pem") \
++                 --signatures $(find ../examples -name "*.sign.sha256")
++  popd
++
++  echo "initiating Teaclave..."
++
++  pushd ${TEACLAVE_SERVICE_INSTALL_DIR}
++  ./teaclave_authentication_service &
++  ./teaclave_storage_service &
++  wait_port 7776 17776 17778 # wait for authentication and storage service
++  ./teaclave_management_service &
++  ./teaclave_scheduler_service &
++  wait_port 17777 17780 # wait for management service and scheduler_service
++  ./teaclave_access_control_service &
++  ./teaclave_frontend_service &
++  wait_port 17779 7777 # wait for other services
++
++  start_storage_server
++
++  # Run of execution services separately
++  ./teaclave_execution_service & exe_pid1=$!
++  sleep 25    # wait for execution services
++  popd
++
++  pushd ${TEACLAVE_CLEANROOMCLI_ROOT}
++  ./run_test.sh
++  popd
++
++  # kill all background services
++  cleanup
++}
++
+ case "$1" in
+     "unit")
+         run_unit_tests
+@@ -355,6 +401,9 @@ case "$1" in
+     "cancel")
+         run_cancel_test
+         ;;
++    "cleanroomcli")
++        run_cleanroomcli_tests
++        ;;
+     *)
+         run_unit_tests
+         run_integration_tests
+@@ -362,5 +411,6 @@ case "$1" in
+         run_sdk_tests
+         run_examples
+         run_cancel_test
++        run_cleanroomcli_tests
+         ;;
+ esac
+diff --git a/cmake/tomls/Cargo.sgx_trusted_lib.toml b/cmake/tomls/Cargo.sgx_trusted_lib.toml
+index 687b4ca..4b2681e 100644
+--- a/cmake/tomls/Cargo.sgx_trusted_lib.toml
++++ b/cmake/tomls/Cargo.sgx_trusted_lib.toml
+@@ -26,6 +26,7 @@ members = [
+   "services/management/enclave",
+   "services/scheduler/enclave",
+   "tests/unit/enclave",
++  "tests/profiling/enclave",
+   "tests/functional/enclave",
+   "tests/integration/enclave",
+   "tool/enclave",
+@@ -90,6 +91,7 @@ sct               = { git = "https://github.com/mesalock-linux/sct.rs", branch =
+ serde             = { git = "https://github.com/mesalock-linux/serde-sgx" }
+ serde_derive      = { git = "https://github.com/mesalock-linux/serde-sgx" }
+ serde_json        = { git = "https://github.com/mesalock-linux/serde-json-sgx" }
++bincode           = { git = "https://github.com/mesalock-linux/bincode-sgx"}
+ threadpool        = { git = "https://github.com/mesalock-linux/rust-threadpool-sgx" }
+ # tiff              = { git = "https://github.com/mesalock-linux/image-tiff-sgx" }
+ toml              = { git = "https://github.com/mesalock-linux/toml-rs-sgx" }
+@@ -99,3 +101,6 @@ uuid              = { git = "https://github.com/mesalock-linux/uuid-sgx" }
+ webpki            = { git = "https://github.com/mesalock-linux/webpki", branch = "mesalock_sgx" }
+ webpki-roots      = { git = "https://github.com/mesalock-linux/webpki-roots", branch = "mesalock_sgx" }
+ yasna             = { git = "https://github.com/mesalock-linux/yasna.rs-sgx" }
++
++[profile.release]
++lto = true
+diff --git a/cmake/tomls/Cargo.sgx_untrusted_app.toml b/cmake/tomls/Cargo.sgx_untrusted_app.toml
+index 2fa8058..bb8c7e3 100644
+--- a/cmake/tomls/Cargo.sgx_untrusted_app.toml
++++ b/cmake/tomls/Cargo.sgx_untrusted_app.toml
+@@ -26,6 +26,7 @@ members = [
+   "services/management/app",
+   "services/scheduler/app",
+   "tests/unit/app",
++  "tests/profiling/app",
+   "tests/functional/app",
+   "tests/integration/app",
+   "tool/app",
+@@ -40,3 +41,6 @@ sgx_urts = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.3"
+ sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.3" }
+ sgx_tstd = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.3" }
+ sgx_trts = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.3" }
++
++[profile.release]
++lto = true
+diff --git a/cmake/tomls/Cargo.unix_app.toml b/cmake/tomls/Cargo.unix_app.toml
+index 718170f..f239c32 100644
+--- a/cmake/tomls/Cargo.unix_app.toml
++++ b/cmake/tomls/Cargo.unix_app.toml
+@@ -34,3 +34,6 @@ exclude = [
+ # sgx_urts = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.3" }
+ sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.3" }
+ sgx_ucrypto = { git = "https://github.com/apache/teaclave-sgx-sdk", rev = "v1.1.3" }
++
++[profile.release]
++lto = true
+diff --git a/common/protected_fs_rs/Cargo.lock b/common/protected_fs_rs/Cargo.lock
+index 84dab3f..b0601a3 100644
+--- a/common/protected_fs_rs/Cargo.lock
++++ b/common/protected_fs_rs/Cargo.lock
+@@ -25,7 +25,7 @@ checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
+ 
+ [[package]]
+ name = "protected_fs_rs"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "cfg-if",
+  "libc",
+diff --git a/common/protected_fs_rs/Cargo.toml b/common/protected_fs_rs/Cargo.toml
+index 8370ae4..ab877b8 100644
+--- a/common/protected_fs_rs/Cargo.toml
++++ b/common/protected_fs_rs/Cargo.toml
+@@ -1,6 +1,6 @@
+ [package]
+ name = "protected_fs_rs"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Ported sgx_protected_fs (Intel SGX SDK) running out side sgx with Rust bindings."
+ license-file = "Apache-2.0"
+diff --git a/common/rusty_leveldb_sgx/Cargo.toml b/common/rusty_leveldb_sgx/Cargo.toml
+index 2c09ebf..5173df2 100644
+--- a/common/rusty_leveldb_sgx/Cargo.toml
++++ b/common/rusty_leveldb_sgx/Cargo.toml
+@@ -24,6 +24,7 @@ integer-encoding = { version = "1.0" }
+ 
+ protected_fs_rs = { path = "../protected_fs_rs", optional = true }
+ teaclave_test_utils = { path = "../../tests/utils", optional = true }
++log         = { version = "0.4.6", features = ["release_max_level_debug"] }
+ 
+ sgx_tstd 	= { version = "1.1.3", optional = true }
+ sgx_trts 	= { version = "1.1.3", optional = true }
+diff --git a/common/rusty_leveldb_sgx/src/db_impl.rs b/common/rusty_leveldb_sgx/src/db_impl.rs
+index 04cb757..56b6a7f 100644
+--- a/common/rusty_leveldb_sgx/src/db_impl.rs
++++ b/common/rusty_leveldb_sgx/src/db_impl.rs
+@@ -136,7 +136,9 @@ impl DB {
+             db.vset.borrow_mut().log_and_apply(ve)?;
+         }
+ 
++        log::warn!("delete_obsolete_files at open");
+         db.delete_obsolete_files()?;
++
+         db.maybe_do_compaction()?;
+         Ok(db)
+     }
+@@ -187,8 +189,8 @@ impl DB {
+         // Recover from all log files not in the descriptor.
+         let mut max_seq = 0;
+         let filenames = self.opt.env.children(&self.path)?;
+-        let mut expected = self.vset.borrow().live_files();
+         let mut log_files = vec![];
++        let mut expected = self.vset.borrow().live_files();
+ 
+         for file in &filenames {
+             if let Ok((num, typ)) = parse_file_name(&file) {
+@@ -201,12 +203,15 @@ impl DB {
+             }
+         }
+         if !expected.is_empty() {
+-            log!(self.opt.log, "Missing at least these files: {:?}", expected);
++            //log!(self.opt.log, "Missing at least these files: {:?}", expected);
++            //return err(StatusCode::Corruption, "missing live files (see log)");
++            log::error!("Missing at least these files: {:?}", expected);
+             return err(StatusCode::Corruption, "missing live files (see log)");
+         }
+ 
+         log_files.sort();
+         for i in 0..log_files.len() {
++            log::info!("Recover log_file: {:?}", log_files[i]);
+             let (save_manifest_, max_seq_) =
+                 self.recover_log_file(log_files[i], i == log_files.len() - 1, ve)?;
+             if save_manifest_ {
+@@ -337,7 +342,8 @@ impl DB {
+                 if typ == FileType::Table {
+                     let _ = self.cache.borrow_mut().evict(num);
+                 }
+-                log!(self.opt.log, "Deleting file type={:?} num={}", typ, num);
++                //log!(self.opt.log, "Deleting file type={:?} num={}", typ, num);
++                log::warn!("Deleting file type={:?} num={}", typ, num);
+                 if let Err(e) = self.opt.env.delete(&self.path.join(&name)) {
+                     log!(self.opt.log, "Deleting file num={} failed: {}", num, e);
+                 }
+diff --git a/common/rusty_leveldb_sgx/src/lib.rs b/common/rusty_leveldb_sgx/src/lib.rs
+index a5727b6..40aa59c 100644
+--- a/common/rusty_leveldb_sgx/src/lib.rs
++++ b/common/rusty_leveldb_sgx/src/lib.rs
+@@ -86,6 +86,79 @@ pub use crate::write_batch::WriteBatch;
+ pub use db_impl::DB;
+ pub use disk_env::PosixDiskEnv;
+ 
++use std::collections::VecDeque;
++use std::path::Path;
++use std::vec::Vec;
++
++use table_cache::TableCache;
++pub struct DBReader {
++    nums: Vec<types::FileNum>,
++    tc: TableCache,
++}
++
++impl DBReader {
++    pub fn new(db_name: impl AsRef<Path>, opt: Options) -> Result<Self> {
++        let filenames = opt.env.children(db_name.as_ref())?;
++        let tc = TableCache::new(db_name.as_ref(), opt, 1024);
++        let mut nums = vec![];
++        for name in filenames {
++            if let Ok((num, typ)) = types::parse_file_name(&name) {
++                match typ {
++                    types::FileType::Table => nums.push(num),
++                    _ => {}
++                }
++            }
++        }
++        Ok(DBReader { nums, tc })
++    }
++}
++
++pub struct DBReaderIntoIterator {
++    tables: VecDeque<table_reader::Table>,
++    table_iter: Option<table_reader::TableIterator>,
++}
++
++impl IntoIterator for DBReader {
++    type Item = (Vec<u8>, Vec<u8>);
++    type IntoIter = DBReaderIntoIterator;
++
++    fn into_iter(mut self) -> Self::IntoIter {
++        let mut tables: VecDeque<_> = self
++            .nums
++            .clone()
++            .into_iter()
++            .map(|num| self.tc.get_table(num).unwrap())
++            .collect();
++
++        let opt_table = tables.pop_front();
++        DBReaderIntoIterator {
++            tables,
++            table_iter: opt_table.map(|table| table.iter()),
++        }
++    }
++}
++
++impl Iterator for DBReaderIntoIterator {
++    type Item = (Vec<u8>, Vec<u8>);
++
++    fn next(&mut self) -> Option<Self::Item> {
++        if self.table_iter.is_none() {
++            return None;
++        }
++
++        let iter = self.table_iter.as_mut().unwrap();
++        if iter.advance() {
++            let (mut k, mut v) = (vec![], vec![]);
++            iter.current(&mut k, &mut v);
++            Some((k, v))
++        } else {
++            let opt_table = self.tables.pop_front();
++            self.table_iter = opt_table.map(|table| table.iter());
++            self.next()
++        }
++    }
++}
++
+ #[cfg(feature = "enclave_unit_test")]
+ pub mod tests {
+     use super::*;
+diff --git a/common/rusty_leveldb_sgx/src/version_set.rs b/common/rusty_leveldb_sgx/src/version_set.rs
+index 3718976..58cd5ef 100644
+--- a/common/rusty_leveldb_sgx/src/version_set.rs
++++ b/common/rusty_leveldb_sgx/src/version_set.rs
+@@ -647,8 +647,7 @@ impl VersionSet {
+         self.finalize(&mut v);
+         self.add_version(v);
+         self.manifest_num = self.next_file_num - 1;
+-        log!(
+-            self.opt.log,
++        log::info!(
+             "Recovered manifest with next_file={} manifest_num={} log_num={} prev_log_num={} \
+              last_seq={}",
+             self.next_file_num,
+diff --git a/config/Cargo.toml b/config/Cargo.toml
+index b4b29dc..8385d88 100644
+--- a/config/Cargo.toml
++++ b/config/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_config"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Build and runtime configurations."
+ license = "Apache-2.0"
+@@ -30,7 +30,7 @@ build_config = []
+ 
+ [dependencies]
+ anyhow = { version = "1.0.26" }
+-log    = { version = "0.4.6", features = ["release_max_level_info"] }
++log    = { version = "0.4.6", features = ["release_max_level_debug"] }
+ serde  = { version = "1.0.92", features = ["derive"] }
+ toml   = { version = "0.5.1" }
+ url    = { version = "2.1.1" }
+diff --git a/config/config_gen/Cargo.lock b/config/config_gen/Cargo.lock
+index 23b17a0..0e22458 100644
+--- a/config/config_gen/Cargo.lock
++++ b/config/config_gen/Cargo.lock
+@@ -329,7 +329,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_config_gen"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "askama",
+  "pem",
+diff --git a/config/config_gen/Cargo.toml b/config/config_gen/Cargo.toml
+index 31e203c..5835865 100644
+--- a/config/config_gen/Cargo.toml
++++ b/config/config_gen/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_config_gen"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Generating build config."
+ license = "Apache-2.0"
+diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml
+index f1f1224..dd507f9 100644
+--- a/crypto/Cargo.toml
++++ b/crypto/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_crypto"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave crypto"
+ license = "Apache-2.0"
+diff --git a/dcap/Cargo.toml b/dcap/Cargo.toml
+index 8b3012c..4affa2e 100644
+--- a/dcap/Cargo.toml
++++ b/dcap/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_dcap_ref_as"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave DCAP Attestation Service (Reference Implementation)"
+ license = "Apache-2.0"
+diff --git a/dcap_deployment/backup_db.sh b/dcap_deployment/backup_db.sh
+new file mode 100755
+index 0000000..4b53025
+--- /dev/null
++++ b/dcap_deployment/backup_db.sh
+@@ -0,0 +1,56 @@
++#!/bin/bash
++set -e
++
++orig_bak=/data/backup/database_$(date +"%Y_%m_%d_%I_%M_%p").tgz
++
++# back and tar original db
++tar czvf $orig_bak /cleanroom-demo-data/database
++
++BASE="$HOME/backup_db/"
++cd $BASE/release/tool
++
++# two working directories
++#  - tool/existing/
++#  - tool/converted/
++
++# ensure clean working dir
++rm -rf ./existing
++mkdir ./existing
++
++# create existing
++tar xzvf $orig_bak -C ./existing
++
++# convert existing to ./converted in docker
++
++DOCKER="teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1"
++LOCAL_AESM="/var/run/aesmd/aesm.socket"
++DOCKER_AESM="/var/run/aesmd/aesm.socket"
++
++BuildScript=$(cat << 'EOF'
++  . /opt/sgxsdk/environment;
++  cd /teaclave/release/tool
++  rm -rf ./converted
++  mkdir ./converted
++  cd ./existing
++  for db in ./cleanroom-demo-data/database/*_db; do
++      existing_db=$(realpath $db)
++      mkdir -p "../converted/$db"
++      new_db=$(realpath ../converted/$db)
++      echo "convert $existing_db to $new_db"
++
++      key="00010203040506070f0e0d0c0b0a0908"
++
++      pushd /teaclave/release/tool
++      ./teaclave_sgx_tool backup $existing_db $new_db --key $key
++      popd
++  done
++EOF
++)
++
++docker run --device /dev/sgx/enclave:/dev/sgx/enclave --device /dev/sgx/provision:/dev/sgx/provision -v ${LOCAL_AESM}:${DOCKER_AESM} -v `pwd`:/teaclave/release/tool $DOCKER /bin/bash -c "$BuildScript"
++
++# tar converted db into the same dir as $orig_bak
++cd ./converted
++tar czvf $orig_bak.converted .
++
++
+diff --git a/dcap_deployment/dcap_release_build.sh b/dcap_deployment/dcap_release_build.sh
+new file mode 100755
+index 0000000..0c32b4f
+--- /dev/null
++++ b/dcap_deployment/dcap_release_build.sh
+@@ -0,0 +1,28 @@
++#!/bin/bash
++set -e
++
++BASE=$HOME/dcap-release
++cd $BASE
++
++git clone git@github.com:organization/incubator-teaclave.git
++cd incubator-teaclave
++
++sed -i 's/https:\/\/github.com\/organization/git@github.com:organization/' .gitmodules
++sed -i 's/ias_root_ca_cert/dcap_root_ca_cert/' config/build.config.toml
++
++mkdir algorithm2_hash_sgx
++cp /xlabfs/ci/cleanroom-workload-devkit-ci-bot/libalgorithm2.a algorithm2_hash_sgx
++
++git submodule update --recursive --init
++mkdir build
++
++BuildScript=$(cat <<-END
++  . /root/.cargo/env;
++  . /opt/sgxsdk/environment;
++  cd /teaclave/build;
++  cmake -DCMAKE_BUILD_TYPE=Release -DTEST_MODE=OFF -DDCAP=ON ..  &&
++  make -j4
++END
++)
++docker run -v `pwd`:/teaclave "teaclave/teaclave-build-ubuntu-2004-sgx-dcap-1.12.1:0.1.1" /bin/bash -c "$BuildScript"
++
+diff --git a/dcap_deployment/docker/README.md b/dcap_deployment/docker/README.md
+new file mode 100644
+index 0000000..139a8c7
+--- /dev/null
++++ b/dcap_deployment/docker/README.md
+@@ -0,0 +1,77 @@
++# Teaclave Docker Internal DCAP Deployment
++
++## Check configuration file
++Make sure the PCCS\_URL is set correctly, and `USE_SECURE_CERT=FALSE`.
++
++```
++❯ cat /etc/sgx_default_qcnl.conf
++# PCCS server address
++PCCS_URL=https://pccs-server:8081/sgx/certification/v3/
++
++# To accept insecure HTTPS certificate, set this option to FALSE
++USE_SECURE_CERT=FALSE
++```
++
++## Check aesmd
++```
++sudo service aesmd status
++● aesmd.service - Intel(R) Architectural Enclave Service Manager
++     Loaded: loaded (/lib/systemd/system/aesmd.service; enabled; vendor preset: enabled)
++     Active: active (running) since Wed 2021-12-15 22:19:20 PST; 1h 48min ago
++    Process: 25632 ExecStartPre=/opt/intel/sgx-aesm-service/aesm/linksgx.sh (code=exited, status=0/SUCCESS)
++    Process: 25639 ExecStartPre=/bin/mkdir -p /var/run/aesmd/ (code=exited, status=0/SUCCESS)
++    Process: 25640 ExecStartPre=/bin/chown -R aesmd:aesmd /var/run/aesmd/ (code=exited, status=0/SUCCESS)
++    Process: 25641 ExecStartPre=/bin/chmod 0755 /var/run/aesmd/ (code=exited, status=0/SUCCESS)
++    Process: 25642 ExecStartPre=/bin/chown -R aesmd:aesmd /var/opt/aesmd/ (code=exited, status=0/SUCCESS)
++    Process: 25643 ExecStartPre=/bin/chmod 0750 /var/opt/aesmd/ (code=exited, status=0/SUCCESS)
++    Process: 25644 ExecStart=/opt/intel/sgx-aesm-service/aesm/aesm_service (code=exited, status=0/SUCCESS)
++   Main PID: 25645 (aesm_service)
++      Tasks: 4 (limit: 76883)
++     Memory: 3.6M
++     CGroup: /system.slice/aesmd.service
++             └─25645 /opt/intel/sgx-aesm-service/aesm/aesm_service
++
++Dec 15 22:19:20 xlab-sgx4 systemd[1]: Starting Intel(R) Architectural Enclave Service Manager...
++Dec 15 22:19:20 xlab-sgx4 systemd[1]: Started Intel(R) Architectural Enclave Service Manager.
++Dec 15 22:19:20 xlab-sgx4 aesm_service[25645]: The server sock is 0x556bdd36bad0
++```
++
++## Check pccs
++```
++sudo service pccs status
++● pccs.service - Provisioning Certificate Caching Service (PCCS)
++     Loaded: loaded (/lib/systemd/system/pccs.service; enabled; vendor preset: enabled)
++     Active: active (running) since Wed 2021-12-15 22:19:15 PST; 1h 49min ago
++       Docs: https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/master/QuoteGeneration/pccs/README.md
++   Main PID: 25609 (node)
++      Tasks: 11 (limit: 76883)
++     Memory: 64.0M
++     CGroup: /system.slice/pccs.service
++             └─25609 /usr/bin/node -r esm /opt/intel/sgx-dcap-pccs/pccs_server.js
++```
++
++Test pccs with the following command:
++```
++curl -v -k -G "https://127.0.0.1:8081/sgx/certification/v3/rootcacrl"
++```
++
++## Launch teaclave\_dcap\_ref\_as on host
++```
++cd release/dcap/
++./teaclave_dcap_ref_as
++```
++
++## Launch service dockers
++
++```
++$ ./run-teaclave-services.sh
++Starting teaclave-file-service           ... done
++Starting teaclave-authentication-service ... done
++Starting teaclave-access-control-service ... done
++Starting teaclave-scheduler-service      ... done
++Starting teaclave-management-service     ... done
++Starting teaclave-execution-service      ... done
++Starting teaclave-frontend-service       ... done
++Attaching to ...
++```
++
+diff --git a/dcap_deployment/docker/deploy_compose_build.sh b/dcap_deployment/docker/deploy_compose_build.sh
+new file mode 100755
+index 0000000..acd7146
+--- /dev/null
++++ b/dcap_deployment/docker/deploy_compose_build.sh
+@@ -0,0 +1,4 @@
++#!/bin/bash
++set -e
++
++docker-compose -f docker-compose-ubuntu-2004.yml -f docker-compose-dcap-dev.override.yml -f docker-compose-aesm-socket.override.yml build
+diff --git a/dcap_deployment/docker/deploy_compose_run.sh b/dcap_deployment/docker/deploy_compose_run.sh
+new file mode 100755
+index 0000000..ef66479
+--- /dev/null
++++ b/dcap_deployment/docker/deploy_compose_run.sh
+@@ -0,0 +1,5 @@
++#!/bin/bash
++set -e
++
++source run.env
++docker-compose -f docker-compose-ubuntu-2004.yml -f docker-compose-dcap-dev.override.yml -f docker-compose-aesm-socket.override.yml up
+diff --git a/dcap_deployment/docker/docker-compose-aesm-socket.override.yml b/dcap_deployment/docker/docker-compose-aesm-socket.override.yml
+new file mode 100644
+index 0000000..20a7ab6
+--- /dev/null
++++ b/dcap_deployment/docker/docker-compose-aesm-socket.override.yml
+@@ -0,0 +1,61 @@
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++version: '3.7'
++
++services:
++  teaclave-authentication-service:
++    volumes:
++      - type: bind
++        source: /var/run/aesmd/aesm.socket
++        target: /var/run/aesmd/aesm.socket
++
++  teaclave-frontend-service:
++    volumes:
++      - type: bind
++        source: /var/run/aesmd/aesm.socket
++        target: /var/run/aesmd/aesm.socket
++
++  teaclave-management-service:
++    volumes:
++      - type: bind
++        source: /var/run/aesmd/aesm.socket
++        target: /var/run/aesmd/aesm.socket
++
++  teaclave-storage-service:
++    volumes:
++      - type: bind
++        source: /var/run/aesmd/aesm.socket
++        target: /var/run/aesmd/aesm.socket
++
++  teaclave-access-control-service:
++    volumes:
++      - type: bind
++        source: /var/run/aesmd/aesm.socket
++        target: /var/run/aesmd/aesm.socket
++
++  teaclave-execution-service:
++    volumes:
++      - type: bind
++        source: /var/run/aesmd/aesm.socket
++        target: /var/run/aesmd/aesm.socket
++
++  teaclave-scheduler-service:
++    volumes:
++      - type: bind
++        source: /var/run/aesmd/aesm.socket
++        target: /var/run/aesmd/aesm.socket
+diff --git a/dcap_deployment/docker/docker-compose-aesm-vol.override.yml b/dcap_deployment/docker/docker-compose-aesm-vol.override.yml
+new file mode 100644
+index 0000000..49459a0
+--- /dev/null
++++ b/dcap_deployment/docker/docker-compose-aesm-vol.override.yml
+@@ -0,0 +1,51 @@
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++version: '3.7'
++
++volumes:
++  aesmd-socket:
++    external: true
++
++services:
++  teaclave-authentication-service:
++    volumes:
++      - aesmd-socket:/var/run/aesmd
++
++  teaclave-frontend-service:
++    volumes:
++      - aesmd-socket:/var/run/aesmd
++
++  teaclave-management-service:
++    volumes:
++      - aesmd-socket:/var/run/aesmd
++
++  teaclave-storage-service:
++    volumes:
++      - aesmd-socket:/var/run/aesmd
++
++  teaclave-access-control-service:
++    volumes:
++      - aesmd-socket:/var/run/aesmd
++
++  teaclave-execution-service:
++    volumes:
++      - aesmd-socket:/var/run/aesmd
++
++  teaclave-scheduler-service:
++    volumes:
++      - aesmd-socket:/var/run/aesmd
+diff --git a/dcap_deployment/docker/docker-compose-dcap-dev.override.yml b/dcap_deployment/docker/docker-compose-dcap-dev.override.yml
+new file mode 100644
+index 0000000..efb0215
+--- /dev/null
++++ b/dcap_deployment/docker/docker-compose-dcap-dev.override.yml
+@@ -0,0 +1,54 @@
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++version: '3.7'
++
++services:
++  teaclave-authentication-service:
++    devices:
++      - /dev/sgx/enclave
++      - /dev/sgx/provision
++
++  teaclave-frontend-service:
++    devices:
++      - /dev/sgx/enclave
++      - /dev/sgx/provision
++
++  teaclave-management-service:
++    devices:
++      - /dev/sgx/enclave
++      - /dev/sgx/provision
++
++  teaclave-storage-service:
++    devices:
++      - /dev/sgx/enclave
++      - /dev/sgx/provision
++
++  teaclave-access-control-service:
++    devices:
++      - /dev/sgx/enclave
++      - /dev/sgx/provision
++
++  teaclave-execution-service:
++    devices:
++      - /dev/sgx/enclave
++      - /dev/sgx/provision
++
++  teaclave-scheduler-service:
++    devices:
++      - /dev/sgx/enclave
++      - /dev/sgx/provision
+diff --git a/dcap_deployment/docker/docker-compose-ubuntu-2004.yml b/dcap_deployment/docker/docker-compose-ubuntu-2004.yml
+new file mode 100644
+index 0000000..aea234a
+--- /dev/null
++++ b/dcap_deployment/docker/docker-compose-ubuntu-2004.yml
+@@ -0,0 +1,230 @@
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++version: '3.7'
++
++services:
++  teaclave-authentication-service:
++    build:
++      context: ../
++      dockerfile: docker/teaclave-rt.ubuntu-2004.Dockerfile
++    ports:
++      - 7776:7776
++    expose:
++      - 7776
++      - 17776
++    volumes:
++      - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /cleanroom-demo-data:/cleanroom-demo-data
++      - /etc/aesmd.conf:/etc/aesmd.conf
++      - ./hosts:/etc/hosts
++    working_dir: /teaclave
++    environment:
++      - AS_SPID
++      - AS_KEY
++      - AS_ALGO
++      - AS_URL
++      - TEACLAVE_LOG
++    entrypoint: ./teaclave_authentication_service
++    container_name: teaclave-authentication-service
++    networks:
++      api:
++      internal:
++
++  teaclave-frontend-service:
++    build:
++      context: ../
++      dockerfile: docker/teaclave-rt.ubuntu-2004.Dockerfile
++    ports:
++      - 7777:7777
++    expose:
++      - 7777
++    volumes:
++      - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /etc/aesmd.conf:/etc/aesmd.conf
++      - ./hosts:/etc/hosts
++    working_dir: /teaclave
++    environment:
++      - AS_SPID
++      - AS_KEY
++      - AS_ALGO
++      - AS_URL
++      - TEACLAVE_LOG
++    entrypoint: ./teaclave_frontend_service
++    depends_on:
++      - teaclave-management-service
++    container_name: teaclave-frontend-service
++    networks:
++      api:
++      internal:
++
++  teaclave-management-service:
++    build:
++      context: ../
++      dockerfile: docker/teaclave-rt.ubuntu-2004.Dockerfile
++    expose:
++      - 17777
++    volumes:
++      - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /cleanroom-demo-data:/cleanroom-demo-data
++      - /etc/aesmd.conf:/etc/aesmd.conf
++      - ./hosts:/etc/hosts
++    working_dir: /teaclave
++    environment:
++      - AS_SPID
++      - AS_KEY
++      - AS_ALGO
++      - AS_URL
++      - TEACLAVE_LOG
++    entrypoint: ./teaclave_management_service
++    depends_on:
++      - teaclave-storage-service
++      - teaclave-access-control-service
++    container_name: teaclave-management-service
++    networks:
++      internal:
++
++  teaclave-storage-service:
++    build:
++      context: ../
++      dockerfile: docker/teaclave-rt.ubuntu-2004.Dockerfile
++    expose:
++      - 17778
++    volumes:
++      - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /cleanroom-demo-data:/cleanroom-demo-data
++      - /etc/aesmd.conf:/etc/aesmd.conf
++      - ./hosts:/etc/hosts
++    working_dir: /teaclave
++    environment:
++      - AS_SPID
++      - AS_KEY
++      - AS_ALGO
++      - AS_URL
++      - TEACLAVE_LOG
++    entrypoint: ./teaclave_storage_service
++    container_name: teaclave-storage-service
++    networks:
++      internal:
++
++  teaclave-access-control-service:
++    build:
++      context: ../
++      dockerfile: docker/teaclave-rt.ubuntu-2004.Dockerfile
++    expose:
++      - 17779
++    volumes:
++      - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /etc/aesmd.conf:/etc/aesmd.conf
++      - ./hosts:/etc/hosts
++    working_dir: /teaclave
++    environment:
++      - AS_SPID
++      - AS_KEY
++      - AS_ALGO
++      - AS_URL
++      - TEACLAVE_LOG
++    container_name: teaclave-access-control-service
++    entrypoint: ./teaclave_access_control_service
++    networks:
++      internal:
++
++  teaclave-execution-service:
++    build:
++      context: ../
++      dockerfile: docker/teaclave-rt.ubuntu-2004.Dockerfile
++    expose:
++      - 17770
++    volumes:
++      - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /cleanroom-demo-data:/cleanroom-demo-data
++      - /etc/aesmd.conf:/etc/aesmd.conf
++      - ./hosts:/etc/hosts
++    working_dir: /teaclave
++    environment:
++      - AS_SPID
++      - AS_KEY
++      - AS_ALGO
++      - AS_URL
++      - TEACLAVE_LOG
++    entrypoint: ./teaclave_execution_service
++    container_name: teaclave-execution-service
++    restart: always
++    depends_on:
++      - teaclave-scheduler-service
++    networks:
++      internal:
++      fs:
++
++  teaclave-scheduler-service:
++    build:
++      context: ../
++      dockerfile: docker/teaclave-rt.ubuntu-2004.Dockerfile
++    expose:
++      - 17780
++    volumes:
++      - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /etc/aesmd.conf:/etc/aesmd.conf
++      - ./hosts:/etc/hosts
++    working_dir: /teaclave
++    environment:
++      - AS_SPID
++      - AS_KEY
++      - AS_ALGO
++      - AS_URL
++      - TEACLAVE_LOG
++    entrypoint: ./teaclave_scheduler_service
++    container_name: teaclave-scheduler-service
++    depends_on:
++      - teaclave-storage-service
++    networks:
++      internal:
++
++  teaclave-file-service:
++    image: python:3
++    container_name: teaclave-file-service
++    volumes:
++      - ../release/tests:/teaclave-file-service
++      - /cleanroom-demo-data/file:/cleanroom-demo-data/file
++    working_dir: /cleanroom-demo-data/file
++    ports:
++      - 6789:6789
++    expose:
++      - 6789
++    entrypoint: /teaclave-file-service/scripts/simple_http_server.py
++    networks:
++      fs:
++
++  teaclave-file-external-service:
++    image: python:3
++    container_name: teaclave-file-external-service
++    volumes:
++      - ../release/tests:/teaclave-file-external-service
++      - /cleanroom-demo-data/file:/cleanroom-demo-data/file
++    working_dir: /cleanroom-demo-data/file
++    ports:
++      - 7789:7789
++    expose:
++      - 7789
++    entrypoint: ["/teaclave-file-external-service/scripts/auth_http_server.py", "7789", "001dda666e88921cfa9cecd5935d387b17b16c70022fe119ce69dee0ec84e3d9"]
++    networks:
++      fs:
++
++networks:
++  internal:
++  api:
++  fs:
+diff --git a/dcap_deployment/docker/hosts b/dcap_deployment/docker/hosts
+new file mode 100644
+index 0000000..7e5fe60
+--- /dev/null
++++ b/dcap_deployment/docker/hosts
+@@ -0,0 +1,2 @@
++172.17.0.1	api-as-dev.cleanroom.com
++
+diff --git a/dcap_deployment/docker/run-teaclave-services.sh b/dcap_deployment/docker/run-teaclave-services.sh
+new file mode 100644
+index 0000000..581edcd
+--- /dev/null
++++ b/dcap_deployment/docker/run-teaclave-services.sh
+@@ -0,0 +1,224 @@
++#!/bin/bash
++
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++SGX_DEV_SEL="none"
++AESM_SEL="none"
++
++function sgx_dev_detect() {
++    local ISGX_DEV=/dev/isgx
++    local ISGX_DEV_EXIST=false
++    if [ -c "$ISGX_DEV" ]; then
++        echo "$ISGX_DEV device detected."
++        ISGX_DEV_EXIST=true
++    fi
++
++    local ENCL_DEV=/dev/sgx/enclave
++    local ENCL_DEV_EXIST=false
++    if [ -L "$ENCL_DEV" ] && [ -c $(realpath $ENCL_DEV) ]; then
++        echo "$ENCL_DEV device detected."
++        ENCL_DEV_EXIST=true
++    fi
++
++    local PROV_DEV=/dev/sgx/provision
++    local PROV_DEV_EXIST=false
++    if [ -L "$PROV_DEV" ] && [ -c $(realpath $PROV_DEV) ]; then
++        echo "$PROV_DEV device detected."
++        PROV_DEV_EXIST=true
++    fi
++
++    if ($ISGX_DEV_EXIST && $ENCL_DEV_EXIST && $PROV_DEV_EXIST); then
++        PS3='Please enter your choice: '
++        options=("ISGX device" "DCAP device" "Quit")
++        select opt in "${options[@]}"
++        do
++            case $opt in
++                "ISGX device")
++                    echo "you chose $opt"
++                    SGX_DEV_SEL="isgx"
++                    break
++                    ;;
++                "DCAP device")
++                    echo "you chose $opt"
++                    SGX_DEV_SEL="dcap"
++                    break
++                    ;;
++                "Quit")
++                    exit 1
++                    ;;
++                *) echo "invalid option $REPLY" ;;
++            esac
++        done
++    else
++        if $ISGX_DEV_EXIST; then
++            SGX_DEV_SEL="isgx"
++        fi
++        if ($ENCL_DEV_EXIST && $PROV_DEV_EXIST); then
++            SGX_DEV_SEL="dcap"
++        fi
++    fi
++}
++
++function aesm_detect() {
++    local AESM_SOCK=/var/run/aesmd/aesm.socket
++    local AESM_SOCK_EXIST=false
++    if [ -S "$AESM_SOCK" ]; then
++        echo "$AESM_SOCK socket detected."
++        AESM_SOCK_EXIST=true
++    fi
++
++    local AESM_VOL=aesmd-socket
++    local AESM_VOL_EXIST=false
++    if docker volume inspect $AESM_VOL 2>&1 > /dev/null ; then
++        echo "$AESM_VOL volume detected."
++        AESM_VOL_EXIST=true
++    fi
++
++    if ($AESM_SOCK_EXIST && $AESM_VOL_EXIST); then
++        PS3='Please enter your choice: '
++        options=("$AESM_SOCK socket" "$AESM_VOL volume" "Quit")
++        select opt in "${options[@]}"
++        do
++            case $opt in
++                "$AESM_SOCK socket")
++                    echo "you chose $opt"
++                    AESM_SEL="sock"
++                    break
++                    ;;
++                "$AESM_VOL volume")
++                    echo "you chose $opt"
++                    AESM_SEL="vol"
++                    break
++                    ;;
++                "Quit")
++                    exit 1
++                    ;;
++                *) echo "invalid option $REPLY" ;;
++            esac
++        done
++    else
++        if $AESM_SOCK_EXIST; then
++            AESM_SEL="sock"
++        fi
++        if $AESM_VOL_EXIST; then
++            AESM_SEL="vol"
++        fi
++    fi
++}
++
++function usage {
++    echo "Usage: $(basename $0) [-hdbm:]" 2>&1
++    echo '   -h           shows usage'
++    echo '   -m           run mode (default: sgx)'
++    echo '   -d           detached mode'
++    echo '   -b           build or rebuild services'
++    echo 'Available run modes: sim, sgx'
++    exit 1
++}
++
++RUN_MODE="sgx"
++DETACH_ARG=""
++optstring="hdbm:"
++while getopts ${optstring} arg; do
++    case ${arg} in
++        h)
++            echo "showing usage!"
++            usage
++            ;;
++        d)
++            DETACH_ARG="-d"
++            ;;
++        b)
++            BUILD_ARG="--build"
++            ;;
++        m)
++            RUN_MODE=$OPTARG
++            ;;
++    esac
++done
++
++shift $((OPTIND-1))
++
++case $RUN_MODE in
++    "sgx")
++        sgx_dev_detect
++        aesm_detect
++        ;;
++    "sim")
++        ;;
++    *)
++        echo "The specified run mode: $RUN_MODE is not recognized."
++        usage
++        ;;
++esac
++
++OV_PREFIX="docker-compose-"
++OV_SUFFIX=".override.yml"
++SGX_DEV_OV_FILE=""
++AESM_OV_FILE=""
++case $SGX_DEV_SEL in
++    "isgx")
++        SGX_DEV_OV_FILE="isgx-dev"
++        ;;
++    "dcap")
++        SGX_DEV_OV_FILE="dcap-dev"
++        ;;
++    "none")
++        ;;
++    *)
++        echo "Invalid SGX device."
++        exit 2
++        ;;
++esac
++SGX_DEV_OV_FILE="${OV_PREFIX}${SGX_DEV_OV_FILE}${OV_SUFFIX}"
++
++case $AESM_SEL in
++    "sock")
++        AESM_OV_FILE="aesm-socket"
++        ;;
++    "vol")
++        AESM_OV_FILE="aesm-vol"
++        ;;
++    "none")
++        ;;
++    *)
++        echo "Invalid AESM service."
++        exit 2
++        ;;
++esac
++AESM_OV_FILE="${OV_PREFIX}${AESM_OV_FILE}${OV_SUFFIX}"
++
++DOCKER_COMPOSE_FILE="docker-compose-ubuntu-1804.yml"
++DC_ARGS=""
++if [ "$RUN_MODE" == "sgx" ]; then
++    if [ "$SGX_DEV_SEL" == "none" ]; then
++        echo "Cannot find a valid sgx device."
++        exit 3
++    fi
++    if [ "$AESM_SEL" == "none" ]; then
++        echo "Cannot find a valid aesm service."
++        exit 6
++    fi
++    DC_ARGS="-f $DOCKER_COMPOSE_FILE -f $SGX_DEV_OV_FILE -f $AESM_OV_FILE"
++else
++    DC_ARGS="-f $DOCKER_COMPOSE_FILE"
++fi
++
++echo COMMAND: docker-compose ${DC_ARGS} up ${DETACH_ARG} ${BUILD_ARG}
++
++#docker-compose ${DC_ARGS} up ${DETACH_ARG} ${BUILD_ARG} --build
+diff --git a/dcap_deployment/docker/run.env b/dcap_deployment/docker/run.env
+new file mode 100644
+index 0000000..25d16de
+--- /dev/null
++++ b/dcap_deployment/docker/run.env
+@@ -0,0 +1,4 @@
++export AS_ALGO=sgx_ecdsa
++export AS_URL=https://api-as-dev.cleanroom.com:8080
++export AS_KEY="00000000000000000000000000000000"
++export AS_SPID="00000000000000000000000000000000"
+diff --git a/dcap_deployment/docker/runtime.config.toml b/dcap_deployment/docker/runtime.config.toml
+new file mode 100644
+index 0000000..e5a7297
+--- /dev/null
++++ b/dcap_deployment/docker/runtime.config.toml
+@@ -0,0 +1,51 @@
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++# Teaclave Runtime Config
++#
++# Note that this config is loaded at running time. We don't have to trust the
++# content though. Maliciously crafted config from this file will not break data
++# confidentiality/integrity.
++
++[api_endpoints]
++authentication = { listen_address = "0.0.0.0:7776" }
++frontend       = { listen_address = "0.0.0.0:7777" }
++
++[internal_endpoints]
++authentication = { listen_address = "0.0.0.0:17776", advertised_address = "teaclave-authentication-service:17776" }
++management     = { listen_address = "0.0.0.0:17777", advertised_address = "teaclave-management-service:17777" }
++storage        = { listen_address = "0.0.0.0:17778", advertised_address = "teaclave-storage-service:17778" }
++access_control = { listen_address = "0.0.0.0:17779", advertised_address = "teaclave-access-control-service:17779" }
++execution      = { listen_address = "0.0.0.0:17770", advertised_address = "teaclave-execution-service:17770" }
++scheduler      = { listen_address = "0.0.0.0:17780", advertised_address = "teaclave-scheduler-service:17780" }
++
++[audit]
++enclave_info = { path = "enclave_info.toml" }
++auditor_signatures = [
++    { path = "auditors/godzilla/godzilla.sign.sha256" },
++    { path = "auditors/optimus_prime/optimus_prime.sign.sha256" },
++    { path = "auditors/albus_dumbledore/albus_dumbledore.sign.sha256" },
++]
++
++[attestation]
++algorithm = "sgx_ecdsa"
++url = "https://api-as-dev.cleanroom.com:8080"
++key = "00000000000000000000000000000000"
++spid = "00000000000000000000000000000000"
++
++[mount]
++fusion_base_dir = "/cleanroom-demo-data"
+diff --git a/dcap_deployment/docker/teaclave-rt.ubuntu-2004.Dockerfile b/dcap_deployment/docker/teaclave-rt.ubuntu-2004.Dockerfile
+new file mode 100644
+index 0000000..5bd4261
+--- /dev/null
++++ b/dcap_deployment/docker/teaclave-rt.ubuntu-2004.Dockerfile
+@@ -0,0 +1,81 @@
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++FROM ubuntu:20.04
++
++ENV VERSION 2.15.101.1-focal1
++ENV SGX_DOWNLOAD_URL_BASE "https://download.01.org/intel-sgx/sgx-linux/2.15.1/distro/ubuntu20.04-server/"
++ENV SGX_LINUX_X64_SDK sgx_linux_x64_sdk_2.15.101.1.bin
++ENV SGX_LINUX_X64_SDK_URL "$SGX_DOWNLOAD_URL_BASE/$SGX_LINUX_X64_SDK"
++
++ENV DEBIAN_FRONTEND=noninteractive
++
++RUN apt-get update && apt-get install -q -y \
++    libcurl4-openssl-dev \
++    libprotobuf-dev \
++    curl \
++    pkg-config \
++    wget \
++    build-essential \
++    gpg-agent
++
++RUN echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | \
++  tee /etc/apt/sources.list.d/intel-sgx.list
++RUN curl -fsSL  https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add -
++
++RUN apt-get update && apt-get install -q -y \
++    libsgx-launch=$VERSION \
++    libsgx-urts=$VERSION \
++    libsgx-quote-ex=$VERSION \
++    libsgx-uae-service=$VERSION
++RUN mkdir /etc/init
++
++# Install Intel SGX SDK for libsgx_urts_sim.so
++RUN wget $SGX_LINUX_X64_SDK_URL               && \
++    chmod u+x $SGX_LINUX_X64_SDK              && \
++    echo -e 'no\n/opt' | ./$SGX_LINUX_X64_SDK && \
++    rm $SGX_LINUX_X64_SDK                     && \
++    echo 'source /opt/sgxsdk/environment' >> /etc/environment
++ENV LD_LIBRARY_PATH=/opt/sgxsdk/sdk_libs
++
++# Make a directory for fusion data. Since we are in the single machine mode,
++# there is no need to mount a network file system.
++RUN mkdir -p /tmp/fusion_data
++
++ADD release/services/teaclave_frontend_service /teaclave/
++ADD release/services/teaclave_frontend_service_enclave.signed.so /teaclave/
++
++ADD release/services/teaclave_authentication_service /teaclave/
++ADD release/services/teaclave_authentication_service_enclave.signed.so /teaclave/
++
++ADD release/services/teaclave_management_service /teaclave/
++ADD release/services/teaclave_management_service_enclave.signed.so /teaclave/
++
++ADD release/services/teaclave_scheduler_service /teaclave/
++ADD release/services/teaclave_scheduler_service_enclave.signed.so /teaclave/
++
++ADD release/services/teaclave_access_control_service /teaclave/
++ADD release/services/teaclave_access_control_service_enclave.signed.so /teaclave/
++
++ADD release/services/teaclave_storage_service /teaclave/
++ADD release/services/teaclave_storage_service_enclave.signed.so /teaclave/
++
++ADD release/services/teaclave_execution_service /teaclave/
++ADD release/services/teaclave_execution_service_enclave.signed.so /teaclave/
++
++ADD release/services/enclave_info.toml /teaclave/
++ADD release/services/auditors /teaclave/auditors
+diff --git a/dcap_deployment/pack_publish.sh b/dcap_deployment/pack_publish.sh
+new file mode 100755
+index 0000000..9f96467
+--- /dev/null
++++ b/dcap_deployment/pack_publish.sh
+@@ -0,0 +1,37 @@
++#!/bin/bash
++
++DEFAULT_PUBLISH_DIR=/xlabfs/shared/teaclave-release
++DEFAULT_VERSION_PREFIX=="0.0.6"
++DEFAULT_REPO=$HOME/dcap-release/incubator-teaclave
++
++read -p "Enter Repo Path [$DEFAULT_REPO]: " repo
++repo=${repo:-$DEFAULT_REPO}
++
++read -p "Enter publish dir [$DEFAULT_PUBLISH_DIR]: " publish_dir
++publish_dir=${publish_dir:-$DEFAULT_PUBLISH_DIR}
++
++read -p "Enter version prefix [$DEFAULT_VERSION_PREFIX]: " version_prefix
++version_prefix=${version_prefix:-$DEFAULT_VERSION_PREFIX}
++
++commit_id=$(git rev-parse --short HEAD)
++version="$version_prefix_$commit_id"
++
++out="dcap_service_release_$version"
++mkdir $out
++cp -r $repo/release $out/release
++cp -r $repo/dcap_deployment/docker $out/docker
++tar czvf $out.tgz $out
++cp $out.tgz $publish_dir/
++rm $out.tgz
++rm -rf $out
++
++out="dcap_sdk_release_$version"
++mkdir $out
++cp -r $repo/sdk/python $out/python
++cp $repo/release/services/enclave_info.toml $out/enclave_info.toml
++cp $repo/keys/dcap_root_ca_cert.pem $out/dcap_root_cert.pem
++tar czvf $out.tgz $out
++cp $out.tgz $publish_dir/
++rm $out.tgz
++rm -rf $out
++
+diff --git a/dcap_deployment/pull_latest_deploy.sh b/dcap_deployment/pull_latest_deploy.sh
+new file mode 100755
+index 0000000..3e2db77
+--- /dev/null
++++ b/dcap_deployment/pull_latest_deploy.sh
+@@ -0,0 +1,41 @@
++#!/bin/bash
++set -e 
++
++DEFAULT_PUBLISH_BASE=/xlabfs/shared/teaclave-release
++DEFAULT_DEPLOY_BASE=$HOME/teaclave-dcap-deploy
++
++read -p "Confirm Publish Path [$DEFAULT_PUBLISH_BASE]: " PUBLISH_BASE
++PUBLISH_BASE=${PUBLISH_BASE:-$DEFAULT_PUBLISH_BASE}
++
++read -p "Confirm Deploy Path [$DEFAULT_DEPLOY_BASE]: " DEPLOY_BASE
++DEPLOY_BASE=${DEPLOY_BASE:-$DEFAULT_DEPLOY_BASE}
++
++mkdir -p $DEPLOY_BASE
++mkdir -p $DEPLOY_BASE/logs
++
++release_tar_path=`ls -t $PUBLISH_BASE/dcap_service_release*.tgz | head -1`
++echo "[+] Latest relase tar is : $release_tar_path ..."
++cp $release_tar_path $DEPLOY_BASE
++
++echo "[+] Copy $release_tar_path to $DEPLOY_BASE ..."
++filename=$(basename -- "$release_tar_path")
++tar_name="${filename%%.tgz}"
++
++
++echo "[+] Extract $tar_name.tgz ..."
++pushd $DEPLOY_BASE
++tar xzf $tar_name.tgz
++
++log_path=$DEPLOY_BASE/logs/$tar_name.log
++echo "[+] Start service and logging to $log_path .."
++
++pushd $DEPLOY_BASE/$tar_name/docker/
++./deploy_compose_build.sh
++popd
++
++echo "Please stop the previous depyloyment and run the following command in a tmux session ... "
++
++echo "cd $DEPLOY_BASE/$tar_name/docker/"
++echo "TEACLAVE_LOG=info ./deploy_compose_run.sh >> $log_path 2>&1"
++
++popd
+diff --git a/docker/docker-compose-ubuntu-1804.yml b/docker/docker-compose-ubuntu-1804.yml
+index ad718b5..bb55584 100644
+--- a/docker/docker-compose-ubuntu-1804.yml
++++ b/docker/docker-compose-ubuntu-1804.yml
+@@ -75,6 +75,7 @@ services:
+       - 17777
+     volumes:
+       - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /tmp/fusion_data:/tmp/fusion_data
+     working_dir: /teaclave
+     environment:
+       - AS_SPID
+@@ -138,6 +139,7 @@ services:
+       - 17770
+     volumes:
+       - ./runtime.config.toml:/teaclave/runtime.config.toml
++      - /tmp/fusion_data:/tmp/fusion_data
+     working_dir: /teaclave
+     environment:
+       - AS_SPID
+@@ -147,6 +149,7 @@ services:
+       - TEACLAVE_LOG
+     entrypoint: ./teaclave_execution_service
+     container_name: teaclave-execution-service
++    restart: always
+     depends_on:
+       - teaclave-scheduler-service
+     networks:
+@@ -181,6 +184,10 @@ services:
+     volumes:
+       - ../tests:/teaclave-file-service
+     working_dir: /teaclave-file-service
++    ports:
++      - 6789:6789
++    expose:
++      - 6789
+     entrypoint: ./scripts/simple_http_server.py
+     networks:
+       fs:
+diff --git a/docker/docker-compose-ubuntu-2004.yml b/docker/docker-compose-ubuntu-2004.yml
+index a639ec7..103dc3b 100644
+--- a/docker/docker-compose-ubuntu-2004.yml
++++ b/docker/docker-compose-ubuntu-2004.yml
+@@ -149,6 +149,7 @@ services:
+       - TEACLAVE_LOG
+     entrypoint: ./teaclave_execution_service
+     container_name: teaclave-execution-service
++    restart: always
+     depends_on:
+       - teaclave-scheduler-service
+     networks:
+diff --git a/docker/run-teaclave-services.sh b/docker/run-teaclave-services.sh
+index a711fd0..d9b4fce 100755
+--- a/docker/run-teaclave-services.sh
++++ b/docker/run-teaclave-services.sh
+@@ -84,7 +84,7 @@ function aesm_detect() {
+ 
+     local AESM_VOL=aesmd-socket
+     local AESM_VOL_EXIST=false
+-    if docker volume inspect $AESM_VOL > /dev/null 2>&1; then
++    if docker volume inspect $AESM_VOL 2>&1 > /dev/null ; then
+         echo "$AESM_VOL volume detected."
+         AESM_VOL_EXIST=true
+     fi
+diff --git a/docs/README.md b/docs/README.md
+index 0366c56..875ca7c 100644
+--- a/docs/README.md
++++ b/docs/README.md
+@@ -25,7 +25,6 @@ permalink: /docs/
+ 
+ ## Contribute
+ 
+-- [Release Guide](release-guide.md)
+ - [Development Tips](development-tips.md)
+ - [Rust Development Guideline](rust-guideline.md)
+ 
+diff --git a/docs/release-guide.md b/docs/release-guide.md
+deleted file mode 100644
+index 57f69f8..0000000
+--- a/docs/release-guide.md
++++ /dev/null
+@@ -1,282 +0,0 @@
+----
+-permalink: /docs/release-guide
+----
+-
+-# Release Guide
+-
+-This document guide you through how to prepare and publish an official release.
+-Releasing a new version in the community contains multiple steps, here is an
+-overview.
+-
+-[[toc]]
+-
+-## Prepare the Release Notes
+-
+-For a new release, you should first prepare the release note. Release note
+-contains summaries of new features, enhancements, bug fixes,
+-docs, known issues, and deprecation, etc. You can see the notes of
+-[past release](https://github.com/apache/incubator-teaclave/releases) as an example.
+-
+-## Prepare the GPG Signing Key
+-
+-You can skip this section if you have already uploaded your key. That is, the
+-GPG signing key has been added in the following places:
+-  - The KEYS file in repo (<https://github.com/apache/incubator-teaclave/blob/master/KEYS>)
+-  - Apache release dist sever (<https://dist.apache.org/repos/dist/release/incubator/teaclave/KEYS>)
+-
+-If you are the first to publish a release, please follow this instruction to
+-generating and uplaoding keys.
+-
+-To generate GPG key, please refer to
+-<https://www.apache.org/dev/openpgp.html#generate-key> for details.
+-
+-If you want to do the release on another machine, you can transfer your GPG key
+-to that machine via the `gpg --export` and `gpg --import` commands.
+-
+-The last step is to update the KEYS file with your code signing key. Check in
+-the changes to the main branch of the repository, as well as ASF SVN,
+-
+-Here is an instruction of editing the KEYS file in the ASF SVN.
+-
+-```
+-# the --depth=files will avoid checkout existing folders
+-svn co --depth=files "https://dist.apache.org/repos/dist/dev/incubator/teaclave" svn-dev-teaclave
+-cd svn-dev-teaclave
+-# edit KEYS file
+-svn ci --username $ASF_USERNAME --password "$ASF_PASSWORD" -m "Update KEYS"
+-# update downloads.apache.org
+-svn rm --username $ASF_USERNAME --password "$ASF_PASSWORD" https://dist.apache.org/repos/dist/release/incubator/teaclave/KEYS -m "Update KEYS"
+-svn cp --username $ASF_USERNAME --password "$ASF_PASSWORD" https://dist.apache.org/repos/dist/dev/incubator/teaclave/KEYS https://dist.apache.org/repos/dist/release/incubator/teaclave/ -m "Update KEYS"
+-```
+-
+-## Cut a Release Candidate
+-
+-To cut a release candidate, one needs to first cut a branch from the main branch
+-using selected version string. We follow the [semantic versioning](https://semver.org/)
+-guidelines for new version string. In short, x.y.z means MAJOR.MINOR.PATCH. Since we
+-already have the release note, we can decide the version string to be released
+-based on the changes.
+-
+-Note that in our workflow, the main branch should be freezed during the
+-releasing period, i.e, no new features and enhancements can be merged into it.
+-Only changes on this release can be merged and committed into the releasing
+-branch.
+-
+-For example, to release version 1.0.0, let us first create a new branch
+-`release-v1.0.0` from the main branch.
+-
+-```
+-git clone https://github.com/apache/incubator-teaclave
+-cd incubator-teaclave
+-git checkout -b release-v1.0.0
+-```
+-
+-The next step is to do a complete version bumping (e.g., changing files which
+-contain versions and bump them from v0.9.0 to v1.0.0). Note that this affect
+-multiple files in different languages. Then, commit the changes to this
+-releasing branch. Other bug fixes and docs improvements can be also commited at
+-this time.
+-
+-When cleanups are done, make sure all tests can be passed. Then, add a tag with
+-the current commit in the form of "v1.0.0-rc.1" where 1 means it's the first
+-release candidate. You can add the tag using git or add on GitHub.
+-
+-Using Git:
+-```
+-git tag v1.0.0-rc.1
+-git push origin v1.0.0-rc.1
+-```
+-
+-## Create Release Artifacts
+-
+-Create the source code artifacts, including a self-contained tarball without git
+-history, a signature file signed by keys in the KEYS file, and a sha256 hash
+-file.
+-
+-```
+-git clone git@github.com:apache/incubator-teaclave.git apache-teaclave-1.0.0-rc.1-incubating
+-cd apache-teaclave-1.0.0-rc.1-incubating
+-git checkout v1.0.0-rc.1
+-mkdir build && cd build && cmake .. && cd ..    # This will init submodules and apply patches
+-rm -rf build
+-find . -name ".git" -print0 | xargs -0 rm -rf   # Remove all .git directories
+-cd ..
+-tar czvf apache-teaclave-1.0.0-rc.1-incubating.tar.gz apache-teaclave-1.0.0-rc.1-incubating
+-```
+-
+-Use your GPG key to sign the created artifact. First make sure your GPG is set
+-to use the correct private key,
+-
+-```
+-$ gpg --list-key
+-/home/user/.gnupg/pubring.kbx
+-------------------------------------
+-pub   rsa4096 2020-08-17 [SC]
+-      154xxx
+-uid           [ unknown] XXX (CODE SIGNING KEY) <xx...@apache.org>
+-sub   rsa4096 2020-08-17 [E]
+-```
+-
+-```
+-gpg -u 154xxx --armor --detach-sign apache-teaclave-1.0.0-rc.1-incubating.tar.gz
+-sha512sum apache-teaclave-1.0.0-rc.1-incubating.tar.gz > apache-teaclave-1.0.0-rc.1-incubating.tar.gz.sha512
+-```
+-
+-At this point, we got three files in the release artifacts:
+-  - `apache-teaclave-1.0.0-rc.1-incubating.tar.gz`: source code tarball
+-  - `apache-teaclave-1.0.0-rc.1-incubating.tar.gz.asc`: signature
+-  - `apache-teaclave-1.0.0-rc.1-incubating.tar.gz.sha512`: SHA512 hash
+-
+-## Check the Artifacts
+-
+-We suggest to double check the release artifacts, e.g., verify the signature,
+-hash value and build from scratch.
+-There is a [checklist](https://cwiki.apache.org/confluence/display/INCUBATOR/Incubator+Release+Checklist) which can help the process.
+-
+-## Upload the Release Candidate Artifacts
+-
+-The release artifacts needs to be uploaded to ASF SVN,
+-
+-```
+-# the --depth=files will avoid checkout existing folders
+-svn co --depth=files "https://dist.apache.org/repos/dist/dev/incubator/teaclave" svn-dev-teaclave
+-cd svn-dev-teaclave
+-mkdir 1.0.0-rc.1
+-# copy files (.tar.gz, .asc, .sha512) into it
+-svn add 1.0.0-rc.1
+-svn ci --username $ASF_USERNAME --password "$ASF_PASSWORD" -m "Add 1.0.0-rc.1"
+-```
+-
+-## Publish the Pre-Release on GitHub
+-
+-The next step is to publish a pre-release. Go to the GitHub repo's "Releases"
+-tab and click "Draft a new release".
+-
+-- Choose a tag and select v1.0.0-rc.1.
+-- Copy and paste the release note draft into the description box.
+-- Select "This is a pre-release".
+-- Upload the artifacts created by the previous steps.
+-- Click "Publish release".
+-
+-## Call a Vote on the Release Candidate
+-
+-There are two votes need to be done for releasing a incubating project.
+-The first vote takes place on the Apache Teaclave developers list
+-(`dev@teaclave.apache.org`). Once it is closed with pass, we can call for the
+-second in the Apache Incubator general list
+-(`general@incubator.apache.org`). Look at past voting threads to see how this
+-proceeds. The email should contains these information.
+-
+-- Provide the link to the draft of the release notes in the email
+-- Provide the link to the release candidate artifacts
+-- Make sure the email is in text format and the links are correct
+-
+-For the dev@ vote, there must be at least 3 binding +1 votes and more +1 votes
+-than -1 votes. Once the vote is done, you should also send out a summary email
+-with the totals, with a subject that looks something like `[VOTE][RESULT]`.
+-
+-In ASF, votes are open at least 72hrs (3 days). If you don't get enough number
+-of binding votes within that time, you cannot close the voting deadline. You
+-need to extend it.
+-
+-If the voting fails, the community needs to modified the release accordingly,
+-create a new release candidate and re-run the voting process.
+-
+-Here are some examples:
+-
+-**Vote in the dev@teaclave list**:
+-
+-- subject: [VOTE] Release Apache Teaclave (incubating) v0.3.0-rc.1
+-- to: dev@teaclave.apache.org
+-- link: <https://lists.apache.org/thread/9dzwv0y9l9qf9hol2rpwv85ns1xfgn7k>
+-
+-**Result in the dev@teaclave list**:
+-
+-- subject: [RESULT][VOTE] Release Apache Teaclave (incubating) v0.3.0-rc.1
+-- to: dev@teaclave.apache.org
+-- link: <https://lists.apache.org/thread/tyqhx2m9q0z1qg7dbxczf58nnpvxfzrn>
+-
+-**Vote in the general@incubator list**:
+-
+-- subject: [VOTE] Release Apache Teaclave (incubating) v0.3.0-rc.1
+-- to: general@incubator.apache.org
+-- link: <https://lists.apache.org/thread/mrwl41shgx60p432mw2lc6zcdw1lk6lk>
+-
+-**Result in the general@incubator list**:
+-
+-- subject: [RESULT][VOTE] Release Apache Teaclave (incubating) v0.3.0-rc.1
+-- to: dev@teaclave.apache.org
+-- link: <https://lists.apache.org/thread/gbv3f7l9bf6t1876byqm1v4stsw7g00z>
+-
+-## Post the Release
+-
+-After the vote passes, we need to crate the final release artifacts:
+-
+-```
+-cd svn-dev-teaclave
+-mkdir 1.0.0
+-# copy RC files (.tar.gz, .asc, .sha512) into it and rename them
+-cp 1.0.0-rc.1/apache-teaclave-1.0.0-rc.1-incubating.tar.gz 1.0.0/apache-teaclave-1.0.0-incubating.tar.gz
+-cp 1.0.0-rc.1/apache-teaclave-1.0.0-rc.1-incubating.tar.gz.asc 1.0.0/apache-teaclave-1.0.0-incubating.tar.gz.asc
+-cp 1.0.0-rc.1/apache-teaclave-1.0.0-rc.1-incubating.tar.gz.sha512 1.0.0/apache-teaclave-1.0.0-incubating.tar.gz.sha512
+-# edit the file name (i.e., remove the rc version) in the sha512 file
+-vi 1.0.0/apache-teaclave-1.0.0-incubating.tar.gz.sha512
+-svn add 1.0.0
+-svn ci --username $ASF_USERNAME --password "$ASF_PASSWORD" -m "Add 1.0.0"
+-```
+-
+-To upload the binaries to Apache mirrors, you copy the binaries from the dev
+-directory (this should be where they are voted) to the dist directory.
+-These artifacts will be automatically propagated to the CDN service.
+-
+-```
+-export SVN_EDITOR=vim
+-svn cp https://dist.apache.org/repos/dist/dev/incubator/teaclave/1.0.0 https://dist.apache.org/repos/dist/release/incubator/teaclave/1.0.0
+-
+-# If you've added your signing key to the KEYS file, also update the release copy.
+-svn co --depth=files "https://dist.apache.org/repos/dist/release/incubator/teaclave" svn-dist-teaclave
+-curl "https://dist.apache.org/repos/dist/dev/incubator/teaclave/KEYS" > svn-dist-teaclave/KEYS
+-(cd svn-dist-teaclave && svn ci --username $ASF_USERNAME --password "$ASF_PASSWORD" -m "Update KEYS")
+-```
+-
+-Merge commits in the release branch to the main branch, create a new release tag
+-(v1.0.0 in this case) on Github and remove the pre-release candidate tag.
+-
+-```
+-git checkout master
+-## merge the release branch and use --ff-only to ensure the commit hash for voting is also in the master branch
+-git merge release-v1.0.0 --ff-only
+-git tag v1.0.0
+-git push origin v1.0.0
+-git push --delete origin v1.0.0-rc.1
+-git push --delete origin release-v1.0.0
+-```
+-
+-At last update the release notes and corresponding artifacts on GitHub.
+-
+-## Update the Website
+-
+-The website repository is located at <https://github.com/apache/incubator-teaclave-website>.
+-Modify the download page to include the release artifacts as well as the GPG
+-signature and SHA hash. Note that only put the latest version in the download page.
+-Older releases are archived in the archive site automatically
+-(<https://archive.apache.org/dist/incubator/teaclave/>).
+-
+-Note that the links to the release artifact should start with
+-`https://www.apache.org/dyn/closer.lua/incubator/teaclave` to better utilize the
+-Apache CND. You can refer to the previous release link.
+-
+-
+-## Post the Announcement
+-
+-Post new version release annoucement to the mailing list, blog and other
+-channels (Twitter, Discord, etc.).
+-
+-**Mailing list example**:
+-- subject: [ANNOUNCE] Apache Teaclave (incubating) 0.3.0 released
+-- to: announce@apache.org, dev@teaclave.apache.org
+-- link: <https://lists.apache.org/thread/frck6z5v135f8c7w64nkgqk86w1soqc7>
+-
+-**Blog example**:
+-- title: Announcing Apache Teaclave (incubating) 0.3.0
+-- link: <https://teaclave.apache.org/blog/2021-10-01-announcing-teaclave-0-3-0/>
+diff --git a/examples/c/builtin_echo.c b/examples/c/builtin_echo.c
+index 3276be3..9a83835 100644
+--- a/examples/c/builtin_echo.c
++++ b/examples/c/builtin_echo.c
+@@ -34,7 +34,7 @@ const char *register_function_request_serialized = QUOTE({
+     "executor_type" : "builtin",
+     "public" : true,
+     "payload" : [],
+-    "arguments" : ["message"],
++    "arguments" : [{"key": "message", "default_value": "", "allow_overwrite": true}],
+     "inputs" : [],
+     "outputs" : [],
+     "user_allowlist": []
+diff --git a/examples/c/builtin_ordered_set_intersect.c b/examples/c/builtin_ordered_set_intersect.c
+index 1ce5e57..21d9c43 100644
+--- a/examples/c/builtin_ordered_set_intersect.c
++++ b/examples/c/builtin_ordered_set_intersect.c
+@@ -60,7 +60,7 @@ const char *register_function_request_serialized = QUOTE(
+     "executor_type": "builtin",
+     "public": true,
+     "payload": [],
+-    "arguments": ["order"],
++    "arguments": [{"key": "order", "default_value": "", "allow_overwrite": true}],
+     "inputs": [
+         {"name": "input_data1", "description": "Client 0 data.", "optional": false},
+         {"name": "input_data2", "description": "Client 1 data.", "optional": false}
+diff --git a/examples/python/builtin_cleanroom_algorithm2.py b/examples/python/builtin_cleanroom_algorithm2.py
+new file mode 100644
+index 0000000..76c8830
+--- /dev/null
++++ b/examples/python/builtin_cleanroom_algorithm2.py
+@@ -0,0 +1,188 @@
++#!/usr/bin/env python3
++
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++import sys
++import time
++import json
++
++from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap, FunctionArgument
++from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
++
++# User 0: an algorithm provider.
++# User 1: a RNA provider.
++
++
++class UserData:
++
++    def __init__(self,
++                 user_id,
++                 password,
++                 input_url="",
++                 output_url="",
++                 input_cmac=[],
++                 key=[]):
++        self.user_id = user_id
++        self.password = password
++        self.input_url = input_url
++        self.output_url = output_url
++        self.input_cmac = input_cmac
++        self.key = key
++
++
++# If you're using `docker-compose` to start the Teaclave server containers,
++# please change `localhost` to `teaclave-file-service`
++INPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-algorithm2-hash/"
++OUTPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-algorithm2-hash/"
++
++# User0 updates the algorithm. User1 sends the RNA information and gets the results.
++USER_DATA_0 = UserData("Algorithm Owner", "password", None, None, None, None)
++
++USER_DATA_1 = UserData("Gene Owner", "password",
++                       INPUT_FILE_URL_PREFIX + "stdout.enc",
++                       OUTPUT_FILE_URL_PREFIX + "result.enc", [
++                           0xff, 0xed, 0x3a, 0xe7, 0xef, 0xc9, 0x1f, 0x2c,
++                           0xd1, 0x24, 0xbf, 0x0b, 0xed, 0xff, 0xb5, 0x1b
++                       ], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
++
++
++class DataList:
++
++    def __init__(self, data_name, data_id):
++        self.data_name = data_name
++        self.data_id = data_id
++
++
++class Client:
++
++    def __init__(self, user_id, user_password):
++        self.user_id = user_id
++        self.user_password = user_password
++        with connect_authentication_service() as client:
++            print(f"[+] {self.user_id} login")
++            token = client.user_login(self.user_id, self.user_password)
++        self.client = connect_frontend_service()
++        metadata = {"id": self.user_id, "token": token}
++        self.client.metadata = metadata
++
++    def register_function(self):
++        client = self.client
++
++        print(f"[+] {self.user_id} registering the algorithm2 function")
++        function_id = client.register_function(
++            name="builtin-cleanroom-algorithm2-hash",
++            description="algorithm2",
++            executor_type="builtin",
++            arguments=[FunctionArgument("args"),
++                       FunctionArgument("debug")],
++            inputs=[FunctionInput("input_file", "protain data.")],
++            outputs=[FunctionOutput("output_file", "Output data.")])
++        return function_id
++
++    def create_task(self, function_id):
++        print(f"[+] {self.user_id} creating the task")
++        client = self.client
++        args = ["algorithm2", "100", "200"]
++        task_id = client.create_task(
++            function_id=function_id,
++            function_arguments=({
++                "args": json.dumps(args),
++                "debug": "false",
++            }),
++            executor="builtin",
++            inputs_ownership=[OwnerList("input_file", [USER_DATA_1.user_id])],
++            outputs_ownership=[
++                OwnerList("output_file", [USER_DATA_1.user_id])
++            ])
++        return task_id
++
++    def run_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} invoking the task")
++        client.invoke_task(task_id)
++
++    def register_data(self, task_id, input_url, input_cmac, output_url,
++                      file_key, input_label, output_label):
++        client = self.client
++        print(f"[+] {self.user_id} registering the input file")
++        cmac = input_cmac
++        schema = "teaclave-file-128"
++        key = file_key
++        iv = []
++        print(input_url)
++        input_id = client.register_input_file(input_url, schema, key, iv, cmac)
++        print(output_url)
++        output_id = client.register_output_file(output_url, schema, key, iv)
++        print(f"[+] {self.user_id} assigning data to task")
++        client.assign_data_to_task(task_id, [DataList(input_label, input_id)],
++                                   [DataList(output_label, output_id)])
++
++    def approve_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} approving task")
++        client.approve_task(task_id)
++
++    def get_task_result(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} getting task result")
++        return bytes(client.get_task_result(task_id))
++
++
++def main():
++    print(
++        "User 0 (Algorithm owner) registers the function and uploads the algorithm."
++    )
++    print(
++        "User 1 (Gene Owner) creates the task, uploads the secret data, and retrieves the result."
++    )
++    # Register user
++    platform_admin = PlatformAdmin("admin", "teaclave")
++    try:
++        platform_admin.register_user(USER_DATA_0.user_id, USER_DATA_0.password)
++        platform_admin.register_user(USER_DATA_1.user_id, USER_DATA_1.password)
++    except Exception:
++        pass
++    user0 = Client(USER_DATA_0.user_id, USER_DATA_0.password)
++    function_id = user0.register_function()
++
++    start = time.time()
++
++    user1 = Client(USER_DATA_1.user_id, USER_DATA_1.password)
++
++    task_id = user1.create_task(function_id)
++    user1.register_data(task_id, USER_DATA_1.input_url, USER_DATA_1.input_cmac,
++                        USER_DATA_1.output_url, USER_DATA_1.key, "input_file",
++                        "output_file")
++
++    # user1.approve_task(task_id)
++    user1.approve_task(task_id)
++
++    ## USER 1 start the computation
++    user1.run_task(task_id)
++
++    ## USER 1 get the result
++    result_user1 = user1.get_task_result(task_id)
++
++    end = time.time()
++
++    print("[+] Gene Owner result: " + result_user1.decode("utf-8"))
++    print("[+] Time: " + str(end - start))
++
++
++if __name__ == '__main__':
++    main()
+diff --git a/examples/python/builtin_echo.py b/examples/python/builtin_echo.py
+index 8c6f154..fdfed5e 100644
+--- a/examples/python/builtin_echo.py
++++ b/examples/python/builtin_echo.py
+@@ -20,6 +20,7 @@
+ import sys
+ 
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service
++from teaclave import FunctionArgument
+ 
+ 
+ class BuiltinEchoExample:
+@@ -42,7 +43,7 @@ class BuiltinEchoExample:
+                 name="builtin-echo",
+                 description="Native Echo Function",
+                 executor_type="builtin",
+-                arguments=["message"])
++                arguments=[FunctionArgument("message")])
+ 
+             print("[+] creating task")
+             task_id = client.create_task(
+diff --git a/examples/python/builtin_face_detection.py b/examples/python/builtin_face_detection.py
+index 416e99c..a074373 100644
+--- a/examples/python/builtin_face_detection.py
++++ b/examples/python/builtin_face_detection.py
+@@ -25,6 +25,7 @@ from PIL import Image, ImageDraw
+ import requests
+ 
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service
++from teaclave import FunctionArgument
+ 
+ 
+ class BuiltinFaceDetectionExample:
+@@ -49,9 +50,12 @@ class BuiltinFaceDetectionExample:
+             executor_type="builtin",
+             inputs=[],
+             arguments=[
+-                "image", "min_face_size", "score_thresh",
+-                "pyramid_scale_factor", "slide_window_step_x",
+-                "slide_window_step_y"
++                FunctionArgument("image"),
++                FunctionArgument("min_face_size"),
++                FunctionArgument("score_thresh"),
++                FunctionArgument("pyramid_scale_factor"),
++                FunctionArgument("slide_window_step_x"),
++                FunctionArgument("slide_window_step_y")
+             ])
+ 
+         print("[+] creating task")
+diff --git a/examples/python/builtin_gbdt_train.py b/examples/python/builtin_gbdt_train.py
+index 43f0898..b5392ab 100644
+--- a/examples/python/builtin_gbdt_train.py
++++ b/examples/python/builtin_gbdt_train.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service
+ 
+ 
+@@ -44,9 +44,15 @@ class BuiltinGbdtExample:
+             description="Native Gbdt Training Function",
+             executor_type="builtin",
+             arguments=[
+-                "feature_size", "max_depth", "iterations", "shrinkage",
+-                "feature_sample_ratio", "data_sample_ratio", "min_leaf_size",
+-                "loss", "training_optimization_level"
++                FunctionArgument("feature_size"),
++                FunctionArgument("max_depth"),
++                FunctionArgument("iterations"),
++                FunctionArgument("shrinkage"),
++                FunctionArgument("feature_sample_ratio"),
++                FunctionArgument("data_sample_ratio"),
++                FunctionArgument("min_leaf_size"),
++                FunctionArgument("loss"),
++                FunctionArgument("training_optimization_level")
+             ],
+             inputs=[
+                 FunctionInput("training_data", "Input traning data file.")
+diff --git a/examples/python/builtin_online_decrypt.py b/examples/python/builtin_online_decrypt.py
+index aee9c80..9a30b3b 100644
+--- a/examples/python/builtin_online_decrypt.py
++++ b/examples/python/builtin_online_decrypt.py
+@@ -21,6 +21,7 @@ import sys
+ import base64
+ 
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service
++from teaclave import FunctionArgument
+ 
+ 
+ class BuiltinOnlineDecryptExample:
+@@ -43,7 +44,12 @@ class BuiltinOnlineDecryptExample:
+             name="builtin_online_decrypt",
+             description="Native Online Decrypt",
+             executor_type="builtin",
+-            arguments=["key", "nonce", "encrypted_data", "algorithm"])
++            arguments=[
++                FunctionArgument("key"),
++                FunctionArgument("nonce"),
++                FunctionArgument("encrypted_data"),
++                FunctionArgument("algorithm")
++            ])
+ 
+         print("[+] creating task")
+         task_id = client.create_task(
+diff --git a/examples/python/builtin_ordered_set_intersect.py b/examples/python/builtin_ordered_set_intersect.py
+index a9eaa65..6cb8981 100644
+--- a/examples/python/builtin_ordered_set_intersect.py
++++ b/examples/python/builtin_ordered_set_intersect.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ # In the example, user 0 creates the task and user 0, 1, upload their private data.
+@@ -91,7 +91,7 @@ class Client:
+             name="builtin-ordered-set-intersect",
+             description="Native Private Set Intersection",
+             executor_type="builtin",
+-            arguments=["order"],
++            arguments=[FunctionArgument("order")],
+             inputs=[
+                 FunctionInput("input_data1", "Client 0 data."),
+                 FunctionInput("input_data2", "Client 1 data.")
+diff --git a/examples/python/builtin_private_join_and_compute.py b/examples/python/builtin_private_join_and_compute.py
+index 461463e..aab8ca7 100644
+--- a/examples/python/builtin_private_join_and_compute.py
++++ b/examples/python/builtin_private_join_and_compute.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ # In the example, user 3 creates the task and user 0, 1, 2 upload their private data.
+@@ -98,7 +98,7 @@ class ConfigClient:
+             name="builtin-private-join-and-compute",
+             description="Native Private Join And Compute",
+             executor_type="builtin",
+-            arguments=["num_user"],
++            arguments=[FunctionArgument("num_user")],
+             inputs=[
+                 FunctionInput("input_data0", "Bank A data file."),
+                 FunctionInput("input_data1", "Bank B data file."),
+diff --git a/examples/python/builtin_rsa_sign.py b/examples/python/builtin_rsa_sign.py
+index 0724756..b21e91c 100644
+--- a/examples/python/builtin_rsa_sign.py
++++ b/examples/python/builtin_rsa_sign.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ 
+@@ -61,7 +61,7 @@ def register_func(client):
+         name="builtin-rsa-sign",
+         description="Native Rsa Signing Function",
+         executor_type="builtin",
+-        arguments=["data"],
++        arguments=[FunctionArgument("data")],
+         inputs=[FunctionInput("rsa_key", "Input key file.")])
+ 
+     return function_id
+diff --git a/examples/python/cleanroom_algorithm1.py b/examples/python/cleanroom_algorithm1.py
+new file mode 100644
+index 0000000..e417039
+--- /dev/null
++++ b/examples/python/cleanroom_algorithm1.py
+@@ -0,0 +1,196 @@
++#!/usr/bin/env python3
++
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++import sys
++import time
++import json
++
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
++from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
++
++# User 0: an algorithm provider.
++# User 1: a RNA provider.
++
++
++class UserData:
++
++    def __init__(self,
++                 user_id,
++                 password,
++                 input_url="",
++                 output_url="",
++                 input_cmac=[],
++                 key=[]):
++        self.user_id = user_id
++        self.password = password
++        self.input_url = input_url
++        self.output_url = output_url
++        self.input_cmac = input_cmac
++        self.key = key
++
++
++# If you're using `docker-compose` to start the Teaclave server containers,
++# please change `localhost` to `teaclave-file-service`
++INPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-algorithm1/"
++OUTPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-algorithm1/"
++
++# User0 updates the algorithm. User1 sends the RNA information and gets the results.
++USER_DATA_0 = UserData("Algorithm Owner", "password", None, None, None, None)
++
++USER_DATA_1 = UserData("Gene Owner", "password",
++                       INPUT_FILE_URL_PREFIX + "testseq.enc",
++                       OUTPUT_FILE_URL_PREFIX + "stdout.enc", [
++                           0x99, 0x88, 0x31, 0x62, 0x30, 0xe6, 0x40, 0x67,
++                           0xde, 0xe1, 0x20, 0xf2, 0xaf, 0x7b, 0xe6, 0xcf
++                       ], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
++
++PAYLOAD_FILE = "../../tests/fixtures/functions/cleanroom-algorithm1/cleanroom-app.cpk"
++
++
++class DataList:
++
++    def __init__(self, data_name, data_id):
++        self.data_name = data_name
++        self.data_id = data_id
++
++
++class Client:
++
++    def __init__(self, user_id, user_password):
++        self.user_id = user_id
++        self.user_password = user_password
++        with connect_authentication_service() as client:
++            print(f"[+] {self.user_id} login")
++            token = client.user_login(self.user_id, self.user_password)
++        self.client = connect_frontend_service()
++        metadata = {"id": self.user_id, "token": token}
++        self.client.metadata = metadata
++
++    def register_function(self):
++        client = self.client
++
++        print(f"[+] {self.user_id} registering the algorithm1 function")
++        with open(PAYLOAD_FILE, "rb") as f:
++            payload = f.read()
++        function_id = client.register_function(
++            name="cleanroom",
++            description="algorithm1",
++            payload=list(payload),
++            executor_type="cleanroom",
++            arguments=[FunctionArgument("args"),
++                       FunctionArgument("debug")],
++            inputs=[FunctionInput("input_file", "RNA data.")],
++            outputs=[FunctionOutput("output_file", "Output data.")])
++        return function_id
++
++    def create_task(self, function_id):
++        print(f"[+] {self.user_id} creating the task")
++        client = self.client
++        args = [
++            "algorithm1_v", "100", "0", "0", "0", "0", "0", "5.0",
++            "example.shape"
++        ]
++        task_id = client.create_task(
++            function_id=function_id,
++            function_arguments=({
++                "args": json.dumps(args),
++                "debug": "true",
++            }),
++            executor="cleanroom",
++            inputs_ownership=[OwnerList("input_file", [USER_DATA_1.user_id])],
++            outputs_ownership=[
++                OwnerList("output_file", [USER_DATA_1.user_id])
++            ])
++        return task_id
++
++    def run_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} invoking the task")
++        client.invoke_task(task_id)
++
++    def register_data(self, task_id, input_url, input_cmac, output_url,
++                      file_key, input_label, output_label):
++        client = self.client
++
++        print(f"[+] {self.user_id} registering the input file")
++        cmac = input_cmac
++        schema = "teaclave-file-128"
++        key = file_key
++        iv = []
++        print(input_url)
++        input_id = client.register_input_file(input_url, schema, key, iv, cmac)
++        print(output_url)
++        output_id = client.register_output_file(output_url, schema, key, iv)
++        print(f"[+] {self.user_id} assigning data to task")
++        client.assign_data_to_task(task_id, [DataList(input_label, input_id)],
++                                   [DataList(output_label, output_id)])
++
++    def approve_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} approving task")
++        client.approve_task(task_id)
++
++    def get_task_result(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} getting task result")
++        return bytes(client.get_task_result(task_id))
++
++
++def main():
++    print(
++        "User 0 (Algorithm owner) registers the function and uploads the algorithm."
++    )
++    print(
++        "User 1 (Gene Owner) creates the task, uploads the secret data, and retrieves the result."
++    )
++    # Register user
++    platform_admin = PlatformAdmin("admin", "teaclave")
++    try:
++        platform_admin.register_user(USER_DATA_0.user_id, USER_DATA_0.password)
++        platform_admin.register_user(USER_DATA_1.user_id, USER_DATA_1.password)
++    except Exception:
++        pass
++    user0 = Client(USER_DATA_0.user_id, USER_DATA_0.password)
++    function_id = user0.register_function()
++
++    start = time.time()
++
++    user1 = Client(USER_DATA_1.user_id, USER_DATA_1.password)
++    task_id = user1.create_task(function_id)
++    user1.register_data(task_id, USER_DATA_1.input_url, USER_DATA_1.input_cmac,
++                        USER_DATA_1.output_url, USER_DATA_1.key, "input_file",
++                        "output_file")
++
++    # user1.approve_task(task_id)
++    user1.approve_task(task_id)
++
++    ## USER 1 start the computation
++    user1.run_task(task_id)
++
++    ## USER 1 get the result
++    result_user1 = user1.get_task_result(task_id)
++
++    end = time.time()
++
++    print("[+] User 1 result: " + result_user1.decode("utf-8"))
++    print("[+] Time: " + str(end - start))
++
++
++if __name__ == '__main__':
++    main()
+diff --git a/examples/python/cleanroom_algorithm1_repeat.py b/examples/python/cleanroom_algorithm1_repeat.py
+new file mode 100644
+index 0000000..2ccaa99
+--- /dev/null
++++ b/examples/python/cleanroom_algorithm1_repeat.py
+@@ -0,0 +1,222 @@
++#!/usr/bin/env python3
++
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++import sys
++import time
++import traceback
++
++from teaclave import (AuthenticationService, FrontendService,
++                      AuthenticationClient, FrontendClient, FunctionInput,
++                      FunctionOutput, FunctionArgument, OwnerList, DataMap)
++from utils import (AUTHENTICATION_SERVICE_ADDRESS, FRONTEND_SERVICE_ADDRESS,
++                   AS_ROOT_CA_CERT_PATH, ENCLAVE_INFO_PATH, USER_ID,
++                   USER_PASSWORD, PlatformAdmin)
++
++# User 0: an algorithm provider.
++# User 1: a RNA provider.
++
++
++class UserData:
++
++    def __init__(self,
++                 user_id,
++                 password,
++                 input_url="",
++                 output_url="",
++                 input_cmac=[],
++                 key=[]):
++        self.user_id = user_id
++        self.password = password
++        self.input_url = input_url
++        self.output_url = output_url
++        self.input_cmac = input_cmac
++        self.key = key
++
++
++# If you're using `docker-compose` to start the Teaclave server containers,
++# please change `localhost` to `teaclave-file-service`
++INPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-algorithm1/"
++OUTPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-algorithm1/"
++
++# User0 updates the algorithm. User1 sends the RNA information and gets the results.
++USER_DATA_0 = UserData("Algorithm Owner", "password", None, None, None, None)
++
++USER_DATA_1 = UserData("Gene Owner", "password",
++                       INPUT_FILE_URL_PREFIX + "testseq.enc",
++                       OUTPUT_FILE_URL_PREFIX + "stdout.enc", [
++                           0x99, 0x88, 0x31, 0x62, 0x30, 0xe6, 0x40, 0x67,
++                           0xde, 0xe1, 0x20, 0xf2, 0xaf, 0x7b, 0xe6, 0xcf
++                       ], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
++
++PAYLOAD_FILE = "../../tests/fixtures/functions/cleanroom-algorithm1/cleanroom-app.cpk"
++
++
++class DataList:
++
++    def __init__(self, data_name, data_id):
++        self.data_name = data_name
++        self.data_id = data_id
++
++
++class Client:
++
++    def __init__(self, user_id, user_password):
++        self.user_id = user_id
++        self.user_password = user_password
++        self.client = AuthenticationService(
++            AUTHENTICATION_SERVICE_ADDRESS, AS_ROOT_CA_CERT_PATH,
++            ENCLAVE_INFO_PATH).connect().get_client()
++        print(f"[+] {self.user_id} login")
++        token = self.client.user_login(self.user_id, self.user_password)
++        self.client = FrontendService(
++            FRONTEND_SERVICE_ADDRESS, AS_ROOT_CA_CERT_PATH,
++            ENCLAVE_INFO_PATH).connect().get_client()
++        metadata = {"id": self.user_id, "token": token}
++        self.client.metadata = metadata
++
++    def register_function(self):
++        client = self.client
++
++        print(f"[+] {self.user_id} registering the algorithm1 function")
++        with open(PAYLOAD_FILE, "rb") as f:
++            payload = f.read()
++        function_id = client.register_function(
++            name="diagnosis",
++            description="algorithm1",
++            payload=list(payload),
++            executor_type="cleanroom",
++            arguments=[FunctionArgument("args"),
++                       FunctionArgument("debug")],
++            inputs=[FunctionInput("input_file", "RNA data.")],
++            outputs=[
++                FunctionOutput("output_file", "Output data."),
++                FunctionOutput("log_file", "Log.")
++            ])
++        return function_id
++
++    def create_task(self, function_id):
++        print(f"[+] {self.user_id} creating the task")
++        client = self.client
++        task_id = client.create_task(
++            function_id=function_id,
++            function_arguments=({
++                "args": "algorithm1_v 100 0 0 0 0 0 5.0 example.shape",
++                "debug": "true",
++            }),
++            executor="cleanroom",
++            inputs_ownership=[OwnerList("input_file", [USER_DATA_1.user_id])],
++            outputs_ownership=[
++                OwnerList("output_file", [USER_DATA_1.user_id]),
++                OwnerList("log_file", [USER_DATA_1.user_id])
++            ])
++        return task_id
++
++    def run_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} invoking the task")
++        client.invoke_task(task_id)
++
++    def register_data(self, task_id, input_url, input_cmac, output_url,
++                      file_key, input_label, output_label):
++        client = self.client
++
++        print(f"[+] {self.user_id} registering the input file")
++        url = input_url
++        cmac = input_cmac
++        schema = "teaclave-file-128"
++        key = file_key
++        iv = []
++        input_id = client.register_input_file(url, schema, key, iv, cmac)
++        print(f"[+] {self.user_id} registering the output file")
++        url = output_url
++        schema = "teaclave-file-128"
++        key = file_key
++        iv = []
++        output_id = client.register_output_file(url, schema, key, iv)
++        log_id = client.register_output_file(
++            OUTPUT_FILE_URL_PREFIX + "stderr.enc", schema, key, iv)
++        print(f"[+] {self.user_id} assigning data to task")
++        client.assign_data_to_task(
++            task_id, [DataList(input_label, input_id)],
++            [DataList(output_label, output_id),
++             DataList("log_file", log_id)])
++
++    def approve_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} approving task")
++        client.approve_task(task_id)
++
++    def get_task_result(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} getting task result")
++        return bytes(client.get_task_result(task_id))
++
++
++def client_run_once(function_id):
++    user1 = Client(USER_DATA_1.user_id, USER_DATA_1.password)
++    task_id = user1.create_task(function_id)
++    user1.register_data(task_id, USER_DATA_1.input_url, USER_DATA_1.input_cmac,
++                        USER_DATA_1.output_url, USER_DATA_1.key, "input_file",
++                        "output_file")
++
++    # user1.approve_task(task_id)
++    user1.approve_task(task_id)
++
++    # USER 1 start the computation
++    user1.run_task(task_id)
++
++    # USER 1 get the result
++    result_user1 = user1.get_task_result(task_id)
++
++
++def main():
++    # Register user
++    platform_admin = PlatformAdmin("admin", "teaclave")
++    platform_admin.register_user(USER_DATA_0.user_id, USER_DATA_0.password)
++    platform_admin.register_user(USER_DATA_1.user_id, USER_DATA_1.password)
++    while True:
++        try:
++            user0 = Client(USER_DATA_0.user_id, USER_DATA_0.password)
++            function_id = user0.register_function()
++            break
++        except Exception as e:
++            print(f"Python Client: Admin register function got execption: {e}",
++                  flush=True)
++            traceback.print_tb(e.__traceback__)
++
++    i = 1
++    while True:
++        try:
++            print(f"Python Client {i}th invocation started...", flush=True)
++            start = time.time()
++            client_run_once(function_id)
++            end = time.time()
++            elapsed = end - start
++            print(
++                f"Python Client {i}th invocation finishied: elapsed {elapsed} seconds...",
++                flush=True)
++            i = i + 1
++        except Exception as e:
++            print(f"Python Client {i}th invocation got execption: {e}",
++                  flush=True)
++            traceback.print_tb(e.__traceback__)
++
++
++if __name__ == '__main__':
++    main()
+diff --git a/examples/python/cleanroom_stderr.py b/examples/python/cleanroom_stderr.py
+new file mode 100644
+index 0000000..6c55689
+--- /dev/null
++++ b/examples/python/cleanroom_stderr.py
+@@ -0,0 +1,200 @@
++#!/usr/bin/env python3
++
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++import sys
++import json
++
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
++from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
++
++# User 0: an algorithm provider.
++# User 1: a RNA provider.
++
++
++class UserData:
++
++    def __init__(self,
++                 user_id,
++                 password,
++                 input_url="",
++                 output_url="",
++                 input_cmac=[],
++                 key=[]):
++        self.user_id = user_id
++        self.password = password
++        self.input_url = input_url
++        self.output_url = output_url
++        self.input_cmac = input_cmac
++        self.key = key
++
++
++# If you're using `docker-compose` to start the Teaclave server containers,
++# please change `localhost` to `teaclave-file-service`
++INPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-stderr/"
++OUTPUT_FILE_URL_PREFIX = "http://localhost:6789/fixtures/functions/cleanroom-stderr/"
++
++# User0 updates the algorithm. User1 sends the RNA information and gets the results.
++USER_DATA_0 = UserData("Algorithm Owner 2", "password", None, None, None, None)
++
++USER_DATA_1 = UserData("Data Owner 2", "password",
++                       INPUT_FILE_URL_PREFIX + "testseq.enc",
++                       OUTPUT_FILE_URL_PREFIX + "stdout.enc", [
++                           0x99, 0x88, 0x31, 0x62, 0x30, 0xe6, 0x40, 0x67,
++                           0xde, 0xe1, 0x20, 0xf2, 0xaf, 0x7b, 0xe6, 0xcf
++                       ], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
++
++PAYLOAD_FILE = "../../tests/fixtures/functions/cleanroom-stderr/app.cpk"
++
++
++class DataList:
++
++    def __init__(self, data_name, data_id):
++        self.data_name = data_name
++        self.data_id = data_id
++
++
++class Client:
++
++    def __init__(self, user_id, user_password):
++        self.user_id = user_id
++        self.user_password = user_password
++        with connect_authentication_service() as client:
++            print(f"[+] {self.user_id} login")
++            token = client.user_login(self.user_id, self.user_password)
++        self.client = connect_frontend_service()
++        metadata = {"id": self.user_id, "token": token}
++        self.client.metadata = metadata
++
++    def register_function_debug(self):
++        client = self.client
++
++        print(f"[+] {self.user_id} registering the algorithm1 function")
++        with open(PAYLOAD_FILE, "rb") as f:
++            payload = f.read()
++        function_id = client.register_function(
++            name="diagnosis",
++            #name="cleanroom",
++            description="algorithm1",
++            payload=list(payload),
++            executor_type="cleanroom",
++            arguments=[FunctionArgument("args"),
++                       FunctionArgument("debug")],
++            inputs=[FunctionInput("input_file", "RNA data.")],
++            outputs=[
++                FunctionOutput("output_file", "Output data."),
++                FunctionOutput("log_file", "Log.")
++            ])
++        return function_id
++
++    def create_task_debug(self, function_id):
++        print(f"[+] {self.user_id} creating the task")
++        client = self.client
++        args = ["algorithm1_v", "100", "0", "0"]
++        task_id = client.create_task(
++            function_id=function_id,
++            function_arguments=({
++                "args": json.dumps(args),
++                "debug": "true",
++            }),
++            executor="cleanroom",
++            inputs_ownership=[OwnerList("input_file", [USER_DATA_1.user_id])],
++            outputs_ownership=[
++                OwnerList("output_file", [USER_DATA_1.user_id]),
++                OwnerList("log_file", [USER_DATA_1.user_id])
++            ])
++        return task_id
++
++    def run_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} invoking the task")
++        client.invoke_task(task_id)
++
++    def register_data_debug(self, task_id, input_url, input_cmac, output_url,
++                            file_key, input_label, output_label):
++        client = self.client
++        print(f"[+] {self.user_id} registering the input file")
++        url = input_url
++        cmac = input_cmac
++        schema = "teaclave-file-128"
++        key = file_key
++        iv = []
++        input_id = client.register_input_file(url, schema, key, iv, cmac)
++        print(f"[+] {self.user_id} registering the output file")
++        url = output_url
++        schema = "teaclave-file-128"
++        key = file_key
++        iv = []
++        output_id = client.register_output_file(url, schema, key, iv)
++        log_id = client.register_output_file(
++            OUTPUT_FILE_URL_PREFIX + "stderr.enc", schema, key, iv)
++        print(f"[+] {self.user_id} assigning data to task")
++        client.assign_data_to_task(
++            task_id, [DataList(input_label, input_id)],
++            [DataList(output_label, output_id),
++             DataList("log_file", log_id)])
++
++    def approve_task(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} approving task")
++        client.approve_task(task_id)
++
++    def get_task_result(self, task_id):
++        client = self.client
++        print(f"[+] {self.user_id} getting task result")
++        return bytes(client.get_task_result(task_id))
++
++
++def main():
++    print(
++        "User 0 (Algorithm owner) registers the function and uploads the algorithm."
++    )
++    print(
++        "User 1 (DATA Owner) creates the task, uploads the secret data, and retrieves the result."
++    )
++    # Register user
++    platform_admin = PlatformAdmin("admin", "teaclave")
++    try:
++        platform_admin.register_user(USER_DATA_0.user_id, USER_DATA_0.password)
++        platform_admin.register_user(USER_DATA_1.user_id, USER_DATA_1.password)
++    except Exception:
++        pass
++    user0 = Client(USER_DATA_0.user_id, USER_DATA_0.password)
++    function_id = user0.register_function_debug()
++
++    user1 = Client(USER_DATA_1.user_id, USER_DATA_1.password)
++
++    task_id = user1.create_task_debug(function_id)
++    user1.register_data_debug(task_id, USER_DATA_1.input_url,
++                              USER_DATA_1.input_cmac, USER_DATA_1.output_url,
++                              USER_DATA_1.key, "input_file", "output_file")
++
++    # user1.approve_task(task_id)
++    user1.approve_task(task_id)
++
++    ## USER 1 start the computation
++    user1.run_task(task_id)
++
++    ## USER 1 get the result
++    result_user1 = user1.get_task_result(task_id)
++
++    print("[+] User 1 result: " + result_user1.decode("utf-8"))
++
++
++if __name__ == '__main__':
++    main()
+diff --git a/examples/python/mesapy_deadloop_cancel.py b/examples/python/mesapy_deadloop_cancel.py
+index a4b0eaa..2bd7206 100644
+--- a/examples/python/mesapy_deadloop_cancel.py
++++ b/examples/python/mesapy_deadloop_cancel.py
+@@ -75,22 +75,22 @@ class MesaPyEchoExample:
+         result = client.get_task(task_id)
+         if result["status"] != TaskStatus.Canceled:
+             print("[+] Task is not canceled, cancel again")
+-            try:
+-                client.cancel_task(task_id)
+-            except Exception as e:
+-                # this happens when the task has already been canceled
+-                print(f"[-] cancel task failed, reason: {str(e)}")
++            client.cancel_task(task_id)
+ 
+         try:
+             result = client.get_task_result(task_id)
+         except Exception as e:
+-            # this is expected, since the task is cancelled
+-            print(f"[-] getting result failed, reason: {str(e)}")
++            print(f"[+] result: {str(e)}")
++            result = str(e)
++
++        return result
+ 
+ 
+ def main():
+     example = MesaPyEchoExample(USER_ID, USER_PASSWORD)
+-    example.deadloop()
++    rv = example.deadloop()
++
++    print("[+] function return: ", rv)
+ 
+ 
+ if __name__ == '__main__':
+diff --git a/examples/python/mesapy_echo.py b/examples/python/mesapy_echo.py
+index d24c2ae..b60df00 100644
+--- a/examples/python/mesapy_echo.py
++++ b/examples/python/mesapy_echo.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ 
+@@ -49,7 +49,7 @@ class MesaPyEchoExample:
+             description="An echo function implemented in Python",
+             executor_type="python",
+             payload=list(payload),
+-            arguments=["message"])
++            arguments=[FunctionArgument("message")])
+ 
+         print("[+] creating task")
+         task_id = client.create_task(function_id=function_id,
+diff --git a/examples/python/mesapy_logistic_reg.py b/examples/python/mesapy_logistic_reg.py
+index 1838c16..6d00ce5 100644
+--- a/examples/python/mesapy_logistic_reg.py
++++ b/examples/python/mesapy_logistic_reg.py
+@@ -23,7 +23,7 @@ An example about Logistic Regression in MesaPy.
+ import sys
+ import binascii
+ from typing import List
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ from enum import Enum
+@@ -117,7 +117,7 @@ class ConfigClient:
+             name=functionname,
+             description="worker: %s" % functionname,
+             executor_type=ex.name,
+-            arguments=list(args.keys()),
++            arguments=[FunctionArgument(arg) for arg in args],
+             payload=list(p_str),
+             inputs=[
+                 FunctionInput(label, "user input data file: %s" % label)
+diff --git a/examples/python/test_default_arguments.py b/examples/python/test_default_arguments.py
+new file mode 100644
+index 0000000..aca7d5d
+--- /dev/null
++++ b/examples/python/test_default_arguments.py
+@@ -0,0 +1,77 @@
++#!/usr/bin/env python3
++
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++import sys
++
++from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service
++from teaclave import FunctionArgument
++
++
++class BuiltinEchoExample:
++
++    def __init__(self, user_id, user_password):
++        self.user_id = user_id
++        self.user_password = user_password
++
++    def echo(self, message="Hello, Teaclave!"):
++        with connect_authentication_service() as client:
++            print("[+] login")
++            token = client.user_login(self.user_id, self.user_password)
++
++        with connect_frontend_service() as client:
++            metadata = {"id": self.user_id, "token": token}
++            client.metadata = metadata
++
++            print("[+] registering function")
++            function_id = client.register_function(
++                name="builtin-echo",
++                description="Native Echo Function",
++                executor_type="builtin",
++                arguments=[
++                    FunctionArgument("message", "Hello, Cleanroom", False)
++                ])
++
++            print("[+] creating task")
++            task_id = client.create_task(function_id=function_id,
++                                         function_arguments={},
++                                         executor="builtin")
++
++            print("[+] invoking task")
++            client.invoke_task(task_id)
++
++            print("[+] getting result")
++            result = client.get_task_result(task_id)
++            print("[+] done")
++
++        return bytes(result)
++
++
++def main():
++    example = BuiltinEchoExample(USER_ID, USER_PASSWORD)
++    if len(sys.argv) > 1:
++        message = sys.argv[1]
++        rt = example.echo(message)
++    else:
++        rt = example.echo()
++
++    print("[+] function return: ", rt)
++
++
++if __name__ == '__main__':
++    main()
+diff --git a/examples/python/test_disable_function.py b/examples/python/test_disable_function.py
+index 5c51e6d..dbea609 100644
+--- a/examples/python/test_disable_function.py
++++ b/examples/python/test_disable_function.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ 
+@@ -50,12 +50,13 @@ class ConfigClient:
+ 
+         print(f"[+] {self.user_id} registering function")
+ 
+-        function_id = client.register_function(name=func_name,
+-                                               description=func_name,
+-                                               executor_type="builtin",
+-                                               arguments=["num_user"],
+-                                               inputs=[],
+-                                               outputs=[])
++        function_id = client.register_function(
++            name=func_name,
++            description=func_name,
++            executor_type="builtin",
++            arguments=[FunctionArgument("num_user")],
++            inputs=[],
++            outputs=[])
+ 
+         return function_id
+ 
+diff --git a/examples/python/wasm_c_simple_add.py b/examples/python/wasm_c_simple_add.py
+index c45175a..b53c5a4 100644
+--- a/examples/python/wasm_c_simple_add.py
++++ b/examples/python/wasm_c_simple_add.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap, FunctionArgument
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ 
+@@ -45,11 +45,13 @@ class WASMAddExample:
+         with open(payload_file, "rb") as f:
+             payload = f.read()
+ 
+-        function_id = client.register_function(name="entrypoint",
+-                                               description="test of wasm",
+-                                               executor_type="wamr",
+-                                               payload=list(payload),
+-                                               arguments=["adder1", "adder2"])
++        function_id = client.register_function(
++            name="entrypoint",
++            description="test of wasm",
++            executor_type="wamr",
++            payload=list(payload),
++            arguments=[FunctionArgument("adder1"),
++                       FunctionArgument("adder2")])
+ 
+         print("[+] creating task")
+         task_id = client.create_task(function_id=function_id,
+diff --git a/examples/python/wasm_rust_psi.py b/examples/python/wasm_rust_psi.py
+index 2713802..53ab0e2 100644
+--- a/examples/python/wasm_rust_psi.py
++++ b/examples/python/wasm_rust_psi.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ 
+@@ -102,7 +102,10 @@ class Client:
+             payload=list(payload),
+             executor_type="wamr",
+             arguments=[
+-                "input1_fid", "input2_fid", "output1_fid", "output2_fid"
++                FunctionArgument("input1_fid"),
++                FunctionArgument("input2_fid"),
++                FunctionArgument("output1_fid"),
++                FunctionArgument("output2_fid")
+             ],
+             inputs=[
+                 FunctionInput(USER_DATA_0.input_fid, "Client 0 data."),
+diff --git a/examples/python/wasm_rust_psi_payload/Cargo.lock b/examples/python/wasm_rust_psi_payload/Cargo.lock
+index 2819d2d..d367651 100644
+--- a/examples/python/wasm_rust_psi_payload/Cargo.lock
++++ b/examples/python/wasm_rust_psi_payload/Cargo.lock
+@@ -2,7 +2,7 @@
+ # It is not intended for manual editing.
+ [[package]]
+ name = "teaclave_context"
+-version = "0.4.0"
++version = "0.2.0"
+ 
+ [[package]]
+ name = "wasm_rust_psi_payload"
+diff --git a/examples/python/wasm_tvm_mnist.py b/examples/python/wasm_tvm_mnist.py
+index 90d1d09..6f33807 100644
+--- a/examples/python/wasm_tvm_mnist.py
++++ b/examples/python/wasm_tvm_mnist.py
+@@ -19,7 +19,7 @@
+ 
+ import sys
+ 
+-from teaclave import FunctionInput, FunctionOutput, OwnerList, DataMap
++from teaclave import FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap
+ from utils import USER_ID, USER_PASSWORD, connect_authentication_service, connect_frontend_service, PlatformAdmin
+ 
+ # If you're using `docker-compose` to start the Teaclave server containers,
+@@ -61,7 +61,7 @@ def main():
+         description="WAMR TVM MNIST Prediction",
+         payload=list(payload),
+         executor_type="wamr",
+-        arguments=["input_img"],
++        arguments=[FunctionArgument("input_img")],
+         inputs=[
+             FunctionInput("input_img",
+                           "Input image for handwriting number perdiction")
+diff --git a/examples/python/wasm_tvm_mnist_payload/Cargo.lock b/examples/python/wasm_tvm_mnist_payload/Cargo.lock
+index 8af6ccb..5d2ad33 100644
+--- a/examples/python/wasm_tvm_mnist_payload/Cargo.lock
++++ b/examples/python/wasm_tvm_mnist_payload/Cargo.lock
+@@ -1632,7 +1632,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_context"
+-version = "0.4.0"
++version = "0.2.0"
+ 
+ [[package]]
+ name = "tempfile"
+diff --git a/examples/rust/builtin_echo/Cargo.lock b/examples/rust/builtin_echo/Cargo.lock
+index 34be5b6..c3634a3 100644
+--- a/examples/rust/builtin_echo/Cargo.lock
++++ b/examples/rust/builtin_echo/Cargo.lock
+@@ -50,7 +50,7 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+ 
+ [[package]]
+ name = "builtin_echo"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "pem",
+@@ -359,7 +359,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "protected_fs_rs"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "cfg-if 0.1.10",
+  "libc",
+@@ -553,7 +553,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_attestation"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "base64 0.13.0",
+@@ -581,7 +581,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_client_sdk"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "libc",
+@@ -597,7 +597,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_config"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "log",
+@@ -608,7 +608,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_crypto"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "hex",
+@@ -621,7 +621,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_proto"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "base64 0.13.0",
+@@ -640,7 +640,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_rpc"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "cfg-if 0.1.10",
+@@ -659,7 +659,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_rpc_proc_macro"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "proc-macro2",
+  "quote",
+@@ -668,7 +668,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_types"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "hex",
+diff --git a/examples/rust/builtin_echo/Cargo.toml b/examples/rust/builtin_echo/Cargo.toml
+index 3f46b0e..95203f0 100644
+--- a/examples/rust/builtin_echo/Cargo.toml
++++ b/examples/rust/builtin_echo/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "builtin_echo"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "builtin_echo function example using Teaclave client SDK."
+ license = "Apache-2.0"
+diff --git a/examples/rust/builtin_ordered_set_intersect/Cargo.lock b/examples/rust/builtin_ordered_set_intersect/Cargo.lock
+index 972321b..4e3bf21 100644
+--- a/examples/rust/builtin_ordered_set_intersect/Cargo.lock
++++ b/examples/rust/builtin_ordered_set_intersect/Cargo.lock
+@@ -50,7 +50,7 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+ 
+ [[package]]
+ name = "builtin_ordered_set_intersect"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "pem",
+@@ -359,7 +359,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "protected_fs_rs"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "cfg-if 0.1.10",
+  "libc",
+@@ -553,7 +553,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_attestation"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "base64 0.13.0",
+@@ -581,7 +581,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_client_sdk"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "libc",
+@@ -597,7 +597,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_config"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "log",
+@@ -608,7 +608,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_crypto"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "hex",
+@@ -621,7 +621,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_proto"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "base64 0.13.0",
+@@ -640,7 +640,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_rpc"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "cfg-if 0.1.10",
+@@ -659,7 +659,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_rpc_proc_macro"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "proc-macro2",
+  "quote",
+@@ -668,7 +668,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_types"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "hex",
+diff --git a/examples/rust/builtin_ordered_set_intersect/Cargo.toml b/examples/rust/builtin_ordered_set_intersect/Cargo.toml
+index f297aa7..b4ca1e7 100644
+--- a/examples/rust/builtin_ordered_set_intersect/Cargo.toml
++++ b/examples/rust/builtin_ordered_set_intersect/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "builtin_ordered_set_intersect"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "builtin_ordered_set_intersect function example using Teaclave client SDK."
+ license = "Apache-2.0"
+diff --git a/executor/Cargo.toml b/executor/Cargo.toml
+index 6f3832b..e32219e 100644
+--- a/executor/Cargo.toml
++++ b/executor/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_executor"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave executor"
+ license = "Apache-2.0"
+@@ -58,6 +58,9 @@ full_builtin_function = [
+   "builtin_principal_components_analysis",
+   "builtin_private_join_and_compute",
+   "builtin_rsa_sign",
++  "builtin_cleanroom_algorithm2_hash",
++  "builtin_cleanroom_algorithm2_hash_trial",
++  "builtin_cleanroom_algorithm2_hash_trial_tier2",
+ ]
+ 
+ builtin_echo = []
+@@ -72,9 +75,13 @@ builtin_ordered_set_intersect = []
+ builtin_principal_components_analysis = []
+ builtin_private_join_and_compute = []
+ builtin_rsa_sign = []
++builtin_cleanroom_algorithm2_hash = []
++builtin_cleanroom_algorithm2_hash_trial = []
++builtin_cleanroom_algorithm2_hash_trial_tier2 = []
++
+ 
+ [dependencies]
+-log           = { version = "0.4.6", features = ["release_max_level_info"] }
++log           = { version = "0.4.6", features = ["release_max_level_debug"] }
+ anyhow        = { version = "1.0.26" }
+ serde_json    = { version = "1.0.39" }
+ serde         = { version = "1.0.92", features = ["derive"] }
+diff --git a/executor/context/Cargo.toml b/executor/context/Cargo.toml
+index 662fa40..05760d1 100644
+--- a/executor/context/Cargo.toml
++++ b/executor/context/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_executor_context"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave executor"
+ license = "Apache-2.0"
+diff --git a/executor/src/builtin.rs b/executor/src/builtin.rs
+index a327432..17ce3dc 100644
+--- a/executor/src/builtin.rs
++++ b/executor/src/builtin.rs
+@@ -19,9 +19,10 @@
+ use std::prelude::v1::*;
+ 
+ use teaclave_function::{
+-    Echo, FaceDetection, GbdtPredict, GbdtTrain, LogisticRegressionPredict,
+-    LogisticRegressionTrain, OnlineDecrypt, OrderedSetIntersect, PasswordCheck,
+-    PrincipalComponentsAnalysis, PrivateJoinAndCompute, RsaSign,
++    Echo, FaceDetection, GbdtPredict, GbdtTrain, Algorithm2Hash, Algorithm2HashTrial,
++    Algorithm2HashTrialTier2, LogisticRegressionPredict, LogisticRegressionTrain, OnlineDecrypt,
++    OrderedSetIntersect, PasswordCheck, PrincipalComponentsAnalysis, PrivateJoinAndCompute,
++    RsaSign,
+ };
+ use teaclave_types::{FunctionArguments, FunctionRuntime, TeaclaveExecutor};
+ 
+@@ -65,6 +66,14 @@ impl TeaclaveExecutor for BuiltinFunctionExecutor {
+             }
+             #[cfg(feature = "builtin_face_detection")]
+             FaceDetection::NAME => FaceDetection::new().run(arguments, runtime),
++            #[cfg(feature = "builtin_cleanroom_algorithm2_hash")]
++            Algorithm2Hash::NAME => Algorithm2Hash::new().run(arguments, runtime),
++            #[cfg(feature = "builtin_cleanroom_algorithm2_hash_trial")]
++            Algorithm2HashTrial::NAME => Algorithm2HashTrial::new().run(arguments, runtime),
++            #[cfg(feature = "builtin_cleanroom_algorithm2_hash_trial_tier2")]
++            Algorithm2HashTrialTier2::NAME => {
++                Algorithm2HashTrialTier2::new().run(arguments, runtime)
++            }
+             #[cfg(feature = "builtin_password_check")]
+             PasswordCheck::NAME => PasswordCheck::new().run(arguments, runtime),
+             _ => bail!("Function not found."),
+diff --git a/executor/src/cleanroom.rs b/executor/src/cleanroom.rs
+new file mode 100644
+index 0000000..bf1e811
+--- /dev/null
++++ b/executor/src/cleanroom.rs
+@@ -0,0 +1,547 @@
++// Licensed to the Apache Software Foundation (ASF) under one
++// or more contributor license agreements.  See the NOTICE file
++// distributed with this work for additional information
++// regarding copyright ownership.  The ASF licenses this file
++// to you under the Apache License, Version 2.0 (the
++// "License"); you may not use this file except in compliance
++// with the License.  You may obtain a copy of the License at
++//
++//   http://www.apache.org/licenses/LICENSE-2.0
++//
++// Unless required by applicable law or agreed to in writing,
++// software distributed under the License is distributed on an
++// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++// KIND, either express or implied.  See the License for the
++// specific language governing permissions and limitations
++// under the License.
++
++use std::prelude::v1::*;
++
++use teaclave_executor_context::context::reset_thread_context;
++use teaclave_executor_context::context::set_thread_context;
++use teaclave_executor_context::context::Context;
++
++use anyhow::anyhow;
++use serde::{Deserialize, Serialize};
++use std::ffi::{c_void, CStr, CString};
++use std::os::raw::c_char;
++use std::ptr;
++use std::time::SystemTime;
++#[cfg(feature = "mesalock_sgx")]
++use std::untrusted::time::SystemTimeEx;
++
++use teaclave_types::{FunctionArguments, FunctionRuntime, TeaclaveExecutor};
++
++const DEFAULT_HEAP_SIZE: u32 = 0;
++const DEFAULT_STACK_SIZE: u32 = 463840;
++const DEFAULT_ERROR_BUF_SIZE: usize = 128;
++
++#[allow(unused)]
++#[no_mangle]
++pub static mut DEBUG_FLAG: i32 = 0;
++
++#[repr(C)]
++#[derive(Debug)]
++struct NativeSymbol {
++    symbol: *const c_char,
++    func_ptr: *const c_void,
++    signature: *const c_char,
++    attachment: *const c_void,
++}
++
++#[allow(unused)]
++#[no_mangle]
++pub extern "C" fn rust_printf(c_buf: *const c_char) {
++    let c_str = unsafe { CStr::from_ptr(c_buf) };
++    let str_slice = c_str.to_string_lossy();
++    log::debug!("Cleanroom: {:?}", str_slice);
++}
++
++#[allow(unused)]
++#[no_mangle]
++pub extern "C" fn teaclave_sgx_log(c_buf: *const c_char) {
++    let c_str = unsafe { CStr::from_ptr(c_buf) };
++    let str_slice = c_str.to_string_lossy();
++    log::warn!(
++        "Cleanroom: The ocall function {:?} should not be reachable.",
++        str_slice
++    );
++}
++
++#[derive(Serialize, Deserialize)]
++struct Summary {
++    status: bool,
++    reason: String,
++    execution_time: f32,
++}
++
++extern "C" {
++
++    fn wasm_runtime_init() -> bool;
++
++    fn wasm_runtime_load(
++        buf: *const u8,
++        size: u32,
++        error_buf: *mut u8,
++        error_buf_size: u32,
++    ) -> *const c_void;
++
++    fn wasm_runtime_set_wasi_args(
++        module: *const c_void,
++        dir_list: *const u8,
++        dir_count: u32,
++        map_dir_list: *const c_void,
++        map_dit_list_count: u32,
++        env_list: *const c_void,
++        env_count: u32,
++        argv: *const u8,
++        argc: u32,
++    );
++
++    fn wasm_application_execute_main(
++        module_inst: *const c_void,
++        argc: u32,
++        argv: *const u8,
++    ) -> bool;
++
++    fn wasm_runtime_instantiate(
++        module: *const c_void,
++        stack_size: u32,
++        heap_size: u32,
++        error_buf: *mut u8,
++        error_buf_size: u32,
++    ) -> *const c_void;
++
++    fn wasm_runtime_get_exception(module_inst: *const c_void) -> *const c_char;
++
++    fn wasm_runtime_deinstantiate(module_inst: *const c_void);
++
++    fn wasm_runtime_unload(module: *const c_void);
++
++    fn wasm_runtime_destroy();
++
++}
++
++fn get_key(arguments: &FunctionArguments, key: &str) -> String {
++    let args = arguments.clone().into_vec();
++    let len = args.len();
++    for (i, arg) in args.iter().enumerate() {
++        if (arg.eq(key)) && i < (len - 1) {
++            return args[i + 1].clone();
++        }
++    }
++    String::from("")
++}
++
++#[derive(Default)]
++pub struct CleanroomRuntime;
++
++impl TeaclaveExecutor for CleanroomRuntime {
++    fn execute(
++        &self,
++        _name: String,
++        arguments: FunctionArguments,
++        payload: Vec<u8>,
++        runtime: FunctionRuntime,
++    ) -> anyhow::Result<String> {
++        let debug_flag = get_key(&arguments, "debug");
++        let argv_string = get_key(&arguments, "args");
++        let dir_argv_string = get_key(&arguments, "wdir");
++        let current_time = SystemTime::now();
++
++        if debug_flag.eq("true") {
++            unsafe { DEBUG_FLAG = 1 };
++        } else {
++            unsafe { DEBUG_FLAG = 0 };
++        }
++        let mut argvs: Vec<String>;
++        if argv_string.trim().is_empty() {
++            argvs = Vec::new();
++        } else {
++            argvs = serde_json::from_str(&argv_string)
++                .map_err(|_| anyhow!("Cleanroom: invalid input arguments"))?;
++            argvs.retain(|x| (!x.is_empty()));
++        }
++        log::warn!("argvs: {:?}", &argvs);
++        let argv_cstr: Vec<_> = argvs
++            .iter()
++            .map(|arg| CString::new(arg.as_str()))
++            .collect::<Result<_, _>>()?;
++
++        let argv: Vec<_> = argv_cstr
++            .iter()
++            .map(|arg| arg.as_bytes_with_nul().as_ptr())
++            .collect();
++        let argc = argv.len();
++        let dir_argvs: Vec<String> = dir_argv_string.split(' ').map(|s| s.to_string()).collect();
++        log::debug!("working directory: {:?}", &dir_argvs);
++        let dir_argv_cstr: Vec<_> = dir_argvs
++            .iter()
++            .map(|arg| CString::new(arg.as_str()))
++            .collect::<Result<_, _>>()?;
++
++        let dir_argv: Vec<_> = dir_argv_cstr
++            .iter()
++            .map(|arg| arg.as_bytes_with_nul().as_ptr())
++            .collect();
++        let dir_argc = dir_argv.len();
++
++        let mut error_buf = [0u8; DEFAULT_ERROR_BUF_SIZE];
++
++        set_thread_context(Context::new(runtime))?;
++        let mut result;
++        let ret = unsafe { wasm_runtime_init() };
++        if !ret {
++            reset_thread_context()?;
++            let time_duration = current_time.elapsed()?;
++            let time_secs = time_duration.as_secs_f32();
++            let summary = Summary {
++                status: false,
++                reason: "wasm runtime init failed".to_string(),
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++
++        let module = unsafe {
++            wasm_runtime_load(
++                payload.as_ptr(),
++                payload.len() as u32,
++                error_buf.as_mut_ptr(),
++                error_buf.len() as u32,
++            )
++        };
++
++        rust_printf(error_buf.as_mut_ptr() as *const i8);
++        if (module as usize) == 0 {
++            unsafe { wasm_runtime_destroy() };
++            reset_thread_context()?;
++            let time_duration = current_time.elapsed()?;
++            let time_secs = time_duration.as_secs_f32();
++
++            let summary = Summary {
++                status: false,
++                reason: "wasm runtime load failed".to_string(),
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++
++        unsafe {
++            wasm_runtime_set_wasi_args(
++                module,
++                dir_argv.as_ptr() as *const u8,
++                dir_argc as u32,
++                ptr::null_mut(),
++                0,
++                ptr::null_mut(),
++                0,
++                argv.as_ptr() as *const u8,
++                argc as u32,
++            )
++        };
++        error_buf = [0u8; DEFAULT_ERROR_BUF_SIZE];
++        let module_instance = unsafe {
++            wasm_runtime_instantiate(
++                module,
++                DEFAULT_STACK_SIZE,
++                DEFAULT_HEAP_SIZE,
++                error_buf.as_mut_ptr(),
++                error_buf.len() as u32,
++            )
++        };
++
++        if (module_instance as usize) == 0 {
++            unsafe { wasm_runtime_unload(module) };
++            unsafe { wasm_runtime_destroy() };
++            reset_thread_context()?;
++            let time_duration = current_time.elapsed()?;
++            let time_secs = time_duration.as_secs_f32();
++            let summary = Summary {
++                status: false,
++                reason: "wasm runtime instantiate failed".to_string(),
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++
++        result = unsafe { wasm_application_execute_main(module_instance, 0, ptr::null_mut()) };
++
++        let exception = unsafe { wasm_runtime_get_exception(module_instance) };
++        unsafe {
++            if !exception.is_null() {
++                log::debug!(
++                    "Exception: {:?}",
++                    CStr::from_ptr(exception).to_string_lossy(),
++                );
++                result = false;
++            }
++        }
++
++        unsafe { wasm_runtime_deinstantiate(module_instance) };
++        unsafe { wasm_runtime_unload(module) };
++        unsafe { wasm_runtime_destroy() };
++        reset_thread_context()?;
++        let time_duration = current_time.elapsed()?;
++        let time_secs = time_duration.as_secs_f32();
++
++        let summary = Summary {
++            status: result,
++            reason: "Succeed".to_string(),
++            execution_time: time_secs,
++        };
++        let summary_result = serde_json::to_string(&summary)?;
++        Ok(summary_result)
++    }
++}
++
++#[cfg(feature = "enclave_unit_test")]
++pub mod tests {
++    use super::*;
++    #[cfg(feature = "mesalock_sgx")]
++    use std::collections::HashMap;
++    use std::untrusted::fs;
++    use teaclave_crypto::*;
++    use teaclave_runtime::*;
++    use teaclave_test_utils::*;
++    use teaclave_types::*;
++
++    const IN_STDIN_FILE: &str = "input_file";
++    const OUT_STDOUT_FILE: &str = "output_file";
++
++    pub fn run_tests() -> bool {
++        run_tests!(
++            test_readfile,
++            test_args,
++            test_stdout,
++            test_stdin,
++            test_algorithm1,
++            test_stderr,
++        )
++    }
++
++    fn test_readfile() {
++        let mut args = HashMap::new();
++        args.insert("args".to_string(), "".to_string());
++        args.insert("wdir".to_string(), "data".to_string());
++        let args = FunctionArguments::from(args);
++        let wa_payload =
++            include_bytes!("../../tests/fixtures/functions/cleanroom-readfile/readfile.wasm");
++
++        let wa_payload = wa_payload.to_vec();
++        let stdin = "fixtures/functions/cleanroom-readfile/stdin";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-readfile/stdout";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file = "fixtures/functions/cleanroom-readfile/data/a.txt";
++        let config_file_info = StagedFileInfo::new(
++            config_file,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(hashmap!(IN_STDIN_FILE => input_info,
++                                                    "data/a.txt" => config_file_info));
++        let output_files = StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++
++        let function = CleanroomRuntime::default();
++        let _summary = function
++            .execute("".to_string(), args, wa_payload, runtime)
++            .unwrap();
++
++        let stdout_result = fs::read_to_string(&stdout).unwrap();
++        log::debug!("{:?}", stdout_result);
++    }
++
++    fn test_stdout() {
++        let args = HashMap::new();
++
++        let args = FunctionArguments::from(args);
++
++        let wa_payload = include_bytes!("../../tests/fixtures/functions/cleanroom-stdout/test.aot");
++
++        let wa_payload = wa_payload.to_vec();
++        let input_seq = "fixtures/functions/cleanroom-stdout/stdin";
++        let input_info =
++            StagedFileInfo::new(input_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let output_seq = "fixtures/functions/cleanroom-stdout/stdout";
++        let output_info = StagedFileInfo::new(
++            output_seq,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(hashmap!(IN_STDIN_FILE => input_info));
++        let output_files = StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++
++        let function = CleanroomRuntime::default();
++        let _summary = function
++            .execute("".to_string(), args, wa_payload, runtime)
++            .unwrap();
++
++        let output_data = fs::read_to_string(&output_seq).unwrap();
++        log::debug!("Hello world: {:?}", output_data);
++    }
++
++    fn test_stdin() {
++        let args = HashMap::new();
++
++        let args = FunctionArguments::from(args);
++
++        let wa_payload =
++            include_bytes!("../../tests/fixtures/functions/cleanroom-stdin/getline.wasm");
++
++        let wa_payload = wa_payload.to_vec();
++        let input_seq = "fixtures/functions/cleanroom-stdin/stdin";
++        let input_info =
++            StagedFileInfo::new(input_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++        let output_seq = "fixtures/functions/cleanroom-stdin/stdout";
++        let output_info = StagedFileInfo::new(
++            output_seq,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(hashmap!(IN_STDIN_FILE => input_info));
++        let output_files = StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++
++        let function = CleanroomRuntime::default();
++        let _summary = function
++            .execute("".to_string(), args, wa_payload, runtime)
++            .unwrap();
++
++        let output_data = fs::read_to_string(&output_seq).unwrap();
++        log::debug!("{:?}", output_data);
++    }
++
++    fn test_args() {
++        let mut args = HashMap::new();
++        args.insert(
++            "args".to_string(),
++            r#"["1", "2", "3", "4", "5", "6", "7"]"#.to_string(),
++        );
++        let args = FunctionArguments::from(args);
++        let wa_payload = include_bytes!("../../tests/fixtures/functions/cleanroom-args/args.wasm");
++
++        let wa_payload = wa_payload.to_vec();
++        let stdin = "fixtures/functions/cleanroom-args/stdin";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-args/stdout";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let input_files = StagedFiles::new(hashmap!(IN_STDIN_FILE => input_info));
++        let output_files = StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++
++        let function = CleanroomRuntime::default();
++        let _summary = function
++            .execute("".to_string(), args, wa_payload, runtime)
++            .unwrap();
++
++        let stdout_result = fs::read_to_string(&stdout).unwrap();
++        log::debug!("{:?}", stdout_result);
++    }
++
++    fn test_algorithm1() {
++        let mut args = HashMap::new();
++        args.insert(
++            "args".to_string(),
++            r#"["algorithm1_v", "100", "0", "0", "0", "0", "0", "5.0", "example.shape"]"#
++                .to_string(),
++        );
++        args.insert("wdir".to_string(), ".".to_string());
++        let args = FunctionArguments::from(args);
++
++        let wa_payload =
++            include_bytes!("../../tests/fixtures/functions/cleanroom-algorithm1/algorithm1.aot");
++
++        let wa_payload = wa_payload.to_vec();
++        let stdin = "fixtures/functions/cleanroom-algorithm1/testseq";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-algorithm1/stdout";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file = "fixtures/functions/cleanroom-algorithm1/example.shape";
++        let config_file_info = StagedFileInfo::new(
++            config_file,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(
++            hashmap!(IN_STDIN_FILE => input_info, "example.shape" => config_file_info),
++        );
++        let output_files = StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++
++        let function = CleanroomRuntime::default();
++        let _summary = function
++            .execute("".to_string(), args, wa_payload, runtime)
++            .unwrap();
++
++        let stdout_result = fs::read_to_string(&stdout).unwrap();
++        log::debug!("{:?}", stdout_result);
++    }
++
++    fn test_stderr() {
++        let mut args = HashMap::new();
++        args.insert("args".to_string(), r#"["1", "12"]"#.to_string());
++        args.insert("debug".to_string(), "true".to_string());
++
++        let args = FunctionArguments::from(args);
++
++        let wa_payload = include_bytes!("../../tests/fixtures/functions/cleanroom-stderr/app.wasm");
++
++        let wa_payload = wa_payload.to_vec();
++        let input_seq = "fixtures/functions/cleanroom-stderr/stdin";
++        let input_info =
++            StagedFileInfo::new(input_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let output_seq = "fixtures/functions/cleanroom-stderr/stdout";
++        let output_info = StagedFileInfo::new(
++            output_seq,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let log_seq = "fixtures/functions/cleanroom-stderr/stderr";
++        let log_info =
++            StagedFileInfo::new(log_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let input_files = StagedFiles::new(hashmap!(IN_STDIN_FILE => input_info));
++        let output_files =
++            StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info,"log_file" => log_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++
++        let function = CleanroomRuntime::default();
++        let _summary = function
++            .execute("cleanroom".to_string(), args, wa_payload, runtime)
++            .unwrap();
++
++        let output_data = fs::read_to_string(&output_seq).unwrap();
++        log::debug!("Hello world: {:?}", output_data);
++    }
++}
+diff --git a/executor/src/lib.rs b/executor/src/lib.rs
+index 86a4c2e..691629b 100644
+--- a/executor/src/lib.rs
++++ b/executor/src/lib.rs
+@@ -26,6 +26,7 @@ extern crate log;
+ 
+ #[cfg(executor_builtin)]
+ mod builtin;
++mod cleanroom;
+ #[cfg(executor_mesapy)]
+ mod mesapy;
+ #[cfg(executor_wamr)]
+@@ -33,6 +34,7 @@ mod wamr;
+ 
+ #[cfg(executor_builtin)]
+ pub use builtin::BuiltinFunctionExecutor;
++pub use cleanroom::CleanroomRuntime;
+ #[cfg(executor_mesapy)]
+ pub use mesapy::MesaPy;
+ #[cfg(executor_wamr)]
+@@ -48,8 +50,9 @@ pub mod tests {
+         v.push(mesapy::tests::run_tests());
+         #[cfg(executor_builtin)]
+         v.push(builtin::tests::run_tests());
+-        #[cfg(executor_wamr)]
+-        v.push(wamr::tests::run_tests());
++        //#[cfg(executor_wamr)]
++        //v.push(wamr::tests::run_tests());
++        v.push(cleanroom::tests::run_tests());
+         v.iter().all(|&x| x)
+     }
+ }
+diff --git a/executor/src/wamr.rs b/executor/src/wamr.rs
+index 21c9cb8..4840200 100644
+--- a/executor/src/wamr.rs
++++ b/executor/src/wamr.rs
+@@ -266,6 +266,7 @@ pub mod tests {
+     use teaclave_test_utils::*;
+     use teaclave_types::*;
+ 
++    #[allow(unused)]
+     pub fn run_tests() -> bool {
+         run_tests!(test_wamr_tvm_mnist, test_wamr_millionaire,)
+     }
+diff --git a/file_agent/Cargo.lock b/file_agent/Cargo.lock
+index 2d01445..fdfbc6c 100644
+--- a/file_agent/Cargo.lock
++++ b/file_agent/Cargo.lock
+@@ -715,7 +715,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "protected_fs_rs"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "cfg-if 0.1.10",
+  "libc",
+@@ -1026,7 +1026,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_crypto"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "hex",
+@@ -1039,7 +1039,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_file_agent"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "base64",
+@@ -1061,7 +1061,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_test_utils"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "inventory",
+  "teaclave_test_utils_proc_macro",
+@@ -1078,7 +1078,7 @@ dependencies = [
+ 
+ [[package]]
+ name = "teaclave_types"
+-version = "0.4.0"
++version = "0.2.0"
+ dependencies = [
+  "anyhow",
+  "hex",
+diff --git a/file_agent/Cargo.toml b/file_agent/Cargo.toml
+index 6878669..d656ee7 100644
+--- a/file_agent/Cargo.toml
++++ b/file_agent/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_file_agent"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave file agent for worker"
+ license = "Apache-2.0"
+@@ -31,7 +31,7 @@ crate-type = ["staticlib", "rlib"]
+ default = []
+ 
+ [dependencies]
+-log           = { version = "0.4.6", features = ["release_max_level_info"] }
++log           = { version = "0.4.6", features = ["release_max_level_debug"] }
+ anyhow        = { version = "1.0.26" }
+ base64        = { version = "0.13.0" }
+ serde_json    = { version = "1.0.39" }
+diff --git a/function/Cargo.toml b/function/Cargo.toml
+index 2c94ca4..a8e084e 100644
+--- a/function/Cargo.toml
++++ b/function/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_function"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave built-in functions."
+ license = "Apache-2.0"
+@@ -43,7 +43,7 @@ enclave_unit_test = [
+ ]
+ 
+ [dependencies]
+-log           = { version = "0.4.6", features = ["release_max_level_info"] }
++log           = { version = "0.4.6", features = ["release_max_level_debug"] }
+ anyhow        = { version = "1.0.26" }
+ serde_json    = { version = "1.0.39" }
+ serde         = { version = "1.0.92", features = ["derive"] }
+@@ -63,6 +63,7 @@ teaclave_runtime = { path = "../runtime", optional = true }
+ teaclave_test_utils = { path = "../tests/utils", optional = true }
+ teaclave_executor_context = { path = "../executor/context" }
+ 
++
+ sgx_cov       = { version = "1.1.3", optional = true }
+ sgx_tstd      = { version = "1.1.3", features = ["net", "thread", "backtrace"], optional = true }
+ sgx_types     = { version = "1.1.3" }
+diff --git a/function/src/cleanroom_algorithm2.rs b/function/src/cleanroom_algorithm2.rs
+new file mode 100644
+index 0000000..2f07a24
+--- /dev/null
++++ b/function/src/cleanroom_algorithm2.rs
+@@ -0,0 +1,325 @@
++// Licensed to the Apache Software Foundation (ASF) under one
++// or more contributor license agreements.  See the NOTICE file
++// distributed with this work for additional information
++// regarding copyright ownership.  The ASF licenses this file
++// to you under the Apache License, Version 2.0 (the
++// "License"); you may not use this file except in compliance
++// with the License.  You may obtain a copy of the License at
++//
++//   http://www.apache.org/licenses/LICENSE-2.0
++//
++// Unless required by applicable law or agreed to in writing,
++// software distributed under the License is distributed on an
++// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++// KIND, either express or implied.  See the License for the
++// specific language governing permissions and limitations
++// under the License.
++
++use std::prelude::v1::*;
++
++use teaclave_executor_context::context::reset_thread_context;
++use teaclave_executor_context::context::set_thread_context;
++use teaclave_executor_context::context::Context;
++
++use crate::cleanroom_algorithm2_hash::CLEANROOM_NATIVE_DEBUG_FLAG;
++use anyhow::anyhow;
++use serde::{Deserialize, Serialize};
++use std::ffi::{CStr, CString};
++use std::format;
++use std::time::SystemTime;
++use teaclave_types::{FunctionArguments, FunctionRuntime};
++
++#[cfg(feature = "mesalock_sgx")]
++use std::untrusted::time::SystemTimeEx;
++
++#[derive(Default)]
++pub struct Algorithm2;
++
++const DEFAULT_ERROR_BUF_SIZE: usize = 128;
++
++#[derive(Serialize, Deserialize)]
++struct Summary {
++    status: bool,
++    reason: String,
++    execution_time: f32,
++}
++
++extern "C" {
++    fn call_algorithm2_classic(
++        argc: u32,
++        argv: *const u8,
++        error_buf: *mut u8,
++        error_buf_size: u32,
++        error_code: *mut u32,
++    ) -> u32;
++}
++
++fn get_key(arguments: &FunctionArguments, key: &str) -> String {
++    let args = arguments.clone().into_vec();
++    let len = args.len();
++    for (i, arg) in args.iter().enumerate() {
++        if (arg.eq(key)) && i < (len - 1) {
++            return args[i + 1].clone();
++        }
++    }
++    String::from("")
++}
++
++impl Algorithm2 {
++    pub const NAME: &'static str = "builtin-cleanroom-algorithm2";
++
++    pub fn new() -> Self {
++        Default::default()
++    }
++
++    pub fn run(
++        &self,
++        arguments: FunctionArguments,
++        runtime: FunctionRuntime,
++    ) -> anyhow::Result<String> {
++        let debug_flag = get_key(&arguments, "debug");
++        let argv_string = get_key(&arguments, "args");
++        let current_time = SystemTime::now();
++        log::info!("Hello cleanroom algorithm2: {:?}", arguments.into_vec());
++
++        if debug_flag.eq("true") {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 1 };
++        } else {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 0 };
++        }
++
++        let mut argvs: Vec<String>;
++        if argv_string.trim().is_empty() {
++            argvs = Vec::new();
++        } else {
++            argvs = serde_json::from_str(&argv_string)
++                .map_err(|_| anyhow!("Cleanroom: invalid input arguments"))?;
++            argvs.retain(|x| (!x.is_empty()));
++        }
++        log::warn!("argvs: {:?}", &argvs);
++        let argv_cstr: Vec<_> = argvs
++            .iter()
++            .map(|arg| CString::new(arg.as_str()))
++            .collect::<Result<_, _>>()?;
++        let argv: Vec<_> = argv_cstr
++            .iter()
++            .map(|arg| arg.as_bytes_with_nul().as_ptr())
++            .collect();
++        let argc = argv.len();
++        let mut error_buf = [0u8; DEFAULT_ERROR_BUF_SIZE];
++        let mut error_code = 0;
++        set_thread_context(Context::new(runtime))?;
++        let ret = unsafe {
++            call_algorithm2_classic(
++                argc as u32,
++                argv.as_ptr() as *const u8,
++                error_buf.as_mut_ptr(),
++                error_buf.len() as u32,
++                &mut error_code,
++            )
++        };
++        log::warn!("Return code {:?}", ret);
++        reset_thread_context()?;
++        let time_duration = current_time.elapsed()?;
++        let time_secs = time_duration.as_secs_f32();
++        if error_code != 0 {
++            let buf_str = unsafe { CStr::from_ptr(error_buf.as_mut_ptr() as *const i8) };
++            let buf_str_slice = buf_str.to_string_lossy();
++            let result_exception = format!(
++                "Function got exceptions ({}). Reason: {}",
++                error_code, buf_str_slice,
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_exception,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        if ret != 0 {
++            let result_error_code = format!(
++                "Function returned with error code: {}. Please enable the diagnosis mode.",
++                ret
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_error_code,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        let summary = Summary {
++            status: true,
++            reason: "Succeeded".to_string(),
++            execution_time: time_secs,
++        };
++        let summary_result = serde_json::to_string(&summary)?;
++        Ok(summary_result)
++    }
++}
++
++#[cfg(feature = "enclave_unit_test")]
++pub mod tests {
++    use super::*;
++    #[cfg(feature = "mesalock_sgx")]
++    use std::collections::HashMap;
++    use std::untrusted::fs;
++    use teaclave_crypto::*;
++    use teaclave_runtime::*;
++    use teaclave_test_utils::*;
++    use teaclave_types::*;
++
++    const IN_STDIN_FILE: &str = "input_file";
++    const OUT_STDOUT_FILE: &str = "output_file";
++
++    pub fn run_tests() -> bool {
++        run_tests!(
++            test_cleanroom_native,
++            test_algorithm2_stderr_native,
++            test_algorithm2_exception_native
++        )
++    }
++
++    fn test_cleanroom_native() {
++        let mut args = HashMap::new();
++        args.insert(
++            "args".to_string(),
++            r#"["algorithm2", "100", "200"]"#.to_string(),
++        );
++        let args = FunctionArguments::from(args);
++
++        let stdin = "fixtures/functions/cleanroom-algorithm2-hash/stdin";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-algorithm2-hash/stdout";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file1 = "fixtures/functions/cleanroom-algorithm2-hash/coding_wheel.txt";
++        let config_file_info1 = StagedFileInfo::new(
++            config_file1,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let config_file2 =
++            "fixtures/functions/cleanroom-algorithm2-hash/codon_usage_freq_table_human.csv";
++        let config_file_info2 = StagedFileInfo::new(
++            config_file2,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(
++            hashmap!(IN_STDIN_FILE => input_info, "./coding_wheel.txt" => config_file_info1, "./codon_usage_freq_table_human.csv" => config_file_info2),
++        );
++
++        let output_files = StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++        let function = Algorithm2;
++
++        let summary = function.run(args, runtime).unwrap();
++        log::warn!("{:?}", summary);
++    }
++
++    fn test_algorithm2_stderr_native() {
++        let mut args = HashMap::new();
++        args.insert("args".to_string(), r#"["algorithm2"]"#.to_string());
++        args.insert("debug".to_string(), "true".to_string());
++        let args = FunctionArguments::from(args);
++
++        let stdin = "fixtures/functions/cleanroom-algorithm2-hash/stdin";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-algorithm2-hash/stdout1";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let log_seq = "fixtures/functions/cleanroom-algorithm2-hash/stderr1";
++        let log_info =
++            StagedFileInfo::new(log_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file1 = "fixtures/functions/cleanroom-algorithm2-hash/coding_wheel.txt";
++        let config_file_info1 = StagedFileInfo::new(
++            config_file1,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let config_file2 =
++            "fixtures/functions/cleanroom-algorithm2-hash/codon_usage_freq_table_human.csv";
++        let config_file_info2 = StagedFileInfo::new(
++            config_file2,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(
++            hashmap!(IN_STDIN_FILE => input_info, "./coding_wheel.txt" => config_file_info1, "./codon_usage_freq_table_human.csv" => config_file_info2),
++        );
++
++        let output_files =
++            StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info, "log_file" => log_info));
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++        let function = Algorithm2;
++
++        let summary = function.run(args, runtime).unwrap();
++        log::warn!("{:?}", summary);
++        let log_info = fs::read_to_string(&log_seq).unwrap();
++        log::warn!("Stderr result: {:?}", log_info);
++    }
++
++    fn test_algorithm2_exception_native() {
++        let mut args = HashMap::new();
++        args.insert(
++            "args".to_string(),
++            r#"["algorithm2", "100", "200"]"#.to_string(),
++        );
++        args.insert("debug".to_string(), "true".to_string());
++        let args = FunctionArguments::from(args);
++
++        let stdin = "fixtures/functions/cleanroom-algorithm2-hash/stdin2";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-algorithm2-hash/stdout2";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let log_seq = "fixtures/functions/cleanroom-algorithm2-hash/stderr2";
++        let log_info =
++            StagedFileInfo::new(log_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file1 = "fixtures/functions/cleanroom-algorithm2-hash/coding_wheel.txt";
++        let config_file_info1 = StagedFileInfo::new(
++            config_file1,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let config_file2 =
++            "fixtures/functions/cleanroom-algorithm2-hash/codon_usage_freq_table_human.csv";
++        let config_file_info2 = StagedFileInfo::new(
++            config_file2,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(
++            hashmap!(IN_STDIN_FILE => input_info, "./coding_wheel.txt" => config_file_info1, "./codon_usage_freq_table_human.csv" => config_file_info2),
++        );
++
++        let output_files =
++            StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info, "log_file" => log_info));
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++        let function = Algorithm2;
++
++        let summary = function.run(args, runtime).unwrap();
++        log::warn!("{:?}", summary);
++    }
++}
+diff --git a/function/src/cleanroom_algorithm2_hash.rs b/function/src/cleanroom_algorithm2_hash.rs
+new file mode 100644
+index 0000000..f98041a
+--- /dev/null
++++ b/function/src/cleanroom_algorithm2_hash.rs
+@@ -0,0 +1,338 @@
++// Licensed to the Apache Software Foundation (ASF) under one
++// or more contributor license agreements.  See the NOTICE file
++// distributed with this work for additional information
++// regarding copyright ownership.  The ASF licenses this file
++// to you under the Apache License, Version 2.0 (the
++// "License"); you may not use this file except in compliance
++// with the License.  You may obtain a copy of the License at
++//
++//   http://www.apache.org/licenses/LICENSE-2.0
++//
++// Unless required by applicable law or agreed to in writing,
++// software distributed under the License is distributed on an
++// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++// KIND, either express or implied.  See the License for the
++// specific language governing permissions and limitations
++// under the License.
++
++use std::prelude::v1::*;
++
++use teaclave_executor_context::context::reset_thread_context;
++use teaclave_executor_context::context::set_thread_context;
++use teaclave_executor_context::context::Context;
++
++use anyhow::anyhow;
++use serde::{Deserialize, Serialize};
++use std::ffi::{CStr, CString};
++use std::format;
++use std::os::raw::c_char;
++use std::time::SystemTime;
++use teaclave_types::{FunctionArguments, FunctionRuntime};
++
++#[cfg(feature = "mesalock_sgx")]
++use std::untrusted::time::SystemTimeEx;
++
++#[derive(Default)]
++pub struct Algorithm2Hash;
++
++const DEFAULT_ERROR_BUF_SIZE: usize = 128;
++
++#[allow(unused)]
++#[no_mangle]
++pub static mut CLEANROOM_NATIVE_DEBUG_FLAG: i32 = 0;
++
++#[allow(unused)]
++#[no_mangle]
++pub extern "C" fn cleanroom_native_printf(c_buf: *const c_char) {
++    let c_str = unsafe { CStr::from_ptr(c_buf) };
++    let str_slice = c_str.to_string_lossy();
++    log::debug!("Cleanroom Algorithm2 hash: {:?}", str_slice);
++}
++
++#[derive(Serialize, Deserialize)]
++struct Summary {
++    status: bool,
++    reason: String,
++    execution_time: f32,
++}
++
++extern "C" {
++    fn call_algorithm2(
++        argc: u32,
++        argv: *const u8,
++        error_buf: *mut u8,
++        error_buf_size: u32,
++        error_code: *mut u32,
++    ) -> u32;
++}
++
++fn get_key(arguments: &FunctionArguments, key: &str) -> String {
++    let args = arguments.clone().into_vec();
++    let len = args.len();
++    for (i, arg) in args.iter().enumerate() {
++        if (arg.eq(key)) && i < (len - 1) {
++            return args[i + 1].clone();
++        }
++    }
++    String::from("")
++}
++
++impl Algorithm2Hash {
++    pub const NAME: &'static str = "builtin-cleanroom-algorithm2-hash";
++
++    pub fn new() -> Self {
++        Default::default()
++    }
++
++    pub fn run(
++        &self,
++        arguments: FunctionArguments,
++        runtime: FunctionRuntime,
++    ) -> anyhow::Result<String> {
++        let debug_flag = get_key(&arguments, "debug");
++        let argv_string = get_key(&arguments, "args");
++        let current_time = SystemTime::now();
++        log::info!("Cleanroom algorithm2 hash: {:?}", arguments.into_vec());
++
++        if debug_flag.eq("true") {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 1 };
++        } else {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 0 };
++        }
++
++        let mut argvs: Vec<String>;
++        if argv_string.trim().is_empty() {
++            argvs = Vec::new();
++        } else {
++            argvs = serde_json::from_str(&argv_string)
++                .map_err(|_| anyhow!("Cleanroom: invalid input arguments"))?;
++            argvs.retain(|x| (!x.is_empty()));
++            argvs.retain(|x| (!x.starts_with("--")));
++        }
++        log::warn!("argvs: {:?}", &argvs);
++        let argv_cstr: Vec<_> = argvs
++            .iter()
++            .map(|arg| CString::new(arg.as_str()))
++            .collect::<Result<_, _>>()?;
++        let argv: Vec<_> = argv_cstr
++            .iter()
++            .map(|arg| arg.as_bytes_with_nul().as_ptr())
++            .collect();
++        let argc = argv.len();
++        let mut error_buf = [0u8; DEFAULT_ERROR_BUF_SIZE];
++        let mut error_code = 0;
++        set_thread_context(Context::new(runtime))?;
++        let ret = unsafe {
++            call_algorithm2(
++                argc as u32,
++                argv.as_ptr() as *const u8,
++                error_buf.as_mut_ptr(),
++                error_buf.len() as u32,
++                &mut error_code,
++            )
++        };
++        log::warn!("Return code {:?}", ret);
++        reset_thread_context()?;
++        let time_duration = current_time.elapsed()?;
++        let time_secs = time_duration.as_secs_f32();
++        if error_code != 0 {
++            let buf_str = unsafe { CStr::from_ptr(error_buf.as_mut_ptr() as *const i8) };
++            let buf_str_slice = buf_str.to_string_lossy();
++            let result_exception = format!(
++                "Function got exceptions ({}). Reason: {}",
++                error_code, buf_str_slice,
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_exception,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        if ret != 0 {
++            let result_error_code = format!(
++                "Function returned with error code: {}. Please enable the diagnosis mode.",
++                ret
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_error_code,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        let summary = Summary {
++            status: true,
++            reason: "Succeeded".to_string(),
++            execution_time: time_secs,
++        };
++        let summary_result = serde_json::to_string(&summary)?;
++        Ok(summary_result)
++    }
++}
++
++#[cfg(feature = "enclave_unit_test")]
++pub mod tests {
++    use super::*;
++    #[cfg(feature = "mesalock_sgx")]
++    use std::collections::HashMap;
++    use std::untrusted::fs;
++    use teaclave_crypto::*;
++    use teaclave_runtime::*;
++    use teaclave_test_utils::*;
++    use teaclave_types::*;
++
++    const IN_STDIN_FILE: &str = "input_file";
++    const OUT_STDOUT_FILE: &str = "output_file";
++
++    pub fn run_tests() -> bool {
++        run_tests!(
++            test_cleanroom_native,
++            test_algorithm2_stderr_native,
++            test_algorithm2_exception_native
++        )
++    }
++
++    fn test_cleanroom_native() {
++        let mut args = HashMap::new();
++        args.insert(
++            "args".to_string(),
++            r#"["algorithm2", "100", "200"]"#.to_string(),
++        );
++        let args = FunctionArguments::from(args);
++
++        let stdin = "fixtures/functions/cleanroom-algorithm2-hash/stdin";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-algorithm2-hash/stdout";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file1 = "fixtures/functions/cleanroom-algorithm2-hash/coding_wheel.txt";
++        let config_file_info1 = StagedFileInfo::new(
++            config_file1,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let config_file2 =
++            "fixtures/functions/cleanroom-algorithm2-hash/codon_usage_freq_table_human.csv";
++        let config_file_info2 = StagedFileInfo::new(
++            config_file2,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(
++            hashmap!(IN_STDIN_FILE => input_info, "./coding_wheel.txt" => config_file_info1, "./codon_usage_freq_table_human.csv" => config_file_info2),
++        );
++
++        let output_files = StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info));
++
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++        let function = Algorithm2Hash;
++
++        let summary = function.run(args, runtime).unwrap();
++        log::warn!("{:?}", summary);
++    }
++
++    fn test_algorithm2_stderr_native() {
++        let mut args = HashMap::new();
++        args.insert("args".to_string(), r#"["algorithm2"]"#.to_string());
++        args.insert("debug".to_string(), "true".to_string());
++        let args = FunctionArguments::from(args);
++
++        let stdin = "fixtures/functions/cleanroom-algorithm2-hash/stdin";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-algorithm2-hash/stdout1";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let log_seq = "fixtures/functions/cleanroom-algorithm2-hash/stderr1";
++        let log_info =
++            StagedFileInfo::new(log_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file1 = "fixtures/functions/cleanroom-algorithm2-hash/coding_wheel.txt";
++        let config_file_info1 = StagedFileInfo::new(
++            config_file1,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let config_file2 =
++            "fixtures/functions/cleanroom-algorithm2-hash/codon_usage_freq_table_human.csv";
++        let config_file_info2 = StagedFileInfo::new(
++            config_file2,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(
++            hashmap!(IN_STDIN_FILE => input_info, "./coding_wheel.txt" => config_file_info1, "./codon_usage_freq_table_human.csv" => config_file_info2),
++        );
++
++        let output_files =
++            StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info, "log_file" => log_info));
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++        let function = Algorithm2Hash;
++
++        let summary = function.run(args, runtime).unwrap();
++        log::warn!("{:?}", summary);
++        let log_info = fs::read_to_string(&log_seq).unwrap();
++        log::warn!("Stderr result: {:?}", log_info);
++    }
++
++    fn test_algorithm2_exception_native() {
++        let mut args = HashMap::new();
++        args.insert(
++            "args".to_string(),
++            r#"["algorithm2", "100", "200"]"#.to_string(),
++        );
++        args.insert("debug".to_string(), "true".to_string());
++        let args = FunctionArguments::from(args);
++
++        let stdin = "fixtures/functions/cleanroom-algorithm2-hash/stdin2";
++        let input_info =
++            StagedFileInfo::new(stdin, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let stdout = "fixtures/functions/cleanroom-algorithm2-hash/stdout2";
++        let output_info =
++            StagedFileInfo::new(stdout, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let log_seq = "fixtures/functions/cleanroom-algorithm2-hash/stderr2";
++        let log_info =
++            StagedFileInfo::new(log_seq, TeaclaveFile128Key::random(), FileAuthTag::mock());
++
++        let config_file1 = "fixtures/functions/cleanroom-algorithm2-hash/coding_wheel.txt";
++        let config_file_info1 = StagedFileInfo::new(
++            config_file1,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let config_file2 =
++            "fixtures/functions/cleanroom-algorithm2-hash/codon_usage_freq_table_human.csv";
++        let config_file_info2 = StagedFileInfo::new(
++            config_file2,
++            TeaclaveFile128Key::random(),
++            FileAuthTag::mock(),
++        );
++
++        let input_files = StagedFiles::new(
++            hashmap!(IN_STDIN_FILE => input_info, "./coding_wheel.txt" => config_file_info1, "./codon_usage_freq_table_human.csv" => config_file_info2),
++        );
++
++        let output_files =
++            StagedFiles::new(hashmap!(OUT_STDOUT_FILE => output_info, "log_file" => log_info));
++        let runtime = Box::new(RawIoRuntime::new(input_files, output_files));
++        let function = Algorithm2Hash;
++
++        let summary = function.run(args, runtime).unwrap();
++        log::warn!("{:?}", summary);
++    }
++}
+diff --git a/function/src/cleanroom_algorithm2_hash_trial.rs b/function/src/cleanroom_algorithm2_hash_trial.rs
+new file mode 100644
+index 0000000..1dc38ed
+--- /dev/null
++++ b/function/src/cleanroom_algorithm2_hash_trial.rs
+@@ -0,0 +1,163 @@
++// Licensed to the Apache Software Foundation (ASF) under one
++// or more contributor license agreements.  See the NOTICE file
++// distributed with this work for additional information
++// regarding copyright ownership.  The ASF licenses this file
++// to you under the Apache License, Version 2.0 (the
++// "License"); you may not use this file except in compliance
++// with the License.  You may obtain a copy of the License at
++//
++//   http://www.apache.org/licenses/LICENSE-2.0
++//
++// Unless required by applicable law or agreed to in writing,
++// software distributed under the License is distributed on an
++// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++// KIND, either express or implied.  See the License for the
++// specific language governing permissions and limitations
++// under the License.
++
++use std::prelude::v1::*;
++
++use crate::cleanroom_algorithm2_hash::CLEANROOM_NATIVE_DEBUG_FLAG;
++use anyhow::anyhow;
++use serde::{Deserialize, Serialize};
++use std::ffi::{CStr, CString};
++use std::format;
++use std::time::SystemTime;
++use teaclave_executor_context::context::reset_thread_context;
++use teaclave_executor_context::context::set_thread_context;
++use teaclave_executor_context::context::Context;
++use teaclave_types::{FunctionArguments, FunctionRuntime};
++
++#[cfg(feature = "mesalock_sgx")]
++use std::untrusted::time::SystemTimeEx;
++
++#[derive(Default)]
++pub struct Algorithm2HashTrial;
++
++const DEFAULT_ERROR_BUF_SIZE: usize = 128;
++
++#[derive(Serialize, Deserialize)]
++struct Summary {
++    status: bool,
++    reason: String,
++    execution_time: f32,
++}
++
++extern "C" {
++    fn call_algorithm2_trial(
++        argc: u32,
++        argv: *const u8,
++        error_buf: *mut u8,
++        error_buf_size: u32,
++        error_code: *mut u32,
++    ) -> u32;
++}
++
++fn get_key(arguments: &FunctionArguments, key: &str) -> String {
++    let args = arguments.clone().into_vec();
++    let len = args.len();
++    for (i, arg) in args.iter().enumerate() {
++        if (arg.eq(key)) && i < (len - 1) {
++            return args[i + 1].clone();
++        }
++    }
++    String::from("")
++}
++
++impl Algorithm2HashTrial {
++    pub const NAME: &'static str = "builtin-cleanroom-algorithm2-hash-trial";
++
++    pub fn new() -> Self {
++        Default::default()
++    }
++
++    pub fn run(
++        &self,
++        arguments: FunctionArguments,
++        runtime: FunctionRuntime,
++    ) -> anyhow::Result<String> {
++        let debug_flag = get_key(&arguments, "debug");
++        let argv_string = get_key(&arguments, "args");
++        let current_time = SystemTime::now();
++        log::info!(
++            "Cleanroom algorithm2 hash trial: {:?}",
++            arguments.into_vec()
++        );
++
++        if debug_flag.eq("true") {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 1 };
++        } else {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 0 };
++        }
++
++        let mut argvs: Vec<String>;
++        if argv_string.trim().is_empty() {
++            argvs = Vec::new();
++        } else {
++            argvs = serde_json::from_str(&argv_string)
++                .map_err(|_| anyhow!("Cleanroom: invalid input arguments"))?;
++            argvs.retain(|x| (!x.is_empty()));
++        }
++        log::warn!("argvs: {:?}", &argvs);
++        let argv_cstr: Vec<_> = argvs
++            .iter()
++            .map(|arg| CString::new(arg.as_str()))
++            .collect::<Result<_, _>>()?;
++        let argv: Vec<_> = argv_cstr
++            .iter()
++            .map(|arg| arg.as_bytes_with_nul().as_ptr())
++            .collect();
++        let argc = argv.len();
++        let mut error_buf = [0u8; DEFAULT_ERROR_BUF_SIZE];
++        let mut error_code = 0;
++        set_thread_context(Context::new(runtime))?;
++        let ret = unsafe {
++            call_algorithm2_trial(
++                argc as u32,
++                argv.as_ptr() as *const u8,
++                error_buf.as_mut_ptr(),
++                error_buf.len() as u32,
++                &mut error_code,
++            )
++        };
++        log::warn!("Return code {:?}", ret);
++        reset_thread_context()?;
++        let time_duration = current_time.elapsed()?;
++        let time_secs = time_duration.as_secs_f32();
++        if error_code != 0 {
++            let buf_str = unsafe { CStr::from_ptr(error_buf.as_mut_ptr() as *const i8) };
++            let buf_str_slice = buf_str.to_string_lossy();
++            let result_exception = format!(
++                "Function got exceptions ({}). Reason: {}",
++                error_code, buf_str_slice,
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_exception,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        if ret != 0 {
++            let result_error_code = format!(
++                "Function returned with error code: {}. Please enable the diagnosis mode.",
++                ret
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_error_code,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        let summary = Summary {
++            status: true,
++            reason: "Succeeded".to_string(),
++            execution_time: time_secs,
++        };
++        let summary_result = serde_json::to_string(&summary)?;
++        Ok(summary_result)
++    }
++}
+diff --git a/function/src/cleanroom_algorithm2_hash_trial_tier2.rs b/function/src/cleanroom_algorithm2_hash_trial_tier2.rs
+new file mode 100644
+index 0000000..44740b4
+--- /dev/null
++++ b/function/src/cleanroom_algorithm2_hash_trial_tier2.rs
+@@ -0,0 +1,207 @@
++// Licensed to the Apache Software Foundation (ASF) under one
++// or more contributor license agreements.  See the NOTICE file
++// distributed with this work for additional information
++// regarding copyright ownership.  The ASF licenses this file
++// to you under the Apache License, Version 2.0 (the
++// "License"); you may not use this file except in compliance
++// with the License.  You may obtain a copy of the License at
++//
++//   http://www.apache.org/licenses/LICENSE-2.0
++//
++// Unless required by applicable law or agreed to in writing,
++// software distributed under the License is distributed on an
++// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++// KIND, either express or implied.  See the License for the
++// specific language governing permissions and limitations
++// under the License.
++
++use std::prelude::v1::*;
++
++use crate::cleanroom_algorithm2_hash::CLEANROOM_NATIVE_DEBUG_FLAG;
++use anyhow::anyhow;
++use serde::{Deserialize, Serialize};
++use std::ffi::{CStr, CString};
++use std::format;
++use std::time::SystemTime;
++use teaclave_executor_context::context::reset_thread_context;
++use teaclave_executor_context::context::set_thread_context;
++use teaclave_executor_context::context::Context;
++use teaclave_types::{FunctionArguments, FunctionRuntime};
++
++#[cfg(feature = "mesalock_sgx")]
++use std::untrusted::time::SystemTimeEx;
++
++#[derive(Default)]
++pub struct Algorithm2HashTrialTier2;
++
++const DEFAULT_ERROR_BUF_SIZE: usize = 128;
++
++#[derive(Serialize, Deserialize)]
++struct Summary {
++    status: bool,
++    reason: String,
++    execution_time: f32,
++}
++
++/**
++ * Call algorithm2 trial tier2 function wrapper.
++ *
++ * [IN]  @param argc the number of arguments. The wrapper only proceeds when the argc is 5.
++ * [IN]  @param argv the arguments array. argv[1] = default_beamsize argv[2] = default_lambda argv[3] = candidate_beamsize argv[4] = candidate_lambda. Each array is serialized as a string. Items in the array are splited with ';'. e.g., [1,2,3] is serialized as "1;2;3;"
++ * [OUT] @param error_buf
++ * [OUT] @param error_buf_size
++ * [OUT] @param error_code
++ *
++ * @return 0 if the algorithm2 always returns 0. Callers can check the error code and the
++ *  error_buf to know the reason.
++ */
++extern "C" {
++    fn call_algorithm2_trial2(
++        argc: u32,
++        argv: *const u8,
++        error_buf: *mut u8,
++        error_buf_size: u32,
++        error_code: *mut u32,
++    ) -> u32;
++}
++
++fn get_key(arguments: &FunctionArguments, key: &str) -> String {
++    let args = arguments.clone().into_vec();
++    let len = args.len();
++    for (i, arg) in args.iter().enumerate() {
++        if (arg.eq(key)) && i < (len - 1) {
++            return args[i + 1].clone();
++        }
++    }
++    String::from("")
++}
++
++impl Algorithm2HashTrialTier2 {
++    pub const NAME: &'static str = "builtin-cleanroom-algorithm2-hash-trial-tier2";
++
++    pub fn new() -> Self {
++        Default::default()
++    }
++
++    pub fn run(
++        &self,
++        arguments: FunctionArguments,
++        runtime: FunctionRuntime,
++    ) -> anyhow::Result<String> {
++        let debug_flag = get_key(&arguments, "debug");
++        let argv_string = get_key(&arguments, "args");
++        let current_time = SystemTime::now();
++        let beamsize_default: [i32; 4] = [10, 100, 500, 1000];
++        let lambda_default: [f32; 9] = [0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 7.0, 10.0];
++        let beamsize_candidate: [i32; 4] = [5, 6, 8, 50];
++        let lambda_candidate: [f32; 2] = [0.02, 0.3];
++        log::info!(
++            "Cleanroom algorithm2 hash trial tier2: {:?}",
++            arguments.into_vec()
++        );
++
++        if debug_flag.eq("true") {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 1 };
++        } else {
++            unsafe { CLEANROOM_NATIVE_DEBUG_FLAG = 0 };
++        }
++
++        let mut argvs: Vec<String>;
++        if argv_string.trim().is_empty() {
++            argvs = Vec::new();
++        } else {
++            argvs = serde_json::from_str(&argv_string)
++                .map_err(|_| anyhow!("Cleanroom: invalid input arguments"))?;
++            argvs.retain(|x| (!x.is_empty()));
++        }
++        if argvs.len() != 5 {
++            log::info!("Use default arguments");
++            argvs.clear();
++            let argv = "cleanroom".to_string();
++            argvs.push(argv);
++            let argv = beamsize_default
++                .iter()
++                .map(|i| format!("{};", i))
++                .collect::<String>();
++            argvs.push(argv);
++            let argv = lambda_default
++                .iter()
++                .map(|i| format!("{};", i))
++                .collect::<String>();
++            argvs.push(argv);
++            let argv = beamsize_candidate
++                .iter()
++                .map(|i| format!("{};", i))
++                .collect::<String>();
++            argvs.push(argv);
++            let argv = lambda_candidate
++                .iter()
++                .map(|i| format!("{};", i))
++                .collect::<String>();
++            argvs.push(argv);
++        } else {
++            log::info!("Use user's arguments");
++        }
++        log::warn!("argvs: {:?}", &argvs);
++        let argv_cstr: Vec<_> = argvs
++            .iter()
++            .map(|arg| CString::new(arg.as_str()))
++            .collect::<Result<_, _>>()?;
++        let argv: Vec<_> = argv_cstr
++            .iter()
++            .map(|arg| arg.as_bytes_with_nul().as_ptr())
++            .collect();
++        let argc = argv.len();
++        let mut error_buf = [0u8; DEFAULT_ERROR_BUF_SIZE];
++        let mut error_code = 0;
++        set_thread_context(Context::new(runtime))?;
++        let ret = unsafe {
++            call_algorithm2_trial2(
++                argc as u32,
++                argv.as_ptr() as *const u8,
++                error_buf.as_mut_ptr(),
++                error_buf.len() as u32,
++                &mut error_code,
++            )
++        };
++        log::warn!("Return code {:?}", ret);
++        reset_thread_context()?;
++        let time_duration = current_time.elapsed()?;
++        let time_secs = time_duration.as_secs_f32();
++        if error_code != 0 {
++            let buf_str = unsafe { CStr::from_ptr(error_buf.as_mut_ptr() as *const i8) };
++            let buf_str_slice = buf_str.to_string_lossy();
++            let result_exception = format!(
++                "Function got exceptions ({}). Reason: {}",
++                error_code, buf_str_slice,
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_exception,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        if ret != 0 {
++            let result_error_code = format!(
++                "Function returned with error code: {}. Please enable the diagnosis mode.",
++                ret
++            );
++            let summary = Summary {
++                status: false,
++                reason: result_error_code,
++                execution_time: time_secs,
++            };
++            let summary_result = serde_json::to_string(&summary)?;
++            return Ok(summary_result);
++        }
++        let summary = Summary {
++            status: true,
++            reason: "Succeeded".to_string(),
++            execution_time: time_secs,
++        };
++        let summary_result = serde_json::to_string(&summary)?;
++        Ok(summary_result)
++    }
++}
+diff --git a/function/src/lib.rs b/function/src/lib.rs
+index 641512c..ce99049 100644
+--- a/function/src/lib.rs
++++ b/function/src/lib.rs
+@@ -22,6 +22,10 @@ extern crate sgx_tstd as std;
+ #[cfg(feature = "mesalock_sgx")]
+ use std::prelude::v1::*;
+ 
++mod cleanroom_algorithm2;
++mod cleanroom_algorithm2_hash;
++mod cleanroom_algorithm2_hash_trial;
++mod cleanroom_algorithm2_hash_trial_tier2;
+ mod echo;
+ mod face_detection;
+ mod gbdt_predict;
+@@ -35,6 +39,10 @@ mod principal_components_analysis;
+ mod private_join_and_compute;
+ mod rsa_sign;
+ 
++pub use cleanroom_algorithm2::Algorithm2;
++pub use cleanroom_algorithm2_hash::Algorithm2Hash;
++pub use cleanroom_algorithm2_hash_trial::Algorithm2HashTrial;
++pub use cleanroom_algorithm2_hash_trial_tier2::Algorithm2HashTrialTier2;
+ pub use echo::Echo;
+ pub use face_detection::FaceDetection;
+ pub use gbdt_predict::GbdtPredict;
+@@ -55,6 +63,8 @@ pub mod tests {
+ 
+     pub fn run_tests() -> bool {
+         check_all_passed!(
++            cleanroom_algorithm2_hash::tests::run_tests(),
++            cleanroom_algorithm2::tests::run_tests(),
+             echo::tests::run_tests(),
+             face_detection::tests::run_tests(),
+             gbdt_predict::tests::run_tests(),
+diff --git a/monitoring/prometheus.py b/monitoring/prometheus.py
+new file mode 100755
+index 0000000..a7d7e79
+--- /dev/null
++++ b/monitoring/prometheus.py
+@@ -0,0 +1,87 @@
++#!/usr/bin/env python3
++from prometheus_client import start_http_server, Counter
++import random
++import time
++import sys
++import re
++
++c = Counter('cleanroom_cpk_usage', 'Description of counter',
++            ['user_id', 'function_id', 'result'])
++f_c = Counter('cleanroom_cpk_usage_function_id', 'Description of counter',
++              ['function_id'])
++u_c = Counter('cleanroom_cpk_usage_user_id', 'Description of counter',
++              ['user_id'])
++
++frontend_service_c = Counter('cleanroom_frontend_service_total',
++                             "Statistics of frontend service",
++                             ['user_id', 'cli_version', 'request'])
++authentication_service_c = Counter('cleanroom_authentication_service_total',
++                                   "Statistics of authentiction service",
++                                   ['user_id', 'cli_version', 'request'])
++
++storage_service_c = Counter('cleanroom_storage_service_total',
++                            "Statistics of storage service", ['request'])
++scheduler_service_c = Counter('cleanroom_scheduler_service_total',
++                              "Statistics of scheduler service", ['request'])
++management_service_c = Counter('cleanroom_management_service_total',
++                               "Statistics of management service", ['request'])
++
++
++def escape_ansi(line: str):
++    ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
++    return ansi_escape.sub('', line)
++
++
++def parse_log(service: str, log: str):
++    log = escape_ansi(log)
++    if "teaclave-execution-service" in service:
++        splits = log.strip().split("[MONITOR] InvokeTask: ")[1].split(",")
++        print(splits)
++        user_id = splits[0].strip('"')
++        function_id = splits[1].strip()
++        result = splits[2].strip()
++
++        c.labels(user_id, function_id, result).inc()
++        f_c.labels(function_id).inc()
++        u_c.labels(user_id).inc()
++    elif "teaclave-frontend-service" in service:
++        splits = log.strip().split("[MONITOR]")[1].split(",")
++        print(splits)
++        user_id = splits[0].strip().strip('"')
++        cli_version = splits[1].strip()
++        request = splits[2].strip()
++        frontend_service_c.labels(user_id, cli_version, request).inc()
++    elif "teaclave-authentication-service" in service:
++        splits = log.strip().split("[MONITOR]")[1].split(",")
++        print(splits)
++        user_id = splits[0].strip().strip('"')
++        cli_version = splits[1].strip()
++        request = splits[2].strip()
++        authentication_service_c.labels(user_id, cli_version, request).inc()
++    elif "teaclave-scheduler-service" in service:
++        splits = log.strip().split("[MONITOR]")[1].split(",")
++        request = splits[2].strip()
++        scheduler_service_c.labels(request).inc()
++    elif "teaclave-storage-service" in service:
++        splits = log.strip().split("[MONITOR]")[1].split(",")
++        request = splits[2].strip()
++        storage_service_c.labels(request).inc()
++    elif "teaclave-management-service" in service:
++        splits = log.strip().split("[MONITOR]")[1].split(",")
++        request = splits[2].strip()
++        management_service_c.labels(request).inc()
++
++
++def main():
++    start_http_server(9000)
++    for l in sys.stdin:
++        try:
++            service, log = (e.strip() for e in l.split("|"))
++            if "[MONITOR]" not in log: continue
++            parse_log(service, log)
++        except Exception as e:
++            print(e)
++
++
++if __name__ == '__main__':
++    main()
+diff --git a/cleanroom-cli/Makefile b/cleanroom-cli/Makefile
+new file mode 100644
+index 0000000..64b1cc7
+--- /dev/null
++++ b/cleanroom-cli/Makefile
+@@ -0,0 +1,29 @@
++PREFIX := install
++OS := $(shell uname -s)
++ARCH := $(shell uname -m)
++
++all: local
++
++local: install
++	cp -r conf $(PREFIX)/conf
++	cp ${CURDIR}/../release/services/enclave_info.toml ${CURDIR}/$(PREFIX)/conf/
++	tar -C $(PREFIX) -cvf ${CURDIR}/cleanroom-cli-${OS}-${ARCH}.tgz bin conf
++
++azure: install
++	cp -r ${CURDIR}/resource/azure/* ${CURDIR}/$(PREFIX)/
++	tar -C ${CURDIR}/$(PREFIX) -cvf ${CURDIR}/cleanroom-cli-${OS}-${ARCH}.tgz bin conf env
++
++install: pyoxidizer
++	mkdir -p ${CURDIR}/$(PREFIX)
++	cp -rf ${CURDIR}/build/*/release/install ${CURDIR}/$(PREFIX)/bin
++
++
++pyoxidizer:
++	pyoxidizer build  --release --path ${CURDIR} 
++
++clean:
++	@rm -rf ${CURDIR}/$(PREFIX)
++	@rm -rf ${CURDIR}/build ${CURDIR}/web_cli ${CURDIR}/package
++	@rm -f ${CURDIR}/*.tgz
++
++.PHONY: clean install deploy
+diff --git a/cleanroom-cli/conf/dcap_root_cert.pem b/cleanroom-cli/conf/dcap_root_cert.pem
+new file mode 100644
+index 0000000..4746925
+--- /dev/null
++++ b/cleanroom-cli/conf/dcap_root_cert.pem
+@@ -0,0 +1,32 @@
++-----BEGIN CERTIFICATE-----
++MIIFdzCCA1+gAwIBAgIUYGJXlZ8CxlRx7P6C+oiRsZAf47UwDQYJKoZIhvcNAQEL
++BQAwSzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRQwEgYDVQQKDAtUZWFjbGF2
++ZSBDQTEZMBcGA1UEAwwQVGVhY2xhdmUgUm9vdCBDQTAeFw0yMDAyMDUxOTA5MjFa
++Fw0zMDAyMDIxOTA5MjFaMEsxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEUMBIG
++A1UECgwLVGVhY2xhdmUgQ0ExGTAXBgNVBAMMEFRlYWNsYXZlIFJvb3QgQ0EwggIi
++MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCpwW+USb44VPeN1zW0DuVv/k7j
++FWbzxx60E3laiPk9K/EQp8L/Ma0mdPWb6O5MkY/DgeLp7UFmgTnBsTNERqAwqZrQ
++drcyyBb3akLEDuiCQWF6B+jZ8PEoSUvLPW+5QeKHvB0KHVon2Z4qNgVnVWTUk26Z
++BUvQjuJHK8GSZx9sS7Aip4s8jkqwWtio7UmRAeOOR5DFj3xZ87BzpWXi/5jD9RLx
++ScnjfR7oM3bnwpQBWyaaBiFUuxB0hZX2HoD1cvjiNshka+XtASquf9WQVj1KgBX/
++J3gUz2UYgYKO5Tr5fdtpuOs/Kbk4FBV10uCzqbSm4tR8aehpIlcADguPPgOIMkrb
++yWEtidEP5CdVETda6HnUnylOtp0Qb+EgPqzJtGlvjOmTvfAKVDTTO9w0K/NVXEMl
++xbaWm0XJgwBM5t4lh8OXw7WmPvCyKYpGfa6lw0CX4S6haMmL2OWYBwcfLSTUntii
++ENRuiBwgTPOvq+9WYMLO+NZ+ILg/j6cvbDB+7mYdsYTmF49KxvpianBRZCk5D/8Y
++/7Ty/NKJKHG0qNfwcPJcsqndiy8nzlFT31hqdDewBqgpgqqXjTJ/Zgv7iTUJ0ZN4
++T+3bo2hkoXw/nsQp+vu5wk1ErQI0G9DlolJGHNpsgYg6dkNpVgO7FEW9cNp4dZoc
++03JgOTfh6fkMD/DMbQIDAQABo1MwUTAdBgNVHQ4EFgQU761M4yztQfbaV8FFK7re
++wSRuJOAwHwYDVR0jBBgwFoAU761M4yztQfbaV8FFK7rewSRuJOAwDwYDVR0TAQH/
++BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAmsqK6jP3ETdkLFuVlE7HNFhQP3Sj
++LcRnrwcIX4X8Wa1Bfi81Cb6AEbE2LqX1tBd0wIeLv9AgEJr3zJLssCB/yxYhyD3i
++La6AP4lxGgckI7XWgwK7BHrDNsWzb5fdp+mn5GAJPzmIWpqIA8Us3UfC08cKhTgL
++lRp5h+u2JHjjLN83BY7poKD1hCf5lKd+a5nNHLTLkMrZOBWz3i7nho4M+9YTeIzm
++7mI/4UqJtUS/yEYw6SZlj3fVHqGHesGTW0ivPb7YLKslflRMnGlaYFK2w+beb3se
++x2L148z2aYBL846feFJ1d+Gvi3FY9W4MzLki+B/9X+aVcIv1OUhQ0v8ARw1gwAOP
++6ogYWzs1/fc3sYY/t4awZHcFDcv07UKDoCmzZ+7DHVwF76zgeYjrRq+YUO6fRpUL
++xRuFXYNylzUqyDCF4rUAB5GrtUvr+8qpHg20Eh5r/R77atOzlLFAlvMhT7TUw27C
++KzHS+OAtUSaRhZfFpDcyCBxTIcWc38K/7ZUKu6O82pudiHnJ2A5UXVqxSAzstJM4
++NEdrMdbIaMx9jiQ+/6JIyrAe1ve/BcFqpOLqEuF6vhBg9du5BdW0JaZDB0jeSFqQ
++Lok/lT48ASwddkUHrFjTst3wXRM1KbxbzSSOrvOPPg4eRhjJUqZgL0akxYZEgEg8
++7Y71NCmZxQdvPmI=
++-----END CERTIFICATE-----
+diff --git a/cleanroom-cli/conf/login.conf b/cleanroom-cli/conf/login.conf
+new file mode 100644
+index 0000000..8a1dfc9
+--- /dev/null
++++ b/cleanroom-cli/conf/login.conf
+@@ -0,0 +1,4 @@
++[login]
++username = 
++token = 
++
+diff --git a/cleanroom-cli/conf/cleanroom.conf b/cleanroom-cli/conf/cleanroom.conf
+new file mode 100644
+index 0000000..7661780
+--- /dev/null
++++ b/cleanroom-cli/conf/cleanroom.conf
+@@ -0,0 +1,10 @@
++[address]
++authentication_service = localhost:7776
++frontend_service = localhost:7777
++file_service = http://localhost:6789
++cli_service = http://localhost:7801
++
++[attestation]
++as_root_ca_cert_path = dcap_root_cert.pem
++enclave_info_path = enclave_info.toml
++
+diff --git a/cleanroom-cli/install.sh b/cleanroom-cli/install.sh
+new file mode 100755
+index 0000000..ab91b03
+--- /dev/null
++++ b/cleanroom-cli/install.sh
+@@ -0,0 +1,193 @@
++#!/bin/sh
++
++set -e
++
++if [ -t 1 ]; then
++  is_tty() {
++    true
++  }
++else
++  is_tty() {
++    false
++  }
++fi
++
++cleanroomcli_dir="$HOME/.cleanroom"
++web_url="https://cli.cleanroom.com/"
++enclave_info_url="https://cli.cleanroom.com/enclave_info.toml"
++
++command_exists() {
++  command -v "$@" >/dev/null 2>&1
++}
++
++
++# Adapted from code and information by Anton Kochkov (@XVilka)
++# Source: https://gist.github.com/XVilka/8346728
++supports_truecolor() {
++  case "$COLORTERM" in
++  truecolor|24bit) return 0 ;;
++  esac
++
++  case "$TERM" in
++  iterm           |\
++  tmux-truecolor  |\
++  linux-truecolor |\
++  xterm-truecolor |\
++  screen-truecolor) return 0 ;;
++  esac
++
++  return 1
++}
++
++
++setup_color() {
++  # Only use colors if connected to a terminal
++  if ! is_tty; then
++    FMT_RAINBOW=""
++    FMT_RED=""
++    FMT_GREEN=""
++    FMT_YELLOW=""
++    FMT_BLUE=""
++    FMT_BOLD=""
++    FMT_RESET=""
++    return
++  fi
++
++  if supports_truecolor; then
++    FMT_RAINBOW="
++      $(printf '\033[38;2;255;0;0m')
++      $(printf '\033[38;2;255;97;0m')
++      $(printf '\033[38;2;247;255;0m')
++      $(printf '\033[38;2;0;255;30m')
++      $(printf '\033[38;2;77;0;255m')
++      $(printf '\033[38;2;168;0;255m')
++      $(printf '\033[38;2;245;0;172m')
++    "
++  else
++    FMT_RAINBOW="
++      $(printf '\033[38;5;196m')
++      $(printf '\033[38;5;202m')
++      $(printf '\033[38;5;226m')
++      $(printf '\033[38;5;082m')
++      $(printf '\033[38;5;021m')
++      $(printf '\033[38;5;093m')
++      $(printf '\033[38;5;163m')
++    "
++  fi
++
++  FMT_RED=$(printf '\033[31m')
++  FMT_GREEN=$(printf '\033[92m')
++  FMT_YELLOW=$(printf '\033[33m')
++  FMT_BLUE=$(printf '\033[34m')
++  FMT_BOLD=$(printf '\033[1m')
++  FMT_RESET=$(printf '\033[0m')
++}
++
++curl_wrapper(){
++  source="$1"
++  option="$2"
++  destination="$3"
++  rm -f "$destination"
++  curl "$source" "$option" > "$destination"
++}
++
++download_cleanroomcli() {
++    echo "${FMT_GREEN}Downloading Cleanroom CLI...${FMT_RESET}"
++    mkdir -p "$cleanroomcli_dir"
++    current_dir="$PWD"
++    arch="$(uname -m)"
++    cd "$cleanroomcli_dir"
++    OS="$(uname -s)"
++      case "${OS}" in
++      Linux*)     
++        if [ "$arch" = "x86_64" ]; then
++          cli_package_name="cleanroom-cli-${OS}-${arch}.tgz"
++        else
++          echo "Not supported architecture: ${OS}-${arch}"
++          exit 1
++        fi;
++      ;;
++      Darwin*)
++        if [ "$arch" = "x86_64" ]; then
++          cli_package_name="cleanroom-cli-${OS}-${arch}.tgz"
++        elif [ "$arch" = "arm64" ]; then
++          cli_package_name="cleanroom-cli-${OS}-${arch}.tgz"
++        else
++          echo "Not supported architecture: ${OS}-${arch}"
++          exit 1
++        fi;
++      ;;
++      *)
++      echo "${FMT_YELLOW}${OS}-${arch} is not supported.${FMT_RESET}"
++      exit 1
++      esac
++    echo "$cli_package_name"
++    release_url="${web_url}${cli_package_name}"
++    curl_wrapper $release_url "--progress-bar" $cli_package_name
++    tar xf $cli_package_name
++    curl_wrapper $enclave_info_url "-s" "conf/enclave_info.toml"
++    rm -f $cli_package_name
++    cd "$current_dir"
++}
++
++matches() {
++    input="$1"
++    pattern="$2"
++    echo "$input" | grep -q "$pattern"
++}
++
++ensure_command_exists() {
++  cmd="$1"
++  if ! command_exists "${cmd}"; then
++    echo "${FMT_YELLOW}${cmd} is not installed.${FMT_RESET} Please install ${cmd} first."
++    exit 1
++  fi
++}
++
++setup_cleanroomcli() {
++    echo "${FMT_GREEN}Setting up Cleanroom CLI environments...${FMT_RESET}"
++    output=$(ps u -p $PPID)
++    parent_shell=${output##* }
++    if matches "${parent_shell}" "bash"; then
++      if ! grep -q ". $cleanroomcli_dir/env" "${HOME}"/.bashrc; then
++        echo ". $cleanroomcli_dir/env" >> "${HOME}"/.bashrc 
++      fi
++    elif matches "${parent_shell}" "zsh"; then
++      if ! grep -q ". $cleanroomcli_dir/env" "${HOME}"/.zshrc; then
++        echo ". $cleanroomcli_dir/env" >> "${HOME}"/.zshrc 
++      fi
++    else
++      echo "${FMT_YELLOW}${parent_shell} is not supported at the present. Please use bash or zsh.${FMT_RESET}"
++    fi
++}
++
++print_success() {
++    echo "${FMT_GREEN}Setup Cleanroom CLI successfully...${FMT_RESET}"
++    echo "To get started you may need to restart your current shell or run 'source $HOME/.cleanroom/env'"
++}
++
++check_env() {
++  	if [ -z "${HOME}" ] ; then
++        echo "HOME environment var is not defined. Please set HOME var by running 'export HOME=<Cleanroom  CLI install path>'"
++        exit 1
++    fi
++}
++
++main() {
++  setup_color
++
++  ensure_command_exists "tar"
++  ensure_command_exists "grep"
++  ensure_command_exists "ps"
++
++  check_env
++  download_cleanroomcli
++  if ! command_exists "cleanroom-cli"; then
++    setup_cleanroomcli
++  fi
++  print_success
++
++}
++
++
++main "$@"
+diff --git a/cleanroom-cli/cleanroom-cli.py b/cleanroom-cli/cleanroom-cli.py
+new file mode 100755
+index 0000000..acba81b
+--- /dev/null
++++ b/cleanroom-cli/cleanroom-cli.py
+@@ -0,0 +1,1366 @@
++#!/usr/bin/env python3
++# PYTHON_ARGCOMPLETE_OK
++
++import argparse
++import getpass
++import sys
++import configparser
++import urllib.parse
++import uuid
++import requests
++import tempfile
++import os
++from os import path
++from urllib.parse import urljoin
++from tabulate import tabulate
++import string
++import random
++import json
++import signal
++import time
++import argcomplete
++import pathlib
++import jwt
++import inspect
++import shutil
++from datetime import timezone
++from datetime import datetime
++from packaging.version import parse as parse_version
++from typing import Tuple, Dict, List, Any
++from urllib.request import Request, urlopen
++from typing import Tuple, Dict, List, Any
++
++__version__ = "0.1.6"
++
++CURRENT_PATH = path.dirname(path.realpath(__file__))
++CURRENT_DIR = os.path.dirname(path.realpath(__file__))
++sys.path.append(path.join(CURRENT_PATH, "../sdk/python"))
++from teaclave import AuthenticationService, FrontendService, FunctionInput, FunctionOutput, FunctionArgument, OwnerList, DataMap, TeaclaveException, FunctionExpirationDate
++
++CWD = os.getcwd()
++
++if path.isdir(path.join(CWD, "conf")):
++    CONFIG_DIR = path.join(CWD, "conf")
++elif path.isdir(path.join(pathlib.Path.home(), ".cleanroom/conf")):
++    CONFIG_DIR = path.join(pathlib.Path.home(), ".cleanroom/conf")
++else:
++    print("Can not find conf files")
++    exit(1)
++
++CONFIG_FILE = path.join(CONFIG_DIR, "cleanroom.conf")
++LOGIN_CONFIG_FILE = path.join(CONFIG_DIR, "login.conf")
++TMP_OUTPUT = path.join(CWD, ".cleanroom_output.txt")
++DUMP_REPORT = False
++
++try:
++    CONFIG = configparser.ConfigParser()
++    CONFIG.read(CONFIG_FILE)
++    LOGIN_CONFIG = configparser.ConfigParser()
++    LOGIN_CONFIG.read(LOGIN_CONFIG_FILE)
++    if not CONFIG["address"]["authentication_service"]:
++        raise Exception("authentication_service address is empty")
++
++    if not CONFIG["address"]["frontend_service"]:
++        raise Exception("authentication_service address is empty")
++
++    if not CONFIG["address"]["file_service"]:
++        raise Exception("file_service address is empty")
++
++    if not CONFIG["address"]["cli_service"]:
++        raise Exception("cli_service address is empty")
++
++    if not CONFIG["attestation"]["as_root_ca_cert_path"]:
++        raise Exception("as_root_ca_cert_path is empty")
++
++    if not CONFIG["attestation"]["enclave_info_path"]:
++        raise Exception("enclave_info_path is empty")
++
++    AS_ROOT_CA_CERT_PATH = path.join(
++        CONFIG_DIR, CONFIG["attestation"]["as_root_ca_cert_path"])
++    ENCLAVE_INFO_PATH = path.join(CONFIG_DIR,
++                                  CONFIG["attestation"]["enclave_info_path"])
++
++except Exception as e:
++    TeaclaveException(f"Failed to read the config file {CONFIG_FILE}: {e}")
++
++FILE_SERVICE_AUTH_HEADERS = {
++    "Authorization":
++    "Basic 001dda666e88921cfa9cecd5935d387b17b16c70022fe119ce69dee0ec84e3d9"
++}
++
++
++def cleanroom_info(info, end='\n'):
++    print('\033[92m' + info + '\033[0m', end=end, flush=True)
++
++
++def cleanroom_warn(warn, end='\n'):
++    print('\033[91m' + warn + '\033[0m', end=end, flush=True)
++
++
++class CleanroomException(TeaclaveException):
++    _cleanroom_error = dict()
++    _cleanroom_error[0] = ('Invalid funtion ID',
++                           'Please run list-functions again')
++    _cleanroom_error[1] = ('Cannot access file services',
++                           'Please check your Internet Connection')
++    _cleanroom_error[2] = ('File not found',
++                           'Please check the location of your input data')
++    _cleanroom_error[3] = ('Service is under maintanance',
++                           'Please wait and try later')
++    _cleanroom_error[4] = ('Invalid input', 'Please enter a valid input')
++    _cleanroom_error[5] = (
++        'Invalid date format',
++        'Please enter a valid date. Format: month/day/year. e.g., 03/01/2021')
++
++    def __init__(self, error_code: int, msg=''):
++        frame, filename, line_number, function_name, lines, index = inspect.stack(
++        )[1]
++        self.function_name = function_name
++        self.error_code = error_code
++        self.message = msg
++
++    def __str__(self):
++        CRED = '\033[91m'
++        CEND = '\033[0m'
++        if (self.error_code) in CleanroomException._cleanroom_error:
++            error = CleanroomException._cleanroom_error[self.error_code][0]
++            action = CleanroomException._cleanroom_error[self.error_code][1]
++            return '\n' + CRED + ('Error: {}. Action: {}. {}'.format(
++                error, action, self.message)) + CEND
++        return str(self.message)
++
++
++def get_role(config):
++    if config['login']['token'] == "":
++        return "NotLogin"
++    try:
++        claims = jwt.decode(config['login']['token'],
++                            options={"verify_signature": False})
++        role = claims['role'].split("-")[0]
++        return role
++    except Exception as e:
++        return "Unknown"
++
++
++def parse_hostport(hp):
++    result = urllib.parse.urlsplit('//' + hp)
++    return result.hostname, result.port
++
++
++def shorten_uuid(fun_uuids):
++    default_length = 8
++    fun_ids = [uuid[-default_length:] for uuid in fun_uuids]
++    fun_ids_set = set(fun_ids)
++    if len(fun_ids_set) != len(fun_uuids):
++        default_length = default_length + 1
++        fun_ids = [uuid[-default_length:] for uuid in fun_uuids]
++        fun_ids_set = set(fun_ids)
++    return fun_ids
++
++
++def uid_to_id(fun_uid):
++    username = LOGIN_CONFIG['login']['username']
++    with connect_frontend_service() as client:
++        functions = client.list_functions(username)
++    fun_uuids = functions['registered_functions'] + functions[
++        'allowed_functions']
++    fun_ids = shorten_uuid(fun_uuids)
++    for i, uuid in enumerate(fun_uuids):
++        if uuid == fun_uid:
++            return fun_ids[i]
++    raise CleanroomException(0)
++
++
++def id_to_uuid(fun_id):
++    username = LOGIN_CONFIG['login']['username']
++    with connect_frontend_service() as client:
++        functions = client.list_functions(username)
++    fun_uuids = functions['registered_functions'] + functions[
++        'allowed_functions']
++    fun_ids = shorten_uuid(fun_uuids)
++    for i, v_id in enumerate(fun_ids):
++        if v_id == fun_id:
++            return fun_uuids[i]
++    raise CleanroomException(0)
++
++
++def yes_or_no(question):
++    cleanroom_info(f'{question} ? (y/n): ')
++    ans = input().strip().lower()
++    if ans not in ['y', 'n']:
++        print(f'{ans} is invalid, please try again...')
++        return yes_or_no(question)
++    if ans == 'y':
++        return True
++    return False
++
++
++def get_algorithm2_hash_time(beamsize, sequence_length) -> float:
++    a = 0.266
++    b = 0.193
++    if sequence_length < beamsize:
++        beamsize = sequence_length
++    return a * beamsize + b * sequence_length
++
++
++def connect_authentication_service():
++    address = parse_hostport(CONFIG["address"]["authentication_service"])
++    if DUMP_REPORT:
++        dump_report = path.join(CWD, "report")
++        if not path.isdir(dump_report):
++            os.mkdir(dump_report)
++    else:
++        dump_report = None
++    client = AuthenticationService(
++        address,
++        AS_ROOT_CA_CERT_PATH,
++        ENCLAVE_INFO_PATH,
++        dump_report,
++    ).connect()
++    client.metadata = {"cli-version": __version__}
++
++    return client
++
++
++def connect_frontend_service():
++    address = parse_hostport(CONFIG["address"]["frontend_service"])
++    if DUMP_REPORT:
++        dump_report = path.join(CWD, "report")
++        if not path.isdir(dump_report):
++            os.mkdir(dump_report)
++    else:
++        dump_report = None
++    client = FrontendService(
++        address,
++        AS_ROOT_CA_CERT_PATH,
++        ENCLAVE_INFO_PATH,
++        dump_report,
++    ).connect()
++    client.metadata = {
++        "id": LOGIN_CONFIG['login']['username'],
++        "token": LOGIN_CONFIG['login']['token'],
++        "cli-version": __version__
++    }
++    return client
++
++
++def login(args):
++    if not args.username:
++        args.username = input("Username: ")
++    if not args.password:
++        args.password = getpass.getpass()
++    with connect_authentication_service() as client:
++        token = client.user_login(args.username, args.password)
++        LOGIN_CONFIG['login']['username'] = args.username
++        LOGIN_CONFIG['login']['token'] = token
++        with open(LOGIN_CONFIG_FILE, 'w') as f:
++            LOGIN_CONFIG.write(f)
++    cleanroom_info(f"Login successfully")
++
++
++def change_password(args):
++    with connect_authentication_service() as client:
++        client.metadata.update({
++            "id": LOGIN_CONFIG['login']['username'],
++            "token": LOGIN_CONFIG['login']['token']
++        })
++        client.user_change_password(args.password)
++        logout(None)
++    cleanroom_info(f"Password change successfully, login you new password.")
++
++
++def logout(args):
++    LOGIN_CONFIG['login']['username'] = ""
++    LOGIN_CONFIG['login']['token'] = ""
++    with open(LOGIN_CONFIG_FILE, 'w') as f:
++        LOGIN_CONFIG.write(f)
++    cleanroom_info(f"Logout successfully")
++
++
++def update_shell_profile(shell_path):
++    shell_content = []
++    if path.isfile(shell_path):
++        with open(shell_path) as f:
++            shell_content = f.readlines()
++        origin_lines = len(shell_content)
++        shell_content = [
++            line for line in shell_content if ".cleanroom/env" not in line
++        ]
++        current_lines = len(shell_content)
++        if origin_lines != current_lines:
++            try:
++                temp_file = tempfile.NamedTemporaryFile(
++                    delete=False,
++                    dir=path.join(pathlib.Path.home(), ".cleanroom"))
++                with open(temp_file.name, 'w') as f:
++                    for line in shell_content:
++                        f.write(line)
++                    f.flush()
++                os.replace(temp_file.name, shell_path)
++            except Exception as e:
++                if os.path.exists(temp_file.name):
++                    try:
++                        os.unlink(temp_file.name)
++                    except:
++                        pass
++
++
++def uninstall(args):
++    bashrc_path = path.join(pathlib.Path.home(), ".bashrc")
++    zshrc_path = path.join(pathlib.Path.home(), ".zshrc")
++    update_shell_profile(bashrc_path)
++    update_shell_profile(zshrc_path)
++    cleanroomcli_path = path.join(pathlib.Path.home(), ".cleanroom")
++    if path.isdir(cleanroomcli_path):
++        shutil.rmtree(cleanroomcli_path, ignore_errors=True)
++    else:
++        cleanroom_info(f"Cannot find the install directory")
++        exit(1)
++    cleanroom_info(f"Uninstall successfully, please restart your shell.")
++
++
++def register_user(args):
++    with connect_authentication_service() as client:
++        client.metadata.update({
++            "id": LOGIN_CONFIG['login']['username'],
++            "token": LOGIN_CONFIG['login']['token']
++        })
++        if args.role:
++            role = args.role
++        else:
++            role = "DataOwner"
++        if args.attribute:
++            attribute = args.attribute
++        else:
++            if args.role == "DataOwnerManager":
++                attribute = args.username
++            else:
++                attribute = LOGIN_CONFIG['login']['username']
++        client.user_register(args.username, args.password, role, attribute)
++    cleanroom_info(f"Register user successfully: {args.username}")
++
++
++def list_users(_args):
++    user_list = []
++    with connect_authentication_service() as client:
++        client.metadata.update({
++            "id": LOGIN_CONFIG['login']['username'],
++            "token": LOGIN_CONFIG['login']['token']
++        })
++        user_list = client.list_users(LOGIN_CONFIG['login']['username'])
++
++    cleanroom_info("List users successfully, managed users: " +
++                   ", ".join(user_list))
++
++
++def register_cpk(args):
++    with connect_frontend_service() as client:
++        with open(args.cpk, "rb") as f:
++            payload = f.read()
++        if args.diagnosis:
++            outputs = [
++                FunctionOutput("output_file", "Output data"),
++                FunctionOutput("log_file", "Log")
++            ]
++        else:
++            outputs = [
++                FunctionOutput("output_file", "Output data"),
++            ]
++        if args.q:
++            usage_quota = args.q
++        else:
++            usage_quota = -1
++        if args.a:
++            function_arg = FunctionArgument("args", args.a, False)
++        else:
++            function_arg = FunctionArgument("args")
++        function_debug = FunctionArgument("debug")
++        function_id = client.register_function(
++            name=args.name,
++            description=args.description,
++            payload=list(payload),
++            executor_type="cleanroom",
++            arguments=[function_arg, function_debug],
++            inputs=[FunctionInput("input_file", "Input data")],
++            outputs=outputs,
++            user_allowlist=args.user_allowlist,
++            usage_quota=usage_quota)
++    cleanroom_info(f"Register CPK successfully: {function_id}")
++
++
++def register_native(args):
++    with connect_frontend_service() as client:
++        payload = b"not empty"
++        if args.diagnosis:
++            outputs = [
++                FunctionOutput("output_file", "Output data"),
++                FunctionOutput("log_file", "Log")
++            ]
++        else:
++            outputs = [
++                FunctionOutput("output_file", "Output data"),
++            ]
++
++        if args.q:
++            usage_quota = args.q
++        else:
++            usage_quota = -1
++        if args.a:
++            function_arg = FunctionArgument("args", args.a, False)
++        else:
++            function_arg = FunctionArgument("args")
++        function_debug = FunctionArgument("debug")
++        if args.expired:
++            try:
++                date = datetime.strptime(args.expired, "%m/%d/%Y")
++                utc_time = date.replace(tzinfo=timezone.utc)
++                utc_timestamp = utc_time.timestamp()
++            except Exception as e:
++                raise CleanroomException(5)
++            expired_date = FunctionExpirationDate(expired=True,
++                                                  seconds=int(utc_timestamp),
++                                                  nanos=0)
++        else:
++            expired_date = FunctionExpirationDate()
++        function_id = client.register_function(
++            name=args.name,
++            description=args.description,
++            payload=list(payload),
++            executor_type="builtin",
++            arguments=[function_arg, function_debug],
++            inputs=[
++                FunctionInput("input_file", "Input data"),
++                FunctionInput("./coding_wheel.txt", "Coding wheel"),
++                FunctionInput("./codon_usage_freq_table_human.csv",
++                              "Codon usage freq table human"),
++            ],
++            outputs=outputs,
++            user_allowlist=args.user_allowlist,
++            usage_quota=usage_quota,
++            expiration_date=expired_date)
++    cleanroom_info(f"Register native function successfully: {function_id}")
++
++
++class CryptoInfo:
++
++    def __init__(self):
++        self.key = os.urandom(16)
++        self.iv = os.urandom(12)
++        self.cmac = None
++
++
++class CryptoInfo:
++
++    def __init__(self):
++        self.key = os.urandom(16)
++        self.iv = os.urandom(12)
++        self.cmac = None
++
++
++def gen_key():
++    return CryptoInfo()
++
++
++def gen_password():
++    all = string.ascii_letters + string.digits
++    return "".join(random.sample(all, 8))
++
++
++CURRENT_RUNNING_TASK_ID = None
++
++
++def signal_handler(sig, frame):
++    with connect_frontend_service() as client:
++        if not CURRENT_RUNNING_TASK_ID:
++            cleanroom_info(f"Ctrl+C pressed. Canceled.")
++            sys.exit(1)
++        else:
++            cleanroom_info(
++                f"Ctrl+C pressed. Canceling task {CURRENT_RUNNING_TASK_ID}")
++
++        try:
++            client.cancel_task(CURRENT_RUNNING_TASK_ID)
++            time.sleep(3)
++            # cancel twice to make sure the task is canceled
++            client.cancel_task(CURRENT_RUNNING_TASK_ID)
++        except:
++            pass
++        sys.exit(0)
++
++
++def get_task_time(task_id, input_length, args):
++    with connect_frontend_service() as client:
++        task_info = client.get_task(task_id)
++        function_id = task_info['function_id']
++        function_info = client.get_function(function_id)
++    total_time = 0
++    if function_info[
++            'name'] == 'builtin-cleanroom-algorithm2-hash-trial-tier2':
++        default_beam_size = [10, 100, 500, 1000]
++        default_lambda = [0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 7.0, 10.0]
++        ratio = len(default_lambda)
++        for beam in default_beam_size:
++            task_time = get_algorithm2_hash_time(beam, input_length)
++            total_time = total_time + ratio * task_time
++    if total_time > 3600.0:
++        hours = total_time / 3600.0
++        if not args.silent:
++            cleanroom_info(
++                f'Estimating the execution time: {round(hours, 1)} hours...')
++            cleanroom_info(
++                'Please keep the process running and networking available during the execution.'
++            )
++            if yes_or_no('Continue submitting the task') == False:
++                exit(1)
++    elif total_time > 60:
++        minutes = total_time / 60.0
++        if not args.silent:
++            cleanroom_info(
++                f'Estimating the execution time: {round(minutes, 1)} minutes...'
++            )
++            cleanroom_info(
++                'Please keep the process running and networking available during the execution.'
++            )
++            if yes_or_no('Continue submitting the task') == False:
++                exit(1)
++    else:
++        return
++
++
++def run(args):
++    start = time.time()
++    signal.signal(signal.SIGINT, signal_handler)
++    native = False
++    function_uuid = id_to_uuid(args.function_id)
++    with connect_frontend_service() as client:
++        f = client.get_function(function_uuid)
++        if "builtin" in f["executor_type"]: native = True
++    get_function_usage_stats(args)
++    if native:
++        result = run_native(args)
++    else:
++        result = run_cpk(args)
++    end = time.time()
++    elapsed = end - start
++    result = json.loads(result)
++    execution = result["execution_time"]
++    queueing = elapsed - execution
++    cleanroom_info(
++        f"Total Time: {elapsed:.2f}s ({queueing:.2f}s queueing, {execution:.2f}s running)"
++    )
++
++    if result["status"] == True:
++        cleanroom_info("Task succeeded!")
++    else:
++        cleanroom_info(f"Task failed. {result['reason']}")
++    if args.output_file != None:
++        cleanroom_info(f"Output file: {args.output_file}")
++    else:
++        with open(TMP_OUTPUT) as f:
++            print(f.read(), end='')
++        os.unlink(TMP_OUTPUT)
++
++
++def upload_register_input_file(client, file_path):
++    input_crypto = gen_key()
++    if not file_path:
++        input_data_id = client.register_input_file("placeholder://",
++                                                   "aes-gcm-128",
++                                                   list(input_crypto.key),
++                                                   list(input_crypto.iv),
++                                                   [0] * 16)
++        return input_data_id
++
++    if not path.exists(file_path):
++        raise CleanroomException(2, f"File not found: {file_path}")
++
++    internal_file_service_url = "http://teaclave-file-service:6789/"
++    file_service_url = CONFIG['address']['file_service']
++    with tempfile.TemporaryDirectory() as dirpath:
++        encrypted_input_file = str(uuid.uuid1())
++        input_file_path = path.join(dirpath, encrypted_input_file)
++        input_crypto = encrypt(file_path, input_file_path, input_crypto)
++        url = urljoin(file_service_url, encrypted_input_file)
++        try:
++            x = requests.put(url,
++                             data=open(input_file_path, 'rb'),
++                             headers=FILE_SERVICE_AUTH_HEADERS)
++            if x.status_code != 200:
++                raise CleanroomException(1, "Cannot access file service")
++        except:
++            raise CleanroomException(1, "Cannot access file service")
++
++    schema = "aes-gcm-128"
++    url = urljoin(internal_file_service_url, encrypted_input_file)
++    input_data_id = client.register_input_file(url, schema,
++                                               list(input_crypto.key),
++                                               list(input_crypto.iv),
++                                               list(input_crypto.cmac))
++    return input_data_id
++
++
++def run_native(args):
++    if not args.arguments:
++        arguments = []
++    elif len(args.arguments) > 1 and args.arguments[0] == "--":
++        arguments = args.arguments[1:]
++    else:
++        raise Exception("Cannot parse arguments")
++
++    output_crypto = gen_key()
++    diagnosis_crypto = gen_key()
++    file_service_url = CONFIG['address']['file_service']
++    internal_file_service_url = "http://teaclave-file-service:6789/"
++
++    username = [LOGIN_CONFIG['login']['username']]
++    with connect_frontend_service() as client:
++        if args.diagnosis:
++            outputs_ownership = [
++                OwnerList("output_file", username),
++                OwnerList("log_file", username)
++            ]
++            debug = "true"
++        else:
++            outputs_ownership = [
++                OwnerList("output_file", username),
++            ]
++            debug = "false"
++        argument_list = ["cleanroom"]
++        argument_list.extend(arguments)
++        arguments = json.dumps(argument_list)
++        function_uuid = id_to_uuid(args.function_id)
++        task_id = client.create_task(
++            function_id=function_uuid,
++            function_arguments=({
++                "args": arguments,
++                "debug": debug
++            }),
++            executor="builtin",
++            inputs_ownership=[
++                OwnerList("input_file", username),
++                OwnerList("./coding_wheel.txt", username),
++                OwnerList("./codon_usage_freq_table_human.csv", username),
++            ],
++            outputs_ownership=outputs_ownership)
++
++        if args.input_file != None:
++            input_data_id = upload_register_input_file(client, args.input_file)
++            with open(args.input_file) as f:
++                data = f.readlines()
++                if len(data) > 0:
++                    input_length = len(data[0])
++                else:
++                    input_length = 0
++        else:
++            cleanroom_info(
++                'If the input sequence is longer than 1024, please use the option -i=<input file path>'
++            )
++            cleanroom_info('Please enter a valid input: ', end='')
++            sequence = input()
++            if sequence.strip() == '':
++                raise CleanroomException(4)
++            input_length = len(sequence)
++            plain_input_file = str(uuid.uuid1())
++            with tempfile.TemporaryDirectory() as dirpath:
++                plain_input_file = str(uuid.uuid1())
++                input_data_file = path.join(dirpath, plain_input_file)
++                with open(input_data_file, "w") as f:
++                    f.write(sequence)
++                input_data_id = upload_register_input_file(
++                    client, input_data_file)
++
++        coding_whell_data_id = upload_register_input_file(
++            client, args.coding_wheel)
++        codon_data_id = upload_register_input_file(client,
++                                                   args.codon_usage_freq_table)
++        cleanroom_info(f"Creating task with input... done")
++        encrypted_output_file = str(uuid.uuid1())
++
++        schema = "aes-gcm-128"
++        url = urljoin(internal_file_service_url, encrypted_output_file)
++        output_data_id = client.register_output_file(url, schema,
++                                                     list(output_crypto.key),
++                                                     list(output_crypto.iv))
++
++        if args.diagnosis:
++            encrypted_diagnosis_file = str(uuid.uuid1())
++            url = urljoin(internal_file_service_url, encrypted_diagnosis_file)
++            diagnosis_data_id = client.register_output_file(
++                url, schema, list(diagnosis_crypto.key),
++                list(diagnosis_crypto.iv))
++            client.assign_data_to_task(task_id, [
++                DataMap("input_file", input_data_id),
++                DataMap("./coding_wheel.txt", coding_whell_data_id),
++                DataMap("./codon_usage_freq_table_human.csv", codon_data_id),
++            ], [
++                DataMap("output_file", output_data_id),
++                DataMap("log_file", diagnosis_data_id)
++            ])
++        else:
++            client.assign_data_to_task(task_id, [
++                DataMap("input_file", input_data_id),
++                DataMap("./coding_wheel.txt", coding_whell_data_id),
++                DataMap("./codon_usage_freq_table_human.csv", codon_data_id),
++            ], [DataMap("output_file", output_data_id)])
++
++        global CURRENT_RUNNING_TASK_ID
++        CURRENT_RUNNING_TASK_ID = task_id
++        get_task_time(task_id, input_length, args)
++        cleanroom_info("Invoking task...", end=" ")
++        client.invoke_task(task_id)
++        cleanroom_info(f"done")
++        cleanroom_info("Getting result...", end=" ")
++        attempt = 0
++        while True:
++            try:
++                result = client.get_task_result(task_id)
++                break
++            except socket.error:
++                attempt = attempt + 1
++                if attempt < 3:
++                    cleanroom_warn('Networking failure. Reconnecting...')
++                    continue
++                else:
++                    raise TeaclaveException(0)
++        cleanroom_info(f"done")
++        result = ''.join([chr(c) for c in result])
++
++        with tempfile.TemporaryDirectory() as dirpath:
++            output_file_path = path.join(dirpath, encrypted_output_file)
++            url = urljoin(file_service_url, encrypted_output_file)
++            x = requests.get(url, headers=FILE_SERVICE_AUTH_HEADERS)
++            if x.status_code != 200:
++                raise CleanroomException(1, "Cannot access file service")
++            with open(output_file_path, "wb") as f:
++                f.write(x.content)
++            if args.output_file != None:
++                decrypt(output_file_path, args.output_file, output_crypto)
++            else:
++                decrypt(output_file_path, TMP_OUTPUT, output_crypto)
++
++        if args.diagnosis:
++            with tempfile.TemporaryDirectory() as dirpath:
++                output_file_path = path.join(dirpath, encrypted_diagnosis_file)
++                url = urljoin(file_service_url, encrypted_diagnosis_file)
++                x = requests.get(url, headers=FILE_SERVICE_AUTH_HEADERS)
++                if x.status_code != 200:
++                    raise CleanroomException(1, "Cannot access file service")
++                with open(output_file_path, "wb") as f:
++                    f.write(x.content)
++                diagnosis_file_path = "diagnosis.txt"
++                decrypt(output_file_path, "diagnosis.txt", diagnosis_crypto)
++                cleanroom_info(f"Diagnosis file: {diagnosis_file_path}")
++
++        return result
++
++
++def run_cpk(args):
++    if not args.arguments:
++        arguments = []
++    elif args.arguments[0] == "--":
++        arguments = args.arguments[1:]
++    else:
++        raise Exception("Cannot parse arguments")
++
++    input_crypto = gen_key()
++    output_crypto = gen_key()
++    diagnosis_crypto = gen_key()
++    file_service_url = CONFIG['address']['file_service']
++    internal_file_service_url = "http://teaclave-file-service:6789/"
++
++    username = [LOGIN_CONFIG['login']['username']]
++    with connect_frontend_service() as client:
++        if args.diagnosis:
++            outputs_ownership = [
++                OwnerList("output_file", username),
++                OwnerList("log_file", username)
++            ]
++            debug = "true"
++        else:
++            outputs_ownership = [
++                OwnerList("output_file", username),
++            ]
++            debug = "false"
++        argument_list = ["cleanroom"]
++        argument_list.extend(arguments)
++        arguments = json.dumps(argument_list)
++
++        function_uuid = id_to_uuid(args.function_id)
++        task_id = client.create_task(
++            function_id=function_uuid,
++            function_arguments=({
++                "args": arguments,
++                "debug": debug
++            }),
++            executor="cleanroom",
++            inputs_ownership=[OwnerList("input_file", username)],
++            outputs_ownership=outputs_ownership)
++        with tempfile.TemporaryDirectory() as dirpath:
++            encrypted_input_file = str(uuid.uuid1())
++            input_file_path = path.join(dirpath, encrypted_input_file)
++            input_data_file = ""
++            if args.input_file != None:
++                input_data_file = args.input_file
++            else:
++                cleanroom_info('Please enter a valid input: ', end='')
++                sequence = input()
++                if sequence.strip() == '':
++                    raise CleanroomException(4)
++                plain_input_file = str(uuid.uuid1())
++                input_data_file = path.join(dirpath, plain_input_file)
++                with open(input_data_file, "w") as f:
++                    f.write(sequence)
++            input_crypto = encrypt(input_data_file, input_file_path,
++                                   input_crypto)
++            url = urljoin(file_service_url, encrypted_input_file)
++            try:
++                x = requests.put(url,
++                                 data=open(input_file_path, 'rb'),
++                                 headers=FILE_SERVICE_AUTH_HEADERS)
++                if x.status_code != 200:
++                    raise CleanroomException(1, "Cannot access file service")
++            except:
++                raise CleanroomException(1, "Cannot access file service")
++
++        schema = "aes-gcm-128"
++        url = urljoin(internal_file_service_url, encrypted_input_file)
++        input_data_id = client.register_input_file(url, schema,
++                                                   list(input_crypto.key),
++                                                   list(input_crypto.iv),
++                                                   list(input_crypto.cmac))
++
++        encrypted_output_file = str(uuid.uuid1())
++
++        schema = "aes-gcm-128"
++        url = urljoin(internal_file_service_url, encrypted_output_file)
++        output_data_id = client.register_output_file(url, schema,
++                                                     list(output_crypto.key),
++                                                     list(output_crypto.iv))
++
++        if args.diagnosis:
++            encrypted_diagnosis_file = str(uuid.uuid1())
++            url = urljoin(internal_file_service_url, encrypted_diagnosis_file)
++            diagnosis_data_id = client.register_output_file(
++                url, schema, list(diagnosis_crypto.key),
++                list(diagnosis_crypto.iv))
++            client.assign_data_to_task(
++                task_id, [DataMap("input_file", input_data_id)], [
++                    DataMap("output_file", output_data_id),
++                    DataMap("log_file", diagnosis_data_id)
++                ])
++        else:
++            client.assign_data_to_task(
++                task_id, [DataMap("input_file", input_data_id)],
++                [DataMap("output_file", output_data_id)])
++        global CURRENT_RUNNING_TASK_ID
++        CURRENT_RUNNING_TASK_ID = task_id
++        cleanroom_info("Invoking task...", end=" ")
++        client.invoke_task(task_id)
++        cleanroom_info(f"done")
++        cleanroom_info("Getting result...", end=" ")
++        result = client.get_task_result(task_id)
++        cleanroom_info(f"done")
++        result = ''.join([chr(c) for c in result])
++
++        with tempfile.TemporaryDirectory() as dirpath:
++            output_file_path = path.join(dirpath, encrypted_output_file)
++            url = urljoin(file_service_url, encrypted_output_file)
++            x = requests.get(url, headers=FILE_SERVICE_AUTH_HEADERS)
++            if x.status_code != 200:
++                raise CleanroomException(1, "Cannot access file service")
++            with open(output_file_path, "wb") as f:
++                f.write(x.content)
++            if args.output_file != None:
++                decrypt(output_file_path, args.output_file, output_crypto)
++            else:
++                decrypt(output_file_path, TMP_OUTPUT, output_crypto)
++
++        if args.diagnosis:
++            with tempfile.TemporaryDirectory() as dirpath:
++                output_file_path = path.join(dirpath, encrypted_diagnosis_file)
++                url = urljoin(file_service_url, encrypted_diagnosis_file)
++                x = requests.get(url, headers=FILE_SERVICE_AUTH_HEADERS)
++                if x.status_code != 200:
++                    raise CleanroomException(1, "Cannot access file service")
++                with open(output_file_path, "wb") as f:
++                    f.write(x.content)
++                diagnosis_file_path = "diagnosis.txt"
++                decrypt(output_file_path, "diagnosis.txt", diagnosis_crypto)
++                cleanroom_info(f"Diagnosis file: {diagnosis_file_path}")
++
++        return result
++
++
++def list_functions(args):
++
++    def print_function_table(functions, title, extra=False):
++        if not functions: return
++        table = []
++        fun_ids = shorten_uuid(functions)
++        for i, function_id in enumerate(functions):
++            f = client.get_function(function_id)
++            description = f['description'][:75] + (f['description'][75:]
++                                                   and '..')
++            if extra:
++                headers = [
++                    "Function ID", "Owner", "Allowed User Groups",
++                    "Description"
++                ]
++                entry = [
++                    fun_ids[i], f['owner'], ",".join(f['user_allowlist']),
++                    f['description'].replace(';', '\n')
++                ]
++            else:
++                headers = ["Function ID", "Description"]
++                entry = [fun_ids[i], f['description'].replace(';', '\n')]
++            table.append(entry)
++
++        print()
++        cleanroom_info("=== " + title + " ===")
++        print()
++        cleanroom_info(tabulate(table, headers=headers, showindex="always"))
++
++    username = LOGIN_CONFIG['login']['username']
++    with connect_frontend_service() as client:
++        functions = client.list_functions(username)
++        print_function_table(functions['registered_functions'],
++                             "Registered Functions",
++                             extra=True)
++        print_function_table(functions['allowed_functions'],
++                             "Allowed Functions")
++
++
++def get_function_usage_stats(args):
++    username = LOGIN_CONFIG['login']['username']
++    function_uuid = id_to_uuid(args.function_id)
++    with connect_frontend_service() as client:
++        function_usage = client.get_function_usage_stats(
++            username, function_uuid)
++    function_quota = function_usage['function_quota']
++    current_usage = function_usage['current_usage']
++    if (function_quota > 0):
++        cleanroom_info(
++            'Max invocation times: {function_quota}. Current invocation times: {current_usage}.'
++            .format(function_quota=function_quota,
++                    current_usage=current_usage))
++    else:
++        cleanroom_info(
++            f'Max invocation times: inf. Current invocation times: {current_usage}.'
++        )
++
++
++def reset_user_password(args):
++    with connect_authentication_service() as client:
++        client.metadata.update({
++            "id": LOGIN_CONFIG['login']['username'],
++            "token": LOGIN_CONFIG['login']['token']
++        })
++        password = client.reset_user_password(args.username)
++        cleanroom_info(
++            f"Password reset successfully. New password: {password}")
++
++
++def delete_user(args):
++    with connect_authentication_service() as client:
++        client.metadata.update({
++            "id": LOGIN_CONFIG['login']['username'],
++            "token": LOGIN_CONFIG['login']['token']
++        })
++        client.delete_user(args.username)
++        cleanroom_info(f"User delete successfully.")
++
++
++def delete_function(args):
++    with connect_frontend_service() as client:
++        function_uuid = id_to_uuid(args.function)
++        client.disable_function(function_uuid)
++        print(f"Function delete successfully.")
++
++
++def upgrade_cli(args):
++    req = Request(urljoin(CONFIG["address"]["cli_service"], "version"),
++                  headers={'User-Agent': 'Mozilla/5.0'})
++    install_scripts_url = urljoin(CONFIG["address"]["cli_service"],
++                                  "install.sh")
++    cmd = 'sh -c "$(curl -kfsSL {url})"'.format(url=install_scripts_url)
++    try:
++        version = urlopen(req).read().decode('utf-8')
++    except:
++        raise CleanroomException(3)
++    if parse_version(version) > parse_version(__version__):
++        cleanroom_info(
++            "Current version: {v}.".format(v=parse_version(__version__)))
++        cleanroom_info("Latest version: {v}.".format(v=parse_version(version)))
++        cleanroom_info("Upgrading...")
++        os.system(cmd)
++    else:
++        cleanroom_info("Current version: {v} is the latest.".format(
++            v=parse_version(__version__)))
++
++
++def update_enclave_info(args):
++    req = Request(urljoin(CONFIG["address"]["cli_service"],
++                          "enclave_info.toml"),
++                  headers={'User-Agent': 'Mozilla/5.0'})
++    try:
++        enclave_info = urlopen(req).read()
++    except:
++        raise CleanroomException(3)
++    cleanroom_info("Updating ceritficates from:  " + req.full_url)
++    with open(ENCLAVE_INFO_PATH, "wb") as f:
++        f.write(enclave_info)
++
++
++def parse_register_cpk(parser):
++    parser_register_cpk = parser.add_parser('register-cpk',
++                                            help='register CPK')
++    parser_register_cpk.add_argument('-c',
++                                     '--cpk',
++                                     type=str,
++                                     required=True,
++                                     help='CPK file path')
++    parser_register_cpk.add_argument('-n',
++                                     '--name',
++                                     default="function name",
++                                     type=str,
++                                     help='function name')
++    parser_register_cpk.add_argument('-d',
++                                     '--description',
++                                     default="fucntion description",
++                                     type=str,
++                                     help='function description')
++    parser_register_cpk.add_argument('-a',
++                                     required=False,
++                                     type=str,
++                                     help='function arguments')
++    parser_register_cpk.add_argument('-q',
++                                     required=False,
++                                     default=-1,
++                                     type=int,
++                                     help='function available quota')
++    parser_register_cpk.add_argument(
++        '-u',
++        '--user-allowlist',
++        nargs='+',
++        required=True,
++        default="A list of data owner managers can use this function",
++        type=str,
++        help='CPK file path')
++    parser_register_cpk.add_argument('--diagnosis',
++                                     action='store_true',
++                                     help='enable diagnosis mode')
++    parser_register_cpk.set_defaults(func=register_cpk)
++
++
++def parse_register_native(parser):
++    parser_register_native = parser.add_parser('register-native',
++                                               help='register native function')
++    parser_register_native.add_argument('-n',
++                                        '--name',
++                                        default="function name",
++                                        type=str,
++                                        help='function name')
++    parser_register_native.add_argument('-d',
++                                        '--description',
++                                        default="fucntion description",
++                                        type=str,
++                                        help='function description')
++    parser_register_native.add_argument('-a',
++                                        required=False,
++                                        type=str,
++                                        help='function argument')
++    parser_register_native.add_argument('-q',
++                                        default=-1,
++                                        required=False,
++                                        type=int,
++                                        help='function available quota')
++    parser_register_native.add_argument(
++        '-e',
++        '--expired',
++        required=False,
++        type=str,
++        help='function expired-date. format: month/day/year')
++    parser_register_native.add_argument(
++        '-u',
++        '--user-allowlist',
++        nargs='+',
++        required=True,
++        default="A list of data owner managers can use this function",
++        type=str,
++        help='CPK file path')
++    parser_register_native.add_argument('--diagnosis',
++                                        action='store_true',
++                                        help='enable diagnosis mode')
++    parser_register_native.set_defaults(func=register_native)
++
++
++def parse_run(parser):
++    parser_run = parser.add_parser('run', help='run cleanroom function')
++    parser_run.add_argument('-f',
++                            '--function-id',
++                            required=True,
++                            type=str,
++                            help='function ID')
++    parser_run.add_argument('-i',
++                            '--input-file',
++                            type=str,
++                            help='input file path')
++    parser_run.add_argument('-o',
++                            '--output-file',
++                            type=str,
++                            help='output file path')
++    parser_run.add_argument('--coding-wheel',
++                            type=str,
++                            help='coding wheel file path')
++    parser_run.add_argument('--codon-usage-freq-table',
++                            type=str,
++                            help='codon usage freq table')
++    parser_run.add_argument('--diagnosis',
++                            action='store_true',
++                            help='enable diagnosis mode')
++    parser_run.add_argument('--silent',
++                            action='store_true',
++                            help='silence mode')
++    parser_run.add_argument('arguments',
++                            nargs=argparse.REMAINDER,
++                            help='arguments of the function')
++    parser_run.set_defaults(func=run)
++
++
++def parse_register_user(parser):
++    parser_register_user = parser.add_parser('register-user',
++                                             help='register a new user')
++    parser_register_user.add_argument('-u',
++                                      '--username',
++                                      type=str,
++                                      required=True,
++                                      help='username')
++    parser_register_user.add_argument('-p',
++                                      '--password',
++                                      required=True,
++                                      type=str,
++                                      help='password')
++    parser_register_user.add_argument('-r', '--role', type=str, help='Role')
++    parser_register_user.add_argument('-a',
++                                      '--attribute',
++                                      type=str,
++                                      help='Attribute')
++    parser_register_user.set_defaults(func=register_user)
++
++
++def parse_login(parser):
++    parser_login = parser.add_parser('login', help='login')
++    parser_login.add_argument(
++        '-u',
++        '--username',
++        type=str,
++        required=False,
++        help='username, request interactively if not set')
++    parser_login.add_argument(
++        '-p',
++        '--password',
++        required=False,
++        type=str,
++        help='password, request interactively if not set')
++    parser_login.set_defaults(func=login)
++
++
++def parse_change_password(parser):
++    parser_change_password = parser.add_parser('change-password',
++                                               help='change current password')
++    parser_change_password.add_argument('-p',
++                                        '--password',
++                                        type=str,
++                                        required=True,
++                                        help='password')
++    parser_change_password.set_defaults(func=change_password)
++
++
++def parse_delete_user(parser):
++    parser_delete_user = parser.add_parser('delete-user', help='delete user')
++    parser_delete_user.add_argument('-u',
++                                    '--username',
++                                    type=str,
++                                    required=True,
++                                    help='username')
++    parser_delete_user.set_defaults(func=delete_user)
++
++
++def parse_delete_function(parser):
++    parser_delete_function = parser.add_parser('delete-function',
++                                               help='delete function')
++    parser_delete_function.add_argument('-f',
++                                        '--function',
++                                        type=str,
++                                        required=True,
++                                        help='function ID')
++    parser_delete_function.set_defaults(func=delete_function)
++
++
++def parse_check_function_usage(parser):
++    parser_check_function_usage = parser.add_parser(
++        'check-usage', help='check function usage')
++    parser_check_function_usage.add_argument('-f',
++                                             '--function-id',
++                                             type=str,
++                                             required=True,
++                                             help='function ID')
++    parser_check_function_usage.set_defaults(func=get_function_usage_stats)
++
++
++def parse_list_users(parser):
++    parser_login = parser.add_parser('list-users',
++                                     help='list all managed users')
++    parser_login.set_defaults(func=list_users)
++
++
++def parse_logout(parser):
++    parser_logout = parser.add_parser('logout', help='logout')
++    parser_logout.set_defaults(func=logout)
++
++
++def parse_uninstall(parser):
++    parser_uninstall = parser.add_parser('uninstall',
++                                         help='uninstall Cleanroom CLI')
++    parser_uninstall.set_defaults(func=uninstall)
++
++
++def parse_list_functions(parser):
++    parser_run = parser.add_parser('list-functions',
++                                   help='list all cleanroom functions')
++    parser_run.set_defaults(func=list_functions)
++
++
++def parse_reset_user_password(parser):
++    parser_reset_user = parser.add_parser('reset-user-password',
++                                          help='reset user password')
++    parser_reset_user.add_argument('-u',
++                                   '--username',
++                                   type=str,
++                                   required=True,
++                                   help='username')
++    parser_reset_user.set_defaults(func=reset_user_password)
++
++
++def parse_upgrade(parser):
++    parser_upgrade = parser.add_parser('upgrade',
++                                       help='upgrade cleanroom-cli')
++    parser_upgrade.set_defaults(func=upgrade_cli)
++
++
++def parse_update_enclave_info(parser):
++    parser_update_enclave_info = parser.add_parser('update-enclave-info',
++                                                   help='update enclave info')
++    parser_update_enclave_info.set_defaults(func=update_enclave_info)
++
++
++def main() -> int:
++    parser = argparse.ArgumentParser(
++        prog='cleanroom-cli',
++        description='Cleanroom Command Line Interface')
++    parser.add_argument('--version',
++                        action='version',
++                        version='%(prog)s ' + __version__)
++    parser.add_argument('--dump-report',
++                        action='store_true',
++                        help='dump attestation report')
++    parser.set_defaults(dump_report=False)
++    subparsers = parser.add_subparsers()
++
++    parse_login(subparsers)
++    parse_change_password(subparsers)
++    parse_logout(subparsers)
++    parse_upgrade(subparsers)
++    parse_update_enclave_info(subparsers)
++    parse_uninstall(subparsers)
++
++    role = get_role(LOGIN_CONFIG)
++    if role == "DataOwner":
++        parse_run(subparsers)
++        parse_check_function_usage(subparsers)
++        parse_list_functions(subparsers)
++    elif role == "DataOwnerManager":
++        parse_run(subparsers)
++        parse_list_functions(subparsers)
++        parse_check_function_usage(subparsers)
++        parse_register_user(subparsers)
++        parse_reset_user_password(subparsers)
++        parse_delete_user(subparsers)
++        parse_list_users(subparsers)
++    elif role == "FunctionOwner":
++        parse_register_cpk(subparsers)
++        parse_run(subparsers)
++        parse_check_function_usage(subparsers)
++        parse_list_functions(subparsers)
++        parse_register_native(subparsers)
++        parse_delete_function(subparsers)
++    elif role == "NotLogin":
++        pass
++    else:
++        parse_check_function_usage(subparsers)
++        parse_register_user(subparsers)
++        parse_reset_user_password(subparsers)
++        parse_delete_user(subparsers)
++        parse_list_users(subparsers)
++        parse_register_cpk(subparsers)
++        parse_register_native(subparsers)
++        parse_run(subparsers)
++        parse_list_functions(subparsers)
++        parse_delete_function(subparsers)
++
++    try:
++        argcomplete.autocomplete(parser)
++        argcomplete.autocomplete(subparsers)
++        args = parser.parse_args()
++    except:
++        return 1
++
++    if args.dump_report:
++        global DUMP_REPORT
++        DUMP_REPORT = True
++
++    try:
++        args.func(args)
++    except AttributeError:
++        parser.print_help()
++        return 0
++    except CleanroomException as e:
++        if os.path.exists(TMP_OUTPUT):
++            os.unlink(TMP_OUTPUT)
++        print(e, file=sys.stderr)
++        return 0
++    except TeaclaveException as e:
++        if path.exists(TMP_OUTPUT):
++            os.unlink(TMP_OUTPUT)
++        print(e, file=sys.stderr)
++        if e.error_code == 3:
++            cleanroom_info("Updating encalve info...")
++            update_enclave_info(args=None)
++            cleanroom_info("Please run previous command again...")
++        return 0
++    except Exception as e:
++        if path.exists(TMP_OUTPUT):
++            os.unlink(TMP_OUTPUT)
++        print(e, file=sys.stderr)
++        return 1
++
++    return 0
++
++
++from teaclave import aes_gcm_file_encrypt, aes_gcm_file_decrypt
++
++
++def encrypt(input_file: str, output_file: str,
++            crypto_info: CryptoInfo) -> CryptoInfo:
++    crypto_info.cmac = aes_gcm_file_encrypt(crypto_info.key, crypto_info.iv,
++                                            input_file, output_file)
++    return crypto_info
++
++
++def decrypt(input_file: str, output_file: str, crypto_info):
++    return aes_gcm_file_decrypt(crypto_info.key, crypto_info.iv, input_file,
++                                output_file)
++
++
++if __name__ == "__main__":
++    sys.exit(main())
+diff --git a/cleanroom-cli/pyoxidizer.bzl b/cleanroom-cli/pyoxidizer.bzl
+new file mode 100644
+index 0000000..9008874
+--- /dev/null
++++ b/cleanroom-cli/pyoxidizer.bzl
+@@ -0,0 +1,33 @@
++def make_exe():
++    dist = default_python_distribution()
++    policy = dist.make_python_packaging_policy()
++    policy.allow_files = True
++    policy.file_scanner_emit_files = True
++    policy.resources_location = "filesystem-relative:lib"
++    python_config = dist.make_python_interpreter_config()
++    python_config.module_search_paths = ["$ORIGIN/lib"]
++    python_config.run_module = "cleanroom-cli"
++    exe = dist.to_python_executable(
++        name="cleanroom-cli",
++        packaging_policy=policy,
++        config=python_config,
++    )
++    exe.add_python_resources(exe.read_package_root(CWD, ["cleanroom-cli"]))
++    exe.add_python_resources(exe.read_package_root("../sdk/python", ["teaclave"]))
++    for resource in exe.pip_install(["-r", "requirements.txt"]):
++        if type(resource) == "File" and ".so." in resource.path:
++            print("Adding " + resource.path + " to bundle")
++            resource.add_include = True
++        exe.add_python_resource(resource)
++    return exe
++
++def make_install(exe):
++    files = FileManifest()
++    files.add_python_resource(".", exe)
++
++    return files
++
++register_target("exe", make_exe)
++register_target("install", make_install, depends=["exe"], default=True)
++
++resolve_targets()
+diff --git a/cleanroom-cli/readme-0.0.5.md b/cleanroom-cli/readme-0.0.5.md
+new file mode 100644
+index 0000000..4a93b1e
+--- /dev/null
++++ b/cleanroom-cli/readme-0.0.5.md
+@@ -0,0 +1,109 @@
++# Cleanroom CLI v0.0.5
++In this document, we will walk you with the steps to invoke a function as 
++data owners.
++There are two roles in the release: `Data owner manager` and `Data owner`.
++The `Data owner manager` registers users for the `Data owner`.
++
++In the current version, we have registered two demo functions in the Teaclave
++Cleanroom service. In the future, we will also support the role `function owner`,
++who can develop a Cleanroom App with the Cleanroom Development Kit and register
++the functions on their owns.
++
++## Start the Docker
++We have prepared a docker image on the DockerHub. Users can get the docker with 
++the following command.
++```
++docker run --rm \
++        --net="host" \
++        -w /cleanroom_sdk_cli \
++        -it organization/cleanroom-cli:0.0.5 \
++        bash
++```
++In addition, you can use `-v $(pwd):/workspace` to mount a host folder 
++into the docker container.
++
++## Data Owner Manager registers users for Data Owner
++```
++cd data-owner-manageer
++./user-manager.py login -u data_owner_manager -p teaclave
++./user-manager.py register-user -u user_A -p teaclave
++./user-manager.py register-user -u user_B -p teaclave
++./user-manager.py logout
++```
++
++## Data Owner lists and invokes current available functions
++```
++cd data-owner
++./cleanroom.py login -u user_A -p teaclave
++./cleanroom.py list-functions
++```
++We have deployed two functions for the `Data Owner Manager`.
++As a data owner, you are expected to see two avaialble functions. Note that the function ids 
++might be different as shown below.
++
++```
++=== Allowed Functions ===
++
++    Function ID                                    Owner    Allowed User Groups    Description
++--  ---------------------------------------------  -------  ---------------------  -------------
++ 0  function-73bf9a9b-6631-4500-8f61-08a518219e4c  admin    data_owner_manager     algorithm1
++ 1  function-98ee3801-6940-4b1a-b78a-a24946b736ef  admin    data_owner_manager     algorithm2
++```
++
++After getting the function id, the data owner (login as user_A), can invoke the function and get the result.
++
++```
++export ALGORITHM1=function-73bf9a9b-6631-4500-8f61-08a518219e4c
++export ALGORITHM2=function-98ee3801-6940-4b1a-b78a-a24946b736ef
++./cleanroom.py run -f $ALGORITHM1 -i sample_inputs/rna1.txt -o result1.txt
++cat result1.txt
++GCCUGGUGACCAUAGCGAGUCGGUACCACCCCUUCCCAUCCCGAACAGGACCGUGAAACGACUCCGCGCCGAUGAUAGUGCGGAUUCCCGUGUGAAAGUAGGUCAUCGCCAGGC
++(((((((((.....((((((((....(((.(((((.......))..)))...)))...)))))).))(((.........((((....)))).........)))..))))))))) (-35.50)
++```
++```
++./cleanroom.py run -f $ALGORITHM2 -i sample_inputs/protein1.txt -o result2.txt
++cat result2.txt 
++using codon table ./codon_usage_freq_table_human.csv
++viterbi score 6460-64
++CAI score 0 -nan
++runtime no backtrace: 20 s
++has bp sequence  GGGACCAUCACUGUCGAGGAGCUUAAGAAGCUCCUCGAGCAGUGGAACCUGGUCAUCGGGUUCCUGUUCCUUACGUGGAUCUGCUUGCUGCAGUUCGCGUAUGCGAACAGGAAC
++has bp structure ..((((((((((((((((((((((...))))))))))).))))))....))))).....(((((((((((.((((((((.((((.....)))))))))))).).))))))))))
++protein length: 38
++RNA length: 114
++sequence:  GGGACCAUCACUGUCGAGGAGCUUAAGAAGCUCCUCGAGCAGUGGAACCUGGUCAUCGGGUUCCUGUUCCUUACGUGGAUCUGCUUGCUGCAGUUCGCGUAUGCGAACAGGAAC
++structure: ..((((((((((((((((((((((...))))))))))).))))))....))))).....(((((((((((.((((((((.((((.....)))))))))))).).))))))))))
++free energy: -64.6
++ln CAI: 0 -nan
++CAI: 0.743604
++tuples: []
++runtime: 11 s
++beam size: -1
++lambda: 0
++s1 size 10000000
++s2 size 10000000
++./cleanroom.py logout
++```
++```
++./cleanroom.py run -f $ALGORITHM2 -i sample_inputs/protein1.txt -o result2_args.txt -- -b -1 -l 10.0 -c codon_usage_freq_table_human.csv  -s1 30 -s2 19
++cat result2_args.txt
++using codon table codon_usage_freq_table_human.csv
++viterbi score 5870-58
++CAI score -94.4436 0.779942
++runtime no backtrace: 20 s
++has bp sequence  GGGACCAUCACUGUCGAGGAGCUUAAGAAGCUCCUCGAGCAGUGGAACCUGGUCAUAGGCUUCCUGUUUCUGACAUGGAUCUGCCUGUUGCAGUUCGCUUAUGCGAACCGCAAC
++has bp structure ..((((((((((((((((((((((...))))))))))).))))))....)))))..((((.(((((((...)))).)))...))))(((((.((((((....)))))).)))))
++protein length: 38
++RNA length: 114
++sequence:  GGGACCAUCACUGUCGAGGAGCUUAAGAAGCUCCUCGAGCAGUGGAACCUGGUCAUAGGCUUCCUGUUUCUGACAUGGAUCUGCCUGUUGCAGUUCGCUUAUGCGAACCGCAAC
++structure: ..((((((((((((((((((((((...))))))))))).))))))....)))))..((((.(((((((...)))).)))...))))(((((.((((((....)))))).)))))
++free energy: -58.7
++ln CAI: -94.4436 0.779942
++CAI: 0.779942
++tuples: []
++runtime: 11 s
++beam size: -1
++lambda: 10
++s1 size 30
++s2 size 19
++```
+diff --git a/cleanroom-cli/readme.md b/cleanroom-cli/readme.md
+new file mode 100644
+index 0000000..9a80d09
+--- /dev/null
++++ b/cleanroom-cli/readme.md
+@@ -0,0 +1,79 @@
++# Cleanroom CLI v0.0.6
++
++This document will walk you through using the Cleanroom CLI to invoke functions and manage users.
++
++## User: Start the Docker
++
++Users can obtain the Cleanroom CLI from Docker Hub with the following command.
++```
++$ docker run --rm \
++              -w /cleanroom_sdk_cli \
++              -it organization/cleanroom-cli:0.0.6 \
++              bash
++```
++Users can use `-v $(pwd):/workspace` to mount a host folder into the docker container.
++
++## User: login and invoke functions
++
++Users are required to log in and obtain a valid function ID before invoking a Cleanroom function.
++Here is an example. 
++
++```bash
++$ cd data-owner
++$ ./cleanroom.py login -u <USERNAME> -p <PASSWORD>
++$ ./cleanroom.py list-functions
++
++=== Allowed Functions ===
++
++    Function ID                                    Description
++--  ---------------------------------------------  -----------------------------
++ 0  function-e6657fe7-5e48-466a-8c86-181d4082eb95  algorithm1
++ 1  function-106503b3-0e78-4a01-b9f3-2ac8ca5b60f1  algorithm2-hash -- <beam> <lambda>
++ 2  function-6aeae4b3-83b1-4334-8b01-4c561665c0ad  algorithm2-hash --diagnosis -- <beam> <lambda>
++```
++
++In this example, three functions are listed by the currently logged-in user. Each function is shown with `FunctionID`, `Owner`, `AllowedUserGroup`, and `Description`.
++
++User can select the `FunctionID` based on its `Description` and invoke the function with `./cleanroom.py run -f <FunctionID> -i <InputPath> -o <OutputPath> -- <Args>`.
++
++Here is an example for invoking the function with the description `algorithm2-hash`.
++
++***Note that `<Args>` of the `algorithm2-hash` function must follow this covension `-- <beam_size> <lambda>`.*** Otherwise, users would get a `Function returned with error code: 1.` error message.
++
++```bash
++$ export ALGORITHM2=function-106503b3-0e78-4a01-b9f3-2ac8ca5b60f1
++$ ./cleanroom.py run -f $ALGORITHM2 -i sample_inputs/protein1.txt -o result2.txt  -- 100 200
++Creating task with input sample_inputs/protein1.txt...done
++Invoking task... done, task_id: task-69e5b639-3041-4057-b0c8-e7b03a9068f4
++Getting result... finished
++Task succeeded!
++Output file: result2.txt
++$ cat result2.txt 
++input protein: GTITVEELKKLLEQWNLVIGFLFLTWICLLQFAYANRN
++sequence:  GGCACCAUCACCGUGGAGGAGCUGAAGAAGCUGCUGGAGCAGUGGAACCUGGUGAUCGGCUUCCUGUUCCUGACCUGGAUCUGCCUGCUGCAGUUCGCCUACGCCAACCGGAAC
++structure: ..........(((.(..((...((.((..((.((((.(((((((((.((.(((.(..(((.....)))..).))).)).)))).))))).))))..)))).))))..))))...
++mRNA folding free energy: -31.20 kcal/mol; mRNA CAI: 1.0000
++```
++
++## About User management
++
++Cleanroom assigns privileged users called `Data Owner Manager`.  `Data Owner Manager` can manage users with the `./user-manager.py` interface.
++
++Here is an example.
++
++```bash
++$ cd data-owner-manageer
++$ ./user-manager.py login -u <MANAGER> -p <MANAGER_PASSWORD>
++$ ./user-manager.py register-user -u <USERA> -p <USERA_PASSWORD>
++$ ./user-manager.py register-user -u <USERB> -p <USERB_PASSWORD>
++```
++
++Compared with the previous version (0.0.5), `Data Owner Manager` can list current
++data owners.
++
++```bash
++$ ./user-manager.py list-users
++List users successful, managed users: <USERA>, <USERB>
++```
++
++
+diff --git a/cleanroom-cli/requirements.txt b/cleanroom-cli/requirements.txt
+new file mode 100644
+index 0000000..db81650
+--- /dev/null
++++ b/cleanroom-cli/requirements.txt
+@@ -0,0 +1,8 @@
++toml==0.10.2
++pyOpenSSL==21.0.0
++tabulate==0.8.9
++requests==2.22.0
++argcomplete==2.0.0
++packaging==21.3
++PyJWT==2.3.0
++cryptography==36.0.1
+diff --git a/cleanroom-cli/resource/azure/conf/dcap_root_cert.pem b/cleanroom-cli/resource/azure/conf/dcap_root_cert.pem
+new file mode 100644
+index 0000000..c2b2907
+--- /dev/null
++++ b/cleanroom-cli/resource/azure/conf/dcap_root_cert.pem
+@@ -0,0 +1,23 @@
++-----BEGIN CERTIFICATE-----
++MIIDxTCCAq2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCVVMx
++EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoT
++EUdvRGFkZHkuY29tLCBJbmMuMTEwLwYDVQQDEyhHbyBEYWRkeSBSb290IENlcnRp
++ZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAwMFoXDTM3MTIzMTIz
++NTk1OVowgYMxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6b25hMRMwEQYDVQQH
++EwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjExMC8GA1UE
++AxMoR28gRGFkZHkgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIw
++DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL9xYgjx+lk09xvJGKP3gElY6SKD
++E6bFIEMBO4Tx5oVJnyfq9oQbTqC023CYxzIBsQU+B07u9PpPL1kwIuerGVZr4oAH
++/PMWdYA5UXvl+TW2dE6pjYIT5LY/qQOD+qK+ihVqf94Lw7YZFAXK6sOoBJQ7Rnwy
++DfMAZiLIjWltNowRGLfTshxgtDj6AozO091GB94KPutdfMh8+7ArU6SSYmlRJQVh
++GkSBjCypQ5Yj36w6gZoOKcUcqeldHraenjAKOc7xiID7S13MMuyFYkMlNAJWJwGR
++tDtwKj9useiciAF9n9T521NtYJ2/LOdYq7hfRvzOxBsDPAnrSTFcaUaz4EcCAwEA
++AaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYE
++FDqahQcQZyi27/a9BUFuIMGU2g/eMA0GCSqGSIb3DQEBCwUAA4IBAQCZ21151fmX
++WWcDYfF+OwYxdS2hII5PZYe096acvNjpL9DbWu7PdIxztDhC2gV7+AJ1uP2lsdeu
++9tfeE8tTEH6KRtGX+rcuKxGrkLAngPnon1rpN5+r5N9ss4UXnT3ZJE95kTXWXwTr
++gIOrmgIttRD02JDHBHNA7XIloKmf7J6raBKZV8aPEjoJpL1E/QYVN8Gb5DKj7Tjo
++2GTzLH4U/ALqn83/B2gX2yKQOC16jdFU8WnjXzPKej17CuPKf1855eJ1usV2GDPO
++LPAvTK33sefOT6jEm0pUBsV/fdUID+Ic/n4XuKxe9tQWskMJDE32p2u0mYRlynqI
++4uJEvlz36hz1
++-----END CERTIFICATE-----
+diff --git a/cleanroom-cli/resource/azure/conf/login.conf b/cleanroom-cli/resource/azure/conf/login.conf
+new file mode 100644
+index 0000000..8a1dfc9
+--- /dev/null
++++ b/cleanroom-cli/resource/azure/conf/login.conf
+@@ -0,0 +1,4 @@
++[login]
++username = 
++token = 
++
+diff --git a/cleanroom-cli/resource/azure/conf/cleanroom.conf b/cleanroom-cli/resource/azure/conf/cleanroom.conf
+new file mode 100644
+index 0000000..511c259
+--- /dev/null
++++ b/cleanroom-cli/resource/azure/conf/cleanroom.conf
+@@ -0,0 +1,10 @@
++[address]
++authentication_service = api.authentication.dev.cleanroom.com:7776
++frontend_service = api.frontend.dev.cleanroom.com:7777
++file_service = http://api.file.dev.cleanroom.com:7789
++cli_service = http://cli.cleanroom.com
++
++[attestation]
++as_root_ca_cert_path = dcap_root_cert.pem
++enclave_info_path = enclave_info.toml
++
+diff --git a/cleanroom-cli/resource/azure/env b/cleanroom-cli/resource/azure/env
+new file mode 100644
+index 0000000..d45707a
+--- /dev/null
++++ b/cleanroom-cli/resource/azure/env
+@@ -0,0 +1,11 @@
++#!/bin/sh
++# cleanroom shell setup
++# affix colons on either side of $PATH to simplify matching
++case ":${PATH}:" in
++    *:"$HOME/.cleanroom/bin":*)
++        ;;
++    *)
++        # Prepending path in case a system-installed version needs to be overridden
++        export PATH="$HOME/.cleanroom/bin:$PATH"
++        ;;
++esac
+diff --git a/cleanroom-cli/run_test.sh b/cleanroom-cli/run_test.sh
+new file mode 100755
+index 0000000..ac23583
+--- /dev/null
++++ b/cleanroom-cli/run_test.sh
+@@ -0,0 +1,24 @@
++#!/bin/bash
++
++set -e
++
++
++
++echo "test attestation"
++./test/test_attestation.sh 
++
++echo "test user management"
++./test/test_user_manage.sh
++
++echo "test register functions"
++./test/test_register_function.sh
++
++echo "test invoke functions"
++./test/test_invoke.sh
++
++echo "test check function usage"
++./test/test_check_usage.sh
++
++echo "test update enclave info"
++./test/test_update.sh
++
+diff --git a/cleanroom-cli/test/install.sh b/cleanroom-cli/test/install.sh
+new file mode 100755
+index 0000000..cc87992
+--- /dev/null
++++ b/cleanroom-cli/test/install.sh
+@@ -0,0 +1,30 @@
++#!/bin/sh
++
++set -e
++
++
++setup_color() {
++  # Only use colors if connected to a terminal
++
++  FMT_RED=$(printf '\033[31m')
++  FMT_GREEN=$(printf '\033[92m')
++  FMT_YELLOW=$(printf '\033[33m')
++  FMT_BLUE=$(printf '\033[34m')
++  FMT_BOLD=$(printf '\033[1m')
++  FMT_RESET=$(printf '\033[0m')
++}
++
++
++
++print_success() {
++    echo "${FMT_GREEN}Setup Cleanroom CLI successfully...${FMT_RESET}"
++    echo "To get started you may need to restart your current shell."
++}
++
++main() {
++  setup_color
++  print_success
++}
++
++
++main "$@"
+diff --git a/cleanroom-cli/test/test_attestation.sh b/cleanroom-cli/test/test_attestation.sh
+new file mode 100755
+index 0000000..d99c711
+--- /dev/null
++++ b/cleanroom-cli/test/test_attestation.sh
+@@ -0,0 +1,11 @@
++#!/bin/bash
++
++set -e
++
++pushd install
++
++cli="bin/cleanroom-cli"
++$cli
++$cli login -u admin -p teaclave 
++
++popd
+\ No newline at end of file
+diff --git a/cleanroom-cli/test/test_check_usage.sh b/cleanroom-cli/test/test_check_usage.sh
+new file mode 100755
+index 0000000..5b10e6b
+--- /dev/null
++++ b/cleanroom-cli/test/test_check_usage.sh
+@@ -0,0 +1,15 @@
++#!/bin/bash
++set -e
++pushd install 
++cli="bin/cleanroom-cli"
++$cli login -u user-trial -p teaclave
++$cli list-functions
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2-trial"))
++ALGORITHM2_TRIAL=${FUNCID[1]}
++$cli check-usage -f "$ALGORITHM2_TRIAL"
++
++
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2-trial-tier2"))
++ALGORITHM2_TRIAL_TIER2=${FUNCID[1]}
++$cli check-usage -f "$ALGORITHM2_TRIAL_TIER2"
++popd
+\ No newline at end of file
+diff --git a/cleanroom-cli/test/test_invoke.sh b/cleanroom-cli/test/test_invoke.sh
+new file mode 100755
+index 0000000..f2e36c2
+--- /dev/null
++++ b/cleanroom-cli/test/test_invoke.sh
+@@ -0,0 +1,67 @@
++#!/bin/bash
++set -e
++
++pushd install 
++cli="bin/cleanroom-cli"
++rna1="GCCUGGUGACCAUAGCGAGUCGGUACCACCCCUUCCCAUCCCGAACAGGACCGUGAAACGACUCCGCGCCGAUGAUAGUGCGGAUUCCCGUGUGAAAGUAGGUCAUCGCCAGGC"
++protein1="GTITVEELKKLLEQWNLVIGFLFLTWICLLQFAYANRN"
++
++$cli login -u admin -p teaclave 
++$cli login -u user1 -p teaclave
++$cli list-functions
++FUNCID=($($cli list-functions | grep -E "^* +algorithm1"))
++ALGORITHM1=${FUNCID[1]}
++
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2"))
++ALGORITHM2=${FUNCID[1]}
++
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2 --diagnosis"))
++ALGORITHM2_DIS=${FUNCID[1]}
++
++echo $rna1 > rna1.txt
++echo $protein1 > protein1.txt
++
++echo "running algorithm1 ${ALGORITHM1}"
++$cli run -f "$ALGORITHM1" -i rna1.txt -o result1.txt
++cat result1.txt
++
++echo "running algorithm2 ${ALGORITHM2}"
++$cli run -f "$ALGORITHM2" -i protein1.txt -o result2.txt -- 100 2
++cat result2.txt
++
++echo "running algorithm2 with the diagnosis mode ${ALGORITHM2_DIS}"
++$cli run -f "$ALGORITHM2_DIS" -i protein1.txt -o result3.txt --diagnosis -- 100 2
++cat result3.txt
++
++$cli login -u user-trial -p teaclave
++$cli list-functions
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2-trial"))
++ALGORITHM2_TRIAL=${FUNCID[1]}
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDDHAKGHGSKMEKGLQKKKITPGNYGNTPRKGPCAVSSNPYAFKNPIYSQPAWMNDSHKDQSKRWLSDEHTGNSDNWREFKPGPRIPVINRQRKDSFQENEDGYRWQDTRGCRTVRRLFHKDLTSLETTSEMEAGSPENKKQRSRPRKPRKTRNEENEQDGDLEGPVIDESVLSTKELLGLQQAEERLKRDCIDRLKRRPRNYPTAKYTCRLCDVLIESIAFAHKHIKEKRHKKNIKEKQEEELLTTLPPPTPSQINAVGIAIDKVVQEFGLHNENLEQRLEIKRIMENVFQHKLPDCSLRLYGSSCSRLGFKNSDVNIDIQFPAIMSQPDVLLLVQECLKNSDSFIDVDADFHARVPVVVCREKQSGLLCKVSAGNENACLTTKHLTALGKLEPKLVPLVIAFRYWAKLCSIDRPEEGGLPPYVFALMAIFFLQQRKEPLLPVYLGSWI [...]
++
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL"
++
++set +e
++$cli list-functions
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2-limited-times"))
++ALGORITHM2_TRIAL_LIMITED_TIMES=${FUNCID[1]}
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL_LIMITED_TIMES" --silent
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL_LIMITED_TIMES" --silent
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL_LIMITED_TIMES" --silent
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL_LIMITED_TIMES" --silent
++
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2-trial-tier2"))
++ALGORITHM2_TRIAL_TIER2=${FUNCID[1]}
++echo MAVLSKEYGFVLLTGAASFIMVAHLAINVSKARKKYKVEYPIMYSTDPENGHIFNCIQRAHQNTLEVYPPFLFFLAVGGVYHPRIASGLGLAWIVGRVLYAYGYYTGEPSKRSRGALGSIALLGLVGTT| $cli run -f "$ALGORITHM2_TRIAL_TIER2" --silent
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL_TIER2" --silent
++
++$cli login -u user-trial1 -p teaclave
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2-trial-expired"))
++ALGORITHM2_TRIAL_EXPIRED=${FUNCID[1]}
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL_EXPIRED"
++
++FUNCID=($($cli list-functions | grep -E "^* +algorithm2-limited-times"))
++ALGORITHM2_TRIAL_LIMITED_TIMES=${FUNCID[1]}
++echo MGDTAKPYFVKRTKDRGTMDDDDFRRGHPQQDYLIIDD | $cli run -f "$ALGORITHM2_TRIAL_LIMITED_TIMES"
++
++popd
+diff --git a/cleanroom-cli/test/test_register_function.sh b/cleanroom-cli/test/test_register_function.sh
+new file mode 100755
+index 0000000..89a39d0
+--- /dev/null
++++ b/cleanroom-cli/test/test_register_function.sh
+@@ -0,0 +1,32 @@
++#!/bin/bash
++set -e
++
++
++pushd install
++
++cli="bin/cleanroom-cli"
++
++$cli login -u admin -p teaclave
++
++function1_description="algorithm1;option: [Empty];registration_time: 2022-02-08 22:51:33;version: 1.0;"
++$cli register-cpk -c ../cpk/algorithm1.cpk -n algorithm1 -d "$function1_description"  -u organization
++
++function2_description="algorithm2;option: --beam <int> --lambda <float>;version: 1.0"
++$cli register-native -n builtin-cleanroom-algorithm2-hash -d "$function2_description" -u organization
++
++function3_description="algorithm2 --diagnosis;version: 1.0 ;option: --beam <int> --lambda <float>"
++$cli register-native -n builtin-cleanroom-algorithm2-hash -d "$function3_description" -u organization --diagnosis
++
++function4_description="algorithm2-trial;option: [Empty];version: 1.0"
++$cli register-native -n builtin-cleanroom-algorithm2-hash-trial -d "$function4_description" -u organization-trial
++
++function5_description="algorithm2-limited-times;option: [Empty];version: 1.0"
++$cli register-native -n builtin-cleanroom-algorithm2-hash-trial -d "$function5_description" -q 3 -u organization-trial
++
++function6_description="algorithm2-trial-tier2;option: [Empty];version: 1.0;usage limits: 10;expired date: 06/01/2022"
++$cli register-native -n builtin-cleanroom-algorithm2-hash-trial-tier2  -d "$function6_description" -q 10 -e 06/01/2022 -u organization-trial
++
++function7_description="algorithm2-trial-expired;option: [Empty];version: 1.0;usage limits: 10;expired date: 01/02/2011"
++$cli register-native -n builtin-cleanroom-algorithm2-hash-trial-tier2  -d "$function7_description" -q 10 -e 01/02/2011 -u organization-trial
++
++popd
+\ No newline at end of file
+diff --git a/cleanroom-cli/test/test_update.sh b/cleanroom-cli/test/test_update.sh
+new file mode 100755
+index 0000000..af69745
+--- /dev/null
++++ b/cleanroom-cli/test/test_update.sh
+@@ -0,0 +1,35 @@
++#!/bin/bash
++
++set -e
++
++
++cleanup() {
++  # gracefully terminate all background services with SIGTERM
++  [[ -z "$(jobs -p -r)" ]] || kill -s SIGTERM $(jobs -p -r)
++  wait # wait for resource release
++  echo "All jobs terminated."
++}
++
++trap cleanup INT TERM ERR
++
++OS=$(uname -s)
++ARCH=$(uname -m)
++cp ../release/services/enclave_info.toml test
++cp cleanroom-cli-"${OS}"-"${ARCH}".tgz test
++python3 -m http.server 7801 -d test &
++
++pushd install
++
++# Test updating enclave_info.toml
++cli="bin/cleanroom-cli"
++$cli login -u admin -p teaclave 
++rm -f conf/enclave_info.toml
++{
++    set +e
++    $cli login -u admin -p teaclave
++}
++
++# Test Upgrading CLI
++$cli upgrade
++cleanup
++popd
+\ No newline at end of file
+diff --git a/cleanroom-cli/test/test_user_manage.sh b/cleanroom-cli/test/test_user_manage.sh
+new file mode 100755
+index 0000000..3997f4b
+--- /dev/null
++++ b/cleanroom-cli/test/test_user_manage.sh
+@@ -0,0 +1,41 @@
++#!/bin/bash
++set -e
++
++pushd install
++
++cli="bin/cleanroom-cli"
++$cli login -u admin -p teaclave 
++$cli register-user -u organization -p teaclave -r DataOwnerManager
++$cli register-user -u organization-trial -p teaclave -r DataOwnerManager
++$cli login -u organization -p teaclave
++$cli register-user -u user1 -p teaclave
++$cli register-user -u user2 -p teaclave
++$cli register-user -u user3 -p teaclave
++$cli register-user -u user4 -p teaclave
++$cli reset-user-password -u user4
++$cli change-password -p new_teaclave
++$cli logout
++$cli login -u organization -p new_teaclave
++$cli delete-user -u user3
++$cli logout
++
++
++$cli login -u organization-trial -p teaclave
++$cli register-user -u user-trial -p teaclave
++$cli register-user -u user-trial1 -p teaclave
++
++
++
++$cli login -u user2 -p teaclave
++$cli change-password -p new_teaclave
++$cli logout
++$cli login -u user2 -p new_teaclave
++
++echo "User3 loses the access"
++$cli logout
++{
++    set +e 
++    $cli login -u user3 -p teaclave
++}
++
++popd
+\ No newline at end of file
+diff --git a/cleanroom-cli/test/version b/cleanroom-cli/test/version
+new file mode 100644
+index 0000000..3eefcb9
+--- /dev/null
++++ b/cleanroom-cli/test/version
+@@ -0,0 +1 @@
++1.0.0
+diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml
+index f35f2fd..b095ebf 100644
+--- a/rpc/Cargo.toml
++++ b/rpc/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_rpc"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave RPC"
+ license = "Apache-2.0"
+@@ -37,7 +37,7 @@ mesalock_sgx = [
+ anyhow     = { version = "1.0.26" }
+ cfg-if     = { version = "0.1.9" }
+ http       = { version = "0.2" }
+-log        = { version = "0.4.6", features = ["release_max_level_info"] }
++log        = { version = "0.4.6", features = ["release_max_level_debug"] }
+ rustls     = { version = "0.16.0", features = ["dangerous_configuration"] }
+ serde      = { version = "1.0.92", features = ["derive"] }
+ serde_json = { version = "1.0.39" }
+diff --git a/rpc/proc_macro/Cargo.toml b/rpc/proc_macro/Cargo.toml
+index 08bf734..55764d7 100644
+--- a/rpc/proc_macro/Cargo.toml
++++ b/rpc/proc_macro/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_rpc_proc_macro"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ license = "Apache-2.0"
+ edition = "2018"
+diff --git a/rpc/src/protocol.rs b/rpc/src/protocol.rs
+index d550850..3f67e53 100644
+--- a/rpc/src/protocol.rs
++++ b/rpc/src/protocol.rs
+@@ -18,11 +18,15 @@
+ #![allow(clippy::nonstandard_macro_braces)]
+ #![allow(clippy::unknown_clippy_lints)]
+ 
++use log::debug;
+ use log::trace;
+ use serde::{Deserialize, Serialize};
+ use std::io;
+ use std::prelude::v1::*;
++#[cfg(feature = "mesalock_sgx")]
++use std::untrusted::time::InstantEx;
+ use std::vec::Vec;
++use teaclave_types::profile_highlight;
+ use teaclave_types::TeaclaveServiceResponseError;
+ use thiserror::Error;
+ 
+@@ -80,37 +84,54 @@ where
+ 
+         self.transport.read_exact(&mut header)?;
+         let buf_len = u64::from_be_bytes(header);
++        let name = std::any::type_name::<V>();
++        if name.contains("Request") {
++            debug!(
++                "[+] Start reading bytes from transport layer {}: {}",
++                name, buf_len
++            );
++        }
+         if buf_len > self.max_frame_len {
+             return Err(ProtocolError::Other(anyhow::anyhow!(
+                 "Exceed max frame length"
+             )));
+         }
+ 
+-        let mut recv_buf: Vec<u8> = vec![0u8; buf_len as usize];
+-        self.transport.read_exact(&mut recv_buf)?;
+-
+-        trace!("Recv: {}", std::string::String::from_utf8_lossy(&recv_buf));
+-        let r: V = serde_json::from_slice(&recv_buf)?;
+-
+-        Ok(r)
++        let recv_buf = profile_highlight!(format!("[+] Read Bytes {}: {}", name, buf_len), {
++            let mut recv_buf: Vec<u8> = vec![0u8; buf_len as usize];
++            self.transport.read_exact(&mut recv_buf)?;
++            recv_buf
++        });
++
++        profile_highlight!(format!("Deserialize {}, {} :", name, recv_buf.len()), {
++            let r: V = serde_json::from_slice(&recv_buf)?;
++            debug!("[+] Deserialize success: {}, {}", name, recv_buf.len());
++            Ok(r)
++        })
+     }
+ 
+     pub fn write_message<U>(&mut self, message: U) -> std::result::Result<(), ProtocolError>
+     where
+         U: Serialize + std::fmt::Debug,
+     {
++        let name = std::any::type_name::<U>();
+         let send_buf = serde_json::to_vec(&message)?;
+ 
+         trace!("Send: {}", std::string::String::from_utf8_lossy(&send_buf));
+ 
+         let buf_len = send_buf.len() as u64;
+-        let header = buf_len.to_be_bytes();
++        profile_highlight!(
++            format!("Sent Resonse bytes {}, size {}: ", name, buf_len),
++            {
++                let header = buf_len.to_be_bytes();
+ 
+-        self.transport.write_all(&header)?;
+-        self.transport.write_all(&send_buf)?;
+-        self.transport.flush()?;
++                self.transport.write_all(&header)?;
++                self.transport.write_all(&send_buf)?;
++                self.transport.flush()?;
+ 
+-        Ok(())
++                Ok(())
++            }
++        )
+     }
+ }
+ 
+diff --git a/rpc/src/transport.rs b/rpc/src/transport.rs
+index c30bb68..ad82dff 100644
+--- a/rpc/src/transport.rs
++++ b/rpc/src/transport.rs
+@@ -19,6 +19,7 @@ use crate::protocol;
+ use crate::Request;
+ use crate::TeaclaveService;
+ use anyhow::Result;
++use log::debug;
+ use log::warn;
+ use serde::{Deserialize, Serialize};
+ use std::prelude::v1::*;
+@@ -115,6 +116,12 @@ where
+             let response: JsonProtocolResult<U, TeaclaveServiceResponseError> =
+                 service.handle_request(request).into();
+             protocol.write_message(response)?;
++            debug!(
++                "[+] {} End handling {} and writing back:  {}. Ready for next request...",
++                std::any::type_name::<X>(),
++                std::any::type_name::<V>(),
++                std::any::type_name::<U>()
++            );
+         }
+     }
+ }
+diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml
+index 30a1814..79ec89b 100644
+--- a/runtime/Cargo.toml
++++ b/runtime/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_runtime"
+-version = "0.4.0"
++version = "0.2.0"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave runtime"
+ license = "Apache-2.0"
+@@ -37,7 +37,7 @@ cov = ["sgx_cov"]
+ enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]
+ 
+ [dependencies]
+-log           = { version = "0.4.6", features = ["release_max_level_info"] }
++log           = { version = "0.4.6", features = ["release_max_level_debug"] }
+ anyhow        = { version = "1.0.26" }
+ 
+ teaclave_types = { path = "../types" }
+diff --git a/scripts/run_teaclave.sh b/scripts/run_teaclave.sh
+new file mode 100755
+index 0000000..98a930c
+--- /dev/null
++++ b/scripts/run_teaclave.sh
+@@ -0,0 +1,64 @@
++#!/bin/bash
++
++# Licensed to the Apache Software Foundation (ASF) under one
++# or more contributor license agreements.  See the NOTICE file
++# distributed with this work for additional information
++# regarding copyright ownership.  The ASF licenses this file
++# to you under the Apache License, Version 2.0 (the
++# "License"); you may not use this file except in compliance
++# with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing,
++# software distributed under the License is distributed on an
++# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++# KIND, either express or implied.  See the License for the
++# specific language governing permissions and limitations
++# under the License.
++
++
++set -e 
++
++TEACLAVE_PROJECT_ROOT="/teaclave"
++TEACLAVE_SERVICE_INSTALL_DIR="/teaclave/release/services"
++
++
++start_storage_server() {
++  python3 ${TEACLAVE_PROJECT_ROOT}/tests/scripts/simple_http_server.py 6789 &
++}
++
++wait_port() {
++  for port in "$@"
++  do
++    timeout 20 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' localhost "$port"
++  done
++}
++
++cleanup() {
++  # gracefully terminate all background services with SIGTERM
++  [[ -z "$(jobs -p -r)" ]] || kill -s SIGTERM $(jobs -p -r)
++  wait # wait for resource release
++  echo "All jobs terminated."
++}
++
++pushd ${TEACLAVE_SERVICE_INSTALL_DIR} || exit
++trap cleanup INT TERM ERR
++./teaclave_authentication_service &
++./teaclave_storage_service &
++wait_port 7776 17776 17778 # wait for authentication and storage service
++./teaclave_management_service &
++./teaclave_scheduler_service &
++wait_port 17777 17780 # wait for management service and scheduler_service
++./teaclave_access_control_service &
++./teaclave_frontend_service &
++wait_port 17779 7777 # wait for other services
++
++start_storage_server
++
++# Run of execution services separately
++./teaclave_execution_service & exe_pid1=$!
++sleep 25    # wait for execution services
++sleep 3600
++popd
++cleanup
+\ No newline at end of file
+diff --git a/sdk/payload/wasm/teaclave_context/Cargo.toml b/sdk/payload/wasm/teaclave_context/Cargo.toml
+index 454e754..3b43659 100644
+--- a/sdk/payload/wasm/teaclave_context/Cargo.toml
++++ b/sdk/payload/wasm/teaclave_context/Cargo.toml
+@@ -17,7 +17,7 @@
+ 
+ [package]
+ name = "teaclave_context"
+-version = "0.4.0"
++version = "0.2.0"
+ edition = "2018"
+ authors = ["Teaclave Contributors <de...@teaclave.apache.org>"]
+ description = "Teaclave Contex File interfaces for WASM payloads"
+diff --git a/sdk/python/teaclave.py b/sdk/python/teaclave.py
+index e6e7aef..835e21a 100644
+--- a/sdk/python/teaclave.py
++++ b/sdk/python/teaclave.py
+@@ -31,9 +31,11 @@ import os
+ import time
+ import ssl
+ import socket
++import inspect
++import ctypes
+ 
+ from typing import Tuple, Dict, List, Any
+-from enum import IntEnum
++from enum import IntEnum, auto
+ 
+ import cryptography
+ from cryptography import x509
+@@ -45,7 +47,8 @@ from OpenSSL import crypto
+ 
+ __all__ = [
+     'FrontendService', 'AuthenticationService', 'FunctionInput',
+-    'FunctionOutput', 'OwnerList', 'DataMap'
++    'FunctionOutput', 'FunctionArgument', 'OwnerList', 'DataMap',
++    'FunctionExpirationDate'
+ ]
+ 
+ Metadata = Dict[str, str]
+@@ -67,7 +70,59 @@ class Request:
+ 
+ 
+ class TeaclaveException(Exception):
+-    pass
++    _teaclave_error = dict()
++    _teaclave_error[0] = ('Networking error',
++                          'Please check your Internet connection')
++    _teaclave_error[1] = ('Remote attestation error',
++                          'Please check your root certificate')
++    _teaclave_error[2] = ('Remote attestation error',
++                          'Please check your root certificate`')
++    _teaclave_error[3] = ('Remote attestation error',
++                          'Please check the `enclave_info.toml` file')
++    _teaclave_error[4] = ('Login error',
++                          'Please check your username and token')
++    _teaclave_error[5] = (
++        'Login error',
++        'Please ask your administrator to register a user for you')
++    _teaclave_error[6] = ('Username already exists',
++                          'Please use a different username')
++    _teaclave_error[7] = ('Permission Deny',
++                          'You are not authorized to run the command')
++    _teaclave_error[8] = ('Authentication error',
++                          'Please login your account first')
++    _teaclave_error[9] = (
++        'Invalid Task',
++        'Function is registered with the diagnosis mode. Please run with the --diagnosis option'
++    )
++    _teaclave_error[10] = ('Fail to disable function',
++                           'Only the function owner can delete a function')
++    _teaclave_error[11] = ('Fail to delete user',
++                           'Only the user-manager can delete a user')
++    _teaclave_error[12] = ('Invalid password',
++                           "Please use a different password")
++    _teaclave_error[13] = ('Authentication error',
++                           "Please login in your account")
++    _teaclave_error[14] = ('Quota has been used up',
++                           'This trial account has reached its usage limits')
++    _teaclave_error[15] = ('The function is expired',
++                           'Please contact the function owner')
++
++    def __init__(self, error_code: int, msg=''):
++        frame, filename, line_number, function_name, lines, index = inspect.stack(
++        )[1]
++        self.function_name = function_name
++        self.error_code = error_code
++        self.message = msg
++
++    def __str__(self):
++        CRED = '\033[91m'
++        CEND = '\033[0m'
++        if (self.error_code) in TeaclaveException._teaclave_error:
++            error = TeaclaveException._teaclave_error[self.error_code][0]
++            action = TeaclaveException._teaclave_error[self.error_code][1]
++            return CRED + ('Error: {}. Action: {}.'.format(error,
++                                                           action)) + CEND
++        return str(self.message)
+ 
+ 
+ class TeaclaveService:
+@@ -79,7 +134,7 @@ class TeaclaveService:
+                  address: Tuple[str, int],
+                  as_root_ca_cert_path: str,
+                  enclave_info_path: str,
+-                 dump_report=False):
++                 dump_report=None):
+         self._context = ssl._create_unverified_context()
+         self._name = name
+         self._address = address
+@@ -108,17 +163,21 @@ class TeaclaveService:
+     def connect(self):
+         """Establish trusted connection and verify remote attestation report.
+         """
+-        sock = socket.create_connection(self._address)
++        try:
++            sock = socket.create_connection(self._address)
++        except Exception as e:
++            raise TeaclaveException(0)
+         channel = self._context.wrap_socket(sock,
+                                             server_hostname=self._address[0])
+         cert = channel.getpeercert(binary_form=True)
+-        if not cert: raise TeaclaveException("Peer cert is None")
++        if not cert: raise TeaclaveException(2)
+         try:
+             self._verify_report(self._as_root_ca_cert_path,
+                                 self._enclave_info_path, cert, self._name)
++        except TeaclaveException as e:
++            raise e
+         except Exception as e:
+-            raise TeaclaveException(
+-                f"Failed to verify attestation report: {e}")
++            raise TeaclaveException(1)
+         self.channel = channel
+ 
+         return self
+@@ -143,7 +202,10 @@ class TeaclaveService:
+ 
+         if self._dump_report:
+             try:
+-                with open(self._name + "_attestation_report.pem", "wb") as f:
++                with open(
++                        os.path.join(self._dump_report,
++                                     self._name + "_attestation_report.pem"),
++                        "wb") as f:
+                     f.write(
+                         cert.public_bytes(cryptography.hazmat.primitives.
+                                           serialization.Encoding.PEM))
+@@ -163,7 +225,7 @@ class TeaclaveService:
+             ]
+         except:
+             raise TeaclaveException(
+-                "Failed to load singing certificate of the report")
++                msg="Failed to load singing certificate of the report")
+ 
+         # verify signing cert with AS root cert
+         try:
+@@ -171,13 +233,13 @@ class TeaclaveService:
+                 as_root_ca_cert = f.read()
+         except:
+             raise TeaclaveException(
+-                "Failed to open attestation service root certificate")
++                msg="Failed to open attestation service root certificate")
+ 
+         try:
+             as_root_ca_cert = load_certificate(FILETYPE_PEM, as_root_ca_cert)
+         except:
+             raise TeaclaveException(
+-                "Failed to load attestation service root certificate")
++                msg="Failed to load attestation service root certificate")
+ 
+         store = X509Store()
+         store.add_cert(as_root_ca_cert)
+@@ -193,7 +255,7 @@ class TeaclaveService:
+             # verify report's signature
+             crypto.verify(certs[0], signature, bytes(ext["report"]), 'sha256')
+         except:
+-            raise TeaclaveException("Failed to verify report signature")
++            raise TeaclaveException(3)
+ 
+         report = json.loads(report)
+         quote = report['isvEnclaveQuoteBody']
+@@ -207,15 +269,15 @@ class TeaclaveService:
+         try:
+             enclave_info = toml.load(enclave_info_path)
+         except:
+-            raise TeaclaveException("Failed to load enclave info")
++            raise TeaclaveException(3)
+ 
+         # verify mr_enclave and mr_signer
+         enclave_name = "teaclave_" + endpoint_name + "_service"
+         if mr_enclave != enclave_info[enclave_name]["mr_enclave"]:
+-            raise Exception("Failed to verify mr_enclave")
++            raise TeaclaveException(3)
+ 
+         if mr_signer != enclave_info[enclave_name]["mr_signer"]:
+-            raise Exception("Failed to verify mr_signer")
++            raise TeaclaveException(3)
+ 
+ 
+ class FunctionInput:
+@@ -248,6 +310,41 @@ class FunctionOutput:
+         self.optional = optional
+ 
+ 
++class FunctionArgument:
++    """Function argument for registring.
++
++    Args:
++        key: Name of the argument.
++        default_value: A default value of the argument. The default value is "". 
++        allow_overwrite: If allow_overwrite flag is set to be true. The service 
++                         will allow the task creator to overwrite the arguement 
++                         value when creating tasks. 
++    """
++
++    def __init__(self,
++                 key: str,
++                 default_value: str = "",
++                 allow_overwrite=True):
++        self.key = key
++        self.default_value = default_value
++        self.allow_overwrite = allow_overwrite
++
++
++class FunctionExpirationDate:
++    """Function expiration date.
++
++    Args:
++        expired:
++        seconds:
++        nanos:
++    """
++
++    def __init__(self, expired=False, seconds: int = 0, nanos: int = 0):
++        self.expired = expired
++        self.seconds = seconds
++        self.nanos = nanos
++
++
+ class OwnerList:
+     """Defines data ownership.
+ 
+@@ -315,8 +412,9 @@ class UserUpdateRequest(Request):
+ 
+ class UserLoginRequest(Request):
+ 
+-    def __init__(self, user_id: str, user_password: str):
++    def __init__(self, metadata: Metadata, user_id: str, user_password: str):
+         self.request = "user_login"
++        self.metadata = metadata
+         self.id = user_id
+         self.password = user_password
+ 
+@@ -370,7 +468,7 @@ class AuthenticationService(TeaclaveService):
+                  address: Tuple[str, int],
+                  as_root_ca_cert_path: str,
+                  enclave_info_path: str,
+-                 dump_report=False):
++                 dump_report=None):
+         super().__init__("authentication", address, as_root_ca_cert_path,
+                          enclave_info_path, dump_report)
+ 
+@@ -396,7 +494,10 @@ class AuthenticationService(TeaclaveService):
+             reason = "unknown"
+             if "request_error" in response:
+                 reason = response["request_error"]
+-            raise TeaclaveException(f"Failed to register user ({reason})")
++            if reason == 'permission denied':
++                raise TeaclaveException(7)
++            else:
++                raise TeaclaveException(6)
+ 
+     def user_update(self, user_id: str, user_password: str, role: str,
+                     attribute: str):
+@@ -433,7 +534,8 @@ class AuthenticationService(TeaclaveService):
+             str: User login token.
+         """
+         self.check_channel()
+-        request = UserLoginRequest(user_id, user_password)
++        metadata = {"id": user_id}
++        request = UserLoginRequest(metadata, user_id, user_password)
+         _write_message(self.channel, request)
+         response = _read_message(self.channel)
+         if response["result"] == "ok":
+@@ -442,7 +544,10 @@ class AuthenticationService(TeaclaveService):
+             reason = "unknown"
+             if "request_error" in response:
+                 reason = response["request_error"]
+-            raise TeaclaveException(f"Failed to login user ({reason})")
++            if reason == 'user id not found':
++                raise TeaclaveException(5)
++            else:
++                raise TeaclaveException(4)
+ 
+     def user_change_password(self, user_password: str):
+         """Change password.
+@@ -461,7 +566,12 @@ class AuthenticationService(TeaclaveService):
+             reason = "unknown"
+             if "request_error" in response:
+                 reason = response["request_error"]
+-            raise TeaclaveException(f"Failed to change password ({reason})")
++            if reason == "permission denied":
++                raise TeaclaveException(7)
++            elif reason == "authentication failed":
++                raise TeaclaveException(13)
++            else:
++                raise TeaclaveException(12)
+ 
+     def reset_user_password(self, user_id: str) -> str:
+         """Reset password of a managed user.
... 8533 lines suppressed ...


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org