Browse Source

It works! Added in unistd write for writing raw bytes.
Can make a protobuf for verifier's Post-LA messages later.

dettanym 4 years ago
parent
commit
f2adf1bb46
7 changed files with 40 additions and 13 deletions
  1. 10 3
      DeploymentStageLogic.cpp
  2. 8 2
      LAInitiator/LA.cpp
  3. 12 2
      PostLA/PostLAMessaging.cpp
  4. 0 2
      crypto.cpp
  5. 4 2
      include/PostLAMessaging.h
  6. 2 0
      include/crypto.h
  7. 4 2
      systemMain.cpp

+ 10 - 3
DeploymentStageLogic.cpp

@@ -19,7 +19,7 @@ int DeploymentStageLogic::set_up_socket_connect(int port)
     int sock = 0;
     int sock = 0;
     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
     {
     {
-        printf("\n Error in socket call - errno is %d \n", errno);
+        printf("\n Error in socket call - errno is %d \n", errno); fflush(stdout);
         return -1;
         return -1;
     }
     }
 
 
@@ -32,13 +32,13 @@ int DeploymentStageLogic::set_up_socket_connect(int port)
     // Convert IPv4 and IPv6 addresses from text to binary form
     // Convert IPv4 and IPv6 addresses from text to binary form
     if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
     if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
     {
     {
-        printf("\nError in inet_pton - errno is %d\n", errno);
+        printf("\nError in inet_pton - errno is %d\n", errno); fflush(stdout);
         return -1;
         return -1;
     }
     }
 
 
     if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
     if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
     {
     {
-        printf("\nError in connect - errno is %d \n", errno);
+        printf("\nError in connect - errno is %d \n", errno); fflush(stdout);
         return -1;
         return -1;
     }
     }
 
 
@@ -60,18 +60,25 @@ int DeploymentStageLogic::main_logic(int decryptor_fd)
     // Conduct LA.
     // Conduct LA.
     ret_status = laInitiator.conduct_la(decryptor_fd);
     ret_status = laInitiator.conduct_la(decryptor_fd);
     if(ret_status != 0)
     if(ret_status != 0)
+    {
+        printf("LA initiator returned an error: %d\n", ret_status);
+        fflush(stdout);
         return ret_status;
         return ret_status;
+    }
     /*
     /*
      *
      *
       printf("\nSuccessful LA with port %d.\n", DECRYPTOR_PORT);
       printf("\nSuccessful LA with port %d.\n", DECRYPTOR_PORT);
       fflush(stdout);
       fflush(stdout);
      */
      */
 
 
+    printf("Setting up fd for post LA messaging.\n"); fflush(stdout);
     // Use the same channel for post-LA messages as the one used above for LA messages.
     // Use the same channel for post-LA messages as the one used above for LA messages.
     postLaMessaging.set_fd(decryptor_fd);
     postLaMessaging.set_fd(decryptor_fd);
 
 
     // Use the symmetric key from LA to send messages for the rest of the deployment stage.
     // Use the symmetric key from LA to send messages for the rest of the deployment stage.
+    printf("Retrieving key from LA inititator.\n "); fflush(stdout);
     laInitiator.get_la_symmetric_key(key);
     laInitiator.get_la_symmetric_key(key);
+    printf("Setting key for post LA messaging.\n "); fflush(stdout);
     postLaMessaging.set_la_symmetric_key(key);
     postLaMessaging.set_la_symmetric_key(key);
 
 
     // Send the target's hash to the decryptor enclave.
     // Send the target's hash to the decryptor enclave.

+ 8 - 2
LAInitiator/LA.cpp

