App.cpp 4.1 KB

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