123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- /*
- * Tencent is pleased to support the open source community by making IoT Hub
- available.
- * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
- * Licensed under the MIT License (the "License"); you may not use this file
- except in
- * compliance with the License. You may obtain a copy of the License at
- * http://opensource.org/licenses/MIT
- * Unless required by applicable law or agreed to in writing, software
- distributed under the License is
- * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND,
- * either express or implied. See the License for the specific language
- governing permissions and
- * limitations under the License.
- *
- */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "qcloud_iot_ca.h"
- #include <stdlib.h>
- #include "qcloud_iot_common.h"
- #include "qcloud_iot_import.h"
- typedef struct _RegionDomain_ {
- const char *region;
- const char *domain;
- } RegionDomain;
- /*mqtt domain*/
- static RegionDomain sg_iot_mqtt_domain[] = {
- {.region = "china", .domain = QCLOUD_IOT_MQTT_DIRECT_DOMAIN}, /* China */
- {.region = "us-east", .domain = QCLOUD_IOT_MQTT_US_EAST_DOMAIN}, /* Eastern US*/
- };
- /*dynreg domain*/
- static RegionDomain sg_iot_dyn_reg_domain[] = {
- {.region = "china", .domain = DYN_REG_SERVER_URL}, /* China */
- {.region = "us-east", .domain = DYN_REG_SERVER_US_EAST_URL}, /* Eastern US*/
- };
- /*log domain*/
- static RegionDomain sg_iot_log_domain[] = {
- {.region = "china", .domain = LOG_UPLOAD_SERVER_DOMAIN}, /* China */
- {.region = "us-east", .domain = LOG_UPLOAD_SERVER_US_EAST_DOMAIN}, /* Eastern US*/
- };
- #ifndef AUTH_WITH_NOTLS
- static const char *iot_ca_crt = {
- "-----BE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Ib3DQEBCwUAA4IBAQDRSjXnBc3T\r\n"
- "d9VmtTCuALXrQELY8KtM+cXYYNgtodHsxmrRMpJofsPGiqPfb82klvswpXxPK8Xx\r\n"
- "SuUUo74Fo+AEyJxMrRKlbJvlEtnpSilKmG6rO9+bFq3nbeOAfat4lPl0DIscWUx3\r\n"
- "ajXtvMCcSwTlF8rPgXbOaSXZidRYNqSyUjC2Q4m93Cv+KlyB+FgOke8x4aKAkf5p\r\n"
- "XR8i1BN1OiMTIRYhGSfeZbVRq5kTdvtahiWFZu9DGO+hxDZObYGIxGHWPftrhBKz\r\n"
- "RT16Amn780rQLWojr70q7o7QP5tO0wDPfCdFSc6CQFq/ngOzYag0kJ2F+O5U6+kS\r\n"
- "QVrcRBDxzx/G\r\n"
- "-----END CERTIFICATE-----"};
- #ifdef OTA_USE_HTTPS
- static const char *iot_https_ca_crt = {
- "-----BEGIN CERTIFICATE-----\r\n"
- "MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\r\n"
- "A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\r\n"
- "b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\r\n"
- "MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\r\n"
- "YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT\r\n"
- "aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ\r\n"
- "jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp\r\n"
- "xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp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hvcNAQELBQADggEBAEYq7l69rgFgNzERhnF0tkZJyBAW/i9iIxerH4f4gu3K3w4s\r\n"
- "32R1juUYcqeMOovJrKV3UPfvnqTgoI8UV6MqX+x+bRDmuo2wCId2Dkyy2VG7EQLy\r\n"
- "XN0cvfNVlg/UBsD84iOKJHDTu/B5GqdhcIOKrwbFINihY9Bsrk8y1658GEV1BSl3\r\n"
- "30JAZGSGvip2CTFvHST0mdCF/vIhCPnG9vHQWe3WVjwIKANnuvD58ZAWR65n5ryA\r\n"
- "SOlCdjSXVWkkDoPWoC209fN5ikkodBpBocLTJIg1MGCUF7ThBCIxPTsvFwayuJ2G\r\n"
- "K1pp74P1S8SqtCr4fKGxhZSM9AyHDPSsQPhZSZg=\r\n"
- "-----END CERTIFICATE-----"};
- #endif
- #endif
- const char *iot_ca_get()
- {
- #ifndef AUTH_WITH_NOTLS
- return iot_ca_crt;
- #else
- return NULL;
- #endif
- }
- const char *iot_https_ca_get()
- {
- #if ((!defined(AUTH_WITH_NOTLS)) && (defined OTA_USE_HTTPS))
- return iot_https_ca_crt;
- #else
- return NULL;
- #endif
- }
- const char *iot_get_mqtt_domain(char *region)
- {
- const char *pDomain = NULL;
- int i;
- if (!region) {
- goto end;
- }
- for (i = 0; i < sizeof(sg_iot_mqtt_domain) / sizeof(sg_iot_mqtt_domain[0]); i++) {
- if (0 == strcmp(region, sg_iot_mqtt_domain[i].region)) {
- pDomain = sg_iot_mqtt_domain[i].domain;
- break;
- }
- }
- end:
- if (!pDomain) {
- pDomain = sg_iot_mqtt_domain[0].domain;
- }
- return pDomain;
- }
- const char *iot_get_dyn_reg_domain(char *region)
- {
- const char *pDomain = NULL;
- int i;
- if (!region) {
- goto end;
- }
- for (i = 0; i < sizeof(sg_iot_dyn_reg_domain) / sizeof(sg_iot_dyn_reg_domain[0]); i++) {
- if (0 == strcmp(region, sg_iot_dyn_reg_domain[i].region)) {
- pDomain = sg_iot_dyn_reg_domain[i].domain;
- break;
- }
- }
- end:
- if (!pDomain) {
- pDomain = sg_iot_dyn_reg_domain[0].domain;
- }
- return pDomain;
- }
- const char *iot_get_log_domain(char *region)
- {
- const char *pDomain = NULL;
- int i;
- if (!region) {
- goto end;
- }
- for (i = 0; i < sizeof(sg_iot_log_domain) / sizeof(sg_iot_log_domain[0]); i++) {
- if (0 == strcmp(region, sg_iot_log_domain[i].region)) {
- pDomain = sg_iot_log_domain[i].domain;
- break;
- }
- }
- end:
- if (!pDomain) {
- pDomain = sg_iot_log_domain[0].domain;
- }
- return pDomain;
- }
- #ifdef __cplusplus
- }
- #endif
|