LA.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #include "../TrustedInclude/LA.h"
  32. //Handle the request from Source Enclave for a session
  33. uint32_t LA::session_request(sgx_dh_msg1_t *dh_msg1, uint32_t *session_id)
  34. {
  35. sgx_dh_session_t sgx_dh_session;
  36. sgx_status_t status = SGX_SUCCESS;
  37. if(!session_id || !dh_msg1)
  38. {
  39. return INVALID_PARAMETER_ERROR;
  40. }
  41. //Intialize the session as a session responder
  42. status = sgx_dh_init_session(SGX_DH_SESSION_RESPONDER, &sgx_dh_session);
  43. if(SGX_SUCCESS != status)
  44. {
  45. return status;
  46. }
  47. *session_id=1;
  48. global_session_info.status = IN_PROGRESS;
  49. //Generate Message1 that will be returned to Source Enclave
  50. status = sgx_dh_responder_gen_msg1((sgx_dh_msg1_t*)dh_msg1, &sgx_dh_session);
  51. if(SGX_SUCCESS != status)
  52. return status;
  53. memcpy(&global_session_info.in_progress.dh_session, &sgx_dh_session, sizeof(sgx_dh_session_t));
  54. return 0;
  55. }
  56. //Verify Message 2, generate Message3 and exchange Message 3 with Source Enclave
  57. uint32_t LA::exchange_report(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *dh_msg3, uint32_t* session_id)
  58. {
  59. sgx_key_128bit_t dh_aek;
  60. uint32_t status = 0;
  61. sgx_dh_session_t sgx_dh_session;
  62. sgx_dh_session_enclave_identity_t initiator_identity;
  63. uint32_t verify_return;
  64. memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
  65. if(!dh_msg2 || !dh_msg3)
  66. return INVALID_PARAMETER_ERROR;
  67. if(global_session_info.status != IN_PROGRESS)
  68. return INVALID_SESSION;
  69. memcpy(&sgx_dh_session, &global_session_info.in_progress.dh_session, sizeof(sgx_dh_session_t));
  70. dh_msg3->msg3_body.additional_prop_length = 0;
  71. //Process message 2 from source enclave and obtain message 3
  72. status = sgx_dh_responder_proc_msg2(dh_msg2, dh_msg3, &sgx_dh_session, &dh_aek, &initiator_identity);
  73. if(SGX_SUCCESS != status)
  74. return status;
  75. //Verify source enclave's trust
  76. // verify_return = Decryptor::verify_peer_enclave_trust(initiator_identity.mr_enclave.m, initiator_identity.mr_signer.m, dh_aek);
  77. // if(verify_return != 0)
  78. // return verify_return;
  79. /*
  80. //save the session ID, status and initialize the session nonce
  81. global_session_info.session_id = *session_id;
  82. global_session_info.status = ACTIVE; // This means that you can't keep calling exchange_report over and over again.
  83. global_session_info.active.counter = 0;
  84. memcpy(&global_session_info.active.AEK, &dh_aek, sizeof(sgx_key_128bit_t));
  85. memset(&dh_aek,0, sizeof(sgx_key_128bit_t));
  86. */
  87. return 0;
  88. }