Skip to content

Conversation

@haxtibal
Copy link
Contributor

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.
@mtrojnar mtrojnar merged commit 5c3fa23 into OpenSC:master Jul 16, 2025
10 checks passed
mtrojnar added a commit that referenced this pull request Jul 16, 2025
@mtrojnar
Copy link
Member

Thank you for your contribution.

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.

2 participants