Skip to content

Commit 1a21ea3

Browse files
committed
Add TLSClientOta
1 parent c261949 commit 1a21ea3

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

src/tls/utility/TLSClientOta.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
#if defined(HAS_TCP) && OTA_ENABLED
14+
15+
#include "TLSClientOta.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 TLSClientOta::begin(ConnectionHandler &connection) {
37+
#if defined(BOARD_HAS_OFFLOADED_ECCX08)
38+
/* AWS Root CAs are configured in nina-fw
39+
* https://github.com/arduino/nina-fw/blob/master/data/roots.pem
40+
*/
41+
#elif defined(BOARD_HAS_ECCX08)
42+
setClient(*getNewClient(connection.getInterface()));
43+
setProfile(aiotc_client_profile_init);
44+
setTrustAnchors(ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM);
45+
onGetTime(getTime);
46+
#elif defined(ARDUINO_PORTENTA_C33)
47+
setClient(*getNewClient(connection.getInterface()));
48+
setCACert(AIoTSSCert);
49+
#elif defined(ARDUINO_NICLA_VISION)
50+
appendCustomCACert(AIoTSSCert);
51+
#elif defined(ARDUINO_EDGE_CONTROL)
52+
appendCustomCACert(AIoTUPCert);
53+
#elif defined(ARDUINO_UNOR4_WIFI)
54+
/* AWS Root CAs are configured in uno-r4-wifi-usb-bridge/libraries/Arduino_ESP32_OTA
55+
* https://github.com/arduino-libraries/Arduino_ESP32_OTA/blob/fc755e7d1d3946232107e2590662ee08d6ccdec4/src/tls/amazon_root_ca.h
56+
*/
57+
#elif defined(ARDUINO_ARCH_ESP32)
58+
setCACertBundle(x509_crt_bundle);
59+
#elif defined(ARDUINO_ARCH_ESP8266)
60+
setInsecure();
61+
#endif
62+
}
63+
64+
#endif

src/tls/utility/TLSClientOta.h

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
#pragma once
12+
13+
#include <Arduino_ConnectionHandler.h>
14+
#include <AIoTC_Config.h>
15+
16+
#if defined(BOARD_HAS_OFFLOADED_ECCX08)
17+
/*
18+
* Arduino MKR WiFi1010 - WiFi
19+
* Arduino NANO 33 IoT - WiFi
20+
*/
21+
#include "WiFiSSLClient.h"
22+
class TLSClientOta : public WiFiBearSSLClient {
23+
#elif defined(BOARD_HAS_ECCX08)
24+
/*
25+
* Arduino MKR GSM 1400
26+
* Arduino MKR NB 1500
27+
* Arduino Portenta H7
28+
* Arduino Giga R1
29+
* OPTA
30+
*/
31+
#include <tls/BearSSLClient.h>
32+
class TLSClientOta : public BearSSLClient {
33+
#elif defined(ARDUINO_PORTENTA_C33)
34+
/*
35+
* Arduino Portenta C33
36+
*/
37+
#include <SSLClient.h>
38+
class TLSClientOta : public SSLClient {
39+
#elif defined(ARDUINO_NICLA_VISION)
40+
/*
41+
* Arduino Nicla Vision
42+
*/
43+
#include <WiFiSSLSE050Client.h>
44+
class TLSClientOta : public WiFiSSLSE050Client {
45+
#elif defined(ARDUINO_EDGE_CONTROL)
46+
/*
47+
* Arduino Edge Control
48+
*/
49+
#include <GSMSSLClient.h>
50+
class TLSClientOta : public GSMSSLClient {
51+
#elif defined(ARDUINO_UNOR4_WIFI)
52+
/*
53+
* Arduino UNO R4 WiFi
54+
*/
55+
#include <WiFiSSLClient.h>
56+
class TLSClientOta : public WiFiSSLClient {
57+
#elif defined(BOARD_ESP)
58+
/*
59+
* ESP32*
60+
* ESP82*
61+
*/
62+
#include <WiFiClientSecure.h>
63+
class TLSClientOta : public WiFiClientSecure {
64+
#endif
65+
66+
public:
67+
void begin(ConnectionHandler & connection);
68+
69+
private:
70+
inline Client* getNewClient(NetworkAdapter net) {
71+
switch(net) {
72+
#ifdef BOARD_HAS_WIFI
73+
case NetworkAdapter::WIFI:
74+
return new WiFiClient();
75+
#endif // BOARD_HAS_WIFI
76+
#ifdef BOARD_HAS_ETHERNET
77+
case NetworkAdapter::ETHERNET:
78+
return new EthernetClient();
79+
#endif // BOARD_HAS_ETHERNET
80+
#ifdef BOARD_HAS_NB
81+
case NetworkAdapter::NB:
82+
return new NBClient();
83+
#endif // BOARD_HAS_NB
84+
#ifdef BOARD_HAS_GSM
85+
case NetworkAdapter::GSM:
86+
return new GSMClient();
87+
#endif // BOARD_HAS_GSM
88+
#ifdef BOARD_HAS_CATM1_NBIOT
89+
case NetworkAdapter::CATM1:
90+
return new GSMClient();
91+
#endif // BOARD_HAS_CATM1_NBIOT
92+
default:
93+
return nullptr;
94+
}
95+
}
96+
};

0 commit comments

Comments
 (0)