You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@teaclave.apache.org by GitBox <gi...@apache.org> on 2021/01/26 06:02:47 UTC

[GitHub] [incubator-teaclave] mssun opened a new pull request #470: C client SDK

mssun opened a new pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470


   ## Description
   
   Introduce C client SDK. There are two types of C APIs:
   - `*_serialized` APIs accept JSON serialized string requests and responses. These APIs is for other high level programming languages.
   - Normal APIs like `teaclave_user_login`.
   
   An echo example using C client SDK is also implemented. Client APIs will be documented later when all useful languages are properly implemented.
   
   CI passed: http://ci.mesalock-linux.org/mssun/incubator-mesatee/1131


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-teaclave] mssun commented on a change in pull request #470: C client SDK

Posted by GitBox <gi...@apache.org>.
mssun commented on a change in pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470#discussion_r564741814



##########
File path: examples/c/builtin_echo.c
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ *
+ */
+
+
+#include "teaclave_client_sdk.h"
+#include <stdio.h>
+#include <string.h>
+
+#define BUFFER_SIZE 4086
+
+const char *authentication_service_address = "localhost:7776";
+const char *frontend_service_address = "localhost:7777";
+const char *enclave_info_path = "../../release/services/enclave_info.toml";
+#ifdef DCAP
+const char *as_root_ca_cert_path = "../../keys/dcap_root_ca_cert.pem";
+#else
+const char *as_root_ca_cert_path = "../../keys/ias_root_ca_cert.pem";
+#endif
+const char *user_id = "test_id";
+const char *user_password = "test_password";
+
+const char *register_function_request_serialized =
+    "{"
+    "    \"request\": \"register_function\","
+    "    \"name\": \"builtin-echo\","
+    "    \"description\": \"Native Echo Function\","
+    "    \"executor_type\": \"builtin\","
+    "    \"public\": true,"
+    "    \"payload\": [],"
+    "    \"arguments\": ["
+    "        \"message\""
+    "    ],"
+    "    \"inputs\": [],"
+    "    \"outputs\": []"
+    "}";
+
+const char *create_task_request_serialized =
+    "{"
+    "    \"request\": \"create_task\","
+    "    \"function_id\": \"%s\","
+    "    \"function_arguments\": \"{\\\"message\\\": \\\"Hello, "
+    "Teaclave!\\\"}\","
+    "    \"executor\": \"builtin\","
+    "    \"inputs_ownership\": [],"
+    "    \"outputs_ownership\": []"
+    "}";
+
+int login(char *token, size_t *token_len) {
+    int ret = 0;
+
+    AuthenticationClient *authentication_client =
+        teaclave_connect_authentication_service(authentication_service_address,
+                                                enclave_info_path,
+                                                as_root_ca_cert_path);
+    if (authentication_client == NULL) {
+        fprintf(stderr,
+                "[-] Failed to connect to the authentication service.\n");
+        ret = 1;
+        goto bail;
+    }
+
+    ret = teaclave_user_register(authentication_client, user_id, user_password);
+    if (ret != 0) {
+        fprintf(stderr, "[-] Failed to register user.\n");
+        fprintf(stderr, "[-] Maybe `%s' already exists. Continue. \n", user_id);
+    }
+
+    ret = teaclave_user_login(authentication_client, user_id, user_password,
+                              token, token_len);
+    if (ret != 0) {
+        fprintf(stderr, "[-] Failed to login.\n");
+        goto bail;
+    }
+    printf("[+] token: %s\n", token);
+
+bail:
+    if (authentication_client) {
+        ret = teaclave_close_authentication_service(authentication_client);
+        if (ret != 0) {
+            fprintf(stderr,
+                    "[-] Failed to close the authentication service client.\n");
+        }
+    }
+
+    return ret;
+}
+
+int main() {
+    int ret = 0;
+    char *token = (char *)calloc(BUFFER_SIZE, sizeof(char));

Review comment:
       Yes, I have replaced them as stack allocated buffers.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-teaclave] jvz commented on a change in pull request #470: C client SDK

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470#discussion_r564637641



