Here's the python client:

cat incubator-teaclave/examples/python/builtin_rustface.py
```
#!/usr/bin/env python3

import sys
import base64

from teaclave import (AuthenticationService, FrontendService,
                      AuthenticationClient, FrontendClient, DataMap)
from utils import (AUTHENTICATION_SERVICE_ADDRESS, FRONTEND_SERVICE_ADDRESS,
                   AS_ROOT_CA_CERT_PATH, ENCLAVE_INFO_PATH, USER_ID,
                   USER_PASSWORD)


class BuiltinRustfaceExample:
    def __init__(self, user_id, user_password):
        self.user_id = user_id
        self.user_password = user_password

    def detect_face(self, image_base64):
        client = AuthenticationService(
            AUTHENTICATION_SERVICE_ADDRESS, AS_ROOT_CA_CERT_PATH,
            ENCLAVE_INFO_PATH).connect().get_client()

        print("[+] registering user")
        client.user_register(self.user_id, self.user_password)

        print("[+] login")
        token = client.user_login(self.user_id, self.user_password)

        client = FrontendService(FRONTEND_SERVICE_ADDRESS,
                                 AS_ROOT_CA_CERT_PATH,
                                 ENCLAVE_INFO_PATH).connect().get_client()
        metadata = {"id": self.user_id, "token": token}
        client.metadata = metadata


        print("[+] registering key file")
        image_id = register_input_file(client)
        print("[+] key file id" + image_id)

        print("[+] registering function")
        function_id = client.register_function(
            name="builtin-rustface-detector",
            description="Native Face Detection Function",
            executor_type="builtin",
            arguments=["image_base64"])

        print("[+] creating task")
        task_id = client.create_task(function_id=function_id,
                                     function_arguments={"image_base64": 
image_base64},
                                     executor="builtin")
        print("[+] assigning data to task")
        client.assign_data_to_task(task_id, [DataMap("image_key", image_id)], 
[])

        print("[+] invoking task")
        client.invoke_task(task_id)

        print("[+] getting result")
        result = client.get_task_result(task_id)
        print("[+] done")

        return bytes(result)


def register_input_file(client):
    url = "file:///home/ubuntu/incubator-teaclave/1.jpg.enc"
    cmac = "cf8a2eec4ab2fb53cd5c0b2ce3c0a828"
    schema = "teaclave-file-128"
    key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]
    iv = []
    key_data_id = client.register_input_file(url, schema, key, iv, cmac)

    return key_data_id

def main():
    example = BuiltinRustfaceExample(USER_ID, USER_PASSWORD)
    if len(sys.argv) > 1:
        image = sys.argv[1]
    else:
        image = "1.jpg"

    with open(image, 'rb') as binary_file:
        binary_file_data = binary_file.read()
        base64_encoded_data = base64.b64encode(binary_file_data)
        base64_message = base64_encoded_data.decode('utf-8')

        rt = example.detect_face(base64_message)

        print("[+] function return: ", rt)


if __name__ == '__main__':
    main()
``` 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave/issues/329#issuecomment-649186151

Reply via email to