Skip to content

Commit ad32b1d

Browse files
committed
Adding ArduinoIoTCloud trust anchor to be injected into ArduinoBearSSL upon construction
1 parent 96d1cb7 commit ad32b1d

File tree

2 files changed

+74
-10
lines changed

2 files changed

+74
-10
lines changed

src/ArduinoIoTCloud.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,13 @@
1515
a commercial license, send an email to [email protected].
1616
*/
1717

18-
<<<<<<< HEAD
1918
#include <ArduinoIoTCloud.h>
2019

2120
#ifdef BOARD_HAS_ECCX08
2221
#include "utility/ECCX08Cert.h"
22+
#include "utility/BearSSLTrustAnchor.h"
2323
#include <ArduinoECCX08.h>
2424
#endif
25-
=======
26-
#include <ArduinoECCX08.h>
27-
#include "utility/ECCX08Cert.h"
28-
#include "CloudSerial.h"
29-
#include "ArduinoIoTCloud.h"
30-
#include <Arduino_DebugUtils.h>
31-
>>>>>>> Remove connection handling and debug messages because those tasks are now handled by 'Arduino_ConnectionHandler' and 'Arduino_DebugUtils'
3225

3326
#ifdef ARDUINO_ARCH_SAMD
3427
#include <RTCZero.h>
@@ -152,9 +145,9 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
152145

153146
#ifdef BOARD_HAS_ECCX08
154147
if (_connection != NULL) {
155-
_sslClient = new BearSSLClient(_connection->getClient());
148+
_sslClient = new BearSSLClient(_connection->getClient(), ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM);
156149
} else {
157-
_sslClient = new BearSSLClient(*_net);
150+
_sslClient = new BearSSLClient(*_net, ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM);
158151
}
159152
_sslClient->setEccSlot(keySlot, ECCX08Cert.bytes(), ECCX08Cert.length());
160153
#elif defined(BOARD_ESP)

src/utility/BearSSLTrustAnchor.h

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
This file is part of ArduinoIoTBearSSL.
3+
4+
Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of ArduinoIoTBearSSL.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to modify or
13+
otherwise use the software for commercial activities involving the Arduino
14+
software without disclosing the source code of your own applications. To purchase
15+
a commercial license, send an email to [email protected].
16+
17+
*/
18+
19+
#ifndef _BEAR_SSL_TRUST_ANCHOR_H_
20+
#define _BEAR_SSL_TRUST_ANCHOR_H_
21+
22+
#include <ArduinoIoTCloud_Defines.h>
23+
24+
#ifdef BOARD_HAS_ECCX08
25+
26+
#include "bearssl/bearssl_ssl.h"
27+
28+
// The following was created by running the BearSSL "brssl" tool in the
29+
// extras/TrustAnchors directory:
30+
//
31+
// brssl ta *.cer
32+
33+
static const unsigned char TA0_DN[] = {
34+
0x30, 0x45, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
35+
0x02, 0x55, 0x53, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x0A,
36+
0x13, 0x0E, 0x41, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F, 0x20, 0x4C, 0x4C,
37+
0x43, 0x20, 0x55, 0x53, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
38+
0x0B, 0x13, 0x02, 0x49, 0x54, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55,
39+
0x04, 0x03, 0x13, 0x07, 0x41, 0x72, 0x64, 0x75, 0x69, 0x6E, 0x6F
40+
};
41+
42+
static const unsigned char TA0_EC_Q[] = {
43+
0x04, 0x6D, 0x77, 0x6C, 0x5A, 0xCF, 0x61, 0x1C, 0x7D, 0x44, 0x98, 0x51,
44+
0xF2, 0x5E, 0xE1, 0x02, 0x40, 0x77, 0xB7, 0x9C, 0xBD, 0x49, 0xA2, 0xA3,
45+
0x8C, 0x4E, 0xAB, 0x5E, 0x98, 0xAC, 0x82, 0xFC, 0x69, 0x5B, 0x44, 0x22,
46+
0x77, 0xB4, 0x4D, 0x2E, 0x8E, 0xDF, 0x2A, 0x71, 0xC1, 0x39, 0x6C, 0xD6,
47+
0x39, 0x14, 0xBD, 0xD9, 0x6B, 0x18, 0x4B, 0x4B, 0xEC, 0xB3, 0xD5, 0xEE,
48+
0x42, 0x89, 0x89, 0x55, 0x22
49+
};
50+
51+
static const br_x509_trust_anchor ArduinoIoTCloudTrustAnchor[1] = {
52+
{
53+
{ (unsigned char *)TA0_DN, sizeof TA0_DN },
54+
BR_X509_TA_CA,
55+
{
56+
BR_KEYTYPE_EC,
57+
{
58+
.ec = {
59+
BR_EC_secp256r1,
60+
(unsigned char *)TA0_EC_Q, sizeof TA0_EC_Q,
61+
}
62+
}
63+
}
64+
}
65+
};
66+
67+
#define ArduinoIoTCloudTrustAnchor_NUM (1)
68+
69+
#endif /* BOARD_HAS_ECCX08 */
70+
71+
#endif /* _BEAR_SSL_TRUST_ANCHOR_H_ */

0 commit comments

Comments
 (0)