endpoint_select_info.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifndef _ENDPOINT_SELECT_INFO_H_
  32. #define _ENDPOINT_SELECT_INFO_H_
  33. #include "se_types.h"
  34. #include "sgx_tseal.h"
  35. #include "aeerror.h"
  36. #include "se_thread.h"
  37. #include "internal/se_rwlock.h"
  38. #include "oal/oal.h"
  39. #include "se_wrapper.h"
  40. #include <time.h>
  41. #include <string.h>
  42. #include "epid_pve_type.h"
  43. #include "default_url_info.hh"
  44. #include "AEClass.h"
  45. #include "aesm_logic.h"
  46. #define AESM_DATA_SERVER_URL_INFOS 'A'
  47. #define AESM_DATA_ENDPOINT_SELECTION_INFOS 'B'
  48. #define AESM_DATA_SERVER_URL_VERSION_1 1
  49. #define AESM_DATA_SERVER_URL_VERSION 2
  50. #define AESM_DATA_ENDPOINT_SELECTION_VERSION 1
  51. #pragma pack(1)
  52. #include "aesm_config.h"
  53. /*Struct for PCE based url information which will be installed by PSW Installer*/
  54. typedef struct _aesm_server_url_infos_t{
  55. uint8_t aesm_data_type;
  56. uint8_t aesm_data_version;
  57. char endpoint_url[MAX_PATH]; /*URL for endpoint selection protocol server*/
  58. char pse_rl_url[MAX_PATH]; /*URL to retrieve PSE rovocation List*/
  59. char pse_ocsp_url[MAX_PATH];
  60. }aesm_server_url_infos_t;
  61. /*Struct for data to save endpoint selection protocol result into persistent data storage*/
  62. typedef struct _endpoint_selection_infos_t{
  63. uint8_t aesm_data_type;
  64. uint8_t aesm_data_version;
  65. signed_pek_t pek;
  66. char provision_url[MAX_PATH];
  67. }endpoint_selection_infos_t;
  68. #pragma pack()
  69. /*An interface to provide the endpoint selection protocol and also provide some URLs (result of ES protocol or some static url)
  70. *Singleton class used to provide a singleton instance in memory and lock used so that it could be shared by PvE/PSEPR
  71. *EndpointSelectionInfo::instance().start_protocol(...) could be used to get endpoint selection result
  72. * It will restart the ES protocol to get updated data. If the protocol fails, it may reuse existing endpoint selection protocol result in persistent storage
  73. */
  74. class EndpointSelectionInfo: public Singleton<EndpointSelectionInfo>{
  75. CLASS_UNCOPYABLE(EndpointSelectionInfo);
  76. friend class Singleton<EndpointSelectionInfo>;
  77. private:
  78. AESMLogicMutex _es_lock; /*lock used since the data will be accessed by two different components: PSEPR and PVE*/
  79. aesm_config_infos_t _config_urls; /*some readonly urls not related to XEGD*/
  80. aesm_server_url_infos_t _server_urls; /*XEGD based readonly url*/
  81. bool _is_server_url_valid; /*Set it to true when field _server_urls is valid*/
  82. bool _is_white_list_url_valid; /*Set it to true after reading _config_urls*/
  83. static ae_error_t read_pek(endpoint_selection_infos_t& es_info); /*read _es_info from persistent storage*/
  84. static ae_error_t write_pek(const endpoint_selection_infos_t& es_info); /*save _es_info to persistent storage*/
  85. ae_error_t verify_signature(const endpoint_selection_infos_t& es_info, uint8_t xid[XID_SIZE], uint8_t rsa_signature[PVE_RSA_KEY_BYTES], uint16_t ttl); /*verify rsa signature in ES protocol result*/
  86. public:
  87. EndpointSelectionInfo(){
  88. memset(&_server_urls, 0, sizeof(_server_urls));
  89. memset(&_config_urls, 0, sizeof(_config_urls));
  90. _is_white_list_url_valid=false;
  91. _is_server_url_valid=false;
  92. }
  93. const char *get_pse_provisioning_url(const endpoint_selection_infos_t& es_info);
  94. public:
  95. static ae_error_t verify_file_by_xgid(uint32_t xgid);
  96. const char* get_dal_emulator_url(){return NULL;}/*dal emulator not supported. The interface is kept to keep PSE untrusted code compilable*/
  97. ae_error_t get_url_info();
  98. ae_error_t get_url_info(aesm_server_url_infos_t& server_url);
  99. const char *get_server_url(aesm_network_server_enum_type_t type);
  100. void get_proxy(uint32_t& proxy_type, char proxy_url[MAX_PATH]);
  101. /*Function to get result of Endpoint Selection Protocol from Backend Server*/
  102. ae_error_t start_protocol(endpoint_selection_infos_t& es_info);
  103. };
  104. #endif /*_ENDPOINT_SELECT_INFO_H_*/