|
| 1 | +/* |
| 2 | + This file is part of the ArduinoIoTCloud library. |
| 3 | +
|
| 4 | + Copyright (c) 2024 Arduino SA |
| 5 | +
|
| 6 | + This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | +*/ |
| 10 | + |
| 11 | +#include <AIoTC_Config.h> |
| 12 | + |
| 13 | +#ifdef HAS_TCP |
| 14 | + |
| 15 | +#include "TLSClientMqtt.h" |
| 16 | + |
| 17 | +#if defined(BOARD_HAS_SECRET_KEY) |
| 18 | + #include "tls/AIoTCUPCert.h" |
| 19 | +#endif |
| 20 | + |
| 21 | +#if defined(BOARD_HAS_SE050) || defined(BOARD_HAS_SOFTSE) |
| 22 | + #include "tls/AIoTCSSCert.h" |
| 23 | +#endif |
| 24 | + |
| 25 | +#ifdef BOARD_HAS_ECCX08 |
| 26 | + #include "tls/BearSSLTrustAnchors.h" |
| 27 | + extern "C" { |
| 28 | + void aiotc_client_profile_init(br_ssl_client_context *cc, |
| 29 | + br_x509_minimal_context *xc, |
| 30 | + const br_x509_trust_anchor *trust_anchors, |
| 31 | + size_t trust_anchors_num); |
| 32 | + unsigned long getTime(); |
| 33 | + } |
| 34 | +#endif |
| 35 | + |
| 36 | +void TLSClientMqtt::begin(ConnectionHandler & connection) { |
| 37 | + |
| 38 | +#if defined(BOARD_HAS_OFFLOADED_ECCX08) |
| 39 | + /* Arduino Root CA is configured in nina-fw |
| 40 | + * https://github.com/arduino/nina-fw/blob/master/arduino/libraries/ArduinoBearSSL/src/BearSSLTrustAnchors.h |
| 41 | + */ |
| 42 | +#elif defined(BOARD_HAS_ECCX08) |
| 43 | + setClient(connection.getClient()); |
| 44 | + setProfile(aiotc_client_profile_init); |
| 45 | + setTrustAnchors(ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM); |
| 46 | + onGetTime(getTime); |
| 47 | +#elif defined(ARDUINO_PORTENTA_C33) |
| 48 | + setClient(connection.getClient()); |
| 49 | + setCACert(AIoTSSCert); |
| 50 | +#elif defined(ARDUINO_NICLA_VISION) |
| 51 | + appendCustomCACert(AIoTSSCert); |
| 52 | +#elif defined(ARDUINO_EDGE_CONTROL) |
| 53 | + appendCustomCACert(AIoTUPCert); |
| 54 | +#elif defined(ARDUINO_UNOR4_WIFI) |
| 55 | + /* Arduino Root CA is configured in uno-r4-wifi-usb-bridge fw >= 0.4.1 |
| 56 | + * https://github.com/arduino/uno-r4-wifi-usb-bridge/blob/main/certificates/cacrt_all.pem |
| 57 | + * Boards using username/password authentication relies on Starfield Class 2 CA |
| 58 | + * also present in older firmware revisions |
| 59 | + * https://github.com/arduino/uno-r4-wifi-usb-bridge/blob/f09ca94fdcab845b8368d4435fdac9f6999d21d2/certificates/certificates.pem#L852 |
| 60 | + */ |
| 61 | +#elif defined(ARDUINO_ARCH_ESP32) |
| 62 | + setCACertBundle(x509_crt_bundle); |
| 63 | +#elif defined(ARDUINO_ARCH_ESP8266) |
| 64 | + setInsecure(); |
| 65 | +#endif |
| 66 | +} |
| 67 | + |
| 68 | +#endif |
0 commit comments