qcloud_iot_ca.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Tencent is pleased to support the open source community by making IoT Hub
  3. available.
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. * Licensed under the MIT License (the "License"); you may not use this file
  6. except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://opensource.org/licenses/MIT
  9. * Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is
  11. * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND,
  13. * either express or implied. See the License for the specific language
  14. governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "qcloud_iot_ca.h"
  22. #include <stdlib.h>
  23. #include "qcloud_iot_common.h"
  24. #include "qcloud_iot_import.h"
  25. typedef struct _RegionDomain_ {
  26. const char *region;
  27. const char *domain;
  28. } RegionDomain;
  29. /*mqtt domain*/
  30. static RegionDomain sg_iot_mqtt_domain[] = {
  31. {.region = "china", .domain = QCLOUD_IOT_MQTT_DIRECT_DOMAIN}, /* China */
  32. {.region = "us-east", .domain = QCLOUD_IOT_MQTT_US_EAST_DOMAIN}, /* Eastern US*/
  33. };
  34. /*dynreg domain*/
  35. static RegionDomain sg_iot_dyn_reg_domain[] = {
  36. {.region = "china", .domain = DYN_REG_SERVER_URL}, /* China */
  37. {.region = "us-east", .domain = DYN_REG_SERVER_US_EAST_URL}, /* Eastern US*/
  38. };
  39. /*log domain*/
  40. static RegionDomain sg_iot_log_domain[] = {
  41. {.region = "china", .domain = LOG_UPLOAD_SERVER_DOMAIN}, /* China */
  42. {.region = "us-east", .domain = LOG_UPLOAD_SERVER_US_EAST_DOMAIN}, /* Eastern US*/
  43. };
  44. #ifndef AUTH_WITH_NOTLS
  45. static const char *iot_ca_crt = {
  46. "-----BEGIN CERTIFICATE-----\r\n"
  47. "MIIDxTCCAq2gAwIBAgIJALM1winYO2xzMA0GCSqGSIb3DQEBCwUAMHkxCzAJBgNV\r\n"
  48. "BAYTAkNOMRIwEAYDVQQIDAlHdWFuZ0RvbmcxETAPBgNVBAcMCFNoZW5aaGVuMRAw\r\n"
  49. "DgYDVQQKDAdUZW5jZW50MRcwFQYDVQQLDA5UZW5jZW50IElvdGh1YjEYMBYGA1UE\r\n"
  50. "AwwPd3d3LnRlbmNlbnQuY29tMB4XDTE3MTEyNzA0MjA1OVoXDTMyMTEyMzA0MjA1\r\n"
  51. "OVoweTELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5nRG9uZzERMA8GA1UEBwwI\r\n"
  52. "U2hlblpoZW4xEDAOBgNVBAoMB1RlbmNlbnQxFzAVBgNVBAsMDlRlbmNlbnQgSW90\r\n"
  53. "aHViMRgwFgYDVQQDDA93d3cudGVuY2VudC5jb20wggEiMA0GCSqGSIb3DQEBAQUA\r\n"
  54. "A4IBDwAwggEKAoIBAQDVxwDZRVkU5WexneBEkdaKs4ehgQbzpbufrWo5Lb5gJ3i0\r\n"
  55. "eukbOB81yAaavb23oiNta4gmMTq2F6/hAFsRv4J2bdTs5SxwEYbiYU1teGHuUQHO\r\n"
  56. "iQsZCdNTJgcikga9JYKWcBjFEnAxKycNsmqsq4AJ0CEyZbo//IYX3czEQtYWHjp7\r\n"
  57. "FJOlPPd1idKtFMVNG6LGXEwS/TPElE+grYOxwB7Anx3iC5ZpE5lo5tTioFTHzqbT\r\n"
  58. "qTN7rbFZRytAPk/JXMTLgO55fldm4JZTP3GQsPzwIh4wNNKhi4yWG1o2u3hAnZDv\r\n"
  59. "UVFV7al2zFdOfuu0KMzuLzrWrK16SPadRDd9eT17AgMBAAGjUDBOMB0GA1UdDgQW\r\n"
  60. "BBQrr48jv4FxdKs3r0BkmJO7zH4ALzAfBgNVHSMEGDAWgBQrr48jv4FxdKs3r0Bk\r\n"
  61. "mJO7zH4ALzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQDRSjXnBc3T\r\n"
  62. "d9VmtTCuALXrQELY8KtM+cXYYNgtodHsxmrRMpJofsPGiqPfb82klvswpXxPK8Xx\r\n"
  63. "SuUUo74Fo+AEyJxMrRKlbJvlEtnpSilKmG6rO9+bFq3nbeOAfat4lPl0DIscWUx3\r\n"
  64. "ajXtvMCcSwTlF8rPgXbOaSXZidRYNqSyUjC2Q4m93Cv+KlyB+FgOke8x4aKAkf5p\r\n"
  65. "XR8i1BN1OiMTIRYhGSfeZbVRq5kTdvtahiWFZu9DGO+hxDZObYGIxGHWPftrhBKz\r\n"
  66. "RT16Amn780rQLWojr70q7o7QP5tO0wDPfCdFSc6CQFq/ngOzYag0kJ2F+O5U6+kS\r\n"
  67. "QVrcRBDxzx/G\r\n"
  68. "-----END CERTIFICATE-----"};
  69. #ifdef OTA_USE_HTTPS
  70. static const char *iot_https_ca_crt = {
  71. "-----BEGIN CERTIFICATE-----\r\n"
  72. "MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\r\n"
  73. "A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\r\n"
  74. "b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\r\n"
  75. "MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\r\n"
  76. "YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT\r\n"
  77. "aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ\r\n"
  78. "jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp\r\n"
  79. "xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp\r\n"
  80. "1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG\r\n"
  81. "snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ\r\n"
  82. "U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8\r\n"
  83. "9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E\r\n"
  84. "BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B\r\n"
  85. "AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz\r\n"
  86. "yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE\r\n"
  87. "38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP\r\n"
  88. "AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad\r\n"
  89. "DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME\r\n"
  90. "HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==\r\n"
  91. "-----END CERTIFICATE-----\r\n"
  92. "-----BEGIN CERTIFICATE-----\r\n"
  93. "MIIEaTCCA1GgAwIBAgILBAAAAAABRE7wQkcwD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MDMGA1UdHwQsMCow\r\n"
  108. "KKAmoCSGImh0dHA6Ly9jcmwuZ2xvYmFsc2lnbi5uZXQvcm9vdC5jcmwwPQYIKwYB\r\n"
  109. "BQUHAQEEMTAvMC0GCCsGAQUFBzABhiFodHRwOi8vb2NzcC5nbG9iYWxzaWduLmNv\r\n"
  110. "bS9yb290cjEwHwYDVR0jBBgwFoAUYHtmGkUNl8qJUC99BM00qP/8/UswDQYJKoZI\r\n"
  111. "hvcNAQELBQADggEBAEYq7l69rgFgNzERhnF0tkZJyBAW/i9iIxerH4f4gu3K3w4s\r\n"
  112. "32R1juUYcqeMOovJrKV3UPfvnqTgoI8UV6MqX+x+bRDmuo2wCId2Dkyy2VG7EQLy\r\n"
  113. "XN0cvfNVlg/UBsD84iOKJHDTu/B5GqdhcIOKrwbFINihY9Bsrk8y1658GEV1BSl3\r\n"
  114. "30JAZGSGvip2CTFvHST0mdCF/vIhCPnG9vHQWe3WVjwIKANnuvD58ZAWR65n5ryA\r\n"
  115. "SOlCdjSXVWkkDoPWoC209fN5ikkodBpBocLTJIg1MGCUF7ThBCIxPTsvFwayuJ2G\r\n"
  116. "K1pp74P1S8SqtCr4fKGxhZSM9AyHDPSsQPhZSZg=\r\n"
  117. "-----END CERTIFICATE-----"};
  118. #endif
  119. #endif
  120. const char *iot_ca_get()
  121. {
  122. #ifndef AUTH_WITH_NOTLS
  123. return iot_ca_crt;
  124. #else
  125. return NULL;
  126. #endif
  127. }
  128. const char *iot_https_ca_get()
  129. {
  130. #if ((!defined(AUTH_WITH_NOTLS)) && (defined OTA_USE_HTTPS))
  131. return iot_https_ca_crt;
  132. #else
  133. return NULL;
  134. #endif
  135. }
  136. const char *iot_get_mqtt_domain(char *region)
  137. {
  138. const char *pDomain = NULL;
  139. int i;
  140. if (!region) {
  141. goto end;
  142. }
  143. for (i = 0; i < sizeof(sg_iot_mqtt_domain) / sizeof(sg_iot_mqtt_domain[0]); i++) {
  144. if (0 == strcmp(region, sg_iot_mqtt_domain[i].region)) {
  145. pDomain = sg_iot_mqtt_domain[i].domain;
  146. break;
  147. }
  148. }
  149. end:
  150. if (!pDomain) {
  151. pDomain = sg_iot_mqtt_domain[0].domain;
  152. }
  153. return pDomain;
  154. }
  155. const char *iot_get_dyn_reg_domain(char *region)
  156. {
  157. const char *pDomain = NULL;
  158. int i;
  159. if (!region) {
  160. goto end;
  161. }
  162. for (i = 0; i < sizeof(sg_iot_dyn_reg_domain) / sizeof(sg_iot_dyn_reg_domain[0]); i++) {
  163. if (0 == strcmp(region, sg_iot_dyn_reg_domain[i].region)) {
  164. pDomain = sg_iot_dyn_reg_domain[i].domain;
  165. break;
  166. }
  167. }
  168. end:
  169. if (!pDomain) {
  170. pDomain = sg_iot_dyn_reg_domain[0].domain;
  171. }
  172. return pDomain;
  173. }
  174. const char *iot_get_log_domain(char *region)
  175. {
  176. const char *pDomain = NULL;
  177. int i;
  178. if (!region) {
  179. goto end;
  180. }
  181. for (i = 0; i < sizeof(sg_iot_log_domain) / sizeof(sg_iot_log_domain[0]); i++) {
  182. if (0 == strcmp(region, sg_iot_log_domain[i].region)) {
  183. pDomain = sg_iot_log_domain[i].domain;
  184. break;
  185. }
  186. }
  187. end:
  188. if (!pDomain) {
  189. pDomain = sg_iot_log_domain[0].domain;
  190. }
  191. return pDomain;
  192. }
  193. #ifdef __cplusplus
  194. }
  195. #endif