Skip to content

Commit b4db6bd

Browse files
committed
Switch to Arduino_SecureElement library
1 parent 60528b9 commit b4db6bd

File tree

9 files changed

+86
-1588
lines changed

9 files changed

+86
-1588
lines changed

examples/utility/Provisioning/ECCX08TLSConfig.h

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/AIoTC_Config.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,16 @@
151151
#define BOARD_STM32H7
152152
#endif
153153

154-
#if defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_EDGE_CONTROL)
154+
#if defined(ARDUINO_EDGE_CONTROL)
155155
#define BOARD_HAS_SECRET_KEY
156156
#define HAS_TCP
157157
#endif
158158

159+
#if defined(ARDUINO_UNOR4_WIFI)
160+
#define BOARD_HAS_SOFTSE
161+
#define HAS_TCP
162+
#endif
163+
159164
/******************************************************************************
160165
* CONSTANTS
161166
******************************************************************************/

src/ArduinoIoTCloudTCP.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,16 @@
2424
#ifdef HAS_TCP
2525
#include <ArduinoIoTCloudTCP.h>
2626

27+
#ifdef BOARD_HAS_SECRET_KEY
28+
#include "tls/AIoTCUPCert.h"
29+
#endif
30+
2731
#ifdef BOARD_HAS_ECCX08
2832
#include "tls/BearSSLTrustAnchors.h"
29-
#include "tls/utility/CryptoUtil.h"
3033
#endif
3134

32-
#ifdef BOARD_HAS_SE050
35+
#if defined(BOARD_HAS_SE050) || defined(BOARD_HAS_SOFTSE)
3336
#include "tls/AIoTCSSCert.h"
34-
#include "tls/utility/CryptoUtil.h"
35-
#endif
36-
37-
#ifdef BOARD_HAS_OFFLOADED_ECCX08
38-
#include <ArduinoECCX08.h>
39-
#include "tls/utility/CryptoUtil.h"
40-
#endif
41-
42-
#ifdef BOARD_HAS_SECRET_KEY
43-
#include "tls/AIoTCUPCert.h"
4437
#endif
4538

4639
#if OTA_ENABLED
@@ -90,9 +83,9 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
9083
#ifdef BOARD_HAS_ECCX08
9184
, _sslClient(nullptr, ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM, getTime)
9285
#endif
93-
#ifdef BOARD_HAS_SECRET_KEY
86+
#ifdef BOARD_HAS_SECRET_KEY
9487
, _password("")
95-
#endif
88+
#endif
9689
, _mqttClient{nullptr}
9790
, _deviceTopicOut("")
9891
, _deviceTopicIn("")
@@ -137,43 +130,50 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
137130
DEBUG_VERBOSE("SHA256: HASH(%d) = %s", strlen(_ota_img_sha256.c_str()), _ota_img_sha256.c_str());
138131
#endif /* OTA_ENABLED */
139132

140-
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08) || defined(BOARD_HAS_SE050)
133+
#if !defined(BOARD_HAS_SECRET_KEY)
141134
if (!_crypto.begin())
142135
{
143136
DEBUG_ERROR("_crypto.begin() failed.");
144137
return 0;
145138
}
146-
if (!_crypto.readDeviceId(getDeviceId(), CryptoSlot::DeviceId))
139+
if (!SElementArduinoCloudDeviceId::read(_crypto, getDeviceId(), SElementArduinoCloudSlot::DeviceId))
147140
{
148141
DEBUG_ERROR("_crypto.readDeviceId(...) failed.");
149142
return 0;
150143
}
151144
#endif
152145

153-
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_SE050)
154-
if (!_crypto.readCert(_cert, CryptoSlot::CompressedCertificate))
146+
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_SE050) || defined(BOARD_HAS_SOFTSE)
147+
if (!SElementArduinoCloudCertificate::read(_crypto, _cert, SElementArduinoCloudSlot::CompressedCertificate))
155148
{
156149
DEBUG_ERROR("Cryptography certificate reconstruction failure.");
157150
return 0;
158151
}
159-
_sslClient.setEccSlot(static_cast<int>(CryptoSlot::Key), _cert.bytes(), _cert.length());
152+
_sslClient.setEccSlot(static_cast<int>(SElementArduinoCloudSlot::Key), _cert.bytes(), _cert.length());
160153
#endif
161154

