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 16:12:38 UTC

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

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