Browse Source

Works with sgx_calc_sealed_data working properly. Had to make it return the uint32_t rather than pass it as a pointer, for some reason.

dettanym 5 years ago
parent
commit
8410c52adb

+ 13 - 12
App/App.cpp

@@ -637,7 +637,7 @@ int local_attestation_initiator(__attribute__((unused))   uint8_t* expected_mr_s
       }
       encode_msg1_to_protobuf(protobuf_msg1, &dh_msg1);
       print_initialized_msg1(protobuf_msg1, &dh_msg1);
-      printf("Done initialization");
+      printf("Done initialization with session id 0x%x", session_id);
       fflush(stdout);
 
       int no_of_msgs_xchanged=0;
@@ -708,18 +708,18 @@ uint32_t unseal_signing_key_pair_from_disk(int fd, __attribute__((unused))  sgx_
   return ret_status;
 }
 */
-uint32_t create_and_seal_signing_key_pair_to_disk( __attribute__((unused))  int fd, sgx_ec256_public_t* pub_key, uint32_t* actual_sealed_msg_length)
+uint32_t create_and_seal_signing_key_pair_to_disk( __attribute__((unused))  int fd, __attribute__((unused))   sgx_ec256_public_t* pub_key, __attribute__((unused))  uint32_t* actual_sealed_msg_length)
 {
-  uint32_t ret_status;
+ // uint32_t ret_status;
   // Generating a signing ECDSA key to sign the encryption key.
-  
-  Decryptor_calculate_sealed_data_size(e2_enclave_id, 3*SGX_ECP256_KEY_SIZE, actual_sealed_msg_length); // sgx_calc_sealed_data_size(0,3*SGX_ECP256_KEY_SIZE);
-  if(*actual_sealed_msg_length == 0xFFFFFFFF)
+  uint32_t length; 
+  Decryptor_calculate_sealed_data_size(e2_enclave_id, &length, 3*SGX_ECP256_KEY_SIZE); // sgx_calc_sealed_data_size(0,3*SGX_ECP256_KEY_SIZE);
+  if(length == 0xFFFFFFFF)
     return 0xFFFFFFFF;
-  printf("%x bytes for sealed msg\n", *actual_sealed_msg_length); fflush(stdout); 
-  uint8_t* sealed_data=(uint8_t*) malloc(*actual_sealed_msg_length);
+  printf("0x%x input msg, 0x%x bytes for sealed msg in parameter value\n", 3*SGX_ECP256_KEY_SIZE, length); fflush(stdout); 
+//  uint8_t* sealed_data=(uint8_t*) malloc(*actual_sealed_msg_length);
   printf("Made call to sgx_calc_sealed_data_size\n");  fflush(stdout); 
-  Decryptor_create_and_seal_ecdsa_signing_key_pair(e2_enclave_id, &ret_status, pub_key, actual_sealed_msg_length, sealed_data);
+/*  Decryptor_create_and_seal_ecdsa_signing_key_pair(e2_enclave_id, &ret_status, pub_key, actual_sealed_msg_length, sealed_data);
   if(ret_status != SGX_SUCCESS)
   {
     printf("create_and_seal called returned an error: %x", ret_status); 
@@ -727,7 +727,8 @@ uint32_t create_and_seal_signing_key_pair_to_disk( __attribute__((unused))  int
     return 0xFFFFFFFF;
   }
   printf("It returned sgx_success\n"); fflush(stdout); 
-/*  ret_status = write_to_fd(fd, sealed_data, actual_sealed_msg_length);
+  
+  ret_status = write_to_fd(fd, sealed_data, actual_sealed_msg_length);
   free(sealed_data);
   return ret_status;*/ return 0; 
 }
@@ -752,13 +753,13 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
     }
     printf("\nDecryptor - EnclaveID %" PRIx64, e2_enclave_id);
     fflush(stdout);
