Skip to content

Commit 44110a1

Browse files
author
Tero Heinonen
authored
Thread bootstrap improvements (ARMmbed#1699)
Improvements for Thread bootstrap sequesnces.
1 parent eaf35d2 commit 44110a1

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

source/6LoWPAN/Thread/thread_extension_bootstrap.c

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "common_functions.h"
3939
#include "coap_service_api.h"
4040
#include "thread_meshcop_lib.h"
41+
#include "randLIB.h"
4142
#include "6LoWPAN/Thread/thread_common.h"
4243
#include "6LoWPAN/Thread/thread_bootstrap.h"
4344
#include "6LoWPAN/Thread/thread_joiner_application.h"
@@ -171,6 +172,25 @@ static int thread_joiner_application_simple_enroll_response_cb(int8_t service_id
171172

172173
return 0;
173174
}
175+
176+
static int thread_joiner_application_csrattrs_response_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr)
177+
{
178+
(void) response_ptr;
179+
180+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(thread_extension_bootstrap_find_id_by_service(service_id));
181+
182+
if (!cur || !cur->thread_info) {
183+
return -1;
184+
}
185+
tr_info("Receiving csrattrs response sending simpleenroll");
186+
187+
// TODO add certificate template to this message with included Private/Public key pair
188+
coap_service_request_send(service_id, COAP_REQUEST_OPTIONS_SECURE_BYPASS, source_address, source_port,
189+
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, ".well-known/est/simpleenroll", THREAD_CONTENT_FORMAT_PKCS10, NULL, 0, thread_joiner_application_simple_enroll_response_cb);
190+
191+
return 0;
192+
}
193+
174194
static int thread_joiner_application_rat_response_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr)
175195
{
176196
(void) response_ptr;
@@ -180,17 +200,52 @@ static int thread_joiner_application_rat_response_cb(int8_t service_id, uint8_t
180200
if (!cur || !cur->thread_info) {
181201
return -1;
182202
}
183-
tr_info("Receiving RAT response sending simpleenroll");
203+
tr_info("Receiving RAT response sending csrattrs request");
204+
// TODO Parse CA certificate from RAT response
205+
206+
// TODO Verify nonce
184207

185208
// TODO add certificate template to this message with included Private/Public key pair
186209
coap_service_request_send(service_id, COAP_REQUEST_OPTIONS_SECURE_BYPASS, source_address, source_port,
187-
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, ".well-known/est/simpleenroll", COAP_CT_OCTET_STREAM, NULL, 0, thread_joiner_application_simple_enroll_response_cb);
210+
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_GET, ".well-known/est/csrattrs", COAP_CT_NONE, NULL, 0, thread_joiner_application_csrattrs_response_cb);
188211

189212
return 0;
190213
}
214+
215+
static int thread_joiner_application_rat_request_build(uint8_t *rat_payload, int length)
216+
{
217+
uint8_t *ptr = rat_payload;
218+
219+
if (length < 25) {
220+
return 0;
221+
}
222+
223+
*rat_payload++ = 0xa2; // map (2)
224+
225+
// text (7) "version" + unsigned (1) "1"
226+
*rat_payload++ = 0x67;
227+
memcpy(rat_payload, "version", 7);
228+
rat_payload += 7;
229+
*rat_payload++ = 0x01;
230+
231+
// text (5) "nonce" + bytes (8) random nonce
232+
// todo: save nonce to verify response against reply.
233+
*rat_payload++ = 0x65;
234+
memcpy(rat_payload, "nonce", 5);
235+
rat_payload += 5;
236+
237+
*rat_payload++ = 0x48;
238+
common_write_64_bit(randLIB_get_64bit(), rat_payload);
239+
rat_payload += 8;
240+
241+
return rat_payload - ptr;
242+
}
243+
191244
static int thread_joiner_application_ae_commission_start(int8_t interface_id, uint8_t parent_address[16], uint16_t port, thread_joiner_application_commission_done_cb *done_cb)
192245
{
193246
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
247+
uint8_t rat_payload[25];
248+
int rat_len;
194249

195250
if (!done_cb || !cur) {
196251
return -1;
@@ -209,9 +264,15 @@ static int thread_joiner_application_ae_commission_start(int8_t interface_id, ui
209264
memcpy(thread_info(cur)->extension_credentials_ptr->ccm_addr, parent_address, 16);
210265
thread_info(cur)->extension_credentials_ptr->ccm_port = port;
211266

267+
rat_len = thread_joiner_application_rat_request_build(rat_payload, sizeof(rat_payload));
268+
if (rat_len == 0) {
269+
tr_debug("RAT request payload build failed");
270+
return -1;
271+
}
272+
212273
// todo: This might not be needed if no extra certificate processing made by device and should directly call simpleenroll
213274
coap_service_request_send(thread_info(cur)->extension_credentials_ptr->coap_service_secure_session_id, COAP_REQUEST_OPTIONS_SECURE_BYPASS, parent_address, port,
214-
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, ".well-known/est/rat", COAP_CT_OCTET_STREAM, NULL, 0, thread_joiner_application_rat_response_cb);
275+
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, ".well-known/est/rat", THREAD_CONTENT_FORMAT_AUDITNONCE, rat_payload, rat_len, thread_joiner_application_rat_response_cb);
215276

216277
return 0;
217278
}

source/6LoWPAN/Thread/thread_extension_constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ typedef struct discovery_additional_info {
106106
#define TMFCOP_TLV_SEQUENCE_NUMBER 13
107107
#define TMFCOP_TLV_IPV6_ADDRESS 14
108108

109+
#define THREAD_CONTENT_FORMAT_AUDITNONCE (sn_coap_content_format_e)65000
110+
#define THREAD_CONTENT_FORMAT_PKCS10 (sn_coap_content_format_e)65003
109111

110112
#define THREAD_VERSION_1_2 3
111113

0 commit comments

Comments
 (0)