Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ssh-pkcs11.c

4 views
Skip to first unread message

Nuno Gonçalves

unread,
Jun 17, 2016, 2:05:14 PM6/17/16
to
Hi,

It seems there is a bug with the pkcs11 feature where a zero-length
PIN is accepted. I believe this is a bug, since the user might want to
press return when asked for the PIN to ignore that slot/key.

This is caused at pkcs11_rsa_private_encrypt:

snprintf(prompt, sizeof(prompt),
"Enter PIN for '%s': ", si->token.label);
pin = read_passphrase(prompt, RP_ALLOW_EOF);
if (pin == NULL)
return (-1); /* bail out */

Actually a zero-length PIN will not cause a NULL to be returned, so it
will still try to authenticate and fail the PIN login!

Also, I think it would be great to support the CKF_* flags to provide
some feedback to the user regarding PIN tries left remaining,
something like this:

if (info.flags & CKF_USER_PIN_COUNT_LOW)
printf("WARNING: User PIN count low\n");
else if (info.flags & CKF_USER_PIN_FINAL_TRY)
printf("WARNING: User PIN final try\n");
else if (info.flags & CKF_USER_PIN_LOCKED) /* Maybe we should bail out
here, or just try to continue? */
printf("WARNING: User PIN reported locked\n");

Thanks,
Nuno
_______________________________________________
openssh-unix-dev mailing list
openssh-...@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev

Alon Bar-Lev

unread,
Jun 17, 2016, 2:59:15 PM6/17/16
to
On 17 June 2016 at 20:58, Nuno Gonçalves <nun...@gmail.com> wrote:
> Hi,
>
> It seems there is a bug with the pkcs11 feature where a zero-length
> PIN is accepted. I believe this is a bug, since the user might want to
> press return when asked for the PIN to ignore that slot/key.

Hi,

Empty PIN is valid case, not sure why you want to avoid supporting it.

Alon

Nuno Gonçalves

unread,
Jun 17, 2016, 3:51:18 PM6/17/16
to
On Fri, Jun 17, 2016 at 7:57 PM, Alon Bar-Lev <alon....@gmail.com> wrote:
> On 17 June 2016 at 20:58, Nuno Gonçalves <nun...@gmail.com> wrote:
>> Hi,
>>
>> It seems there is a bug with the pkcs11 feature where a zero-length
>> PIN is accepted. I believe this is a bug, since the user might want to
>> press return when asked for the PIN to ignore that slot/key.
>
> Hi,
>
> Empty PIN is valid case, not sure why you want to avoid supporting it.
>
> Alon

I didn't know it was valid but the reasoning still applies. I don't
really know the standard use cases, but I think it could eventually be
useful for the user, when asked for the PIN, to decide not enter it.
Currently it can only be done by killing ssh. If empty PIN is valid,
but eventually not usual, maybe we should ask if the user really wants
to try a empty pin or just continue to another authentication option?


Regarding the CKF_USER_PIN flags, do you think it is a good idea to
implement the warning messages?

Thanks,
Nuno

Alon Bar-Lev

unread,
Jun 17, 2016, 4:10:14 PM6/17/16
to
On 17 June 2016 at 22:45, Nuno Gonçalves <nun...@gmail.com> wrote:
> On Fri, Jun 17, 2016 at 7:57 PM, Alon Bar-Lev <alon....@gmail.com> wrote:
>> On 17 June 2016 at 20:58, Nuno Gonçalves <nun...@gmail.com> wrote:
>>> Hi,
>>>
>>> It seems there is a bug with the pkcs11 feature where a zero-length
>>> PIN is accepted. I believe this is a bug, since the user might want to
>>> press return when asked for the PIN to ignore that slot/key.
>>
>> Hi,
>>
>> Empty PIN is valid case, not sure why you want to avoid supporting it.
>>
>> Alon
>
> I didn't know it was valid but the reasoning still applies. I don't
> really know the standard use cases, but I think it could eventually be
> useful for the user, when asked for the PIN, to decide not enter it.
> Currently it can only be done by killing ssh. If empty PIN is valid,
> but eventually not usual, maybe we should ask if the user really wants
> to try a empty pin or just continue to another authentication option?

Not sure what best solution, but ignoring empty PIN is the same as
ignoring "cancel" or similar constants, which is more explicit.
What's wrong with plain <Ctrl>-C, as without PIN there is no use to
continue session anyway.

> Regarding the CKF_USER_PIN flags, do you think it is a good idea to
> implement the warning messages?

Most implementations do not support these.

Regards,
Alon

Nuno Gonçalves

unread,
Jun 17, 2016, 4:11:14 PM6/17/16
to
On Fri, Jun 17, 2016 at 9:04 PM, Alon Bar-Lev <alon....@gmail.com> wrote:
> Not sure what best solution, but ignoring empty PIN is the same as
> ignoring "cancel" or similar constants, which is more explicit.
> What's wrong with plain <Ctrl>-C, as without PIN there is no use to
> continue session anyway.

The session could continue with other publickey auth or even password,
that could be asked after. Anyway I was confuses by the behaviour as a
user, such that it eventually locked my card. I agree there is no
clear cut solution, so I'll just live with it as it is.

