Skip to content

Commit 6c8c91b

Browse files
committed
MCU8MASS-1777 Use TNG to extract certificates, include functionality in ECC608 to extract certificates and update cryptoauthlib
1 parent 3d5ffb7 commit 6c8c91b

File tree

86 files changed

+4376
-1622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4376
-1622
lines changed

examples/extract_certificates/extract_certificates.ino

Lines changed: 100 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#include <Arduino.h>
2-
#include <atca_helpers.h>
3-
#include <atcacert/atcacert_client.h>
4-
#include <cryptoauthlib.h>
2+
3+
#include <ecc608.h>
54
#include <log.h>
65

7-
#include "cert_def_1_signer.h"
8-
#include "cert_def_3_device.h"
6+
static void printCertificate(const uint8_t* certificate, const size_t size) {
7+
8+
size_t buffer_size = ECC608.calculateBase64EncodedCertificateSize(size);
9+
10+
char buffer[buffer_size];
911

10-
void printCertificate(uint8_t* certificate, uint16_t size) {
11-
char buffer[1024];
12-
size_t buffer_size = sizeof(buffer);
13-
ATCA_STATUS result =
14-
atcab_base64encode(certificate, size, buffer, &buffer_size);
12+
ATCA_STATUS status =
13+
ECC608.base64EncodeCertificate(certificate, size, buffer, &buffer_size);
1514

16-
if (result != ATCA_SUCCESS) {
17-
Log.errorf("Failed to encode into base64: %x\r\n", result);
15+
if (status != ATCA_SUCCESS) {
16+
Log.errorf("Failed to encode into base64: %x\r\n", status);
1817
return;
1918
}
2019

21-
buffer[buffer_size] = 0;
2220
Log.rawf(
2321
"-----BEGIN CERTIFICATE-----\r\n%s\r\n-----END CERTIFICATE-----\r\n",
2422
buffer);
@@ -27,62 +25,113 @@ void printCertificate(uint8_t* certificate, uint16_t size) {
2725
void setup() {
2826
Log.begin(115200);
2927

30-
int status;
31-
32-
static ATCAIfaceCfg cfg_atecc608b_i2c = {ATCA_I2C_IFACE,
33-
ATECC608B,
34-
{
35-
0x58, // 7 bit address of ECC
36-
2, // Bus number
37-
100000 // Baud rate
38-
},
39-
1560,
40-
20,
41-
NULL};
42-
43-
if (ATCA_SUCCESS != (status = atcab_init(&cfg_atecc608b_i2c))) {
44-
Log.errorf("Failed to init: %d\r\n", status);
28+
ATCA_STATUS atca_status = ECC608.begin();
29+
30+
if (atca_status != ATCA_SUCCESS) {
31+
Log.errorf("Failed to initialize ECC608, status code: 0x%X\r\n",
32+
atca_status);
33+
}
34+
35+
// Extract the max size of the certificates first
36+
37+
size_t max_root_certificate_size = 0, max_signer_certificate_size = 0,
38+
max_device_certificate_size = 0;
39+
40+
int atca_cert_status = ATCACERT_E_SUCCESS;
41+
42+
if ((atca_cert_status = ECC608.getRootCertificateSize(
43+
&max_root_certificate_size)) != ATCACERT_E_SUCCESS) {
44+
45+
Log.errorf("Failed to get root certificate's max size, status code: "
46+
"0x%X\r\n",
47+
atca_cert_status);
4548
return;
46-
} else {
47-
Log.info("Initialized ECC\r\n");
4849
}
4950

50-
// Retrieve public root key
51-
uint8_t public_key[ATCA_PUB_KEY_SIZE];
52-
if (ATCA_SUCCESS != (status = atcab_get_pubkey(0, public_key))) {
53-
Log.errorf("Failed to get public key: %x\r\n", status);
51+
if ((atca_cert_status = ECC608.getSignerCertificateSize(
52+
&max_signer_certificate_size)) != ATCACERT_E_SUCCESS) {
53+
54+
Log.errorf("Failed to get signer certificate's max size, status code: "
55+
"0x%X\r\n",
56+
atca_cert_status);
5457
return;
5558
}
5659

60+
if ((atca_cert_status = ECC608.getDeviceCertificateSize(
61+
&max_device_certificate_size)) != ATCACERT_E_SUCCESS) {
62+
63+
Log.errorf("Failed to get device certificate's max size, status code: "
64+
"0x%X\r\n",
65+
atca_cert_status);
66+
return;
67+
}
68+
69+
// We reuse the buffer for the certificates, so have to find the max
70+
// size of them so we have enough space for the biggest certificate
71+
const size_t certificate_buffer_size = max(
72+
max(max_root_certificate_size, max_signer_certificate_size),
73+
max_device_certificate_size);
74+
75+
uint8_t certificate_buffer[certificate_buffer_size];
76+
77+
// --- Root certificate ---
78+
79+
size_t root_certificate_size = certificate_buffer_size;
80+
5781
Log.raw("\r\n\r\n");
5882

59-
// Retrive sign certificate
60-
uint8_t buffer[g_cert_def_1_signer.cert_template_size + 4];
61-
size_t size = sizeof(buffer);
83+
if ((atca_cert_status = ECC608.getRootCertificate(
84+
certificate_buffer,
85+
&root_certificate_size)) != ATCACERT_E_SUCCESS) {
6286

63-
if (ATCA_SUCCESS != (status = atcacert_read_cert(&g_cert_def_1_signer,
64-
public_key,
65-
buffer,
66-
&size))) {
67-
Log.errorf("Failed to read signing certificate: %d\r\n", status);
87+
Log.errorf("Failed to get root certificate, status code: "
88+
"0x%X\r\n",
89+
atca_cert_status);
6890
return;
6991
} else {
70-
Log.info("Printing signing certificate...\r\n");
71-
printCertificate(buffer, size);
92+
93+
Log.info("Printing root certificate...\r\n");
94+
printCertificate(certificate_buffer, root_certificate_size);
7295
}
7396

97+
// --- Signer certificate ---
98+
99+
size_t signer_certificate_size = max_signer_certificate_size;
100+
74101
Log.raw("\r\n\r\n");
75102

76-
// Retrive device certificate
77-
if (ATCA_SUCCESS != (status = atcacert_read_cert(&g_cert_def_3_device,
78-
public_key,
79-
buffer,
80-
&size))) {
81-
Log.errorf("Failed to read device certificate: %d\r\n", status);
103+
if ((atca_cert_status = ECC608.getSignerCertificate(
104+
certificate_buffer,
105+
&signer_certificate_size)) != ATCACERT_E_SUCCESS) {
106+
107+
Log.errorf("Failed to get signer certificate, status code: "
108+
"0x%X\r\n",
109+
atca_cert_status);
82110
return;
83111
} else {
112+
113+
Log.info("Printing signer certificate...\r\n");
114+
printCertificate(certificate_buffer, signer_certificate_size);
115+
}
116+
117+
// --- Device certificate ---
118+
119+
size_t device_certificate_size = max_device_certificate_size;
120+
121+
Log.raw("\r\n\r\n");
122+
123+
if ((atca_cert_status = ECC608.getDeviceCertificate(
124+
certificate_buffer,
125+
&device_certificate_size)) != ATCACERT_E_SUCCESS) {
126+
127+
Log.errorf("Failed to get device certificate, status code: "
128+
"0x%X\r\n",
129+
atca_cert_status);
130+
return;
131+
} else {
132+
84133
Log.info("Printing device certificate...\r\n");
85-
printCertificate(buffer, size);
134+
printCertificate(certificate_buffer, device_certificate_size);
86135
}
87136
}
88137

examples/mqtt_low_power/mqtt_low_power.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ bool initMQTTTopics() {
2222

2323
// Find the thing ID and set the publish and subscription topics
2424
uint8_t thingName[128];
25-
uint8_t thingNameLen = sizeof(thingName);
25+
size_t thingNameLen = sizeof(thingName);
2626

2727
// -- Get the thingname
28-
uint8_t err = ECC608.getThingName(thingName, &thingNameLen);
29-
if (err != ECC608.ERR_OK) {
28+
ATCA_STATUS status = ECC608.getThingName(thingName, &thingNameLen);
29+
if (status != ATCA_SUCCESS) {
3030
Log.error("Could not retrieve thingname from the ECC");
3131
return false;
3232
}

examples/mqtt_polling_aws/mqtt_polling_aws.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ bool initMQTTTopics() {
2727

2828
// Find the thing ID and set the publish and subscription topics
2929
uint8_t thingName[128];
30-
uint8_t thingNameLen = sizeof(thingName);
30+
size_t thingNameLen = sizeof(thingName);
3131

3232
// -- Get the thingname
33-
uint8_t err = ECC608.getThingName(thingName, &thingNameLen);
34-
if (err != ECC608.ERR_OK) {
33+
ATCA_STATUS status = ECC608.getThingName(thingName, &thingNameLen);
34+
if (status != ATCA_SUCCESS) {
3535
Log.error("Could not retrieve thingname from the ECC");
3636
return false;
3737
}

examples/mqtt_with_connection_loss_handling/mqtt_with_connection_loss_handling.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ bool initMQTTTopics() {
2929

3030
// Find the thing ID and set the publish and subscription topics
3131
uint8_t thingName[128];
32-
uint8_t thingNameLen = sizeof(thingName);
32+
size_t thingNameLen = sizeof(thingName);
3333

3434
// -- Get the thingname
35-
uint8_t err = ECC608.getThingName(thingName, &thingNameLen);
36-
if (err != ECC608.ERR_OK) {
35+
ATCA_STATUS status = ECC608.getThingName(thingName, &thingNameLen);
36+
if (status != ATCA_SUCCESS) {
3737
Log.error("Could not retrieve thingname from the ECC");
3838
return false;
3939
}

examples/provision/provision.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,9 @@ static ATCA_STATUS constructCSR(char* pem, size_t* pem_size) {
737737
// Retrieve the thing name from the ECC and use that as the common name
738738
// field
739739
uint8_t common_name[128];
740-
uint8_t common_name_length = sizeof(common_name);
740+
size_t common_name_length = sizeof(common_name);
741741

742-
if (ECC608.getThingName(common_name, &common_name_length) !=
743-
ECC608.ERR_OK) {
742+
if (ECC608.getThingName(common_name, &common_name_length) != ATCA_SUCCES) {
744743
const char* default_identifier = "AVR-IoT Cellular Mini";
745744
common_name_length = strlen(default_identifier);
746745
memcpy(common_name, default_identifier, common_name_length);

examples/sandbox/sandbox.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ void setup() {
308308

309309
// Find the thing ID and set the publish and subscription topics
310310
uint8_t thing_name[128];
311-
uint8_t thing_name_len = sizeof(thing_name);
311+
size_t thing_name_len = sizeof(thing_name);
312312

313-
uint8_t err = ECC608.getThingName(thing_name, &thing_name_len);
314-
if (err != ECC608.ERR_OK) {
313+
ATCA_STATUS status = ECC608.getThingName(thing_name, &thing_name_len);
314+
if (status != ATCA_SUCCESS) {
315315
Log.error("Could not retrieve thing name from the ECC");
316316
Log.error("Unable to initialize the MQTT topics. Stopping...");
317317
LedCtrl.on(Led::ERROR);

lib/cryptoauth/CMakeLists.txt

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

lib/cryptoauth/atca_config.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
/* Auto-generated config file atca_config.h */
21
#ifndef ATCA_CONFIG_H
32
#define ATCA_CONFIG_H
43

4+
#define __DELAY_BACKWARD_COMPATIBLE__
5+
6+
#include <util/delay.h>
7+
8+
#define atca_delay_ms _delay_ms
9+
#define atca_delay_us _delay_us
10+
511
/* Included HALS */
612
#define ATCA_HAL_I2C
713

8-
#define ATCA_ATECC608_SUPPORT
9-
1014
/* \brief How long to wait after an initial wake failure for the POST to
1115
* complete.
1216
* If Power-on self test (POST) is enabled, the self test will run on waking
@@ -20,21 +24,16 @@
2024

2125
/** Enable debug messages */
2226
// #define ATCA_PRINTF
23-
//
2427

2528
/******************** Platform Configuration Section ***********************/
2629

30+
#define ATCA_ATECC608_SUPPORT FEATURE_ENABLED
31+
#define ATCA_TFLEX_SUPPORT FEATURE_ENABLED
32+
2733
/** Define platform malloc/free */
2834
#define ATCA_PLATFORM_MALLOC malloc
2935
#define ATCA_PLATFORM_FREE free
3036

31-
#define __DELAY_BACKWARD_COMPATIBLE__
32-
33-
#include <util/delay.h>
34-
35-
#define atca_delay_ms _delay_ms
36-
#define atca_delay_us _delay_us
37-
3837
/* API Configuration Options */
3938
#define ATCAB_AES_EN FEATURE_DISABLED
4039
#define ATCAB_AES_GCM_EN FEATURE_DISABLED
@@ -55,6 +54,7 @@
5554
#define ATCAB_AES_CBC_ENCRYPT_EN FEATURE_DISABLED
5655
#define ATCAB_RANDOM_EN FEATURE_DISABLED
5756
#define ATCAB_READ_ENC_EN FEATURE_DISABLED
57+
#define ATCAB_WRITE_ENC_EN FEATURE_DISABLED
5858
#define ATCAB_SECUREBOOT_EN FEATURE_DISABLED
5959
#define ATCAB_SECUREBOOT_MAC_EN FEATURE_DISABLED
6060
#define ATCAB_SELFTEST_EN FEATURE_DISABLED
@@ -72,12 +72,18 @@
7272
#define TALIB_AES_EN FEATURE_DISABLED
7373
#define TALIB_SHA_HMAC_EN FEATURE_DISABLED
7474

75+
#define CALIB_SHA104_EN FEATURE_DISABLED
76+
#define CALIB_SHA105_EN FEATURE_DISABLED
77+
#define CALIB_SHA204_EN FEATURE_DISABLED
78+
#define CALIB_SHA206_EN FEATURE_DISABLED
7579
#define CALIB_ECC108_EN FEATURE_DISABLED
7680
#define CALIB_ECC204_EN FEATURE_DISABLED
7781
#define CALIB_ECC508_EN FEATURE_DISABLED
82+
#define CALIB_TA010_EN FEATURE_DISABLED
7883
#define CALIB_ECDH_ENC FEATURE_DISABLED
79-
#define CALIB_SHA204_EN FEATURE_DISABLED
80-
#define CALIB_SHA206_EN FEATURE_DISABLED
84+
85+
#define CALIB_WRITE_ENC_CA2_EN FEATURE_DISABLED
86+
#define CALIB_WRITE_ENC_ECC204_EN FEATURE_DISABLED
8187

8288
#define WPC_MSG_PR_EN FEATURE_DISABLED
8389

@@ -87,4 +93,4 @@
8793
#define ATCACERT_DATEFMT_ISO_EN FEATURE_DISABLED
8894
#define ATCACERT_DATEFMT_POSIX_EN FEATURE_DISABLED
8995

90-
#endif // ATCA_CONFIG_H
96+
#endif // ATCA_CONFIG_H

0 commit comments

Comments
 (0)