Переглянути джерело

Stubs for the I/O functions in and out of the enclave

Ian Goldberg 1 рік тому
батько
коміт
ae76624b90
7 змінених файлів з 71 додано та 2 видалено
  1. 21 0
      App/net.cpp
  2. 2 0
      App/net.hpp
  3. 2 0
      App/teems.cpp
  4. 18 1
      Enclave/Enclave.edl
  5. 11 0
      Enclave/comms.cpp
  6. 2 1
      Makefile
  7. 15 0
      Untrusted/Untrusted.cpp

+ 21 - 0
App/net.cpp

@@ -1,5 +1,6 @@
 #include <iostream>
 
+#include "Enclave_u.h"
 #include "net.hpp"
 
 // The command type byte values
@@ -8,6 +9,8 @@
 #define COMMAND_MESSAGE 0x01
 #define COMMAND_CHUNK 0x02
 
+NetIO *g_netio = NULL;
+
 NodeIO::NodeIO(tcp::socket &&socket) : sock(std::move(socket))
 {
 }
@@ -230,3 +233,21 @@ NetIO::NetIO(boost::asio::io_context &io_context, const Config &config)
 #endif
     }
 }
+
+/* The enclave calls this to inform the untrusted app that there's a new
+ * messaage to send. The return value is the frame the enclave should
+ * use to store the first (encrypted) chunk of this message. */
+uint8_t *ocall_message(nodenum_t node_num, uint32_t message_len)
+{
+    return NULL;
+}
+
+/* The enclave calls this to inform the untrusted app that there's a new
+ * chunk to send.  The return value is the frame the enclave should use
+ * to store the next (encrypted) chunk of this message, or NULL if this
+ * was the last chunk. */
+uint8_t *ocall_chunk(nodenum_t node_num, const uint8_t *chunkdata,
+    uint32_t chunklen)
+{
+    return NULL;
+}

+ 2 - 0
App/net.hpp

@@ -135,4 +135,6 @@ public:
     NodeIO &node(size_t node_num) { return nodeios[node_num].value(); }
 };
 
+extern NetIO *g_netio;
+
 #endif

+ 2 - 0
App/teems.cpp

@@ -209,6 +209,7 @@ int main(int argc, char **argv)
 
     // The NetIO will keep a (const) reference to the config
     NetIO netio(io_context, config);
+    g_netio = &netio;
 
     // Queue up the actual work
     boost::asio::post(io_context, [&]{
@@ -222,6 +223,7 @@ int main(int argc, char **argv)
     t.join();
 
     // All done
+    g_netio = NULL;
     sgx_destroy_enclave(global_eid);
 
     return 0;

+ 18 - 1
Enclave/Enclave.edl

@@ -17,13 +17,30 @@ enclave {
             [in] struct EnclaveAPIParams *apiparams,
             [in,count=num_nodes] struct EnclaveAPINodeConfig *apinodeconfigs,
             nodenum_t num_nodes, nodenum_t my_node_num);
+
+        public bool ecall_message(
+            nodenum_t node_num, uint32_t message_len);
+
+        public bool ecall_chunk(
+            nodenum_t node_num,
+            [user_check] const uint8_t *chunkdata,
+            uint32_t chunklen);
     };
 
     untrusted {
-        void ocall_print_string([in, string] const char *str);
+        void ocall_print_string(
+            [in, string] const char *str);
         unsigned long ocall_print_string_with_rtclock(
             [in, string] const char *str);
         unsigned long ocall_print_string_with_rtclock_diff(
             [in, string] const char *str, unsigned long before);
+
+        uint8_t *ocall_message(
+            nodenum_t node_num, uint32_t message_len);
+
+        uint8_t *ocall_chunk(
+            nodenum_t node_num,
+            [user_check] const uint8_t *chunkdata,
+            uint32_t chunklen);
     };
 };

+ 11 - 0
Enclave/comms.cpp

@@ -123,3 +123,14 @@ bool comms_init_nodestate(const EnclaveAPINodeConfig *apinodeconfigs,
 
     return true;
 }
+
+bool ecall_message(nodenum_t node_num, uint32_t message_len)
+{
+    return false;
+}
+
+bool ecall_chunk(nodenum_t node_num, const uint8_t *chunkdata,
+    uint32_t chunklen)
+{
+    return false;
+}

+ 2 - 1
Makefile

@@ -284,7 +284,8 @@ depend:
 
 App/appconfig.o: Untrusted/Untrusted.hpp Enclave/enclave_api.h
 App/appconfig.o: App/appconfig.hpp
-App/net.o: App/net.hpp App/appconfig.hpp Enclave/enclave_api.h
+App/net.o: Untrusted/Enclave_u.h Enclave/enclave_api.h App/net.hpp
+App/net.o: App/appconfig.hpp
 App/start.o: App/start.hpp App/net.hpp App/appconfig.hpp
 App/start.o: Enclave/enclave_api.h
 App/teems.o: Untrusted/Untrusted.hpp Enclave/enclave_api.h App/appconfig.hpp

+ 15 - 0
Untrusted/Untrusted.cpp

@@ -234,3 +234,18 @@ bool ecall_config_load(struct EnclaveAPIParams *apiparams,
         num_nodes, my_node_num);
     return ret;
 }
+
+bool ecall_message(nodenum_t node_num, uint32_t message_len)
+{
+    bool ret;
+    ecall_message(global_eid, &ret, node_num, message_len);
+    return ret;
+}
+
+bool ecall_chunk(nodenum_t node_num, const uint8_t *chunkdata,
+    uint32_t chunklen)
+{
+    bool ret;
+    ecall_chunk(global_eid, &ret, node_num, chunkdata, chunklen);
+    return ret;
+}