session_mgr.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2011-2018 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. #ifndef SESSION_MGR_H
  32. #define SESSION_MGR_H
  33. #include "pse_inc.h"
  34. #include "pse_types.h"
  35. #include "t_pairing_blob.h"
  36. #include "sgx_dh.h"
  37. //session array parameters
  38. #define SESSION_CONNECTION 128
  39. #define SESSION_IDLE_TIME (uint64_t)1000*60 //one minute in milliseconds
  40. #define MAX_INST_PER_ENCLAVE 32
  41. #define INVADE_SESSION_ID -1
  42. //session status
  43. #define SESSION_CLOSE 0x0
  44. #define SESSION_IN_PROGRESS 0x1
  45. #define SESSION_ACTIVE 0x2
  46. //session counter
  47. #define SESSION_COUNTER_MAX ((uint32_t)-1)
  48. #define DEFAULT_VMC_ACCESS_CTL_ATTRI_MASK 0xFFFFFFFFFFFFFFCB
  49. #pragma pack(push, 1)
  50. typedef struct _isv_attributes_t
  51. {
  52. uint64_t tick_count; //ULONGLONG WINAPI GetTickCount64(void)
  53. sgx_isv_svn_t isv_svn;
  54. sgx_prod_id_t isv_prod_id;
  55. sgx_attributes_t attribute;
  56. sgx_measurement_t mr_signer; // The value of the enclave SIGNER's measurement
  57. sgx_measurement_t mr_enclave; // The value of the enclave's measurement
  58. }isv_attributes_t;
  59. typedef struct _pse_session_t
  60. {
  61. uint32_t sid;
  62. uint32_t state;
  63. union
  64. {
  65. struct
  66. {
  67. sgx_dh_session_t dh_session;
  68. }in_progress;
  69. struct
  70. {
  71. sgx_key_128bit_t AEK;
  72. uint32_t counter;
  73. }active;
  74. };
  75. uint32_t isv_attributes_len;
  76. isv_attributes_t isv_attributes;
  77. }pse_session_t;
  78. typedef struct _eph_session_t
  79. {
  80. uint32_t seq_num;
  81. uint32_t sid;
  82. uint32_t state;
  83. sgx_key_128bit_t TSK;
  84. sgx_key_128bit_t TMK;
  85. }eph_session_t;
  86. #pragma pack(pop)
  87. pse_op_error_t pse_create_session(
  88. uint64_t tick,
  89. uint32_t &id,
  90. pse_dh_msg1_t &dh_msg1);
  91. pse_op_error_t pse_exchange_report(
  92. uint64_t tick,
  93. uint32_t sid,
  94. const sgx_dh_msg2_t &dh_msg2,
  95. pse_dh_msg3_t &dh_msg3);
  96. pse_op_error_t pse_close_session(uint32_t sid);
  97. pse_session_t* sid2session(uint32_t sid);
  98. pse_op_error_t ephemeral_session_m2m3(
  99. pairing_blob_t* sealed_blob,
  100. const pse_cse_msg2_t &pse_cse_msg2,
  101. pse_cse_msg3_t &pse_cse_msg3);
  102. pse_op_error_t ephemeral_session_m4(const pse_cse_msg4_t &pse_cse_msg4);
  103. bool copy_global_pairing_nonce(uint8_t* target_buffer);
  104. void free_session(pse_session_t* session);
  105. bool is_eph_session_active();
  106. bool is_isv_session_valid(pse_session_t* session);
  107. uint32_t get_session_seq_num(pse_session_t* session);
  108. void set_session_seq_num(pse_session_t* session, uint32_t seq_num);
  109. void update_session_tick_count(pse_session_t* session, uint64_t new_tick_count);
  110. void copy_pse_instance_id(uint8_t* pse_instance_id);
  111. #endif