@@ -132,16 +132,15 @@ static uint32_t _next_cid(void)
132
132
}
133
133
134
134
135
- void u2f_send_message (const uint8_t * data , const uint32_t len )
135
+ void u2f_queue_message (const uint8_t * data , const uint32_t len )
136
136
{
137
137
usb_reply_queue_load_msg (U2FHID_MSG , data , len , _cid );
138
138
}
139
139
140
140
141
- void u2f_send_err_hid (uint32_t fcid , uint8_t err )
141
+ void u2f_queue_error_hid (uint32_t fcid , uint8_t err )
142
142
{
143
143
USB_FRAME f ;
144
-
145
144
utils_zero (& f , sizeof (f ));
146
145
f .cid = fcid ;
147
146
f .init .cmd = U2FHID_ERROR ;
@@ -151,24 +150,24 @@ void u2f_send_err_hid(uint32_t fcid, uint8_t err)
151
150
}
152
151
153
152
154
- static void _send_error (const uint16_t err )
153
+ static void _queue_error (const uint16_t err )
155
154
{
156
155
uint8_t data [2 ];
157
156
data [0 ] = err >> 8 & 0xFF ;
158
157
data [1 ] = err & 0xFF ;
159
- u2f_send_message (data , 2 );
158
+ u2f_queue_message (data , 2 );
160
159
}
161
160
162
161
163
162
static void _version (const USB_APDU * a )
164
163
{
165
164
if (APDU_LEN (* a ) != 0 ) {
166
- _send_error (U2F_SW_WRONG_LENGTH );
165
+ _queue_error (U2F_SW_WRONG_LENGTH );
167
166
return ;
168
167
}
169
168
170
169
static const uint8_t version_response [] = {'U' , '2' , 'F' , '_' , 'V' , '2' , 0x90 , 0x00 };
171
- u2f_send_message (version_response , sizeof (version_response ));
170
+ u2f_queue_message (version_response , sizeof (version_response ));
172
171
}
173
172
174
173
@@ -195,12 +194,12 @@ static void _register(const USB_APDU *a)
195
194
const U2F_REGISTER_REQ * req = (const U2F_REGISTER_REQ * )a -> data ;
196
195
197
196
if (APDU_LEN (* a ) != sizeof (U2F_REGISTER_REQ )) {
198
- _send_error (U2F_SW_WRONG_LENGTH );
197
+ _queue_error (U2F_SW_WRONG_LENGTH );
199
198
return ;
200
199
}
201
200
202
201
if (touch_button_press (TOUCH_TIMEOUT ) != DBB_TOUCHED ) {
203
- _send_error (U2F_SW_CONDITIONS_NOT_SATISFIED );
202
+ _queue_error (U2F_SW_CONDITIONS_NOT_SATISFIED );
204
203
return ;
205
204
206
205
} else {
@@ -213,7 +212,7 @@ static void _register(const USB_APDU *a)
213
212
utils_zero (data , sizeof (data ));
214
213
215
214
if (random_bytes (nonce , sizeof (nonce ), 0 ) == DBB_ERROR ) {
216
- _send_error (U2F_SW_WRONG_DATA );
215
+ _queue_error (U2F_SW_WRONG_DATA );
217
216
return ;
218
217
}
219
218
@@ -237,7 +236,7 @@ static void _register(const USB_APDU *a)
237
236
238
237
if (ecc_sign (U2F_ATT_PRIV_KEY , (uint8_t * )& sig_base , sizeof (sig_base ), sig ,
239
238
NULL , ECC_SECP256r1 )) {
240
- _send_error (U2F_SW_WRONG_DATA );
239
+ _queue_error (U2F_SW_WRONG_DATA );
241
240
return ;
242
241
}
243
242
@@ -253,7 +252,7 @@ static void _register(const USB_APDU *a)
253
252
1 /* keyhandleLen */ + resp -> keyHandleLen +
254
253
sizeof (U2F_ATT_CERT ) + sig_len + 2 ;
255
254
256
- u2f_send_message (data , len );
255
+ u2f_queue_message (data , len );
257
256
}
258
257
}
259
258
@@ -282,6 +281,7 @@ static uint16_t _frame_hijack_report(char *report, uint16_t len, uint16_t report
282
281
return report_len ;
283
282
}
284
283
284
+
285
285
static void _hijack (const U2F_AUTHENTICATE_REQ * req )
286
286
{
287
287
static char hijack_cmd [COMMANDER_REPORT_SIZE ] = {0 };
@@ -320,7 +320,7 @@ static void _authenticate(const USB_APDU *a)
320
320
U2F_AUTHENTICATE_SIG_STR sig_base ;
321
321
322
322
if (APDU_LEN (* a ) < U2F_KEYHANDLE_LEN ) { // actual size could vary
323
- _send_error (U2F_SW_WRONG_LENGTH );
323
+ _queue_error (U2F_SW_WRONG_LENGTH );
324
324
return ;
325
325
}
326
326
@@ -330,7 +330,7 @@ static void _authenticate(const USB_APDU *a)
330
330
if (MEMEQ (req -> appId , _hijack_code [i ], U2F_APPID_SIZE )) {
331
331
if (!(memory_report_ext_flags () & MEM_EXT_MASK_U2F_HIJACK )) {
332
332
// Abort U2F hijack commands if the U2F_hijack bit is not set (== disabled).
333
- u2f_send_err_hid (_cid , U2FHID_ERR_CHANNEL_BUSY );
333
+ u2f_queue_error_hid (_cid , U2FHID_ERR_CHANNEL_BUSY );
334
334
} else {
335
335
_hijack (req );
336
336
}
@@ -339,7 +339,7 @@ static void _authenticate(const USB_APDU *a)
339
339
}
340
340
341
341
if (req -> keyHandleLen != U2F_KEYHANDLE_LEN ) {
342
- _send_error (U2F_SW_WRONG_DATA );
342
+ _queue_error (U2F_SW_WRONG_DATA );
343
343
return ;
344
344
}
345
345
@@ -348,22 +348,22 @@ static void _authenticate(const USB_APDU *a)
348
348
_keyhandle_gen (req -> appId , nonce , privkey , mac );
349
349
350
350
if (!MEMEQ (req -> keyHandle , mac , SHA256_DIGEST_LENGTH )) {
351
- _send_error (U2F_SW_WRONG_DATA );
351
+ _queue_error (U2F_SW_WRONG_DATA );
352
352
return ;
353
353
}
354
354
355
355
if (a -> p1 == U2F_AUTH_CHECK_ONLY ) {
356
- _send_error (U2F_SW_CONDITIONS_NOT_SATISFIED );
356
+ _queue_error (U2F_SW_CONDITIONS_NOT_SATISFIED );
357
357
return ;
358
358
}
359
359
360
360
if (a -> p1 != U2F_AUTH_ENFORCE ) {
361
- _send_error (U2F_SW_WRONG_DATA );
361
+ _queue_error (U2F_SW_WRONG_DATA );
362
362
return ;
363
363
}
364
364
365
365
if (touch_button_press (TOUCH_TIMEOUT ) != DBB_TOUCHED ) {
366
- _send_error (U2F_SW_CONDITIONS_NOT_SATISFIED );
366
+ _queue_error (U2F_SW_CONDITIONS_NOT_SATISFIED );
367
367
return ;
368
368
369
369
} else {
@@ -385,7 +385,7 @@ static void _authenticate(const USB_APDU *a)
385
385
memcpy (sig_base .challenge , req -> challenge , U2F_NONCE_LENGTH );
386
386
387
387
if (ecc_sign (privkey , (uint8_t * )& sig_base , sizeof (sig_base ), sig , NULL , ECC_SECP256r1 )) {
388
- _send_error (U2F_SW_WRONG_DATA );
388
+ _queue_error (U2F_SW_WRONG_DATA );
389
389
return ;
390
390
}
391
391
@@ -395,7 +395,7 @@ static void _authenticate(const USB_APDU *a)
395
395
memcpy (buf + sizeof (U2F_AUTHENTICATE_RESP ) - U2F_MAX_EC_SIG_SIZE + sig_len , "\x90\x00" ,
396
396
2 );
397
397
398
- u2f_send_message (buf , sizeof (U2F_AUTHENTICATE_RESP ) - U2F_MAX_EC_SIG_SIZE + sig_len + 2 );
398
+ u2f_queue_message (buf , sizeof (U2F_AUTHENTICATE_RESP ) - U2F_MAX_EC_SIG_SIZE + sig_len + 2 );
399
399
}
400
400
}
401
401
@@ -418,7 +418,7 @@ static void _cmd_wink(const uint8_t *buf, uint32_t len)
418
418
(void )buf ;
419
419
420
420
if (len > 0 ) {
421
- u2f_send_err_hid (_cid , U2FHID_ERR_INVALID_LEN );
421
+ u2f_queue_error_hid (_cid , U2FHID_ERR_INVALID_LEN );
422
422
return ;
423
423
}
424
424
@@ -456,7 +456,7 @@ static void _cmd_init(const USB_FRAME *in)
456
456
U2FHID_INIT_RESP resp ;
457
457
458
458
if (in -> cid == 0 ) {
459
- u2f_send_err_hid (in -> cid , U2FHID_ERR_INVALID_CID );
459
+ u2f_queue_error_hid (in -> cid , U2FHID_ERR_INVALID_CID );
460
460
return ;
461
461
}
462
462
@@ -486,7 +486,7 @@ static void _cmd_msg(const USB_APDU *a, uint32_t len)
486
486
}
487
487
488
488
if (a -> cla != 0 ) {
489
- _send_error (U2F_SW_CLA_NOT_SUPPORTED );
489
+ _queue_error (U2F_SW_CLA_NOT_SUPPORTED );
490
490
return ;
491
491
}
492
492
@@ -501,7 +501,7 @@ static void _cmd_msg(const USB_APDU *a, uint32_t len)
501
501
_version (a );
502
502
break ;
503
503
default :
504
- _send_error (U2F_SW_INS_NOT_SUPPORTED );
504
+ _queue_error (U2F_SW_INS_NOT_SUPPORTED );
505
505
}
506
506
}
507
507
@@ -521,7 +521,7 @@ static void _continue(const USB_FRAME *f)
521
521
!(memory_report_ext_flags () & MEM_EXT_MASK_U2F ) ) {
522
522
// Abort U2F commands if the U2F bit is not set (==U2F disabled).
523
523
// Vendor specific commands are passed through.
524
- u2f_send_err_hid (_cid , U2FHID_ERR_CHANNEL_BUSY );
524
+ u2f_queue_error_hid (_cid , U2FHID_ERR_CHANNEL_BUSY );
525
525
} else {
526
526
// Received all data
527
527
switch (_reader .cmd ) {
@@ -542,7 +542,7 @@ static void _continue(const USB_FRAME *f)
542
542
break ;
543
543
}
544
544
default :
545
- u2f_send_err_hid (_cid , U2FHID_ERR_INVALID_CMD );
545
+ u2f_queue_error_hid (_cid , U2FHID_ERR_INVALID_CMD );
546
546
break ;
547
547
}
548
548
}
@@ -556,12 +556,12 @@ static void _continue(const USB_FRAME *f)
556
556
static void _init (const USB_FRAME * f )
557
557
{
558
558
if (f -> cid == U2FHID_CID_BROADCAST || f -> cid == 0 ) {
559
- u2f_send_err_hid (f -> cid , U2FHID_ERR_INVALID_CID );
559
+ u2f_queue_error_hid (f -> cid , U2FHID_ERR_INVALID_CID );
560
560
return ;
561
561
}
562
562
563
563
if ((unsigned )U2FHID_MSG_LEN (* f ) > sizeof (_reader .buf )) {
564
- u2f_send_err_hid (f -> cid , U2FHID_ERR_INVALID_LEN );
564
+ u2f_queue_error_hid (f -> cid , U2FHID_ERR_INVALID_LEN );
565
565
return ;
566
566
}
567
567
@@ -593,9 +593,9 @@ void u2f_device_run(const USB_FRAME *f)
593
593
if (f -> cid == _cid ) {
594
594
usb_reply_queue_clear ();
595
595
_reset_state ();
596
- u2f_send_err_hid (f -> cid , U2FHID_ERR_INVALID_SEQ );
596
+ u2f_queue_error_hid (f -> cid , U2FHID_ERR_INVALID_SEQ );
597
597
} else {
598
- u2f_send_err_hid (f -> cid , U2FHID_ERR_CHANNEL_BUSY );
598
+ u2f_queue_error_hid (f -> cid , U2FHID_ERR_CHANNEL_BUSY );
599
599
}
600
600
} else {
601
601
_init (f );
@@ -610,14 +610,14 @@ void u2f_device_run(const USB_FRAME *f)
610
610
}
611
611
612
612
if (_cid != f -> cid ) {
613
- u2f_send_err_hid (f -> cid , U2FHID_ERR_CHANNEL_BUSY );
613
+ u2f_queue_error_hid (f -> cid , U2FHID_ERR_CHANNEL_BUSY );
614
614
goto exit ;
615
615
}
616
616
617
617
if (_reader .seq != f -> cont .seq ) {
618
618
usb_reply_queue_clear ();
619
619
_reset_state ();
620
- u2f_send_err_hid (f -> cid , U2FHID_ERR_INVALID_SEQ );
620
+ u2f_queue_error_hid (f -> cid , U2FHID_ERR_INVALID_SEQ );
621
621
goto exit ;
622
622
}
623
623
@@ -649,7 +649,7 @@ void u2f_device_timeout(void)
649
649
650
650
if (_current_time_ms > U2F_TIMEOUT ) {
651
651
_reset_state ();
652
- u2f_send_err_hid (_cid , U2FHID_ERR_MSG_TIMEOUT );
652
+ u2f_queue_error_hid (_cid , U2FHID_ERR_MSG_TIMEOUT );
653
653
usb_reply_queue_send ();
654
654
}
655
655
}
0 commit comments