Skip to content

Skip trailing newlines in pin-source files #610

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

haxtibal
Copy link

Text editors usually append '\n' to the last line when saving a text file. Also echo "mypin" > ~/pinfile.txt appends a newline. It's therefore likely we encounter PIN files where the PIN is delimited with '\n'. Currently, PIN validation would fail in such a case since libp11 passes on the newline to PKCS#11 modules as if it was part of the PIN.

We now ignore trailing newlines. There's no specification mandating this, but since PINs are meant for interactive input it seems safe to assume PINs will never be allowed to contain a trailing newline. Further, the pkcs11-provider project is doing the same in their src/util.c:get_pin_file.

The change is backwards compatible. PIN files without trailing newline will work as well.

haxtibal added 2 commits June 27, 2025 11:44
Text editors usually append '\n' to the last line when saving a text
file. Also 'echo "mypin" > ~/pinfile.txt' appends a newline. It's
therefore likely we encounter PIN files where the PIN is delimited with
'\n'. Currently, PIN validation would fail in such a case since libp11
passes on the newline to PKCS#11 modules as if it was part of the PIN.

We now ignore trailing newlines. There's no specification mandating
this, but since PINs are meant for interactive input it seems safe to
assume PINs will never be allowed to contain a trailing newline.
Further, the pkcs11-provider project is doing the same in their
src/util.c:get_pin_file.

The change is backwards compatible. PIN files without trailing newline
will work as well.
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.

1 participant