11/* *
2- * @brief This provisioning is for HTTPS as well as MQTT with TLS (with or
3- * without the ECC). In order to start the provisioning, just upload this sketch
2+ * @brief This provisioning is for HTTPS as well as MQTT with TLS (with or
3+ * without the ECC). In order to start the provisioning, just upload this sketch
44 * to the board.
55 */
66
3838#define AT_HTTPS_SECURITY_PROFILE " AT+SQNSPCFG=3,%u,\"\" ,%u,%u"
3939
4040#define AT_WRITE_CERTIFICATE " AT+SQNSNVW=\" certificate\" ,%u,%u"
41+ #define AT_ERASE_CERTIFICATE " AT+SQNSNVW=\" certificate\" ,%u,0"
4142#define AT_WRITE_PRIVATE_KEY " AT+SQNSNVW=\" privatekey\" ,%u,%u"
43+ #define AT_ERASE_PRIVATE_KEY " AT+SQNSNVW=\" privatekey\" ,%u,0"
4244
4345#define NUMBER_OF_CIPHERS (64 )
4446#define CIPHER_VALUE_LENGTH (6 )
@@ -139,8 +141,7 @@ PGM_P const cipher_values[NUMBER_OF_CIPHERS] PROGMEM = {
139141 cipher42, cipher43, cipher44, cipher45, cipher46, cipher47, cipher48,
140142 cipher49, cipher50, cipher51, cipher52, cipher53, cipher54, cipher55,
141143 cipher56, cipher57, cipher58, cipher59, cipher60, cipher61, cipher62,
142- cipher63
143- };
144+ cipher63};
144145
145146// clang-format off
146147const char cipher_text_0[50 ] PROGMEM = " TLS_AES_128_GCM_SHA256" ;
@@ -590,8 +591,15 @@ static bool requestAndSaveToNonVolatileMemory(const char* message,
590591 SequansController.clearReceiveBuffer ();
591592
592593 if (is_certificate) {
594+ // First erase the existing certifiate at the slot (if any)
595+ sprintf (command, AT_ERASE_CERTIFICATE, slot);
596+ SequansController.writeCommand (command);
597+
593598 sprintf (command, AT_WRITE_CERTIFICATE, slot, data_length);
594599 } else {
600+ sprintf (command, AT_ERASE_PRIVATE_KEY, slot);
601+ SequansController.writeCommand (command);
602+
595603 sprintf (command, AT_WRITE_PRIVATE_KEY, slot, data_length);
596604 }
597605
@@ -1073,7 +1081,6 @@ void provisionMqtt() {
10731081 }
10741082 }
10751083
1076-
10771084 char line[82 ] = " " ;
10781085 bool has_chosen_psk_cipher = false ;
10791086 size_t cipher_count = 0 ;
@@ -1086,7 +1093,8 @@ void provisionMqtt() {
10861093
10871094 // Append the cipher to the string which will be passed with the
10881095 // command to the modem
1089- strcpy_P (&ciphers[cipher_character_index], (PGM_P)pgm_read_word (&(cipher_values[i])));
1096+ strcpy_P (&ciphers[cipher_character_index],
1097+ (PGM_P)pgm_read_word (&(cipher_values[i])));
10901098 cipher_character_index += CIPHER_VALUE_LENGTH;
10911099 cipher_count++;
10921100
@@ -1231,8 +1239,9 @@ void provisionMqtt() {
12311239 } else {
12321240
12331241 bool use_ecc = askCloseEndedQuestion (
1234- " Do you want to utilize the ECC rather than storing the "
1235- " certificates in the non-volatile memory of the modem?" );
1242+ " Do you want to utilize the ECC cryptography chip rather than "
1243+ " storing the certificates in the non-volatile memory of the "
1244+ " modem?" );
12361245
12371246 SerialModule.println (" \r\n " );
12381247
@@ -1334,7 +1343,7 @@ void provisionMqtt() {
13341343
13351344 SerialModule.println (" \r\n " );
13361345 if (!requestAndSaveToNonVolatileMemory (
1337- " Please paste in the private key and press enter."
1346+ " Please paste in the private key and press enter. "
13381347 " It should be on the following form:\r\n "
13391348 " -----BEGIN RSA/EC PRIVATE KEY-----\r\n "
13401349 " ...\r\n "
0 commit comments