Skip to content

Timeout too short for multiple HID packets to be sent in send_transport_response #25

@svareille

Description

@svareille

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);):

libraries/onlykey/okcore.cpp

Lines 2552 to 2566 in a133bea

{ //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

libraries/fido2/device.cpp

Lines 181 to 194 in a133bea

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions