App.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <stdio.h>
  2. #include "UntrustedInclude/LocalAttestationUntrusted.h"
  3. #include "UntrustedInclude/SealingUntrusted.h"
  4. #include "../Decryptor/Decryptor_u.h"
  5. #include "sgx_eid.h"
  6. #include "sgx_urts.h"
  7. #define __STDC_FORMAT_MACROS
  8. #include <inttypes.h>
  9. #include<unistd.h>
  10. #define Decryptor_PATH "libDecryptor.so"
  11. //////////////////////////////////////////////////
  12. int main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
  13. {
  14. uint32_t ret_status;
  15. sgx_status_t status;
  16. // For sgx setup
  17. int launch_token_updated;
  18. sgx_launch_token_t launch_token;
  19. uint32_t counter;
  20. int server_fd, accept_fd;
  21. uint8_t verification_key[64];
  22. status = sgx_create_enclave(Decryptor_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e2_enclave_id, NULL);
  23. if(status != SGX_SUCCESS)
  24. {
  25. printf("\nLoad Enclave Failure");
  26. return -1;
  27. }
  28. printf("\nDecryptor - EnclaveID %" PRIx64, e2_enclave_id);
  29. fflush(stdout);
  30. ret_status = SealingUntrusted::look_for_signing_key_or_regenerate_it("sealed_signing_key.txt");
  31. if(ret_status != 0)
  32. {
  33. printf("Some error \n");
  34. fflush(stdout);
  35. sgx_destroy_enclave(e2_enclave_id);
  36. return 0xFFFFFFFF;
  37. }
  38. Decryptor_get_long_term_verification_key_wrapper(e2_enclave_id, verification_key);
  39. printf("Verification key\n"); fflush(stdout);
  40. for(counter=0;counter<32;counter++)
  41. printf("%02x", verification_key[counter]);
  42. printf("\n"); fflush(stdout);
  43. for(counter=0;counter<32;counter++)
  44. printf("%02x", verification_key[counter + 32]);
  45. printf("\n"); fflush(stdout);
  46. ret_status = LocalAttestationUntrusted::prepare_local_attestation_as_responder_msg1(e2_enclave_id);
  47. if(ret_status !=0)
  48. {
  49. printf("Could not prepare_local_attestation_as_responder_msg1"); fflush(stdout); sgx_destroy_enclave(e2_enclave_id);
  50. return ret_status;
  51. }
  52. server_fd=LocalAttestationUntrusted::setup_socket_for_local_attestation_requests(3824);
  53. if(server_fd <=0)
  54. {
  55. printf("Error in setting up server socket."); fflush(stdout);
  56. sgx_destroy_enclave(e2_enclave_id);
  57. return server_fd;
  58. }
  59. printf("Successfully set up a socket to communicate with the verifier enclave.\n");
  60. fflush(stdout);
  61. // LA with the verifier
  62. ret_status = LocalAttestationUntrusted::local_attestation_as_responder_msg2_msg3(e2_enclave_id, server_fd, &accept_fd);
  63. if(ret_status!=0)
  64. {
  65. printf("local attestation - with the verifier - did not successfully return: %x\n", ret_status); fflush(stdout);
  66. sgx_destroy_enclave(e2_enclave_id);
  67. return 0x32;
  68. }
  69. ret_status = LocalAttestationUntrusted::post_local_attestation_with_verifier(e2_enclave_id, accept_fd);
  70. if(ret_status!=0)
  71. {
  72. printf("post local attestation - with the verifier - did not successfully return: %x\n", ret_status); fflush(stdout);
  73. sgx_destroy_enclave(e2_enclave_id);
  74. return 0x33;
  75. }
  76. // LA with apache
  77. server_fd=LocalAttestationUntrusted::setup_socket_for_local_attestation_requests(3825);
  78. if(server_fd <=0)
  79. {
  80. printf("Error in setting up server socket."); fflush(stdout);
  81. sgx_destroy_enclave(e2_enclave_id);
  82. return 0x34;
  83. }
  84. printf("Successfully set up a socket to communicate with the Apache enclave.\n");
  85. fflush(stdout);
  86. ret_status = LocalAttestationUntrusted::local_attestation_as_responder_msg2_msg3(e2_enclave_id,server_fd,&accept_fd);
  87. if(ret_status != 0)
  88. {
  89. printf("local attestation - with the apache - did not successfully return: %x\n", ret_status); fflush(stdout);
  90. sgx_destroy_enclave(e2_enclave_id);
  91. return 0x35;
  92. }
  93. ret_status = LocalAttestationUntrusted::post_local_attestation_with_apache(e2_enclave_id,accept_fd);
  94. if(ret_status!=0)
  95. {
  96. printf("post local attestation - with the apache - did not successfully return: %x\n", ret_status); fflush(stdout);
  97. sgx_destroy_enclave(e2_enclave_id);
  98. return 0x36;
  99. }
  100. sgx_destroy_enclave(e2_enclave_id);
  101. return 0;
  102. }