systemMain.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <phpcpp.h>
  2. #include <string.h>
  3. #include <string>
  4. #include <unistd.h>
  5. #include <errno.h>
  6. #include <fcntl.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <stdio.h>
  10. #include "crypto.h"
  11. #include "ProtobufLAInitiator.h"
  12. using namespace std;
  13. // #include <unistd.h>
  14. // based off the example functionreturnvalue.cpp in PHP-CPP
  15. /**
  16. * Namespace to use
  17. */
  18. using namespace std;
  19. #define DECRYPTOR_PORT 3825
  20. int local_attestation_successful=0;
  21. int __ImageBase=0;
  22. // Symbols are exported according to the "C" language
  23. extern "C"
  24. {
  25. void local_attestation_initiator_wrapper()
  26. {
  27. setbuf(stdout,NULL);
  28. uint32_t return_sgx;
  29. return_sgx = local_attestation_initiator(DECRYPTOR_PORT);
  30. if(return_sgx != 0)
  31. {
  32. if(return_sgx== 0xFFFFFFFF)
  33. {
  34. perror("\nCould not set up the socket: had the following error: ");
  35. fflush(stderr);
  36. }
  37. else
  38. {
  39. printf("\nHad the following error in SGX local attestation: 0x%x", return_sgx);
  40. fflush(stdout);
  41. }
  42. // return return_sgx;
  43. }
  44. printf("\nSuccessful LA with port %d.\n", DECRYPTOR_PORT);
  45. fflush(stdout);
  46. local_attestation_successful=1;
  47. // return 0;
  48. }
  49. // export the "get_module" function that will be called by the Zend engine
  50. PHPCPP_EXPORT void *get_module()
  51. {
  52. // create extension
  53. static Php::Extension extension("decryptor_la_setup_and_decryption","1.0");
  54. // add function to extension - make this the decryption function
  55. // extension.add<my_return_value_function>("my_return_value_function");
  56. extension.onStartup(&local_attestation_initiator_wrapper);
  57. // return the extension module
  58. return extension.module();
  59. }
  60. }