-    ret_status=local_attestation_initiator(NULL); 
+/*    ret_status=local_attestation_initiator(NULL); 
     if(ret_status!=0)
     {
 	printf("local attestation did not successfully return: %x\n", ret_status); fflush(stdout); return 0xFFFFFFFF; 
 
     }
-    int sealed_signing_key_fd = open("sealed_signing_key.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+  */  int sealed_signing_key_fd = open("sealed_signing_key.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
     if(sealed_signing_key_fd == -1)
     {
       perror("\nError in opening the file sealed_signing_key.txt - ");

+ 3 - 1
Decryptor/Decryptor.edl

@@ -33,7 +33,9 @@
 enclave {
     include "sgx_eid.h"
     from "../LocalAttestationCode/LocalAttestationCode.edl" import *;
-    from "sgx_tstdc.edl" import *;
+//    from "sgx_tstdc.edl" import *;
+//    from "sgx_tae_service.edl" import *;
+
     trusted{
 		public uint32_t foo(); 
 //              public uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id);

+ 9 - 8
LocalAttestationCode/EnclaveMessageExchange.cpp

@@ -43,6 +43,7 @@
 #include "sgx_tcrypto.h"
 #include "LocalAttestationCode_t.h"
 #include "sgx_tseal.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -238,15 +239,15 @@ uint32_t create_and_seal_ecdsa_signing_key_pair(__attribute__((unused))   sgx_ec
     if(ret_status!=SGX_SUCCESS)
        return ret_status;
     // generating the entire string as there is no SGX function to generate the public key from the private one.
-    // uint8_t* private_public_key_string = (uint8_t*) malloc(3*SGX_ECP256_KEY_SIZE);
-//    uint8_t* sealed_data2 = (uint8_t*) malloc(*sealed_data_length);
+    uint8_t* private_public_key_string = (uint8_t*) malloc(3*SGX_ECP256_KEY_SIZE);
+    uint8_t* sealed_data2 = (uint8_t*) malloc(*sealed_data_length);
     // serializing keypair to string
-//    serialize_signing_key_pair_to_string(pub_key, &signing_priv_key, private_public_key_string);
+    serialize_signing_key_pair_to_string(pub_key, &signing_priv_key, private_public_key_string);
     // sealing serialized keypair to disk
 //    ret_status = sgx_unseal_data(NULL /*(sgx_sealed_data_t*)sealed_data2*/, NULL, 0, NULL  /*temp_plaintext*/ ,0 /*&expected_plaintext_msg_length*/);
   // sgx_seal_data(0, NULL,  3*SGX_ECP256_KEY_SIZE, private_public_key_string, *sealed_data_length, (sgx_sealed_data_t*) sealed_data2);
-  //  free(sealed_data2);
-  //  free(private_public_key_string);
+    free(sealed_data2);
+    free(private_public_key_string);
 //    return ret_status;
 	return SGX_SUCCESS; 
 
@@ -259,10 +260,10 @@ uint32_t unseal_and_restore_sealed_signing_key_pair(__attribute__((unused)) sgx_
 
 }
 
-
-void calculate_sealed_data_size(uint32_t input_size, uint32_t* output_size) 
+uint32_t calculate_sealed_data_size( uint32_t input_size) 
 {
-	*output_size=sgx_calc_sealed_data_size(0, input_size);
+//	*op_size=sgx_calc_sealed_data_size(0, input_size); 
+	return sgx_calc_sealed_data_size(0, input_size);
 
 }
 

+ 2 - 1
LocalAttestationCode/LocalAttestationCode.edl

@@ -30,6 +30,7 @@
  */
 
 enclave  {
+    from "sgx_tae_service.edl" import *;
     include "sgx_eid.h"
     include "datatypes.h"
     include "../Include/dh_session_protocol.h"
@@ -44,7 +45,7 @@ enclave  {
 void serialize_signing_key_pair_to_string([in] sgx_ec256_public_t* pub_key, [in] sgx_ec256_private_t* signing_priv_key, [out] uint8_t* private_public_key_string);
         void deserialize_string_to_public_private_key_pair([in] uint8_t* private_public_key_string, [out] sgx_ec256_public_t* pub_key, [out] sgx_ec256_private_t* priv_key); 
         public uint32_t end_session();
-        void calculate_sealed_data_size(uint32_t input_size, [out] uint32_t* output_size);
+        public uint32_t calculate_sealed_data_size(uint32_t input_size); //, [out] uint32_t *opsize);
 
         // public uint32_t generate_response([in, size = req_message_size] secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, [out, size=resp_message_size] secure_message_t* resp_message, size_t resp_message_size );
 //        public uint32_t end_session();

+ 6 - 6
Makefile

@@ -31,10 +31,10 @@
 
 ######## SGX SDK Settings ########
 
-SGX_SDK ?= /home/m2mazmud/sgx2.1_original/sgxsdk
-SGX_MODE ?= HW
-SGX_ARCH ?= x64
-SGX_DEBUG ?= 1
+SGX_SDK ?= /opt/intel/sgxsdk #/home/m2mazmud/sgx2.1_original/sgxsdk
+SGX_MODE := HW
+SGX_ARCH := x64
+SGX_DEBUG := 1
 
 ifeq ($(shell getconf LONG_BIT), 32)
 	SGX_ARCH := x86
@@ -159,7 +159,7 @@ Enclave_Compile_Flags += $(Enclave_Include_Paths)
 # Otherwise, you may get some undesirable errors.
 Common_Enclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
 	-Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \
-	-Wl,--start-group -lsgx_tstdc -lsgx_tcxx -l$(Crypto_Library_Name) -L. -lLocalAttestation_Trusted -l$(Service_Library_Name) -Wl,--end-group \
+	-Wl,--start-group -L. -lLocalAttestation_Trusted   -lsgx_tstdc -lsgx_tcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \
 	-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
 	-Wl,-pie,-eenclave_entry -Wl,--export-dynamic  \
 	-Wl,--defsym,__ImageBase=0 -Wl,--gc-sections
@@ -273,7 +273,7 @@ Decryptor/%.o: Decryptor/%.cpp
 	@echo "CXX  <=  $<"
 
 Decryptor.so: Decryptor/Decryptor_t.o $(Enclave_Cpp_Objects_2) $(Trust_Lib_Name)
-	@$(CXX) --verbose Decryptor/Decryptor_t.o $(Enclave_Cpp_Objects_2) -o $@ $(Decryptor_Link_Flags)
+	@$(CXX) -Wl,--verbose --verbose Decryptor/Decryptor_t.o $(Enclave_Cpp_Objects_2) -o $@ $(Decryptor_Link_Flags)
 	@echo "LINK =>  $@"
 
 $(Enclave_Name_2): Decryptor.so