|
20 | 20 | // This results in 36 + 127 + 5 + 1 + 1 = 170 |
21 | 21 | #define HTTP_CONFIGURE_SIZE 170 |
22 | 22 |
|
| 23 | +#define QUERY_SECURITY_PROFILE "AT+SQNSPCFG" |
| 24 | + |
| 25 | +#define SECURITY_PROFILE_PREFIX_LENGTH 11 |
| 26 | +#define HTTPS_SECURITY_PROFILE_NUMBER '3' |
| 27 | + |
23 | 28 | #define HTTP_SEND "AT+SQNHTTPSND=0,%u,\"%s\",%lu" |
24 | 29 | #define HTTP_RECEIVE "AT+SQNHTTPRCV=0,%lu" |
25 | 30 | #define HTTP_QUERY "AT+SQNHTTPQRY=0,%u,\"%s\"" |
@@ -235,6 +240,49 @@ bool HttpClientClass::configure(const char *host, |
235 | 240 |
|
236 | 241 | SequansController.clearReceiveBuffer(); |
237 | 242 |
|
| 243 | + if (enable_tls) { |
| 244 | + |
| 245 | + SequansController.writeCommand(QUERY_SECURITY_PROFILE); |
| 246 | + |
| 247 | + char response[128] = ""; |
| 248 | + |
| 249 | + ResponseResult result = |
| 250 | + SequansController.readResponse(response, sizeof(response)); |
| 251 | + |
| 252 | + if (result != ResponseResult::OK) { |
| 253 | + Log.error("Failed to query HTTPS security profile"); |
| 254 | + return false; |
| 255 | + } |
| 256 | + |
| 257 | + // Split by line feed and carriage return to retrieve each entry |
| 258 | + char *ptr = strtok(response, "\r\n"); |
| 259 | + bool security_profile_found = false; |
| 260 | + |
| 261 | + while (ptr != NULL) { |
| 262 | + |
| 263 | + // Skip the prefix of '+SQNSPCFG: ' |
| 264 | + ptr += SECURITY_PROFILE_PREFIX_LENGTH; |
| 265 | + |
| 266 | + // Now we check if the entry has the third security profile |
| 267 | + if (*ptr == HTTPS_SECURITY_PROFILE_NUMBER) { |
| 268 | + security_profile_found = true; |
| 269 | + break; |
| 270 | + } |
| 271 | + |
| 272 | + ptr = strtok(NULL, "\r\n"); |
| 273 | + } |
| 274 | + |
| 275 | + if (!security_profile_found) { |
| 276 | + Log.error( |
| 277 | + "Security profile not set up for HTTPS. Run the " |
| 278 | + "'https_configure_ca' Arduino sketch example to set this up so " |
| 279 | + "that HTTPS can be used. More information here: " |
| 280 | + "https://iot.microchip.com/docs/arduino/userguide/http"); |
| 281 | + |
| 282 | + return false; |
| 283 | + } |
| 284 | + } |
| 285 | + |
238 | 286 | char command[HTTP_CONFIGURE_SIZE] = ""; |
239 | 287 | sprintf(command, HTTP_CONFIGURE, host, port, enable_tls ? 1 : 0); |
240 | 288 |
|
|
0 commit comments