@@ -25,9 +25,10 @@ uint32_t LA::process_protobuf_dh_msg1_generate_protobuf_dh_msg2(protobuf_sgx_dh_
   uint32_t ret_status;
   uint32_t ret_status;
 
 
   if(Transforms::decode_msg1_from_protobuf(protobuf_msg1, &dh_msg1)!=0)
   if(Transforms::decode_msg1_from_protobuf(protobuf_msg1, &dh_msg1)!=0)
-    return -1;
+    return 0x1;
 
 
   //Intialize the session as a session initiator
   //Intialize the session as a session initiator
+  sgx_dh_session = (sgx_dh_session_t*) malloc(sizeof(sgx_dh_session_t));
   ret_status = sgx_dh_init_session(SGX_DH_SESSION_INITIATOR, sgx_dh_session);
   ret_status = sgx_dh_init_session(SGX_DH_SESSION_INITIATOR, sgx_dh_session);
   if(ret_status != SGX_SUCCESS)
   if(ret_status != SGX_SUCCESS)
     return ret_status;
     return ret_status;
@@ -80,21 +81,26 @@ uint32_t LA::conduct_la(int decryptor_fd) {
 
 
     protobufReaderWriter.set_fd(decryptor_fd);
     protobufReaderWriter.set_fd(decryptor_fd);
 
 
+    printf("Reading message 1\n"); fflush(stdout);
     if(protobufReaderWriter.read_msg(protobuf_msg1)!=0)
     if(protobufReaderWriter.read_msg(protobuf_msg1)!=0)
         return -1;
         return -1;
 
 
+    printf("Generating message 2\n"); fflush(stdout);
     protobuf_sgx_ret = process_protobuf_dh_msg1_generate_protobuf_dh_msg2(protobuf_msg1, protobuf_msg2);
     protobuf_sgx_ret = process_protobuf_dh_msg1_generate_protobuf_dh_msg2(protobuf_msg1, protobuf_msg2);
     if(protobuf_sgx_ret != 0)
     if(protobuf_sgx_ret != 0)
     {
     {
         printf("Error in process_protobuf_dh_msg1_generate_protobuf_dh_msg2: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret;
         printf("Error in process_protobuf_dh_msg1_generate_protobuf_dh_msg2: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret;
     }
     }
 
 
+    printf("Writing message 2\n"); fflush(stdout);
     if(protobufReaderWriter.write_msg(protobuf_msg2)!=0)
     if(protobufReaderWriter.write_msg(protobuf_msg2)!=0)
         return -1;
         return -1;
 
 
+    printf("Reading message 3\n"); fflush(stdout);
     if(protobufReaderWriter.read_msg(protobuf_msg3)!=0)
     if(protobufReaderWriter.read_msg(protobuf_msg3)!=0)
         return -1;
         return -1;
 
 
+    printf("Processing message 3\n"); fflush(stdout);
     protobuf_sgx_ret = process_protobuf_dh_msg3(protobuf_msg3);
     protobuf_sgx_ret = process_protobuf_dh_msg3(protobuf_msg3);
     if(protobuf_sgx_ret != 0)
     if(protobuf_sgx_ret != 0)
     {
     {
@@ -106,6 +112,6 @@ uint32_t LA::conduct_la(int decryptor_fd) {
 void LA::get_la_symmetric_key(uint8_t* op_key)
 void LA::get_la_symmetric_key(uint8_t* op_key)
 {
 {
     uint32_t counter;
     uint32_t counter;
-    for(counter=0; counter<32; counter++)
+    for(counter=0; counter<16; counter++)
         op_key[counter] = key[counter];
         op_key[counter] = key[counter];
 }
 }

+ 12 - 2
PostLA/PostLAMessaging.cpp

@@ -5,7 +5,8 @@
 #include "PostLAMessaging.h"
 #include "PostLAMessaging.h"
 #include "sgx_trts.h" // for sgx_read_rand
 #include "sgx_trts.h" // for sgx_read_rand
 #include "crypto.h" // for aes_gcm_128
 #include "crypto.h" // for aes_gcm_128
-
+#include <unistd.h>
+#include <stdio.h>
 uint32_t PostLAMessaging::aes_gcm_wrapper(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length)
 uint32_t PostLAMessaging::aes_gcm_wrapper(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length)
 {
 {
     uint32_t actual_plaintext_length=plaintext_length;
     uint32_t actual_plaintext_length=plaintext_length;
@@ -48,6 +49,14 @@ uint32_t PostLAMessaging::send_secure_msg(uint8_t* input, uint32_t input_size)
     if(ret != 0)
     if(ret != 0)
         return ret;
         return ret;
 
 
+    size_t post_la_bytes_written = write(fd, output, output_size);
+    printf("Wrote the hash and the tag to the decryptor socket.\n Wrote this many bytes: %d\n", post_la_bytes_written); fflush(stdout);
+
+    if(close(fd)!= 0)
+    {
+        printf("Error in closing the socket connection.\n"); fflush(stdout); return 0xfd;
+    }
+
     // TODO: Conversion logic to protobuf. Set msg or whatever.
     // TODO: Conversion logic to protobuf. Set msg or whatever.
     /*  google::protobuf::MessageLite protobuf_msg;
     /*  google::protobuf::MessageLite protobuf_msg;
      * if(protobufReaderWriter->write_msg(protobuf_msg) != 0)
      * if(protobufReaderWriter->write_msg(protobuf_msg) != 0)
@@ -66,7 +75,8 @@ void PostLAMessaging::set_la_symmetric_key(uint8_t* given_key) {
 
 
 void PostLAMessaging::set_fd(int given_fd)
 void PostLAMessaging::set_fd(int given_fd)
 {
 {
-    protobufReaderWriter.set_fd(given_fd);
+    // protobufReaderWriter.set_fd(given_fd);
+    fd = given_fd;
 }
 }
 
 
 /*
 /*

+ 0 - 2
crypto.cpp

@@ -1,5 +1,3 @@
-#include <stdio.h> 
-#include <string> 
 #include <memory>
 #include <memory>
 using std::unique_ptr;
 using std::unique_ptr;
 #include <openssl/err.h> 
 #include <openssl/err.h> 

+ 4 - 2
include/PostLAMessaging.h

@@ -4,11 +4,13 @@
 
 
 #ifndef VERIFIER_POSTLAMESSAGING_H
 #ifndef VERIFIER_POSTLAMESSAGING_H
 #define VERIFIER_POSTLAMESSAGING_H
 #define VERIFIER_POSTLAMESSAGING_H
+#include <stdint.h>
 //#include "crypto.h"
 //#include "crypto.h"
-#include "ProtobufMessageRW.h"
+//#include "ProtobufMessageRW.h"
 class PostLAMessaging {
 class PostLAMessaging {
     uint8_t key[16];
     uint8_t key[16];
-    ProtobufMessageRW protobufReaderWriter;
+    int fd;
+    // ProtobufMessageRW protobufReaderWriter;
     uint32_t aes_gcm_wrapper(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length);
     uint32_t aes_gcm_wrapper(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length);
 public:
 public:
     void set_la_symmetric_key(uint8_t* given_key);
     void set_la_symmetric_key(uint8_t* given_key);

+ 2 - 0
include/crypto.h

@@ -1,5 +1,7 @@
 #ifndef CRYPTO_H
 #ifndef CRYPTO_H
 #define CRYPTO_H
 #define CRYPTO_H
+#include <stdio.h>
+#include <string>
 
 
 uint32_t generate_rsa_keypair(FILE* fp, std::string& priv_key_str, std::string& pub_key_str); //, uint8_t* hash);
 uint32_t generate_rsa_keypair(FILE* fp, std::string& priv_key_str, std::string& pub_key_str); //, uint8_t* hash);
 uint32_t generate_rsa_keypair_hash(uint8_t* hash);
 uint32_t generate_rsa_keypair_hash(uint8_t* hash);

+ 4 - 2
systemMain.cpp

@@ -164,14 +164,16 @@ int main(int argc, char** argv)
 
 
     deploymentStage.set_target_hash(target_hash);
     deploymentStage.set_target_hash(target_hash);
 
 
+    printf("Setting up SOCKET:\n"); fflush(stdout);
     int fd = deploymentStage.set_up_socket_connect(DECRYPTOR_PORT);
     int fd = deploymentStage.set_up_socket_connect(DECRYPTOR_PORT);
-    if(fd != 0)
+    if(fd <= 0)
         // Set up an IPC channel for local attestation and post-LA messages.
         // Set up an IPC channel for local attestation and post-LA messages.
     {
     {
-        printf("\nCould not set up the socket: had the following error: ");
+        printf("\nCould not set up the socket: had the following error: %d\n", fd);
         fflush(stdout);
         fflush(stdout);
         return fd;
         return fd;
     }
     }
+    printf("Starting main logic with fd: %d\n", fd); fflush(stdout);
 
 
     int ret_status = deploymentStage.main_logic(fd);
     int ret_status = deploymentStage.main_logic(fd);
     if(ret_status != 0)
     if(ret_status != 0)