@@ -185,21 +185,39 @@ static int thread_joiner_application_simple_enroll_response_cb(int8_t service_id
185
185
{
186
186
(void ) source_address ;
187
187
(void ) source_port ;
188
+ uint8_t * ptr ;
189
+ uint16_t len , flen ;
188
190
189
191
// re-attach in any case and close the secure connection
190
192
thread_extension_bootstrap_network_reattach (service_id , 1000 );
191
193
coap_service_close_secure_connection (service_id , source_address , source_port );
192
194
193
195
protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (thread_extension_bootstrap_find_id_by_service (service_id ));
194
196
195
- tr_debug ("Simple enrollment received" );
197
+ tr_debug ("Simple enrollment received %s" , trace_array ( response_ptr -> payload_ptr , response_ptr -> payload_len ) );
196
198
197
199
if (!cur || !cur -> thread_info || !response_ptr ) {
198
200
return -1 ;
199
201
}
202
+ ptr = response_ptr -> payload_ptr ;
203
+ len = response_ptr -> payload_len ;
204
+ // CBOR format check
205
+ if (* ptr == 0x58 ) {
206
+ flen = * (ptr + 1 );
207
+ ptr += 2 ;
208
+ len -= 2 ;
209
+ } else if (* ptr == 0x59 ) {
210
+ flen = common_read_16_bit (ptr + 1 );
211
+ ptr += 3 ;
212
+ len -= 3 ;
213
+ } else {
214
+ // no shorter than 23 byte certificates supported
215
+ flen = 0 ;
216
+ }
200
217
201
- if (0 > thread_extension_bootstrap_network_certificate_set (cur , response_ptr -> payload_ptr , response_ptr -> payload_len )) {
202
- tr_warn ("ae response parse failed" );
218
+ if ( flen != len ||
219
+ 0 > thread_extension_bootstrap_network_certificate_set (cur , ptr , len )) {
220
+ tr_warn ("ae response parse failed, len %d != %d" ,len ,flen );
203
221
}
204
222
205
223
return 0 ;
@@ -269,16 +287,26 @@ static int thread_joiner_application_rat_response_cb(int8_t service_id, uint8_t
269
287
// TODO Verify nonce
270
288
271
289
coap_service_request_send (service_id , COAP_REQUEST_OPTIONS_SECURE_BYPASS , source_address , source_port ,
272
- COAP_MSG_TYPE_CONFIRMABLE , COAP_MSG_CODE_REQUEST_GET , ".well-known/est/csrattrs" , COAP_CT_NONE , NULL , 0 , thread_joiner_application_csrattrs_response_cb );
290
+ COAP_MSG_TYPE_CONFIRMABLE , COAP_MSG_CODE_REQUEST_GET , ".well-known/est/csrattrs" , THREAD_CONTENT_FORMAT_CSRATTRS , NULL , 0 , thread_joiner_application_csrattrs_response_cb );
273
291
274
292
return 0 ;
275
293
}
276
-
294
+ /*A2 # map(2)
295
+ 67 # text(7)
296
+ 76657273696F6E # "version"
297
+ 61 # text(1)
298
+ 31 # "1"
299
+ 65 # text(5)
300
+ 6E6F6E6365 # "nonce"
301
+ 48 # bytes(8)
302
+ 13ADD904605D973E # "\x13\xAD\xD9\x04`]\x97>"
303
+ *
304
+ */
277
305
static int thread_joiner_application_rat_request_build (uint8_t * rat_payload , int length )
278
306
{
279
307
uint8_t * ptr = rat_payload ;
280
308
281
- if (length < 25 ) {
309
+ if (length < 30 ) {
282
310
return 0 ;
283
311
}
284
312
@@ -288,7 +316,8 @@ static int thread_joiner_application_rat_request_build(uint8_t *rat_payload, int
288
316
* rat_payload ++ = 0x67 ;
289
317
memcpy (rat_payload , "version" , 7 );
290
318
rat_payload += 7 ;
291
- * rat_payload ++ = 0x01 ;
319
+ * rat_payload ++ = 0x61 ;
320
+ * rat_payload ++ = 0x31 ;
292
321
293
322
// text (5) "nonce" + bytes (8) random nonce
294
323
// todo: save nonce to verify response against reply.
@@ -306,7 +335,7 @@ static int thread_joiner_application_rat_request_build(uint8_t *rat_payload, int
306
335
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 )
307
336
{
308
337
protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
309
- uint8_t rat_payload [25 ];
338
+ uint8_t rat_payload [30 ];
310
339
int rat_len ;
311
340
312
341
if (!done_cb || !cur ) {
0 commit comments