Skip to content

Offload SSL on NINA based boards #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
#define OTA_ENABLED (0)
#endif

#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
#define BOARD_HAS_NINA (1)
#else
#define BOARD_HAS_NINA (0)
#endif

#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || \
defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_PORTENTA_H7_M7) || \
Expand Down
12 changes: 8 additions & 4 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
, _mqtt_data_buf{0}
, _mqtt_data_len{0}
, _mqtt_data_request_retransmit{false}
#ifdef BOARD_HAS_ECCX08
#if BOARD_HAS_NINA
/* Do nothing here because we are using onboard onboard SSL on NINA. */
#elif defined(BOARD_HAS_ECCX08)
, _sslClient(nullptr, ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM, getTime)
#endif
#ifdef BOARD_ESP
Expand Down Expand Up @@ -112,15 +114,17 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
_ota_img_sha256 = FlashSHA256::calc(0x2000, 0x40000 - 0x2000);
#endif /* OTA_ENABLED */

#ifdef BOARD_HAS_ECCX08
#if BOARD_HAS_NINA
/* Do nothing here because we are using onboard SSL on NINA. */
#elif defined(BOARD_HAS_ECCX08)
if (!ECCX08.begin()) { DBG_ERROR(F("Cryptography processor failure. Make sure you have a compatible board.")); return 0; }
if (!CryptoUtil::readDeviceId(ECCX08, getDeviceId(), ECCX08Slot::DeviceId)) { DBG_ERROR(F("Cryptography processor read failure.")); return 0; }
if (!CryptoUtil::reconstructCertificate(_eccx08_cert, getDeviceId(), ECCX08Slot::Key, ECCX08Slot::CompressedCertificate, ECCX08Slot::SerialNumberAndAuthorityKeyIdentifier)) { DBG_ERROR(F("Cryptography certificate reconstruction failure.")); return 0; }
_sslClient.setClient(_connection->getClient());
_sslClient.setEccSlot(static_cast<int>(ECCX08Slot::Key), _eccx08_cert.bytes(), _eccx08_cert.length());
#elif defined(BOARD_ESP)
#elif defined(BOARD_ESP)
_sslClient.setInsecure();
#endif
#endif

_mqttClient.setClient(_sslClient);
#ifdef BOARD_ESP
Expand Down
8 changes: 5 additions & 3 deletions src/ArduinoIoTCloudTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
int _mqtt_data_len;
bool _mqtt_data_request_retransmit;

#ifdef BOARD_HAS_ECCX08
#if BOARD_HAS_NINA
WiFiSSLClient _sslClient;
#elif defined(BOARD_HAS_ECCX08)
ECCX08CertClass _eccx08_cert;
BearSSLClient _sslClient;
#elif defined(BOARD_ESP)
#elif defined(BOARD_ESP)
WiFiClientSecure _sslClient;
String _password;
#endif
#endif

MqttClient _mqttClient;

Expand Down