##########
File path: examples/c/builtin_echo.c
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.
+ *
+ */
+
+
+#include "teaclave_client_sdk.h"
+#include <stdio.h>
+#include <string.h>
+
+#define BUFFER_SIZE 4086
+
+const char *authentication_service_address = "localhost:7776";
+const char *frontend_service_address = "localhost:7777";
+const char *enclave_info_path = "../../release/services/enclave_info.toml";
+#ifdef DCAP
+const char *as_root_ca_cert_path = "../../keys/dcap_root_ca_cert.pem";
+#else
+const char *as_root_ca_cert_path = "../../keys/ias_root_ca_cert.pem";
+#endif
+const char *user_id = "test_id";
+const char *user_password = "test_password";
+
+const char *register_function_request_serialized =
+    "{"
+    "    \"request\": \"register_function\","
+    "    \"name\": \"builtin-echo\","
+    "    \"description\": \"Native Echo Function\","
+    "    \"executor_type\": \"builtin\","
+    "    \"public\": true,"
+    "    \"payload\": [],"
+    "    \"arguments\": ["
+    "        \"message\""
+    "    ],"
+    "    \"inputs\": [],"
+    "    \"outputs\": []"
+    "}";
+
+const char *create_task_request_serialized =
+    "{"
+    "    \"request\": \"create_task\","
+    "    \"function_id\": \"%s\","
+    "    \"function_arguments\": \"{\\\"message\\\": \\\"Hello, "
+    "Teaclave!\\\"}\","
+    "    \"executor\": \"builtin\","
+    "    \"inputs_ownership\": [],"
+    "    \"outputs_ownership\": []"
+    "}";
+
+int login(char *token, size_t *token_len) {
+    int ret = 0;
+
+    AuthenticationClient *authentication_client =
+        teaclave_connect_authentication_service(authentication_service_address,
+                                                enclave_info_path,
+                                                as_root_ca_cert_path);
+    if (authentication_client == NULL) {
+        fprintf(stderr,
+                "[-] Failed to connect to the authentication service.\n");
+        ret = 1;
+        goto bail;
+    }
+
+    ret = teaclave_user_register(authentication_client, user_id, user_password);
+    if (ret != 0) {
+        fprintf(stderr, "[-] Failed to register user.\n");
+        fprintf(stderr, "[-] Maybe `%s' already exists. Continue. \n", user_id);
+    }
+
+    ret = teaclave_user_login(authentication_client, user_id, user_password,
+                              token, token_len);
+    if (ret != 0) {
+        fprintf(stderr, "[-] Failed to login.\n");
+        goto bail;
+    }
+    printf("[+] token: %s\n", token);
+
+bail:
+    if (authentication_client) {
+        ret = teaclave_close_authentication_service(authentication_client);
+        if (ret != 0) {
+            fprintf(stderr,
+                    "[-] Failed to close the authentication service client.\n");
+        }
+    }
+
+    return ret;
+}
+
+int main() {
+    int ret = 0;
+    char *token = (char *)calloc(BUFFER_SIZE, sizeof(char));

Review comment:
       Wouldn't it be nice to encourage stack allocation instead? Especially since you're using a fixed size buffer anyhow.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-teaclave] mssun commented on pull request #470: C client SDK

Posted by GitBox <gi...@apache.org>.
mssun commented on pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470#issuecomment-767745980


   Thanks for the review! Merged.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-teaclave] jvz commented on a change in pull request #470: C client SDK

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470#discussion_r564737914



##########
File path: sdk/c/teaclave_client_sdk.h
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ *
+ */
+
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+typedef struct AuthenticationClient AuthenticationClient;
+
+typedef struct FrontendClient FrontendClient;
+
+struct AuthenticationClient *teaclave_connect_authentication_service(const char *address,
+                                                                     const char *enclave_info_path,
+                                                                     const char *as_root_ca_cert_path);
+
+int teaclave_close_authentication_service(struct AuthenticationClient *client);
+
+int teaclave_user_register(struct AuthenticationClient *client,

Review comment:
       Ah neat, that looks pretty cool. I'm not a big C developer myself, either, but I was playing around with it the past couple weeks, so the knowledge was fresh :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-teaclave] mssun merged pull request #470: C client SDK

Posted by GitBox <gi...@apache.org>.
mssun merged pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-teaclave] mssun commented on a change in pull request #470: C client SDK

Posted by GitBox <gi...@apache.org>.
mssun commented on a change in pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470#discussion_r564736165



##########
File path: sdk/c/teaclave_client_sdk.h
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ *
+ */
+
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+typedef struct AuthenticationClient AuthenticationClient;
+
+typedef struct FrontendClient FrontendClient;
+
+struct AuthenticationClient *teaclave_connect_authentication_service(const char *address,
+                                                                     const char *enclave_info_path,
+                                                                     const char *as_root_ca_cert_path);
+
+int teaclave_close_authentication_service(struct AuthenticationClient *client);
+
+int teaclave_user_register(struct AuthenticationClient *client,

Review comment:
       Thanks for pointing out. This header file is auto generated from the Rust SDK by a tool called `cbindgen` (https://github.com/eqrion/cbindgen). I'm adding a comment in the header to explain this.
   
   I don't write C very often. Learned new from the ed488-goldilocks. Thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [incubator-teaclave] jvz commented on a change in pull request #470: C client SDK

Posted by GitBox <gi...@apache.org>.
jvz commented on a change in pull request #470:
URL: https://github.com/apache/incubator-teaclave/pull/470#discussion_r564651055



##########
File path: sdk/c/teaclave_client_sdk.h
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ *
+ */
+
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+typedef struct AuthenticationClient AuthenticationClient;
+
+typedef struct FrontendClient FrontendClient;
+
+struct AuthenticationClient *teaclave_connect_authentication_service(const char *address,
+                                                                     const char *enclave_info_path,
+                                                                     const char *as_root_ca_cert_path);
+
+int teaclave_close_authentication_service(struct AuthenticationClient *client);
+
+int teaclave_user_register(struct AuthenticationClient *client,

Review comment:
       You don't need the `struct` keyword in all these functions thanks to the `typedef`.
   
   Also, one C design pattern I've come across elsewhere (in ed448-goldilocks) is to typedef a single element array as `foo_t` while naming the struct `foo_s` so that you can provide typedefs for both use cases while discouraging improper pointer use with uninitialized data. Random example: https://sourceforge.net/p/ed448goldilocks/code/ci/master/tree/src/public_include/decaf/shake.h




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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