Skip to content

Commit 564cb06

Browse files
pennamandreagilardoni
authored andcommitted
Add TLSClientOta
1 parent c5a795d commit 564cb06

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

src/tls/utility/TLSClientOta.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
39+
#elif defined(BOARD_HAS_ECCX08)
40+
setClient(*getNewClient(connection.getInterface()));
41+
setProfile(aiotc_client_profile_init);
42+
setTrustAnchors(ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM);
43+
onGetTime(getTime);
44+
#elif defined(ARDUINO_PORTENTA_C33)
45+
setClient(*getNewClient(connection.getInterface()));
46+
setCACert(AIoTSSCert);
47+
#elif defined(ARDUINO_NICLA_VISION)
48+
appendCustomCACert(AIoTSSCert);
49+
#elif defined(ARDUINO_EDGE_CONTROL)
50+
appendCustomCACert(AIoTUPCert);
51+
#elif defined(ARDUINO_UNOR4_WIFI)
52+
53+
#elif defined(ARDUINO_ARCH_ESP32)
54+
setCACertBundle(x509_crt_bundle);
55+
#elif defined(ARDUINO_ARCH_ESP8266)
56+
setInsecure();
57+
#endif
58+
}
59+
60+
#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)