Skip to content

Commit c261949

Browse files
committed
Add TLSClientMqtt
1 parent e9e4b3e commit c261949

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

src/tls/utility/TLSClientMqtt.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

src/tls/utility/TLSClientMqtt.h

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 TLSClientMqtt : 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 TLSClientMqtt : public BearSSLClient {
33+
#elif defined(ARDUINO_PORTENTA_C33)
34+
/*
35+
* Arduino Portenta C33
36+
*/
37+
#include <SSLClient.h>
38+
class TLSClientMqtt : public SSLClient {
39+
#elif defined(ARDUINO_NICLA_VISION)
40+
/*
41+
* Arduino Nicla Vision
42+
*/
43+
#include <WiFiSSLSE050Client.h>
44+
class TLSClientMqtt : public WiFiSSLSE050Client {
45+
#elif defined(ARDUINO_EDGE_CONTROL)
46+
/*
47+
* Arduino Edge Control
48+
*/
49+
#include <GSMSSLClient.h>
50+
class TLSClientMqtt : public GSMSSLClient {
51+
#elif defined(ARDUINO_UNOR4_WIFI)
52+
/*
53+
* Arduino UNO R4 WiFi
54+
*/
55+
#include <WiFiSSLClient.h>
56+
class TLSClientMqtt : public WiFiSSLClient {
57+
#elif defined(BOARD_ESP)
58+
/*
59+
* ESP32*
60+
* ESP82*
61+
*/
62+
#include <WiFiClientSecure.h>
63+
class TLSClientMqtt : public WiFiClientSecure {
64+
#endif
65+
66+
public:
67+
void begin(ConnectionHandler & connection);
68+
69+
};

0 commit comments

Comments
 (0)