systemSealerWrapper.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <stdlib.h>
  2. #include <unistd.h> // Read/write
  3. #include <string>
  4. #include <iostream>
  5. #include <vector>
  6. #include "SgxSealer.h"
  7. //class SealerWrapper {
  8. uint32_t seal_message_to_file(int fd, std::string& plaintext, uint32_t* actual_sealed_msg_length)
  9. {
  10. uint32_t ret; ssize_t bytes_written; std::string sgx_sealed_msg;
  11. ret = seal_message(plaintext, sgx_sealed_msg);
  12. if(ret!=0)
  13. return ret;
  14. bytes_written = write(fd, sgx_sealed_msg.c_str(), sgx_sealed_msg.length());
  15. if(bytes_written > 0)
  16. {
  17. fsync(fd);
  18. *actual_sealed_msg_length = bytes_written;
  19. return 0;
  20. }
  21. else
  22. return 0xFFFFFFFF;
  23. }
  24. // need to return a msg of the length returned by the get_encrypt_txt_len call.
  25. uint32_t unseal_message_from_file(int fd, std::string& plaintext, uint32_t* expected_sealed_msg_length)
  26. {
  27. uint32_t ret; ssize_t bytes_read; char* sgx_sealed_msg; std::string sgx_sealed_msg_str;
  28. sgx_sealed_msg = (char*) malloc(*expected_sealed_msg_length);
  29. lseek(fd, 0, SEEK_SET);
  30. bytes_read = read(fd, sgx_sealed_msg, *expected_sealed_msg_length);
  31. if(bytes_read <= 0)
  32. {
  33. free(sgx_sealed_msg);
  34. return 0xFFFFFFFF;
  35. }
  36. sgx_sealed_msg_str = std::string(sgx_sealed_msg, *expected_sealed_msg_length);
  37. free(sgx_sealed_msg);
  38. ret = unseal_and_verify_sealed_message(sgx_sealed_msg_str, plaintext);
  39. return ret;
  40. }
  41. //};