Better token parsing in authorized_yubikeys file (check_user_token) #244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a possible bug while having
/home/$USER/.yubico/authorized_yubikeys
file longer than 1024 bytes in a single line. I can see that the authorized_yubikeys file is parsed by buffering 1024 bytes. The code relies on the fact that the first token is always the username. But when the file is larger than 1024 bytes, the second time called fgets returns the rest of the yubikeys line, but the rest of the line does (and probably shouldn't) start with the username. So when the yubikey is not found in the first 1025 bytes, the auth will fail. To fix the username problem I have added a check if the username is undefined (NULL), so it won't change the username every time a part of the file is loaded.The second problem is that when the 1024 buffer cuts the token in two parts. For this, I have added a check that if the last token length is less than 12, it will move back the file pointer for the token length, so it can be read as a whole in the next fgets.
We have found this possible bug when creating a uthorized_yubikeys with many tokens so the final file size is larger than 1024 bytes. We have been able to hotfix this by splitting the file by '\n' character after the last correctly read token.
Thank you.