diff --git a/.env b/.env
index 5840847..4f83cff 100644
--- a/.env
+++ b/.env
@@ -1,12 +1,6 @@
-PORT = 1212
-
TASK_EXECUTOR_HOST=http://localhost
TASK_EXECUTOR_PORT=2591
IPFS_NODE_URL=http://localhost:5001
PYMECA_ACTOR_SERVER_HOST=http://localhost
PYMECA_ACTOR_SERVER_PORT=9999
-
-# deprecating
-REGISTRATION_SERVICE_API_URL=http://localhost:7000
-TRANSACTION_SERVICE_API_URL=http://localhost:8000
diff --git a/.env.example b/.env.example
index c0e3582..da68eb1 100644
--- a/.env.example
+++ b/.env.example
@@ -1,12 +1,6 @@
-# PORT=1212
-
# TASK_EXECUTOR_HOST=http://localhost
# TASK_EXECUTOR_PORT=2591
# IPFS_NODE_URL=http://localhost:5001
# PYMECA_ACTOR_SERVER_HOST=http://localhost
# PYMECA_ACTOR_SERVER_PORT=9999
-
-# # deprecating
-# REGISTRATION_SERVICE_API_URL=http://localhost:7000
-# TRANSACTION_SERVICE_API_URL=http://localhost:8000
diff --git a/docs/source/_static/developer_guide.md b/docs/source/_static/developer_guide.md
index 2a97502..b91dd1d 100644
--- a/docs/source/_static/developer_guide.md
+++ b/docs/source/_static/developer_guide.md
@@ -54,7 +54,6 @@ Note:
The main process executes the entry point script defined in the package.json (as 'main'). It manages the application's lifecycle, and has native access to desktop functionality, such as menus, dialogs, and tray icons. More specifically, the main process for this app is responsible for the following:
- Manage lifecycle events (e.g. 'ready', 'closed'. Refer to the official docs for a complete list: *https://www.electronjs.org/docs/latest/api/app*)
- Create BrowserWindows (see *Renderer* below), Menu, Tray.
-- Communicating with the MECA SDK to handle task processing via sockets (see ```sdk\README.md```).
- Communicating with the Docker Daemon with Dockerode to orchestrate the execution of Task Executor containers during Node.js runtime (see ```task_executor\README.md```).
- Communicating with IPFS to upload and download tasks.
- In Linux, the default download directory is `/home/$USER/.MECA/ipfsFiles`
diff --git a/sdk/.gitignore b/sdk/.gitignore
deleted file mode 100644
index cd916e7..0000000
--- a/sdk/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-.env
-/build
diff --git a/sdk/README.md b/sdk/README.md
deleted file mode 100644
index 2e370f7..0000000
--- a/sdk/README.md
+++ /dev/null
@@ -1,70 +0,0 @@
-# SDK for developers using MECAnywhere
-
-- "Developers" in this document refers to developers who want to offload their tasks to MECAnywhere.
-
-The task execution flow is as such
-
-
-Therefore, developers only have 2 things to do:
-1. Use the SDK in their application to connect to MECAnywhere desktop app.
-2. Build a containerized task and upload it to IPFS via our CLI.
-
-## Python SDK
-
-This SDK only provides offloading asynchronously and receiving results via callback. To do synchronous offloading, you may use the `join` function immediately after an offload.
-
-#### async def initiate_connection([timeout]) -> None
- Starts a socket connection to the local MECA desktop app.
-
- - timeout: int (optional)
-
-#### async def offload_task(task_id, container_ref, data, callback, resource, runtime) -> str
- Sends a task input to the local MECA desktop app that helps to run the task on a remote MECA host.
- The task is the containerized application you have uploaded to the container repository that returns some result given the input data.
-
- - task_id: str - identifier for the task to correlate with the callback results
- - container_ref: str - image name of the task for the data to be processed
- - data: str
- - callback: Callable[[str], None] - function to be called when the results are received
- - resource: dict (optional) - resource requirements for the task
- - runtime: str (optional) - runtime environment for the task
-
-#### async def disconnect() -> None
- Closes the socket connection to the local MECA desktop app.
-#### async def join(task_timeout, join_timeout) -> None
- Waits for all tasks to finish.
-
- - task_timeout: int - timeout for each task
- - join_timeout: int - timeout for all tasks
-
-### Test (with KNN example)
-
-> You may skip step 1 if you uploaded your image to a public container repository or have it built in your local device.
-
-1. Go to example_containers and build dockerized task with
-
-```
-docker build -t example_containers/knn
-```
-
-2. Start MECAnywhere desktop app.
-3. Go to knn.py and change the container_ref to the tag you just built.
-Start virtual env, install requirements and run knn.py.
-
-```
-pip install torch==2.0.1+cpu --index-url https://download.pytorch.org/whl/cpu
-pip install -r requirements.txt
-python knn.py
-```
-
-### Examples
-
-This folder contains examples of how to use the SDK to offload tasks. The example_containers folder contains example tasks that can be called and run by the host.
-
-- [basic_offload.py](basic_offload.py) uses the [sampleserver](../task_executor/sample/) container.
-
-- [knn.py](knn.py) uses the [knn](example_containers/knn) container.
-
-## JavaScript
-
-Not in use
diff --git a/sdk/basic_offload.py b/sdk/basic_offload.py
deleted file mode 100644
index 0fd8c45..0000000
--- a/sdk/basic_offload.py
+++ /dev/null
@@ -1,51 +0,0 @@
-from py import meca_api
-from dotenv import load_dotenv
-import asyncio
-
-
-task_corr_ids = dict()
-results = dict()
-NUMBER_OF_TASKS = 2
-
-def callback_on_receive(task_id, status, response, err, corr_id):
- if status == 1:
- results[task_id] = response
- print("Received result for task", task_id, ":", response)
- else:
- print(err, "for task: ", task_id, "corr_id:", corr_id)
- results[task_id] = response
-
-async def main():
- load_dotenv()
- try:
- await meca_api.initiate_connection()
- except Exception as e:
- await meca_api.disconnect()
- return
-
- for i in range(NUMBER_OF_TASKS):
- await meca_api.offload_task(
- str(i),
- 'sampleserver:latest',
- "{\"name\": \"meca dev " + str(i) + "\"}",
- callback=callback_on_receive,
- resource={
- "cpu": 1,
- "memory": 256
- },
- use_gpu=True,
- gpu_count=1
- )
-
- await meca_api.join()
-
- print("All results received:", results)
- print("Result count:", len(results))
- await meca_api.disconnect()
-
-if __name__ == '__main__':
- try:
- asyncio.run(main())
- except KeyboardInterrupt:
- print("Program closed by user.")
- asyncio.run(meca_api.disconnect())
diff --git a/sdk/example_containers/.gitignore b/sdk/example_containers/.gitignore
deleted file mode 100644
index d455b0a..0000000
--- a/sdk/example_containers/.gitignore
+++ /dev/null
@@ -1,136 +0,0 @@
-/out/
-output.png
-
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-build/
-develop-eggs/
-dist/
-downloads/
-eggs/
-.eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-wheels/
-pip-wheel-metadata/
-share/python-wheels/
-*.egg-info/
-.installed.cfg
-*.egg
-MANIFEST
-
-# PyInstaller
-# Usually these files are written by a python script from a template
-# before PyInstaller builds the exe, so as to inject date/other infos into it.
-*.manifest
-*.spec
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-htmlcov/
-.tox/
-.nox/
-.coverage
-.coverage.*
-.cache
-nosetests.xml
-coverage.xml
-*.cover
-*.py,cover
-.hypothesis/
-.pytest_cache/
-
-# Translations
-*.mo
-*.pot
-
-# Django stuff:
-*.log
-local_settings.py
-db.sqlite3
-db.sqlite3-journal
-
-# Flask stuff:
-instance/
-.webassets-cache
-
-# Scrapy stuff:
-.scrapy
-
-# Sphinx documentation
-docs/_build/
-
-# PyBuilder
-target/
-
-# Jupyter Notebook
-.ipynb_checkpoints
-
-# IPython
-profile_default/
-ipython_config.py
-
-# pyenv
-.python-version
-
-# pipenv
-# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
-# However, in case of collaboration, if having platform-specific dependencies or dependencies
-# having no cross-platform support, pipenv may install dependencies that don't work, or not
-# install all needed dependencies.
-#Pipfile.lock
-
-# PEP 582; used by e.g. github.com/David-OConnor/pyflow
-__pypackages__/
-
-# Celery stuff
-celerybeat-schedule
-celerybeat.pid
-
-# SageMath parsed files
-*.sage.py
-
-# Environments
-.env
-.venv
-env/
-venv/
-ENV/
-env.bak/
-venv.bak/
-
-# Spyder project settings
-.spyderproject
-.spyproject
-
-# Rope project settings
-.ropeproject
-
-# mkdocs documentation
-/site
-
-# mypy
-.mypy_cache/
-.dmypy.json
-dmypy.json
-
-# Pyre type checker
-.pyre/
-
-tmp/
-.idea
-result.png
diff --git a/sdk/example_containers/README.md b/sdk/example_containers/README.md
deleted file mode 100644
index a101bf2..0000000
--- a/sdk/example_containers/README.md
+++ /dev/null
@@ -1,89 +0,0 @@
-# Example task containers
-
-This folder contains example task containers showing how to build your own task container. Each folder must contain all of the files listed in the structure below.
-
-## Structure
-
-The structure of the task container is as follows:
-
-```
-- template
- - Dockerfile
- - src
- - description.txt
- - name.txt
- - example_input.bin
- - example_output.bin
- - config.json
-
-```
-
-## Building a task container
-
-### 1. App that handles requests
-
-The app will receive a post request at `localhost:8080\` and return the result. The input format is any json object and the output format is a string. After the app starts up, print `"meca-init-done"`.
-
-For example, we create a flask app:
-
-```python
- from flask import Flask, request
- import json
-
- app = Flask(__name__)
-
- @app.route('/', methods=['POST'])
- def hello_world():
- data = request.json
- return data['input']
-
- print("meca-init-done")
-```
-
-### 2. Dockerfile
-
-Expose port 8080 to the app of the request handler.
-
-Following the flask app created above, the Dockerfile may look like this:
-
-```dockerfile
-FROM python:3.9-slim
-
-WORKDIR /app
-
-COPY flask_app.py flask_app.py
-
-EXPOSE 8080
-
-CMD ["python", "-m", "flask", "--app", "flask_app.py", "run", "--host=0.0.0.0", "--port=8080"]
-```
-
-### 3. config.json fields
-
-The `config.json` file contains the configuration of the task with the following default fields:
-
-DEFAULTS:
-
-```json
-{
- "resource": {
- "cpu": 1,
- "mem": 128,
- "use_gpu": false,
- "gpu_count": 0
- }
-}
-```
-
-field | description
---- | ---
-`resource.cpu` | The number of CPUs to allocate to the task. This field will limit the users that can run the task to those with the same or more CPUs available.
-`resource.mem` | The amount of memory to allocate to the task in MB. This field will limit the users that can run the task to those with the same or more memory available.
-`resource.use_gpu` | Whether the task requires a GPU to run.
-`resource.gpu_count` | The number of GPUs to allocate to the task, if `use_gpu` is true.
-
-### 4. Using and uploading the container
-
-Build the image and push it to IPFS via the MECA CLI as a task developer. You will be compensated with the task fee that you list for each task executed by a MECA client.
-
-Test your task folder structure by running the test function in the MECA CLI.
diff --git a/sdk/example_containers/knn/Dockerfile b/sdk/example_containers/knn/Dockerfile
deleted file mode 100644
index 53c7577..0000000
--- a/sdk/example_containers/knn/Dockerfile
+++ /dev/null
@@ -1,14 +0,0 @@
-FROM python:3.9-slim
-
-WORKDIR /app
-
-COPY /src/requirements.txt requirements.txt
-
-RUN pip install torch==2.0.1+cpu --index-url https://download.pytorch.org/whl/cpu
-RUN pip install -r requirements.txt
-
-COPY /src/app.py app.py
-
-EXPOSE 8080
-
-CMD ["python", "-m", "flask", "--app", "app.py", "run", "--host=0.0.0.0", "--port=8080"]
diff --git a/sdk/example_containers/knn/config.json b/sdk/example_containers/knn/config.json
deleted file mode 100644
index 2fe573f..0000000
--- a/sdk/example_containers/knn/config.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "resource": {
- "cpu": 2,
- "mem": 1024
- }
-}
diff --git a/sdk/example_containers/knn/description.txt b/sdk/example_containers/knn/description.txt
deleted file mode 100644
index cf59838..0000000
--- a/sdk/example_containers/knn/description.txt
+++ /dev/null
@@ -1 +0,0 @@
-This app serves HTTP requests to run K-nearest neighbors algorithm on a chunked dataset in a distributed fashion.
diff --git a/sdk/example_containers/knn/example_input.bin b/sdk/example_containers/knn/example_input.bin
deleted file mode 100644
index bdef437..0000000
--- a/sdk/example_containers/knn/example_input.bin
+++ /dev/null
@@ -1 +0,0 @@
-{"dataset":[[1,2],[3,4],[5,6],[7,8],[9,10]],"point":[2,3],"k":2,"num_processes":2}
diff --git a/sdk/example_containers/knn/example_output.bin b/sdk/example_containers/knn/example_output.bin
deleted file mode 100644
index ed22a6f..0000000
--- a/sdk/example_containers/knn/example_output.bin
+++ /dev/null
@@ -1 +0,0 @@
-[0, 1]
diff --git a/sdk/example_containers/knn/name.txt b/sdk/example_containers/knn/name.txt
deleted file mode 100644
index c9ce200..0000000
--- a/sdk/example_containers/knn/name.txt
+++ /dev/null
@@ -1 +0,0 @@
-knn
diff --git a/sdk/example_containers/knn/src/app.py b/sdk/example_containers/knn/src/app.py
deleted file mode 100644
index a669913..0000000
--- a/sdk/example_containers/knn/src/app.py
+++ /dev/null
@@ -1,72 +0,0 @@
-import json
-import torch
-import multiprocessing
-from flask import Flask, request
-
-app = Flask(__name__)
-
-@app.route('/', methods=['POST'])
-def entry_point():
- input = request.json
-
- dataset = torch.Tensor(input.get('dataset'))
- point = torch.Tensor(input.get('point'))
- k = input.get('k')
- num_processes = input.get('num_processes')
-
- print("Number of processes:", num_processes)
- print("Number of nearest neighbors:", k)
-
- neighbors = distributed_knn(point, dataset, k, num_processes)
-
- print("Nearest neighbors indices:", neighbors)
- print("Nearest neighbors data points:", dataset[neighbors])
-
- return json.dumps(neighbors)
-
-
-def euclidean_distance(a, b):
- return torch.sqrt(torch.sum((a - b) ** 2))
-
-def find_k_nearest_neighbors(point, dataset_chunk, k):
- distances = [(index, euclidean_distance(point, data_point)) for index, data_point in enumerate(dataset_chunk)]
- distances.sort(key=lambda x: x[1])
- return [index for index, _ in distances[:k]]
-
-def process_data_chunk(point, dataset_chunk, k, chunk_start_index, result_queue):
- neighbors = find_k_nearest_neighbors(point, dataset_chunk, k)
- adjusted_neighbors = [index + chunk_start_index for index in neighbors]
- result_queue.put(adjusted_neighbors)
-
-def distributed_knn(point, dataset, k, num_processes):
- num_data_points = len(dataset)
- chunk_size = num_data_points // num_processes
-
- manager = multiprocessing.Manager()
- result_queue = manager.Queue()
-
- processes = []
- for i in range(num_processes):
- start_index = i * chunk_size
- end_index = (i + 1) * chunk_size if i < num_processes - 1 else num_data_points
- sliced_dataset = dataset[start_index:end_index].clone().detach()
- process = multiprocessing.Process(target=process_data_chunk, args=(point, sliced_dataset, k, start_index, result_queue))
- processes.append(process)
-
- for process in processes:
- process.start()
-
- for process in processes:
- process.join()
-
- neighbors_list = []
- while not result_queue.empty():
- neighbors_list.extend(result_queue.get())
-
- distances = [(index, euclidean_distance(point, dataset[index])) for index in neighbors_list]
- distances.sort(key=lambda x: x[1])
- overall_neighbors = [index for index, _ in distances[:k]]
-
- return overall_neighbors
-
-print("meca-init-done")
diff --git a/sdk/example_containers/knn/src/requirements.txt b/sdk/example_containers/knn/src/requirements.txt
deleted file mode 100644
index 1e595cb..0000000
--- a/sdk/example_containers/knn/src/requirements.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-blinker==1.6.2
-click==8.1.6
-colorama==0.4.6
-Flask==2.3.2
-itsdangerous==2.1.2
-Jinja2==3.1.2
-MarkupSafe==2.1.3
-numpy==1.25.2
-Werkzeug==2.3.6
diff --git a/sdk/example_containers/python-template/Dockerfile b/sdk/example_containers/python-template/Dockerfile
deleted file mode 100644
index a389098..0000000
--- a/sdk/example_containers/python-template/Dockerfile
+++ /dev/null
@@ -1,7 +0,0 @@
-FROM python:3.9.0
-WORKDIR /app
-COPY /src .
-RUN pip install -r requirements.txt
-EXPOSE 8080
-CMD ["flask", "run", "--host=0.0.0.0", "--port=8080"]
-
diff --git a/sdk/example_containers/python-template/config.json b/sdk/example_containers/python-template/config.json
deleted file mode 100644
index 3cf832b..0000000
--- a/sdk/example_containers/python-template/config.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "resource": {
- "cpu": 1,
- "mem": 128
- }
-}
diff --git a/sdk/example_containers/python-template/description.txt b/sdk/example_containers/python-template/description.txt
deleted file mode 100644
index 6793fb5..0000000
--- a/sdk/example_containers/python-template/description.txt
+++ /dev/null
@@ -1 +0,0 @@
-description of the task
diff --git a/sdk/example_containers/python-template/example_input.bin b/sdk/example_containers/python-template/example_input.bin
deleted file mode 100644
index 756ef39..0000000
--- a/sdk/example_containers/python-template/example_input.bin
+++ /dev/null
@@ -1,2 +0,0 @@
-{"json": "example input for the task"}
-
diff --git a/sdk/example_containers/python-template/example_output.bin b/sdk/example_containers/python-template/example_output.bin
deleted file mode 100644
index b5a9f83..0000000
--- a/sdk/example_containers/python-template/example_output.bin
+++ /dev/null
@@ -1 +0,0 @@
-{"json": "example input for the task"}
diff --git a/sdk/example_containers/python-template/name.txt b/sdk/example_containers/python-template/name.txt
deleted file mode 100644
index c6cbceb..0000000
--- a/sdk/example_containers/python-template/name.txt
+++ /dev/null
@@ -1 +0,0 @@
-name of the task
diff --git a/sdk/example_containers/python-template/src/app.py b/sdk/example_containers/python-template/src/app.py
deleted file mode 100644
index 596fa41..0000000
--- a/sdk/example_containers/python-template/src/app.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import json
-from flask import Flask, request
-
-app = Flask(__name__)
-
-@app.route('/', methods=['POST'])
-def entry_point():
- input = request.json
-
- return json.dumps(input)
-
-print("meca-init-done")
diff --git a/sdk/example_containers/python-template/src/requirements.txt b/sdk/example_containers/python-template/src/requirements.txt
deleted file mode 100644
index e3e9a71..0000000
--- a/sdk/example_containers/python-template/src/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-Flask
diff --git a/sdk/example_containers/sgx-task/Dockerfile b/sdk/example_containers/sgx-task/Dockerfile
deleted file mode 100644
index 747742f..0000000
--- a/sdk/example_containers/sgx-task/Dockerfile
+++ /dev/null
@@ -1,148 +0,0 @@
-FROM ubuntu:20.04 as sgx_dcap_2.14_1.11
-
-USER root
-
-# avoid tzdata interactive config during apt install.
-ENV TZ=Asia/Singapore
-RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
-
-RUN apt-get update && apt-get install -y \
- build-essential \
- git \
- wget
-
-# install sdk
-RUN wget https://download.01.org/intel-sgx/sgx-dcap/1.11/linux/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.14.100.2.bin \
- && chmod 755 sgx_linux_x64_sdk_2.14.100.2.bin \
- && ./sgx_linux_x64_sdk_2.14.100.2.bin --prefix=/opt/intel \
- source /opt/intel/sgxsdk/environment
-
-# install dcap libs
-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 > /dev/null \
- && wget -O - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add - \
- && apt update
-
-RUN apt install -y \
- libsgx-epid=2.14.100.2-focal1 \
- libsgx-headers=2.14.100.2-focal1 \
- libsgx-urts=2.14.100.2-focal1 \
- libsgx-launch=2.14.100.2-focal1 \
- libsgx-ae-le=2.14.100.2-focal1 \
- libsgx-ae-pce=2.14.100.2-focal1 \
- libsgx-ae-qe3=1.11.100.2-focal1 \
- libsgx-ae-qve=1.11.100.2-focal1 \
- libsgx-ae-epid=2.14.100.2-focal1 \
- libsgx-qe3-logic=1.11.100.2-focal1 \
- libsgx-pce-logic=1.11.100.2-focal1 \
- libsgx-enclave-common=2.14.100.2-focal1 \
- sgx-aesm-service=2.14.100.2-focal1 \
- libsgx-quote-ex=2.14.100.2-focal1 \
- libsgx-dcap-ql=1.11.100.2-focal1 \
- libsgx-dcap-quote-verify=1.11.100.2-focal1 \
- # workload system additional packages
- libsgx-quote-ex-dev=2.14.100.2-focal1 \
- libsgx-dcap-ql-dev=1.11.100.2-focal1 \
- libsgx-dcap-quote-verify-dev=1.11.100.2-focal1 \
- # qpl needed for verification
- libsgx-dcap-default-qpl=1.11.100.2-focal1 \
- # runtime
- libsgx-uae-service=2.14.100.2-focal1
-
-# install sgx-sdk mitigation tools (necessary to build sgxssl)
-RUN apt-get install -y \
- build-essential \
- ocaml \
- ocamlbuild \
- automake \
- autoconf \
- libtool \
- wget \
- python-is-python3 \
- libssl-dev \
- git \
- cmake \
- perl \
- libssl-dev \
- libcurl4-openssl-dev \
- protobuf-compiler \
- libprotobuf-dev \
- debhelper \
- reprepro \
- unzip \
- && cd / && git clone https://github.com/intel/linux-sgx.git && cd linux-sgx && git checkout sgx_2.14 && make preparation
-
-RUN ls /linux-sgx/external/toolset/ubuntu20.04/ && cp /linux-sgx/external/toolset/ubuntu20.04/* /usr/local/bin && cd / && ls /usr/local/bin
-
-# install sgxssl
-RUN wget https://github.com/intel/intel-sgx-ssl/archive/refs/tags/lin_2.14_1.1.1k.tar.gz \
- && tar -xzvf lin_2.14_1.1.1k.tar.gz \
- && cd intel-sgx-ssl-lin_2.14_1.1.1k/openssl_source \
- && wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz \
- && cd ../Linux && make all && make install && cd ../
-
-# should remove the sources
-RUN rm -rf /linux-sgx && rm -rf /lin_2.14_1.1.1k.tar.gz /intel-sgx-ssl-lin_2.14_1.1.1k
-
-# image size: 1.94GB
-
-FROM sgx_dcap_2.14_1.11 as server_builder
-
-USER root
-
-ENV SGX_SDK=/opt/intel/sgxsdk
-
-# avoid tzdata interactive config during apt install.
-ENV TZ=Asia/Singapore
-RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
-
-RUN apt-get update && apt-get install -y \
- # install deps (libuv)
- cmake \
- clang
-
-# # without -i the bash will not load .bashrc. With -i docker complains but we can ignore it.
-# SHELL ["/bin/bash", "--login", "-i", "-c"]
-# ENV NODE_VERSION=16.15.0
-# ENV NVM_DIR /tmp/nvm
-# WORKDIR $NVM_DIR
-# RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
-# && . $NVM_DIR/nvm.sh \
-# && nvm install $NODE_VERSION \
-# && nvm alias default $NODE_VERSION \
-# && nvm use default
-# ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
-# ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH
-
-# a cleaner version of the above
-ENV NVM_DIR /usr/local/nvm
-ENV NODE_VERSION v16.15.0
-RUN mkdir -p /usr/local/nvm
-RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
-RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
-ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin
-ENV PATH $NODE_PATH:$PATH
-
-RUN node --version && npm --version
-
-COPY ./src /sgx-task
-RUN cd /sgx-task/ && make mrproper && make deps \
- && cd worker && make mrproper && make all && make install && cd ..\
- && cd server && make mrproper && make all && make install && cd ..
-
-# image
-FROM sgx_dcap_2.14_1.11
-
-USER root
-
-# # default libuv thread pool size to 8.
-# ARG UV_THREADPOOL_SIZE=8
-# RUN echo UV_THREADPOOL_SIZE=${UV_THREADPOOL_SIZE}
-# ENV UV_THREADPOOL_SIZE ${UV_THREADPOOL_SIZE}
-# sequential request execution
-ENV UV_THREADPOOL_SIZE 1
-
-COPY --from=server_builder /sgx-task/server/install /install
-
-EXPOSE 8080
-
-CMD SGX_AESM_ADDR=1 /install/bin/server /install/lib/Worker_Enclave.signed.so
diff --git a/sdk/example_containers/sgx-task/README.md b/sdk/example_containers/sgx-task/README.md
deleted file mode 100644
index 8d3ed16..0000000
--- a/sdk/example_containers/sgx-task/README.md
+++ /dev/null
@@ -1,61 +0,0 @@
-# sgx-task-worker
-
-SGX task worker sample: It creates a server that conforms to the meca requirement and respond to users input `name` with `hello name`.
-
-## setup
-
-Environment setup
-
-Follow the DCAP setup guides to register the worker machine to Intel Platform Certification Service and cache its attestation collateral at the meca designated Platform Certification Caching Service server.
-
-The sgx-task server shall be able to prepare an attestation report during RA.
-
-## build
-
-To build the sample app, under `sgx-task/` run
-
-```sh
-docker build -t sgx-task .
-```
-
-To test the server
-
-```sh
-docker run -it -p 2333:8080 --device /dev/sgx_enclave:/dev/sgx/enclave -v /var/run/aesmd:/var/run/aesmd sgx-task
-```
-
-issue a request (now requires the client to perform encryption decryption)
-
-
-
-```sh
-cd src/client_test
-make clean && make all
-./client_ec_test
-```
-
-## example input and output
-
-These are the input packaged and response received with the `client_test`.
-
-The example input:
-
-```json
-{
- "value" : "e2668b74921293303890963bc088b4478d827ea42d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d485977454159484b6f5a497a6a3043415159464b344545414349445967414535314376636e4a496f6f455866563834614941676a6d75596a3647334252464d0a5a577770434f65514c324349745a4751713075435a794e4e747972414563767970615a47674f4f7156772f534e533166737062474d5a4e6f2b656b37584536450a433644537a503043617332494e4769312f6757577351616773414835504566360a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a000000000000000000000000bd7c85ff9a050361b53372a4bdb1bd7e"
-}
-```
-
-The hex value are encrypted with the users key value of `sbip` with the output encryption key encrypted by the shared session key established after remote attestation.
-
-The example output:
-
-```json
-{
- "msg" : "c4631eafeb6044a9fa0300000000000000000000000072988629eb5cad55f89ad8315553727e"
-}
-```
-
-The hex value is `hello-sbip` encrypted with the output encryption key.
diff --git a/sdk/example_containers/sgx-task/config.json b/sdk/example_containers/sgx-task/config.json
deleted file mode 100644
index ac5b3c5..0000000
--- a/sdk/example_containers/sgx-task/config.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "resource": {
- "cpu": 1,
- "memory": 128,
- "use_gpu": false,
- "gpu_count": 0,
- "use_sgx": true
- }
-}
diff --git a/sdk/example_containers/sgx-task/description.txt b/sdk/example_containers/sgx-task/description.txt
deleted file mode 100644
index 0429875..0000000
--- a/sdk/example_containers/sgx-task/description.txt
+++ /dev/null
@@ -1 +0,0 @@
-This app serves HTTP requests to echo back input. The encrypted input is decrypted inside SGX enclave and reencrypted as output.
diff --git a/sdk/example_containers/sgx-task/example_input.bin b/sdk/example_containers/sgx-task/example_input.bin
deleted file mode 100644
index d697571..0000000
--- a/sdk/example_containers/sgx-task/example_input.bin
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "value" : "e2668b74921293303890963bc088b4478d827ea42d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d485977454159484b6f5a497a6a3043415159464b344545414349445967414535314376636e4a496f6f455866563834614941676a6d75596a3647334252464d0a5a577770434f65514c324349745a4751713075435a794e4e747972414563767970615a47674f4f7156772f534e533166737062474d5a4e6f2b656b37584536450a433644537a503043617332494e4769312f6757577351616773414835504566360a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a000000000000000000000000bd7c85ff9a050361b53372a4bdb1bd7e"
- }
\ No newline at end of file
diff --git a/sdk/example_containers/sgx-task/example_output.bin b/sdk/example_containers/sgx-task/example_output.bin
deleted file mode 100644
index d5312ab..0000000
--- a/sdk/example_containers/sgx-task/example_output.bin
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "msg" : "c4631eafeb6044a9fa0300000000000000000000000072988629eb5cad55f89ad8315553727e"
- }
diff --git a/sdk/example_containers/sgx-task/name.txt b/sdk/example_containers/sgx-task/name.txt
deleted file mode 100644
index ccb3d0d..0000000
--- a/sdk/example_containers/sgx-task/name.txt
+++ /dev/null
@@ -1 +0,0 @@
-sgx-sample
\ No newline at end of file
diff --git a/sdk/example_containers/sgx-task/src/Makefile b/sdk/example_containers/sgx-task/src/Makefile
deleted file mode 100644
index b737cba..0000000
--- a/sdk/example_containers/sgx-task/src/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-# used to mainly build dependencies
-PROJECT_ROOT_DIR := $(shell readlink -f .)
-
-DEPS_INSTALL_DIR = $(PROJECT_ROOT_DIR)/deps/install
-
-LIBUV_DIR = $(PROJECT_ROOT_DIR)/deps/libuv
-LLHTTP_DIR = $(PROJECT_ROOT_DIR)/deps/llhttp
-
-.PHONY: all concurrent_runtime_deps deps mrproper preparation
-
-preparation:
- git submodule update --init --recursive
-
-server_deps:
- mkdir -p $(DEPS_INSTALL_DIR)
- cd $(LIBUV_DIR) && mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=$(DEPS_INSTALL_DIR)/libuv && make && make install && cd $(PROJECT_ROOT_DIR)
- mkdir -p $(DEPS_INSTALL_DIR)/llhttp/include && mkdir $(DEPS_INSTALL_DIR)/llhttp/lib
- npm --version
- cd $(LLHTTP_DIR) && npm install && make && PREFIX=$(DEPS_INSTALL_DIR)/llhttp make install && cd $(PROJECT_ROOT_DIR)
-
-server_deps_clean:
- make -C $(LLHTTP_DIR) clean
- rm -rf $(LLHTTP_DIR)/node_modules
- rm -rf $(LIBUV_DIR)/build
-
-deps: server_deps
-
-all: preparation deps
-
-clean:
- @echo "nothing to clean"
-
-mrproper: clean server_deps_clean
- rm -rf deps/install
diff --git a/sdk/example_containers/sgx-task/src/client_test/Makefile b/sdk/example_containers/sgx-task/src/client_test/Makefile
deleted file mode 100644
index 8276c3e..0000000
--- a/sdk/example_containers/sgx-task/src/client_test/Makefile
+++ /dev/null
@@ -1,29 +0,0 @@
-PROJECT_ROOT_DIR ?= $(shell readlink -f ..)
-
-App_C_Cpp_Flags := -O0 -g -fPIC -Wno-attributes -I.
-App_C_Cpp_Flags += -I$(PROJECT_ROOT_DIR)
-
-.PHONY: all clean
-
-all: client_ec_test
-
-hexutil.o: $(PROJECT_ROOT_DIR)/common/hexutil.cc
- g++ $(App_C_Cpp_Flags) -c $< -o $@
- @echo "CXX <= $<"
-
-json.o: $(PROJECT_ROOT_DIR)/common/json.cc
- g++ $(App_C_Cpp_Flags) -c $< -o $@
- @echo "CXX <= $<"
-
-%.o: %.cc
- g++ $(App_C_Cpp_Flags) -c $< -o $@
- @echo "CXX <= $<"
-
-App_Cpp_Objects := hexutil.o json.o
-
-client_ec_test: main_ec.o $(App_Cpp_Objects)
- g++ $^ -o $@ -lcrypto -lssl -lcurl
- @echo "Link => $@"
-
-clean:
- rm -f client_ec_test *.o
diff --git a/sdk/example_containers/sgx-task/src/client_test/main_ec.cc b/sdk/example_containers/sgx-task/src/client_test/main_ec.cc
deleted file mode 100644
index cb3ab49..0000000
--- a/sdk/example_containers/sgx-task/src/client_test/main_ec.cc
+++ /dev/null
@@ -1,450 +0,0 @@
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-
-#include "common/hexutil.h"
-#include "common/json.h"
-
-#define MAX_SESSION_KEY_IV_LENGTH 16
-
-unsigned char default_output_key[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
- 0x36, 0x37, 0x38, 0x39, 0x30, 0x31,
- 0x32, 0x33, 0x34, 0x35};
-
-#define EC_PUBLIC_KEY_SIZE 215
-
-int get_pkey_by_ec(EVP_PKEY* pk) {
- int res = -1;
- EVP_PKEY_CTX* ctx;
-
- ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
- if (ctx == NULL) return res;
- res = EVP_PKEY_keygen_init(ctx);
- if (res <= 0) {
- // PRINT("EC_generate_key failed (%d)\n", res);
- goto done;
- }
-
- res = EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, NID_secp384r1);
- if (res <= 0) {
- // PRINT("EC_generate_key failed (%d)\n", res);
- goto done;
- }
-
- /* Generate key */
- res = EVP_PKEY_keygen(ctx, &pk);
- if (res <= 0) {
- // PRINT("EC_generate_key failed (%d)\n", res);
- goto done;
- }
-
-done:
- if (ctx) EVP_PKEY_CTX_free(ctx);
-
- return res;
-}
-
-std::string get_public_key_as_string(EVP_PKEY* pkey) {
- BIO* bio = BIO_new(BIO_s_mem());
- PEM_write_bio_PUBKEY(bio, pkey);
- // Allocate memory
- uint8_t* local_public_key = (uint8_t*)malloc(EC_PUBLIC_KEY_SIZE + 1);
- if (!local_public_key) {
- BIO_free(bio);
- return "";
- }
- memset(local_public_key, 0x00, EC_PUBLIC_KEY_SIZE + 1);
- if (!BIO_read(bio, local_public_key, EC_PUBLIC_KEY_SIZE + 1)) {
- BIO_free(bio);
- return "";
- }
-
- BIO_free(bio);
- auto ret =
- std::string((char*)local_public_key, strlen((char*)local_public_key));
- free(local_public_key);
- return ret;
-}
-
-void load_public_key(const char* pub_key, size_t pub_key_size,
- EVP_PKEY** pkey) {
- BIO* bio = BIO_new_mem_buf(pub_key, pub_key_size);
- EC_KEY* ecPublicKey = NULL;
- PEM_read_bio_EC_PUBKEY(bio, &ecPublicKey, NULL, NULL);
- EVP_PKEY_assign_EC_KEY(*pkey, ecPublicKey);
- printf("public key size: %d\n", EVP_PKEY_size(*pkey));
- BIO_free(bio);
-}
-
-void load_private_key(const char* pri_key, size_t pri_key_size,
- EVP_PKEY** pkey) {
- BIO* bio = BIO_new_mem_buf(pri_key, pri_key_size);
- EC_KEY* ecPrivateKey = NULL;
- PEM_read_bio_ECPrivateKey(bio, &ecPrivateKey, NULL, NULL);
- EVP_PKEY_assign_EC_KEY(*pkey, ecPrivateKey);
- printf("private key size: %d\n", EVP_PKEY_size(*pkey));
- BIO_free(bio);
-}
-
-std::string derive_ecdh_secret(EVP_PKEY* own_key, EVP_PKEY* peer_key) {
- EVP_PKEY_CTX* ctx = EVP_PKEY_CTX_new(own_key, NULL);
- if (!ctx) {
- printf("EVP_PKEY_CTX_new failed\n");
- return "";
- }
- if (EVP_PKEY_derive_init(ctx) != 1) {
- printf("EVP_PKEY_derive_init failed\n");
- return "";
- }
-
- if (EVP_PKEY_derive_set_peer(ctx, peer_key) != 1) {
- printf("EVP_PKEY_derive_set_peer failed\n");
- return "";
- }
-
- size_t secret_len;
- if (1 != EVP_PKEY_derive(ctx, NULL, &secret_len)) {
- return "";
- }
-
- unsigned char* secret = (unsigned char*)malloc(secret_len);
- if (!secret) {
- printf("malloc secret failed\n");
- return "";
- }
-
- if (EVP_PKEY_derive(ctx, secret, &secret_len) != 1) {
- printf("EVP_PKEY_derive failed\n");
- return "";
- }
- auto ret = std::string((char*)secret, secret_len);
- EVP_PKEY_CTX_free(ctx);
- free(secret);
- return ret;
-}
-
-std::string kdf_derive(const unsigned char* secret, size_t secret_len,
- const char* info, size_t info_len, size_t key_size) {
- char* key = (char*)malloc(key_size);
- if (!key) {
- return "";
- }
- memset(key, 0, key_size);
- EVP_PKEY_CTX* ctx;
- if (NULL == (ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL))) {
- return "";
- }
- if (1 != EVP_PKEY_derive_init(ctx)) {
- return "";
- }
- if (1 != EVP_PKEY_CTX_set_hkdf_md(ctx, EVP_sha256())) {
- return "";
- }
- if (1 != EVP_PKEY_CTX_set1_hkdf_key(ctx, secret, secret_len)) {
- return "";
- }
- if (1 != EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, 0)) {
- return "";
- }
- if (1 != EVP_PKEY_CTX_add1_hkdf_info(ctx, info, info_len)) {
- return "";
- }
- if (1 != EVP_PKEY_derive(ctx, (unsigned char*)key, &key_size)) {
- return "";
- }
- EVP_PKEY_CTX_free(ctx);
- std::string ret{key, key_size};
- free(key);
- return ret;
-}
-
-std::string encrypt_request(const std::string& data,
- const std::string& enclave_public_key,
- const std::string& output_key) {
- std::string plaintext{data};
- plaintext.append(output_key.c_str(), 16);
- int encrypted_message_len = 0;
- unsigned char* ek = NULL;
- int ek_len = 0;
- unsigned char iv[MAX_SESSION_KEY_IV_LENGTH];
- memset(iv, 0, MAX_SESSION_KEY_IV_LENGTH);
- size_t encrypted_message_max_length = plaintext.size() + EVP_MAX_IV_LENGTH;
- unsigned char encrypted[encrypted_message_max_length];
- memset(encrypted, 0, encrypted_message_max_length);
- EVP_PKEY* pkey = EVP_PKEY_new();
- load_public_key(enclave_public_key.data(), enclave_public_key.size(), &pkey);
-
- EVP_PKEY* tmp_ec_key_pair = EVP_PKEY_new();
- get_pkey_by_ec(tmp_ec_key_pair);
-
- // derive shared seccret
- auto secret = derive_ecdh_secret(tmp_ec_key_pair, pkey);
- auto session_key = kdf_derive((const unsigned char*)secret.c_str(),
- secret.size(), "info", 4, 16);
-
- // encrypt data with the derived secret
- EVP_CIPHER_CTX* ctx2 = EVP_CIPHER_CTX_new();
- if (EVP_EncryptInit_ex(ctx2, EVP_aes_128_gcm(), NULL,
- (const unsigned char*)session_key.c_str(), iv) != 1) {
- printf("EVP_EncryptInit_ex failed\n");
- EVP_CIPHER_CTX_free(ctx2);
- return "";
- }
- int ciphertext_len = 0;
- int len;
- if (EVP_EncryptUpdate(ctx2, encrypted, &len,
- (const unsigned char*)plaintext.data(),
- plaintext.size()) != 1) {
- printf("EVP_EncryptUpdate failed\n");
- EVP_CIPHER_CTX_free(ctx2);
- return "";
- }
- ciphertext_len = len;
- printf("encrypted data updated to (%dB)\n", ciphertext_len);
-
- if (EVP_EncryptFinal_ex(ctx2, encrypted + len, &len) != 1) {
- printf("EVP_EncryptFinal_ex failed\n");
- EVP_CIPHER_CTX_free(ctx2);
- return "";
- }
- ciphertext_len += len;
- printf("encrypted data updated to (%dB)\n", ciphertext_len);
-
- unsigned char tag[16] = {
- 0,
- };
- EVP_CIPHER_CTX_ctrl(ctx2, EVP_CTRL_GCM_GET_TAG, 16, tag);
- printf("tag: \n");
- BIO_dump_fp(stdout, (const char*)tag, 16);
-
- EVP_CIPHER_CTX_free(ctx2);
-
- auto tmp_ec_key_pair_str = get_public_key_as_string(tmp_ec_key_pair);
- printf("tmp ec key pair (len: %ld) : %s\n", tmp_ec_key_pair_str.size(),
- tmp_ec_key_pair_str.c_str());
-
- EVP_PKEY_free(pkey);
- EVP_PKEY_free(tmp_ec_key_pair);
-
- return std::string((char*)encrypted, ciphertext_len) + tmp_ec_key_pair_str +
- std::string((char*)iv, 12) + std::string((char*)tag, 16);
-}
-
-std::string decrypt_response(const std::string& data,
- const std::string& output_key) {
- uint8_t tag[16];
- memcpy(tag, data.data() + data.size() - 16, 16);
- uint8_t iv[12];
- memcpy(iv, data.data() + data.size() - 28, 12);
- size_t encrypt_len = data.size() - 28;
- EVP_CIPHER_CTX* ctx;
- /* Create and initialise the context */
- if (!(ctx = EVP_CIPHER_CTX_new())) return "";
-
- if (EVP_DecryptInit_ex(
- ctx, EVP_aes_128_gcm(), NULL,
- reinterpret_cast(output_key.c_str()),
- iv) != 1) {
- EVP_CIPHER_CTX_free(ctx);
- return "";
- }
-
- EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag);
-
- uint8_t plaintext[encrypt_len];
- int plaintext_len;
- int len;
- if (EVP_DecryptUpdate(ctx, plaintext, &len, (const unsigned char*)data.data(),
- encrypt_len) != 1) {
- EVP_CIPHER_CTX_free(ctx);
- return "";
- }
- plaintext_len = len;
- // printf("so far plaintext len: %d\n", plaintext_len);
-
- if (EVP_DecryptFinal_ex(ctx, plaintext + len, &len) != 1) {
- EVP_CIPHER_CTX_free(ctx);
- return "";
- }
- plaintext_len += len;
-
- EVP_CIPHER_CTX_free(ctx);
- return std::string((char*)plaintext, plaintext_len);
-}
-
-class HttpClient {
- public:
- HttpClient() {
- // Initialize curl
- curl_global_init(CURL_GLOBAL_DEFAULT);
- curl = curl_easy_init();
- }
-
- ~HttpClient() {
- std::cout << "HttpClient destructor called\n";
- // Cleanup curl
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- }
-
- std::string get(const std::string& url) {
- if (curl) {
- // Set the URL to send the GET request to
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-
- // Store response in a string
- std::string response;
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
-
- // Perform the GET request
- CURLcode res = curl_easy_perform(curl);
- if (res != CURLE_OK) {
- std::cerr << "Failed to perform GET request: "
- << curl_easy_strerror(res) << "\n";
- }
-
- return response;
- }
-
- return "";
- }
-
- std::string post(const std::string& url, const std::string& data) {
- if (curl) {
- // Set the URL to send the GET request to
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-
- // set the post data
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
-
- // Store response in a string
- std::string response;
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
-
- // Perform the GET request
- CURLcode res = curl_easy_perform(curl);
- if (res != CURLE_OK) {
- std::cerr << "Failed to perform GET request: "
- << curl_easy_strerror(res) << "\n";
- }
-
- return response;
- }
-
- return "";
- }
-
- private:
- static size_t writeCallback(char* data, size_t size, size_t nmemb,
- std::string* buffer) {
- // Append the data to the buffer
- buffer->append(data, size * nmemb);
- return size * nmemb;
- }
-
- CURL* curl;
-};
-
-class SGXTaskClient : public HttpClient {
- public:
- SGXTaskClient(const std::string& addr) : HttpClient(), addr_(addr) {}
-
- ~SGXTaskClient() = default;
-
- void ra() {
- // get report
- std::string url = addr_ + "/ra";
- std::string response = get(url);
- if (response.size() == 0) {
- std::cerr << "Failed to get report from server\n";
- return;
- }
-
- std::cout << "RA Response: " << response << "\n";
-
- // decode the response:
- auto data = json::JSON::Load(response);
- auto msg = json::JSON::Load(data["msg"].ToString());
- this->report_ = msg["report"].ToString();
- this->enclave_key_ = msg["key"].ToString();
- }
-
- std::string exec(const std::string& input, const std::string& output_key) {
- if (this->enclave_key_.size() == 0 || this->enclave_key_ == "null") {
- std::cerr << "Enclave key not initialized\n";
- return "";
- }
-
- // encrypt the input
- std::string encrypted_input =
- encrypt_request(input, enclave_key_, output_key);
-
- std::cout << "prepared sample size: " << encrypted_input.size() << "\n";
-
- // send the request
- std::string url = addr_ + "/run";
- json::JSON json_request;
-
- json_request["value"] =
- hex_encode(encrypted_input.data(), encrypted_input.size());
-
- // std::string response = post(url, "{\"value\": \"" + encrypted_input+
- // "\"}");
- auto request_data = json_request.dump();
- std::cout << "request data: " << request_data << "\n";
- std::string response = post(url, request_data);
- if (response.size() == 0) {
- std::cerr << "Failed to get response from server\n";
- return "";
- }
-
- std::cout << "exec Response: " << response << "\n";
-
- auto data = json::JSON::Load(response);
- auto msg = data["msg"].ToString();
- // decrypt the response
- std::string decrypted_response =
- decrypt_response(hex_decode(msg.c_str(), msg.size()), output_key);
- return decrypted_response;
- }
-
- private:
- std::string addr_;
- // initialized after ra
- std::string report_;
- std::string enclave_key_;
-};
-
-int main() {
- // {
- // std::string url = "127.0.0.1:8080";
- // HttpClient client;
-
- // // get
- // std::string response = client.get(url);
- // std::cout << "Response: " << response << "\n";
-
- // // put
- // response = client.post(url, "{\"name\": \"sbip\"}");
- // std::cout << "Response: " << response << "\n";
- // }
-
- {
- SGXTaskClient client{"127.0.0.1:2333"};
- // SGXTaskClient client{"172.18.0.255:8080"};
- client.ra();
- auto response =
- client.exec("sbip", std::string((char*)default_output_key, 16));
- std::cout << "Response: " << response << "\n";
- }
-
- return 0;
-}
diff --git a/sdk/example_containers/sgx-task/src/common/fileutil.cc b/sdk/example_containers/sgx-task/src/common/fileutil.cc
deleted file mode 100644
index 8f900f6..0000000
--- a/sdk/example_containers/sgx-task/src/common/fileutil.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "fileutil.h"
-
-#include
-#include
-
-int ReadFileToString(const std::string& file_path, std::string* content) {
- assert(content);
- std::ifstream infile(file_path);
- if (!infile.good()) {
- printf("file failed to load: %s\n", file_path.c_str());
- return 0; // cannot differentiate file not exist or error in openning
- }
- std::stringstream ss;
- ss << infile.rdbuf();
- *content = ss.str();
- return 0;
-}
-
-/**
- * @brief read the content of a file into a char array.
- *
- * @param file_path
- * @param output_len output_len will be updated with the len of read content,
- * if succeeded
- * @return char* : read content (caller owns the data and shall free it).
- */
-char* ReadFileToCharArray(const char* file_path, size_t* output_len) {
- assert(file_path);
- assert(output_len);
- FILE* fp = std::fopen(file_path, "rb");
- if (fp == nullptr) {
- printf("failed to open file: %s\n", file_path);
- return nullptr;
- }
- if (std::fseek(fp, 0, SEEK_END) == -1) {
- printf("fseek error\n");
- return nullptr;
- }
- auto file_len = std::ftell(fp);
- if (file_len == -1) {
- printf("ftell error\n");
- return nullptr;
- }
- if (file_len == 0) {
- *output_len = 0;
- return nullptr;
- }
- auto ret = malloc(file_len + 1);
- if (ret == nullptr) {
- printf("malloc failed\n");
- return nullptr;
- }
- std::rewind(fp);
- if (std::fread(ret, 1, file_len, fp) != static_cast(file_len)) {
- printf("fread error");
- free(ret);
- return nullptr;
- }
- if (std::fclose(fp) == -1) {
- printf("close error");
- free(ret);
- return nullptr;
- }
- *output_len = file_len;
- ((char*)ret)[file_len] = '\0';
- return (char*)ret;
-}
-
-int WriteStringToFile(const std::string& file_path,
- const std::string& content) {
- std::ofstream outfile(file_path, std::ios::out);
- outfile << content;
- outfile.flush();
- outfile.close();
- return 0;
-}
-
-/**
- * @brief write a char array to a file
- *
- * @param file_path
- * @param src
- * @param len : len of the char array
- * @return int : 0 for success; -1 for failure
- */
-int WriteCharArrayToFile(const char* file_path, const char* src, size_t len) {
- assert(file_path);
- assert(src);
- FILE* fp = std::fopen(file_path, "wb");
- if (fp == nullptr) {
- printf("failed to open file\n");
- return -1;
- }
- if (std::fwrite(src, 1, len, fp) != len) {
- printf("fwrite error");
- return -1;
- }
- if (std::fclose(fp) == -1) {
- printf("close error");
- return -1;
- }
- return 0;
-}
diff --git a/sdk/example_containers/sgx-task/src/common/fileutil.h b/sdk/example_containers/sgx-task/src/common/fileutil.h
deleted file mode 100644
index 098f23c..0000000
--- a/sdk/example_containers/sgx-task/src/common/fileutil.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef MECA_SGX_COMMON_U_FILEUTIL_H_
-#define MECA_SGX_COMMON_U_FILEUTIL_H_
-
-#include
-
-inline bool IsFileExist(const std::string& file_path) {
- std::ifstream infile(file_path);
- return infile.good();
-}
-
-int ReadFileToString(const std::string& file_path, std::string* content);
-
-/**
- * @brief read the content of a file into a char array.
- *
- * @param file_path
- * @param output_len output_len will be updated with the len of read content,
- * if succeeded
- * @return char* : read content (caller owns the data and shall free it).
- */
-char* ReadFileToCharArray(const char* file_path, size_t* output_len);
-
-int WriteStringToFile(const std::string& file_path, const std::string& content);
-
-/**
- * @brief write a char array to a file
- *
- * @param file_path
- * @param src
- * @param len : len of the char array
- * @return int : 0 for success; -1 for failure
- */
-int WriteCharArrayToFile(const char* file_path, const char* src, size_t len);
-
-#endif // MECA_SGX_COMMON_U_FILEUTIL_H_
diff --git a/sdk/example_containers/sgx-task/src/common/hexutil.cc b/sdk/example_containers/sgx-task/src/common/hexutil.cc
deleted file mode 100644
index 4172cef..0000000
--- a/sdk/example_containers/sgx-task/src/common/hexutil.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-#include "hexutil.h"
-
-#include
-#include
-#include
-
-namespace {
-const char _hextable[] = "0123456789abcdef";
-
-struct hex_buffer_deleter {
- void operator()(void *p) const { free(p); }
-};
-
-thread_local std::unique_ptr _hex_buffer{nullptr};
-thread_local size_t _hex_buffer_size = 0;
-} // anonymous namespace
-
-void print_hexstring(FILE *fp, const void *vsrc, size_t len) {
- const unsigned char *sp = (const unsigned char *)vsrc;
- size_t i;
- for (i = 0; i < len; ++i) {
- fprintf(fp, "%02x", sp[i]);
- }
- fprintf(fp, "\n");
-}
-
-const char *hexstring(const void *vsrc, size_t len) {
- size_t i, bsz;
- const char *src = (const char *)vsrc;
- char *bp;
-
- bsz = len * 2 + 1; /* Make room for NULL byte */
- if (bsz >= _hex_buffer_size) {
- /* Allocate in 1K increments. Make room for the NULL byte. */
- size_t newsz = 1024 * (bsz / 1024) + ((bsz % 1024) ? 1024 : 0);
- _hex_buffer_size = newsz;
- auto _hex_buffer_ptr = (char *)realloc(_hex_buffer.get(), newsz);
- if (_hex_buffer_ptr == NULL) {
- return "(out of memory)";
- }
- _hex_buffer.release();
- _hex_buffer.reset(_hex_buffer_ptr);
- }
-
- for (i = 0, bp = _hex_buffer.get(); i < len; ++i) {
- *bp = _hextable[(uint8_t)src[i] >> 4];
- ++bp;
- *bp = _hextable[(uint8_t)src[i] & 0xf];
- ++bp;
- }
- _hex_buffer.get()[len * 2] = 0;
-
- return (const char *)_hex_buffer.get();
-}
-
-// need testing
-std::string hex_encode(const void *vsrc, size_t len) {
- const char *src = (const char *)vsrc;
- char ret[len * 2 + 1];
- char *bp = ret;
- for (size_t i = 0; i < len; ++i) {
- *bp = _hextable[(uint8_t)src[i] >> 4];
- ++bp;
- *bp = _hextable[(uint8_t)src[i] & 0xf];
- ++bp;
- }
- ret[len * 2] = 0;
- return std::string(ret, len * 2);
-}
-
-// need testing
-std::string hex_decode(const char *vsrc, size_t len) {
- const char *src = (const char *)vsrc;
- char ret[len / 2];
- char *bp = ret;
- for (size_t i = 0; i < len; i += 2) {
- *bp = (uint8_t)((src[i] >= 'a' ? src[i] - 'a' + 10 : src[i] - '0') << 4);
- *bp |=
- (uint8_t)(src[i + 1] >= 'a' ? src[i + 1] - 'a' + 10 : src[i + 1] - '0');
- ++bp;
- }
- return std::string(ret, len / 2);
-}
\ No newline at end of file
diff --git a/sdk/example_containers/sgx-task/src/common/hexutil.h b/sdk/example_containers/sgx-task/src/common/hexutil.h
deleted file mode 100644
index d27be56..0000000
--- a/sdk/example_containers/sgx-task/src/common/hexutil.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef MECA_SGX_COMMON_IOPATCHT_H_
-#define MECA_SGX_COMMON_IOPATCHT_H_
-
-#include
-#include
-
-void print_hexstring(FILE *fp, const void *src, size_t len);
-
-const char *hexstring(const void *src, size_t len);
-
-std::string hex_encode(const void *vsrc, size_t len);
-std::string hex_decode(const char *vsrc, size_t len);
-
-#endif // MECA_SGX_COMMON_IOPATCHT_H_
diff --git a/sdk/example_containers/sgx-task/src/common/json.cc b/sdk/example_containers/sgx-task/src/common/json.cc
deleted file mode 100644
index adb49b5..0000000
--- a/sdk/example_containers/sgx-task/src/common/json.cc
+++ /dev/null
@@ -1,340 +0,0 @@
-/**********************************************************************************
- * Obtained from https://github.com/nbsdx/SimpleJSON , under the terms of the
- *WTFPL.
- ***********************************************************************************/
-#include "json.h"
-
-namespace json {
-
-namespace {
-string json_escape(const string &str) {
- string output;
- for (unsigned i = 0; i < str.length(); ++i) switch (str[i]) {
- case '\"':
- output += "\\\"";
- break;
- case '\\':
- output += "\\\\";
- break;
- case '\b':
- output += "\\b";
- break;
- case '\f':
- output += "\\f";
- break;
- case '\n':
- output += "\\n";
- break;
- case '\r':
- output += "\\r";
- break;
- case '\t':
- output += "\\t";
- break;
- default:
- output += str[i];
- break;
- }
- return output;
-}
-
-JSON parse_next(const string &, size_t &);
-
-void consume_ws(const string &str, size_t &offset) {
- while (isspace(str[offset])) ++offset;
-}
-
-JSON parse_object(const string &str, size_t &offset) {
- JSON Object = JSON::Make(JSON::Class::Object);
-
- ++offset;
- consume_ws(str, offset);
- if (str[offset] == '}') {
- ++offset;
- return Object;
- }
-
- while (true) {
- JSON Key = parse_next(str, offset);
- consume_ws(str, offset);
- if (str[offset] != ':') {
- // std::cerr << "Error: Object: Expected colon, found '" << str[offset] <<
- // "'\n";
- break;
- }
- consume_ws(str, ++offset);
- JSON Value = parse_next(str, offset);
- Object[Key.ToString()] = Value;
-
- consume_ws(str, offset);
- if (str[offset] == ',') {
- ++offset;
- continue;
- } else if (str[offset] == '}') {
- ++offset;
- break;
- } else {
- // std::cerr << "ERROR: Object: Expected comma, found '" << str[offset] <<
- // "'\n";
- break;
- }
- }
-
- return Object;
-}
-
-JSON parse_array(const string &str, size_t &offset) {
- JSON Array = JSON::Make(JSON::Class::Array);
- unsigned index = 0;
-
- ++offset;
- consume_ws(str, offset);
- if (str[offset] == ']') {
- ++offset;
- return Array;
- }
-
- while (true) {
- Array[index++] = parse_next(str, offset);
- consume_ws(str, offset);
-
- if (str[offset] == ',') {
- ++offset;
- continue;
- } else if (str[offset] == ']') {
- ++offset;
- break;
- } else {
- // std::cerr << "ERROR: Array: Expected ',' or ']', found '" <<
- // str[offset] << "'\n";
- return std::move(JSON::Make(JSON::Class::Array));
- }
- }
-
- return Array;
-}
-
-JSON parse_string(const string &str, size_t &offset) {
- JSON String;
- string val;
- for (char c = str[++offset]; c != '\"'; c = str[++offset]) {
- if (c == '\\') {
- switch (str[++offset]) {
- case '\"':
- val += '\"';
- break;
- case '\\':
- val += '\\';
- break;
- // case '/' : val += '/' ; break;
- case 'b':
- val += '\b';
- break;
- case 'f':
- val += '\f';
- break;
- case 'n':
- val += '\n';
- break;
- case 'r':
- val += '\r';
- break;
- case 't':
- val += '\t';
- break;
- case 'u': {
- val += "\\u";
- for (unsigned i = 1; i <= 4; ++i) {
- c = str[offset + i];
- if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
- (c >= 'A' && c <= 'F'))
- val += c;
- else {
- // std::cerr << "ERROR: String: Expected hex character in unicode
- // escape, found '" << c << "'\n";
- return std::move(JSON::Make(JSON::Class::String));
- }
- }
- offset += 4;
- } break;
- default:
- val += '\\';
- break;
- }
- } else
- val += c;
- }
- ++offset;
- String = val;
- return String;
-}
-
-JSON parse_number(const string &str, size_t &offset) {
- JSON Number;
- string val, exp_str;
- char c;
- bool isDouble = false;
- long exp = 0;
- while (true) {
- c = str[offset++];
- if ((c == '-') || (c >= '0' && c <= '9'))
- val += c;
- else if (c == '.') {
- val += c;
- isDouble = true;
- } else
- break;
- }
- if (c == 'E' || c == 'e') {
- c = str[offset++];
- if (c == '-') {
- ++offset;
- exp_str += '-';
- }
- while (true) {
- c = str[offset++];
- if (c >= '0' && c <= '9')
- exp_str += c;
- else if (!isspace(c) && c != ',' && c != ']' && c != '}') {
- // std::cerr << "ERROR: Number: Expected a number for exponent, found '"
- // << c << "'\n";
- return std::move(JSON::Make(JSON::Class::Null));
- } else
- break;
- }
- exp = std::stol(exp_str);
- } else if (!isspace(c) && c != ',' && c != ']' && c != '}') {
- // std::cerr << "ERROR: Number: unexpected character '" << c << "'\n";
- return std::move(JSON::Make(JSON::Class::Null));
- }
- --offset;
-
- if (isDouble)
- Number = std::stod(val) * std::pow(10, exp);
- else {
- if (!exp_str.empty())
- Number = (double)std::stol(val) * std::pow(10, exp);
- else
- Number = std::stol(val);
- }
- return Number;
-}
-
-JSON parse_bool(const string &str, size_t &offset) {
- JSON Bool;
- if (str.substr(offset, 4) == "true")
- Bool = true;
- else if (str.substr(offset, 5) == "false")
- Bool = false;
- else {
- // std::cerr << "ERROR: Bool: Expected 'true' or 'false', found '" <<
- // str.substr( offset, 5 ) << "'\n";
- return std::move(JSON::Make(JSON::Class::Null));
- }
- offset += (Bool.ToBool() ? 4 : 5);
- return Bool;
-}
-
-JSON parse_null(const string &str, size_t &offset) {
- JSON Null;
- if (str.substr(offset, 4) != "null") {
- // std::cerr << "ERROR: Null: Expected 'null', found '" << str.substr(
- // offset, 4 ) << "'\n";
- return std::move(JSON::Make(JSON::Class::Null));
- }
- offset += 4;
- return Null;
-}
-
-JSON parse_next(const string &str, size_t &offset) {
- char value;
- consume_ws(str, offset);
- value = str[offset];
- switch (value) {
- case '[':
- return std::move(parse_array(str, offset));
- case '{':
- return std::move(parse_object(str, offset));
- case '\"':
- return std::move(parse_string(str, offset));
- case 't':
- case 'f':
- return std::move(parse_bool(str, offset));
- case 'n':
- return std::move(parse_null(str, offset));
- default:
- if ((value <= '9' && value >= '0') || value == '-')
- return std::move(parse_number(str, offset));
- }
- // std::cerr << "ERROR: Parse: Unknown starting character '" << value <<
- // "'\n"; printf("ERROR: Parse: Unknown starting character %02hhX\n", value);
- return JSON();
-}
-} // anonymous namespace
-
-string JSON::ToString(bool &ok) const {
- ok = (Type == Class::String);
- // return ok ? std::move( json_escape( *Internal.String ) ): string("");
- // return ok ? *Internal.String: string("");
- return ok ? *Internal.String : dump();
-}
-
-string JSON::dump(int depth, string tab) const {
- string pad = "";
- for (int i = 0; i < depth; ++i, pad += tab);
-
- switch (Type) {
- case Class::Null:
- return "null";
- case Class::Object: {
- string s = "{\n";
- bool skip = true;
- for (auto &p : *Internal.Map) {
- if (!skip) s += ",\n";
- s += (pad + "\"" + p.first + "\" : " + p.second.dump(depth + 1, tab));
- skip = false;
- }
- s += ("\n" + pad.erase(0, 2) + "}");
- return s;
- }
- case Class::Array: {
- string s = "[";
- bool skip = true;
- for (auto &p : *Internal.List) {
- if (!skip) s += ", ";
- s += p.dump(depth + 1, tab);
- skip = false;
- }
- s += "]";
- return s;
- }
- case Class::String:
- return "\"" + json_escape(*Internal.String) + "\"";
- case Class::Floating:
- return std::to_string(Internal.Float);
- case Class::Integral:
- return std::to_string(Internal.Int);
- case Class::Boolean:
- return Internal.Bool ? "true" : "false";
- default:
- return "";
- }
- return "";
-}
-JSON JSON::Load(const string &str) {
- size_t offset = 0;
- return std::move(parse_next(str, offset));
-}
-
-JSON Array() { return std::move(JSON::Make(JSON::Class::Array)); }
-
-template
-JSON Array(T... args) {
- JSON arr = JSON::Make(JSON::Class::Array);
- arr.append(args...);
- return std::move(arr);
-}
-
-JSON Object() { return std::move(JSON::Make(JSON::Class::Object)); }
-
-} // namespace json
\ No newline at end of file
diff --git a/sdk/example_containers/sgx-task/src/common/json.h b/sdk/example_containers/sgx-task/src/common/json.h
deleted file mode 100644
index d81adb8..0000000
--- a/sdk/example_containers/sgx-task/src/common/json.h
+++ /dev/null
@@ -1,411 +0,0 @@
-/**********************************************************************************
- * Obtained from https://github.com/nbsdx/SimpleJSON , under the terms of the
- *WTFPL.
- ***********************************************************************************/
-#ifndef MECA_SGX_COMMON_JSON_H_
-#define MECA_SGX_COMMON_JSON_H_
-
-#include
-#include
-#include
-#include
-#include
-#include