Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase user password buffer in IsAESSupported command #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

d-e-s-o
Copy link
Contributor

@d-e-s-o d-e-s-o commented May 27, 2019

The IsAESSupported command struct has a 20 byte buffer size for storing
the user password. That is in contrast to, say, the EnablePasswordSafe
struct which uses a 30 byte buffer. Such a smaller buffer can cause
string length errors to be emitted for a legitimate user PIN as has been
found as part of the investigation for d-e-s-o/nitrocli#85. That is, the
nitrokey allows for setting a user PIN of 21 characters. Retrieving an
OTP using such a PIN works fine, whereas inquiring the PWS status does
not, as it first tries to cram the supplied password into 20 characters,
which fails.
This change increases the buffer size in the IsAESSupported command
struct to 30 bytes.

The IsAESSupported command struct has a 20 byte buffer size for storing
the user password. That is in contrast to, say, the EnablePasswordSafe
struct which uses a 30 byte buffer. Such a smaller buffer can cause
string length errors to be emitted for a legitimate user PIN as has been
found as part of the investigation for d-e-s-o/nitrocli#85. That is, the
nitrokey allows for setting a user PIN of 21 characters. Retrieving an
OTP using such a PIN works fine, whereas inquiring the PWS status does
not, as it first tries to cram the supplied password into 20 characters,
which fails.
This change increases the buffer size in the IsAESSupported command
struct to 30 bytes.
@szszszsz
Copy link
Member

szszszsz commented May 27, 2019

Hi!
Thank you for the PR! I was sure this is the same size as in the Pro's and Storage's firmwares, but turned out it should be 25 bytes (in Pro case), not 20. In Storage case it seems there is no handling at all for this command (DETECT_SC_AES, ==0x6a), so the call in libnitrokey could be removed for this device.
Will correct that to 25 bytes to maintain correct mapping with the Pro firmware. What's more, I need to confirm that yet with the historical data (not sure if the v0.7 was the first released ever), but I think that this command call is redundant and could be removed altogether.

As for the size choice, the 25 bytes PIN size used in commands was selected to allow packing both old and new PIN inside one USB 1.1 HID command 64 bytes buffer, for case of its update through HID (to keep things simple, and avoid more complicated transport protocol). Some of the commands indeed allow 30 bytes PIN length, and this is inconsistent (though might be usable in case, when the longer PIN is set via the CCID interface).

Our use-case rule for the maximum PIN size is 20 bytes (link to FAQ), and usual size is expected to be about 10 characters (or less), since smart card does not allow more than 3 guess attempts anyway, and thus brute-forcing here could not apply.

Edit: added link to FAQ

@szszszsz szszszsz added this to the v3.5 milestone May 27, 2019
@d-e-s-o
Copy link
Contributor Author

d-e-s-o commented May 27, 2019

Thanks for the explanation! Sounds good. If there is nothing you need from my side then feel free to close this pull request.

Some of the commands indeed allow 30 bytes PIN length, and this is inconsistent (though might be usable in case, when the longer PIN is set via the CCID interface).

Okay, but can we somehow at least make the command for changing the PIN accept the lowest of the sizes of the other command's buffers? Otherwise we can change the PIN successfully and then have other commands fail with errors when really they must not.

@szszszsz
Copy link
Member

If there is nothing you need from my side then feel free to close this pull request.

I plan to merge it with a modification in a separate commit, to keep your work included.

Okay, but can we somehow at least make the command for changing the PIN accept the lowest of the sizes of the other command's buffers? Otherwise we can change the PIN successfully and then have other commands fail with errors when really they must not.

You are right with that case of course. I will decrease it to 20 bytes, with a 5 bytes padding to keep the structure size. Perhaps I will treat the other PIN related structures similarly, to make this consistent.

Thank you for the idea!

@szszszsz szszszsz modified the milestones: v3.5, v3.6 Jul 10, 2019
sgued pushed a commit to sgued/libnitrokey that referenced this pull request Feb 14, 2022
@szszszsz szszszsz modified the milestones: v3.7, v3.8 Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants