protobufLAInitiator.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "../Decryptor/Decryptor_u.h"
  2. #include "sgx_eid.h"
  3. #include "sgx_urts.h"
  4. #define __STDC_FORMAT_MACROS
  5. #include <inttypes.h>
  6. #include "ProtobufLAMessages.pb.h"
  7. #include "protobufSgxLATransformsInitiator.h"
  8. #include <stdio.h>
  9. int generate_protobuf_dh_msg1(uint32_t own_enclave_id, protobuf_sgx_dh_msg1_t& protobuf_msg1, uint32_t* session_id)
  10. {
  11. sgx_dh_msg1_t dh_msg1; //Diffie-Hellman Message 1
  12. memset(&dh_msg1, 0, sizeof(sgx_dh_msg1_t));
  13. uint32_t ret_status;
  14. Decryptor_session_request_wrapper(own_enclave_id, &ret_status, &dh_msg1, session_id); // TODO: Check Return status
  15. if(ret_status != SGX_SUCCESS)
  16. return 0xffffffff;
  17. encode_msg1_to_protobuf(protobuf_msg1, &dh_msg1);
  18. printf("Generated the following Msg1: ------------- \n"); fflush(stdout);
  19. print_initialized_msg1(protobuf_msg1, &dh_msg1);
  20. return 0;
  21. }
  22. int 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)
  23. {
  24. uint32_t ret_status;
  25. sgx_dh_msg2_t dh_msg2; //Diffie-Hellman Message 2
  26. sgx_dh_msg3_t dh_msg3; //Diffie-Hellman Message 3
  27. sgx_key_128bit_t dh_aek; // Session Key
  28. memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
  29. memset(&dh_msg2, 0, sizeof(sgx_dh_msg2_t));
  30. memset(&dh_msg3, 0, sizeof(sgx_dh_msg3_t));
  31. if(decode_msg2_from_protobuf(protobuf_msg2, &dh_msg2)!=0)
  32. return -1;
  33. // process msg2 and generate msg3
  34. Decryptor_exchange_report_wrapper(own_enclave_id, &ret_status, &dh_msg2, &dh_msg3, session_id);
  35. if(ret_status!=SGX_SUCCESS)
  36. return 0x35;
  37. // convert msg3 sgx_dh_msg3_t object to a protobuf msg3 object.
  38. encode_msg3_to_protobuf(protobuf_msg3, &dh_msg3);
  39. return 0;
  40. }