|
@@ -0,0 +1,97 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include "../../Decryptor/Decryptor_u.h"
|
|
|
+#include "sgx_eid.h"
|
|
|
+#include "sgx_urts.h"
|
|
|
+#define __STDC_FORMAT_MACROS
|
|
|
+#include <inttypes.h>
|
|
|
+#include "ProtobufLAMessages.pb.h"
|
|
|
+#include "Transforms.h"
|
|
|
+
|
|
|
+int LA::generate_protobuf_dh_msg1(uint32_t own_enclave_id, protobuf_sgx_dh_msg1_t& protobuf_msg1)
|
|
|
+{
|
|
|
+ sgx_dh_msg1_t dh_msg1;
|
|
|
+ memset(&dh_msg1, 0, sizeof(sgx_dh_msg1_t));
|
|
|
+ uint32_t ret_status;
|
|
|
+ Decryptor_session_request_wrapper(own_enclave_id, &ret_status, &dh_msg1);
|
|
|
+ if(ret_status != SGX_SUCCESS)
|
|
|
+ return 0xffffffff;
|
|
|
+
|
|
|
+ Transforms::encode_msg1_to_protobuf(protobuf_msg1, &dh_msg1);
|
|
|
+ printf("Generated the following Msg1: ------------- \n"); fflush(stdout);
|
|
|
+ Transforms::print_initialized_msg1(protobuf_msg1, &dh_msg1);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int LA::process_protobuf_dh_msg2_generate_protobuf_dh_msg3(uint32_t own_enclave_id, protobuf_sgx_dh_msg2_t& protobuf_msg2, protobuf_sgx_dh_msg3_t& protobuf_msg3, uint32_t* session_id)
|
|
|
+{
|
|
|
+ uint32_t ret_status;
|
|
|
+ sgx_dh_msg2_t dh_msg2;
|
|
|
+ sgx_dh_msg3_t dh_msg3;
|
|
|
+ sgx_key_128bit_t dh_aek;
|
|
|
+ memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
|
|
|
+ memset(&dh_msg2, 0, sizeof(sgx_dh_msg2_t));
|
|
|
+ memset(&dh_msg3, 0, sizeof(sgx_dh_msg3_t));
|
|
|
+
|
|
|
+ if(decode_msg2_from_protobuf(protobuf_msg2, &dh_msg2)!=0)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+
|
|
|
+ Decryptor_exchange_report_wrapper(own_enclave_id, &ret_status, &dh_msg2, &dh_msg3);
|
|
|
+ if(ret_status!=SGX_SUCCESS)
|
|
|
+ return 0x35;
|
|
|
+
|
|
|
+
|
|
|
+ encode_msg3_to_protobuf(protobuf_msg3, &dh_msg3);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int LA::conduct_la(uint32_t own_enclave_id, int fd)
|
|
|
+{
|
|
|
+
|
|
|
+ protobuf_sgx_dh_msg1_t protobuf_msg1;
|
|
|
+ protobuf_sgx_dh_msg2_t protobuf_msg2;
|
|
|
+ protobuf_sgx_dh_msg3_t protobuf_msg3;
|
|
|
+ uint32_t protobuf_sgx_ret;
|
|
|
+
|
|
|
+ setbuf(stdout,NULL);
|
|
|
+
|
|
|
+ protobufReaderWriter.set_fd(fd);
|
|
|
+
|
|
|
+ protobuf_sgx_ret = generate_protobuf_dh_msg1(own_enclave_id, protobuf_msg1);
|
|
|
+ if(protobuf_sgx_ret != 0)
|
|
|
+ {
|
|
|
+ printf("Error in generate_protobuf_dh_msg1: 0x%x", protobuf_sgx_ret); fflush(stdout); return protobuf_sgx_ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("Writing message 1\n"); fflush(stdout);
|
|
|
+ if(protobufReaderWriter.write_msg(protobuf_msg1)!=0)
|
|
|
+ return 0x1;
|
|
|
+
|
|
|
+ printf("Reading message 2\n"); fflush(stdout);
|
|
|
+ if(protobufReaderWriter.read_msg(protobuf_msg2)!=0)
|
|
|
+ return 0x2;
|
|
|
+
|
|
|
+ protobuf_sgx_ret = process_protobuf_dh_msg2_generate_protobuf_dh_msg3(own_enclave_id, protobuf_msg2, protobuf_msg3);
|
|
|
+ if(protobuf_sgx_ret != 0)
|
|
|
+ {
|
|
|
+ printf("Error in process_protobuf_dh_msg2_generate_protobuf_dh_msg3: 0x%x", protobuf_sgx_ret);
|
|
|
+ fflush(stdout);
|
|
|
+ return protobuf_sgx_ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("Writing message 3\n"); fflush(stdout);
|
|
|
+ if(protobufReaderWriter.write_msg(protobuf_msg3)!=0)
|
|
|
+ return 0x3;
|
|
|
+ return 0;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void LA::get_la_symmetric_key(uint8_t* op_key)
|
|
|
+{
|
|
|
+ uint32_t counter;
|
|
|
+ for(counter=0; counter<16; counter++)
|
|
|
+ op_key[counter] = key[counter];
|
|
|
+}
|