162-
#if defined(BOARD_HAS_ECCX08)
155+
156+
#if defined(BOARD_HAS_SECRET_KEY)
157+
#if defined(ARDUINO_EDGE_CONTROL)
158+
_sslClient.appendCustomCACert(AIoTUPCert);
159+
#elif defined(ARDUINO_ARCH_ESP32)
160+
_sslClient.setCACertBundle(x509_crt_bundle);
161+
#else
162+
_sslClient.setInsecure();
163+
#endif
164+
#else
165+
#if defined(BOARD_HAS_ECCX08)
163166
_sslClient.setClient(_connection->getClient());
164-
#elif defined(ARDUINO_PORTENTA_C33)
167+
#elif defined(BOARD_HAS_SE050)
168+
#if defined(ARDUINO_PORTENTA_C33)
165169
_sslClient.setClient(_connection->getClient());
166170
_sslClient.setCACert(AIoTSSCert);
167-
#elif defined(BOARD_HAS_SE050)
171+
#else
168172
_sslClient.appendCustomCACert(AIoTSSCert);
169-
#elif defined(BOARD_ESP)
170-
#if defined(ARDUINO_ARCH_ESP8266)
171-
_sslClient.setInsecure();
172-
#else
173-
_sslClient.setCACertBundle(x509_crt_bundle);
173+
#endif
174+
#elif defined(BOARD_HAS_SOFTSE)
175+
_sslClient.setCACert(AIoTSSCert, strlen(AIoTSSCert));
174176
#endif
175-
#elif defined(ARDUINO_EDGE_CONTROL)
176-
_sslClient.appendCustomCACert(AIoTUPCert);
177177
#endif
178178

179179
_mqttClient.setClient(_sslClient);

src/ArduinoIoTCloudTCP.h

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,37 @@
2323
******************************************************************************/
2424

2525
#include <AIoTC_Config.h>
26-
2726
#include <ArduinoIoTCloud.h>
27+
#include <ArduinoMqttClient.h>
2828

29-
#ifdef BOARD_HAS_ECCX08
30-
#include "tls/BearSSLClient.h"
31-
#include "tls/utility/CryptoUtil.h"
32-
#elif defined(BOARD_ESP)
33-
#include <WiFiClientSecure.h>
34-
#elif defined(ARDUINO_UNOR4_WIFI)
35-
#include <WiFiSSLClient.h>
36-
#elif defined(ARDUINO_PORTENTA_C33)
37-
#include "tls/utility/CryptoUtil.h"
38-
#include <SSLClient.h>
39-
#elif defined(BOARD_HAS_SE050)
40-
#include "tls/utility/CryptoUtil.h"
41-
#include <WiFiSSLSE050Client.h>
42-
#endif
43-
44-
#ifdef BOARD_HAS_OFFLOADED_ECCX08
45-
#include "tls/utility/CryptoUtil.h"
46-
#include <WiFiSSLClient.h>
29+
#if defined(BOARD_HAS_SECRET_KEY)
30+
#if defined(BOARD_ESP)
31+
#include <WiFiClientSecure.h>
32+
#elif defined(ARDUINO_EDGE_CONTROL)
33+
#include <GSMSSLClient.h>
34+
#endif
35+
#else
36+
#include <Arduino_SecureElement.h>
37+
#include <utility/SElementArduinoCloudDeviceId.h>
38+
#if defined(BOARD_HAS_OFFLOADED_ECCX08)
39+
#else
40+
#include <utility/SElementArduinoCloudCertificate.h>
41+
#ifdef BOARD_HAS_ECCX08
42+
#include "tls/BearSSLClient.h"
43+
#elif defined(BOARD_HAS_OFFLOADED_ECCX08)
44+
#include <WiFiSSLClient.h>
45+
#elif defined(BOARD_HAS_SE050)
46+
#if defined(ARDUINO_PORTENTA_C33)
47+
#include <SSLClient.h>
48+
#else
49+
#include <WiFiSSLSE050Client.h>
50+
#endif
51+
#elif defined(BOARD_HAS_SOFTSE)
52+
#include <WiFiSSLClient.h>
53+
#endif
54+
#endif
4755
#endif
4856

