Browse Source

teems reads its config.json from stdin on startup

It just does a test parse for now
Ian Goldberg 1 year ago
parent
commit
716c1eaca1
1 changed files with 23 additions and 4 deletions
  1. 23 4
      App/teems.cpp

+ 23 - 4
App/teems.cpp

@@ -1,3 +1,4 @@
+#include <iostream>
 #include <cstdio>
 #include <cstring>
 
@@ -6,6 +7,11 @@
 #include "sgx_tseal.h"
 #include "Untrusted.hpp"
 
+// The next line suppresses a deprecation warning within boost
+#define BOOST_BIND_GLOBAL_PLACEHOLDERS
+#include "boost/property_tree/ptree.hpp"
+#include "boost/property_tree/json_parser.hpp"
+
 static bool hexdump(FILE *outf, const char *label, void *p, size_t len)
 {
     unsigned char *pc = (unsigned char *)p;
@@ -128,7 +134,7 @@ static void usage(const char *argv0)
 {
     fprintf(stderr, "Usage: %s --gen sealedprivkeyfile pubkeyfile\n",
         argv0);
-    fprintf(stderr, "or     %s sealedprivkeyfile configfile myname\n",
+    fprintf(stderr, "or     %s sealedprivkeyfile myname [args] < config.json\n",
         argv0);
 }
 
@@ -169,14 +175,19 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    if (argc != 4) {
+    if (argc < 3) {
         usage(argv[0]);
         exit(1);
     }
 
     const char *sealedprivkeyfile = argv[1];
-    const char *configile = argv[2];
-    const char *myname = argv[3];
+    const char *myname = argv[2];
+
+    // Read the config.json from the first line of stdin.  We have to do
+    // this before outputting anything to avoid potential deadlock with
+    // the launch program.
+    std::string config;
+    std::getline(std::cin, config);
 
     // Load the sealed private key
     FILE *sprivf = fopen(sealedprivkeyfile, "rb");
@@ -190,6 +201,14 @@ int main(int argc, char **argv)
     }
     fclose(sprivf);
 
+    using boost::property_tree::ptree;
+
+    ptree conf;
+
+    std::istringstream configstream(config);
+
+    read_json(configstream, conf);
+
     sgx_destroy_enclave(global_eid);
 
     return 0;