|
20 | 20 | #include <ArduinoIoTCloudTCP.h>
|
21 | 21 | #include "utility/time/TimeService.h"
|
22 | 22 | #ifdef BOARD_HAS_ECCX08
|
23 |
| - #include "utility/crypto/ECCX08Cert.h" |
24 |
| - #include "utility/crypto/BearSSLTrustAnchor.h" |
25 | 23 | #include <ArduinoECCX08.h>
|
| 24 | + #include "utility/crypto/BearSSLTrustAnchor.h" |
26 | 25 | #include "utility/crypto/CryptoUtil.h"
|
27 | 26 | #endif
|
28 | 27 |
|
29 | 28 | TimeService time_service;
|
30 | 29 |
|
31 |
| -#ifdef BOARD_HAS_ECCX08 |
32 |
| - const static int keySlot = 0; |
33 |
| - const static int compressedCertSlot = 10; |
34 |
| - const static int serialNumberAndAuthorityKeyIdentifierSlot = 11; |
35 |
| -#endif |
36 |
| - |
37 | 30 | const static int CONNECT_SUCCESS = 1;
|
38 | 31 | const static int CONNECT_FAILURE = 0;
|
39 | 32 | const static int CONNECT_FAILURE_SUBSCRIBE = -1;
|
@@ -86,28 +79,14 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) {
|
86 | 79 | _device_id = CryptoUtil::readDeviceId(ECCX08, ECCX08Slot::DeviceId);
|
87 | 80 | if(_device_id.length() == 0) { Debug.print(DBG_ERROR, "Cryptography processor read failure."); return 0; }
|
88 | 81 |
|
89 |
| - if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) { |
90 |
| - Debug.print(DBG_ERROR, "Cryptography certificate reconstruction failure."); |
91 |
| - return 0; |
92 |
| - } |
93 |
| - |
94 |
| - ECCX08Cert.setSubjectCommonName(_device_id); |
95 |
| - ECCX08Cert.setIssuerCountryName("US"); |
96 |
| - ECCX08Cert.setIssuerOrganizationName("Arduino LLC US"); |
97 |
| - ECCX08Cert.setIssuerOrganizationalUnitName("IT"); |
98 |
| - ECCX08Cert.setIssuerCommonName("Arduino"); |
99 |
| - |
100 |
| - if (!ECCX08Cert.endReconstruction()) { |
101 |
| - Debug.print(DBG_ERROR, "Cryptography certificate reconstruction failure."); |
102 |
| - return 0; |
103 |
| - } |
| 82 | + if (!CryptoUtil::reconstructCertificate(ECCX08Cert, _device_id, ECCX08Slot::Key, ECCX08Slot::CompressedCertificate, ECCX08Slot::SerialNumberAndAuthorityKeyIdentifier)) { Debug.print(DBG_ERROR, "Cryptography certificate reconstruction failure."); return 0; } |
104 | 83 |
|
105 | 84 | ArduinoBearSSL.onGetTime(getTime);
|
106 | 85 | #endif /* BOARD_HAS_ECCX08 */
|
107 | 86 |
|
108 | 87 | #ifdef BOARD_HAS_ECCX08
|
109 | 88 | _sslClient = new BearSSLClient(_connection->getClient(), ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM);
|
110 |
| - _sslClient->setEccSlot(keySlot, ECCX08Cert.bytes(), ECCX08Cert.length()); |
| 89 | + _sslClient->setEccSlot(static_cast<int>(ECCX08Slot::Key), ECCX08Cert.bytes(), ECCX08Cert.length()); |
111 | 90 | #elif defined(BOARD_ESP)
|
112 | 91 | _sslClient = new WiFiClientSecure();
|
113 | 92 | _sslClient->setInsecure();
|
|
0 commit comments