49-
#include <ArduinoMqttClient.h>
50-
5157
/******************************************************************************
5258
CONSTANTS
5359
******************************************************************************/
@@ -79,7 +85,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
7985
virtual int connected () override;
8086
virtual void printDebugInfo() override;
8187

82-
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08) || defined(BOARD_HAS_SE050)
88+
#if !defined(BOARD_HAS_SECRET_KEY)
8389
int begin(ConnectionHandler & connection, bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS_SECURE_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_SECURE_AUTH);
8490
#else
8591
int begin(ConnectionHandler & connection, bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS_USER_PASS_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_USER_PASS_AUTH);
@@ -140,33 +146,32 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
140146
int _mqtt_data_len;
141147
bool _mqtt_data_request_retransmit;
142148

143-
#if defined(BOARD_HAS_ECCX08)
144-
ArduinoIoTCloudCertClass _cert;
145-
BearSSLClient _sslClient;
146-
CryptoUtil _crypto;
147-
#elif defined(BOARD_HAS_OFFLOADED_ECCX08)
148-
ArduinoIoTCloudCertClass _cert;
149-
WiFiBearSSLClient _sslClient;
150-
CryptoUtil _crypto;
151-
#elif defined(BOARD_ESP)
149+
#if defined(BOARD_HAS_SECRET_KEY)
150+
String _password;
151+
#if defined(BOARD_ESP)
152152
WiFiClientSecure _sslClient;
153-
#elif defined(ARDUINO_UNOR4_WIFI)
154-
WiFiSSLClient _sslClient;
155-
#elif defined(ARDUINO_EDGE_CONTROL)
153+
#elif defined(ARDUINO_EDGE_CONTROL)
156154
GSMSSLClient _sslClient;
157-
#elif defined(ARDUINO_PORTENTA_C33)
158-
ArduinoIoTCloudCertClass _cert;
159-
SSLClient _sslClient;
160-
CryptoUtil _crypto;
155+
#endif
156+
#else
157+
SecureElement _crypto;
158+
#if defined(BOARD_HAS_OFFLOADED_ECCX08)
159+
WiFiBearSSLClient _sslClient;
160+
#else
161+
ECP256Certificate _cert;
162+
#if defined(BOARD_HAS_ECCX08)
163+
BearSSLClient _sslClient;
161164
#elif defined(BOARD_HAS_SE050)
162-
ArduinoIoTCloudCertClass _cert;
165+
#if defined(ARDUINO_PORTENTA_C33)
166+
SSLClient _sslClient;
167+
#else
163168
WiFiSSLSE050Client _sslClient;
164-
CryptoUtil _crypto;
165-
#endif
166-
167-
#if defined (BOARD_HAS_SECRET_KEY)
168-
String _password;
169+
#endif
170+
#elif defined(BOARD_HAS_SOFTSE)
171+
WiFiSSLClient _sslClient;
169172
#endif
173+
#endif
174+
#endif
170175

171176
MqttClient _mqttClient;
172177

src/tls/AIoTCSSCert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
******************************************************************************/
2525

2626
#include <AIoTC_Config.h>
27-
#ifdef BOARD_HAS_SE050
27+
#if defined(BOARD_HAS_SE050) || defined(BOARD_HAS_SOFTSE)
2828

2929
/******************************************************************************
3030
* CONSTANTS
@@ -43,6 +43,6 @@ static const char AIoTSSCert[] =
4343
"AiEA6tnZ2lrNElKXCajtZg/hjWRE/+giFzBP8riar8qOz2w=\n"
4444
"-----END CERTIFICATE-----\n";
4545

46-
#endif /* #ifdef BOARD_HAS_SE050 */
46+
#endif /* #if defined(BOARD_HAS_SE050) || defined(BOARD_HAS_SOFTSE) */
4747

4848
#endif /* _AIOTC_SS_CERT_H_ */

0 commit comments

Comments
 (0)