>> Regarding the CKF_USER_PIN flags, do you think it is a good idea to
>> implement the warning messages?

OpenSC does. I have no idea what is the OpenSC quota for ssh users.
Anyway the libraries can be waiting for the clients to support it!
I'll provide a patch and hope it is acceptable.

Thanks for the replies!

Nuno

Nuno Gonçalves

unread,
Jul 25, 2016, 3:02:22 AM7/25/16
to
Hi Alon,

I confirmed with pkcs11-tool (from OpenSC) and I can confirm that
pressing return when asked for the pin causes the login to stop (and
not to try a empty pin).

Can you confirm if a empty pin is actually a valid pin, and if not,
can the patch be accepted?

Once again, the problem is that from a user experience, *some/most*
users would expect they can skip pkcs11 token authentication just by
pressing return and trying then other authentication method, like
password.

But currently that is not what happens, and users can find out too
late that they have instead tried a wrong pin too many times and
locked their token...

Regards,
Nuno

On Fri, Jun 17, 2016 at 10:04 PM, Alon Bar-Lev <alon....@gmail.com> wrote:
> On 17 June 2016 at 22:45, Nuno Gonçalves <nun...@gmail.com> wrote:
>> On Fri, Jun 17, 2016 at 7:57 PM, Alon Bar-Lev <alon....@gmail.com> wrote:
>>> On 17 June 2016 at 20:58, Nuno Gonçalves <nun...@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> It seems there is a bug with the pkcs11 feature where a zero-length
>>>> PIN is accepted. I believe this is a bug, since the user might want to
>>>> press return when asked for the PIN to ignore that slot/key.
>>>
>>> Hi,
>>>
>>> Empty PIN is valid case, not sure why you want to avoid supporting it.
>>>
>>> Alon
>>
>> I didn't know it was valid but the reasoning still applies. I don't
>> really know the standard use cases, but I think it could eventually be
>> useful for the user, when asked for the PIN, to decide not enter it.
>> Currently it can only be done by killing ssh. If empty PIN is valid,
>> but eventually not usual, maybe we should ask if the user really wants
>> to try a empty pin or just continue to another authentication option?
>

> Not sure what best solution, but ignoring empty PIN is the same as
> ignoring "cancel" or similar constants, which is more explicit.
> What's wrong with plain <Ctrl>-C, as without PIN there is no use to
> continue session anyway.
>

>> Regarding the CKF_USER_PIN flags, do you think it is a good idea to
>> implement the warning messages?
>

> Most implementations do not support these.
>
> Regards,
> Alon

Alon Bar-Lev

unread,
Jul 25, 2016, 3:44:07 AM7/25/16
to
Hi,

I am not the maintainer of openssh pkcs11 module, so I cannot accept anything :)

However, I do believe that empty PIN is a valid PIN in PKCS#11 spec.

Regards,
Alon

Jakub Jelen

unread,
Jul 25, 2016, 7:28:24 AM7/25/16
to
On 07/25/2016 09:38 AM, Alon Bar-Lev wrote:
> Hi,
>
> I am not the maintainer of openssh pkcs11 module, so I cannot accept anything :)
>
> However, I do believe that empty PIN is a valid PIN in PKCS#11 spec.
PKCS#11 tokens provide ulMinPinLen and ulMaxPinLen fields. So the
enforced length is token-specific [1] and nothing what would be enforced
by the specification.

[1] http://www.cryptsoft.com/pkcs11doc/STANDARD/pkcs-11v2-11r1.pdf

--
Jakub Jelen
Associate Software Engineer
Security Technologies
Red Hat

Douglas E Engert

unread,
Jul 27, 2016, 10:32:33 AM7/27/16
to

On 7/25/2016 1:56 AM, Nuno Gonçalves wrote:
> Hi Alon,
>
> I confirmed with pkcs11-tool (from OpenSC) and I can confirm that
> pressing return when asked for the pin causes the login to stop (and
> not to try a empty pin).
>
> Can you confirm if a empty pin is actually a valid pin, and if not,
> can the patch be accepted?

By Empty pin do you mean pPin != NULL && ulPinLen = 0 or do you mean pPin == NULL?

If the card supports CKF_PROTECTED_AUTHENTICATION_PATH (may have a pin pad reader) , the a call to C_Login with pPin = NULL wil use the pin pad reader.

Without CKF_PROTECTED_AUTHENTICATION_PATH I would find it strange if a card would allow a zero length pin. If no pin is needed a C_Login would not be required either the CKS_RO_PUBLIC_SESSION would
work and the key one wants to use does not require PIN protection. (Does SSH check if the key requires the PIN?)

What return code does C_Login return if you try and use an "empty pin"?

--

Douglas E. Engert <DEEn...@gmail.com>

Nuno Gonçalves

unread,
Jul 28, 2016, 4:31:42 AM7/28/16
to
On Mon, Jul 25, 2016 at 1:22 PM, Jakub Jelen <jje...@redhat.com> wrote:
> PKCS#11 tokens provide ulMinPinLen and ulMaxPinLen fields. So the
> enforced length is token-specific [1] and nothing what would be enforced by
> the specification.

Thanks for the info. And do you have any idea if the special case or a
0-length pin is acceptable/used in any application?

Thanks,
Nuno
0 new messages