Hi!
I'm currently playing with PGP key signature and decryption using my OnlyKey. I dialogue directly with the key, sending the OKSIGN and OKDECRYPT messages over HID. While testing with a 4096 bits RSA key, signing gives a wrong signature:
Signatures with a 4096 bits RSA key should be 512 bytes long (8 HID packets). However I only get 448 bytes (7 HID packets). I think I understand why: the usb_rawhid_send2 function will send a packet only if there is less than 4 packets processed at the moment. If there is 4 packets currently processed, the function will "sleep" a little then try again until the packet can be sent or a timeout is reached. That's the problem: the send_transport_response function has to send 8 packets, but a timeout of 0 ms is specified (RawHID.send2(resp_buffer, 0);):
|
{ //USB |
|
for (int i = 0; i < len; i += 64) |
|
{ |
|
if (len-i>=64) { |
|
memcpy(resp_buffer, data+i, 64); |
|
} |
|
else { |
|
memcpy(resp_buffer, data+i, len-i); |
|
} |
|
#ifdef DEBUG |
|
byteprint(resp_buffer, 64); |
|
#endif |
|
RawHID.send2(resp_buffer, 0); |
|
} |
|
} |
I guess the timeout is too short for the packet to be sent, thus the loss.
Increasing this timeout to 100 ms (as for FIDO) should be enough I think
|
void usbhid_send(uint8_t * msg) |
|
{ |
|
printf1(TAG_GREEN, "Sending FIDO response block"); |
|
#ifdef DEBUG |
|
byteprint(msg, 64); |
|
#endif |
|
extern uint8_t useinterface; |
|
|
|
if (useinterface == 2) { |
|
RawHID.send2(msg, 100); |
|
} else { |
|
RawHID.send(msg, 100); |
|
} |
|
} |
Hi!
I'm currently playing with PGP key signature and decryption using my OnlyKey. I dialogue directly with the key, sending the OKSIGN and OKDECRYPT messages over HID. While testing with a 4096 bits RSA key, signing gives a wrong signature:
Signatures with a 4096 bits RSA key should be 512 bytes long (8 HID packets). However I only get 448 bytes (7 HID packets). I think I understand why: the
usb_rawhid_send2function will send a packet only if there is less than 4 packets processed at the moment. If there is 4 packets currently processed, the function will "sleep" a little then try again until the packet can be sent or a timeout is reached. That's the problem: thesend_transport_responsefunction has to send 8 packets, but a timeout of 0 ms is specified (RawHID.send2(resp_buffer, 0);):libraries/onlykey/okcore.cpp
Lines 2552 to 2566 in a133bea
I guess the timeout is too short for the packet to be sent, thus the loss.
Increasing this timeout to 100 ms (as for FIDO) should be enough I think
libraries/fido2/device.cpp
Lines 181 to 194 in a133bea