Skip to content

Commit aff9ebd

Browse files
committed
Offload SSL Client w/ crypto on Nina modules
Temporarily remove OTA support since it depends on bearssl's SHA256 APIs
1 parent 12f5d2c commit aff9ebd

7 files changed

+34
-9
lines changed

src/AIoTC_Config.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,20 @@
7272
#define OTA_ENABLED (0)
7373
#endif
7474

75-
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || \
76-
defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
75+
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKR1000) || \
7776
defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_PORTENTA_H7_M7) || \
7877
defined(ARDUINO_PORTENTA_H7_M4)
7978
#define BOARD_HAS_ECCX08
8079
#define HAS_TCP
8180
#endif
8281

82+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
83+
#define BOARD_HAS_OFFLOADED_ECCX08
84+
#define HAS_TCP
85+
#undef OTA_ENABLED
86+
#define OTA_ENABLED (0)
87+
#endif
88+
8389
#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
8490
#define HAS_LORA
8591
#endif

src/ArduinoIoTCloudTCP.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include "tls/utility/CryptoUtil.h"
2929
#endif
3030

31+
#ifdef BOARD_HAS_OFFLOADED_ECCX08
32+
#include <ArduinoECCX08.h>
33+
#include "tls/utility/CryptoUtil.h"
34+
#endif
35+
3136
#include "utility/ota/OTA.h"
3237
#include "utility/ota/FlashSHA256.h"
3338

@@ -112,6 +117,12 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
112117
_ota_img_sha256 = FlashSHA256::calc(0x2000, 0x40000 - 0x2000);
113118
#endif /* OTA_ENABLED */
114119

120+
#ifdef BOARD_HAS_OFFLOADED_ECCX08
121+
if (!ECCX08.begin()) { DBG_ERROR(F("Cryptography processor failure. Make sure you have a compatible board.")); return 0; }
122+
if (!CryptoUtil::readDeviceId(ECCX08, getDeviceId(), ECCX08Slot::DeviceId)) { DBG_ERROR(F("Cryptography processor read failure.")); return 0; }
123+
ECCX08.end();
124+
#endif
125+
115126
#ifdef BOARD_HAS_ECCX08
116127
if (!ECCX08.begin()) { DBG_ERROR(F("Cryptography processor failure. Make sure you have a compatible board.")); return 0; }
117128
if (!CryptoUtil::readDeviceId(ECCX08, getDeviceId(), ECCX08Slot::DeviceId)) { DBG_ERROR(F("Cryptography processor read failure.")); return 0; }
@@ -144,7 +155,7 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
144155
addPropertyReal(_ota_req, "OTA_REQ", Permission::ReadWrite).onSync(DEVICE_WINS);
145156
#endif /* OTA_ENABLED */
146157

147-
#if OTA_STORAGE_SNU
158+
#if OTA_STORAGE_SNU && OTA_ENABLED
148159
String const nina_fw_version = WiFi.firmwareVersion();
149160
if (nina_fw_version < "1.4.1") {
150161
_ota_cap = false;

src/ArduinoIoTCloudTCP.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
#include <WiFiClientSecure.h>
3434
#endif
3535

36+
#ifdef BOARD_HAS_OFFLOADED_ECCX08
37+
#include "tls/utility/ECCX08Cert.h"
38+
#include <WiFiSSLClient.h>
39+
#endif
40+
3641
#include <ArduinoMqttClient.h>
3742

3843
/******************************************************************************
@@ -60,7 +65,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
6065
virtual int connected () override;
6166
virtual void printDebugInfo() override;
6267

63-
#ifdef BOARD_HAS_ECCX08
68+
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08)
6469
int begin(ConnectionHandler & connection, String brokerAddress = DEFAULT_BROKER_ADDRESS_SECURE_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_SECURE_AUTH);
6570
#else
6671
int begin(ConnectionHandler & connection, String brokerAddress = DEFAULT_BROKER_ADDRESS_USER_PASS_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_USER_PASS_AUTH);
@@ -98,9 +103,12 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
98103
int _mqtt_data_len;
99104
bool _mqtt_data_request_retransmit;
100105

101-
#ifdef BOARD_HAS_ECCX08
106+
#if defined(BOARD_HAS_ECCX08)
102107
ECCX08CertClass _eccx08_cert;
103108
BearSSLClient _sslClient;
109+
#elif defined(BOARD_HAS_OFFLOADED_ECCX08)
110+
ECCX08CertClass _eccx08_cert;
111+
WiFiBearSSLClient _sslClient;
104112
#elif defined(BOARD_ESP)
105113
WiFiClientSecure _sslClient;
106114
String _password;

src/tls/utility/CryptoUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "CryptoUtil.h"
2323

24-
#ifdef BOARD_HAS_ECCX08
24+
#if defined(BOARD_HAS_ECCX08) || defined (BOARD_HAS_OFFLOADED_ECCX08)
2525

2626
/******************************************************************************
2727
* PUBLIC MEMBER FUNCTIONS

src/tls/utility/CryptoUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include <AIoTC_Config.h>
2626

27-
#ifdef BOARD_HAS_ECCX08
27+
#if defined(BOARD_HAS_ECCX08) || defined (BOARD_HAS_OFFLOADED_ECCX08)
2828

2929
#include <Arduino.h>
3030
#include <ArduinoECCX08.h>

src/tls/utility/ECCX08Cert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <AIoTC_Config.h>
2323

24-
#ifdef BOARD_HAS_ECCX08
24+
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08)
2525

2626
#include "../../tls/bearssl/bearssl_hash.h"
2727
#include <ArduinoECCX08.h>

src/tls/utility/ECCX08Cert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include <AIoTC_Config.h>
2626

27-
#ifdef BOARD_HAS_ECCX08
27+
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08)
2828

2929
#include <Arduino.h>
3030

0 commit comments

Comments
 (0)