Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 152170 - net-misc/openssh - PKCS#11 support
Summary: net-misc/openssh - PKCS#11 support
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High enhancement
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on: 215981
Blocks:
  Show dependency tree
 
Reported: 2006-10-20 15:27 UTC by Alon Bar-Lev (RETIRED)
Modified: 2009-02-25 21:30 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
openssh-4.4_p1-r4.ebuild.diff (openssh-4.4_p1-r4.ebuild.diff,1.69 KB, patch)
2006-10-20 15:29 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-4.5_p1.ebuild.diff (openssh-4.5_p1.ebuild.diff,2.56 KB, patch)
2007-01-05 08:04 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-4.7_p1-r1.ebuild.diff (openssh-4.7_p1-r1.ebuild.diff,2.36 KB, patch)
2007-09-29 08:31 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-4.7_p1-r2.ebuild.diff (openssh-4.7_p1-r2.ebuild.diff,2.34 KB, patch)
2007-09-30 08:27 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-4.7_p1-r3.ebuild.diff (openssh-4.7_p1-r3.ebuild.diff,2.56 KB, patch)
2008-01-19 18:24 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-4.7_p1-r20.ebuild.diff (openssh-4.7_p1-r20.ebuild.diff,2.76 KB, patch)
2008-03-21 21:38 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-4.9_p1.ebuild.diff (openssh-4.9_p1.ebuild.diff,3.14 KB, patch)
2008-04-02 17:07 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-5.0_p1.ebuild.diff (openssh-5.0_p1.ebuild.diff,3.00 KB, patch)
2008-04-05 07:50 UTC, Alon Bar-Lev (RETIRED)
Details | Diff
openssh-5.1_p1-r2.ebuild.diff (openssh-5.1_p1-r2.ebuild.diff,2.96 KB, patch)
2008-12-07 05:45 UTC, Alon Bar-Lev
Details | Diff
openssh-5.2_p1.ebuild.diff (openssh-5.2_p1.ebuild.diff,489 bytes, patch)
2009-02-24 18:04 UTC, Alon Bar-Lev
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alon Bar-Lev (RETIRED) gentoo-dev 2006-10-20 15:27:52 UTC
Hello,

I've written PKCS#11 support to OpenSSH to allow it to work with standard smartcards.

I got some very positive responses from users, and I think it is ready to go into portage.

It works with or without X.509 support, I use it to access gentoo resources... :)

I've tried to touch as little up-stream as I could, so there should be no conflict with normal openssh operation.

More details can be found at:
http://alon.barlev.googlepages.com/openssh-pkcs11

I will be happy if you include this. Putting me a maintainer to every issue caused by this patch.

Best Regards,
Alon Bar-Lev.
Comment 1 Alon Bar-Lev (RETIRED) gentoo-dev 2006-10-20 15:29:06 UTC
Created attachment 100108 [details, diff]
openssh-4.4_p1-r4.ebuild.diff
Comment 2 SpanKY gentoo-dev 2006-10-21 00:06:28 UTC
i'd like to cut down on openssh patches, not expand ... have you tried submitting this upstream ?
Comment 3 Alon Bar-Lev (RETIRED) gentoo-dev 2006-10-21 00:53:39 UTC
Yes.
Damien Miller is very interested in this one, but he had no time (the last year) to review it properly.

It is important patch since it allows OpenSSH to work with almost all smartcards, since almost all support PKCS#11 interface. It even make the use of OpenSC safer, by not remembering the PIN if card is removed, and prompt the user for card insert and removal (If you use OpenSC PKCS#11).

The code used here is the same as I've merged into OpenVPN, Upcoming KDE-QCA, my recent gnupg-pkcs11-scd.

X509 patch is also very important one, but OpenSSH community have no plans to integrate it... PKCS#11 and X509 enabled OpenSSH is very powerful!

Please consider adding, I will handle all defects resulting this change.
Comment 4 Alon Bar-Lev (RETIRED) gentoo-dev 2006-10-25 08:22:15 UTC
Hello SpanKY,

I see you re-added SecurID patches.
SecurID is not really a smartcard, so adding this for smartcard USE is not really correct.

There is a difference between the internal OpenSC support of OpenSSH, which can be called smartcard, although not generic as the PKCS#11 support I introduce, and a password generator such as SecurID.

Please consider adding a different use flag for SecurID patch.

Thanks!
Comment 5 SpanKY gentoo-dev 2006-12-29 18:03:17 UTC
i poked through your patch and looks like there are a few logic quirks in the configure script

ssh_pkcs11_x509 is only defined, not used

SSH_PKCS11_X509_DISABLED depends only on ssh_x509, not ssh_x509 and ssh_pkcs11
Comment 6 Alon Bar-Lev (RETIRED) gentoo-dev 2006-12-30 02:46:49 UTC
Thanks for looking into it.

ssh_pkcs11_x509 is defined so you can test in other patches if PKCS#11 support exists or not. So it meant to be used by others.
I had this problem when I tried to detect if x509 patch was applied. I asked Roumen to put such for his too.

Regarding SSH_PKCS11_X509_DISABLED, it is used only if PKCS#11 is enabled... But I will modify my code to test for if PKCS#11 is also enabled.

I am working on releasing pkcs11-helper as a standalone library as part of OpenSC
http://www.opensc-project.org/pkcs11-helper/

I will release it soon, it will make this patch much smaller, also it will be used by OpenVPN, qca-pkcs11 and gnupg-pkcs11-scd and I am wokring with others.

Regards,
Comment 7 SpanKY gentoo-dev 2006-12-30 03:35:27 UTC
ok, lemme know when you have the newer/smaller one done, and i'll merge that into our tree
Comment 8 Alon Bar-Lev (RETIRED) gentoo-dev 2007-01-05 08:04:57 UTC
Created attachment 105538 [details, diff]
openssh-4.5_p1.ebuild.diff

Hi!
Here is the latest version.
It is much more smaller, since it depends on pkcs11-helper.
Regards,
Comment 9 SpanKY gentoo-dev 2007-01-06 10:20:30 UTC
it all looks fine except for the change to ssh-agent.c ... why are these hunks needed:
@@ -1064,7 +1234,7 @@ main(int ac, char **av)
            s_flag++;
            break;
        case 'd':
-           if (d_flag)
+           if (d_flag > 3)
                usage();
            d_flag++;
            break;
@@ -1167,7 +1337,7 @@ main(int ac, char **av)
     * the socket data.  The child continues as the authentication agent.
     */
    if (d_flag) {
-       log_init(__progname, SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 1);
+       log_init(__progname, SYSLOG_LEVEL_DEBUG1+d_flag-1, SYSLOG_FACILITY_AUTH, 1);
        format = c_flag ? "setenv %s %s;\n" : "%s=%s; export %s;\n";
        printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
            SSH_AUTHSOCKET_ENV_NAME);
Comment 10 Alon Bar-Lev (RETIRED) gentoo-dev 2007-01-06 10:25:14 UTC
(In reply to comment #9)
> it all looks fine except for the change to ssh-agent.c ... why are
> these hunks needed:

Thank you again for reviewing!

This is needed because there is no way to turn on debugging level in current implementation of ssh-agent... (Specifying -d -d -d)

Because I am adding a new functionality I need a better logging...

This was taken from ssh it-self and do not break current implementation.
Comment 11 Wolfram Schlich (RETIRED) gentoo-dev 2007-08-17 18:55:41 UTC
vapier, please either move the SecurID patch to USE=securid or similar (NOT USE=smartcard) or just remove the SecurID patch from our openssh ebuilds.
I am currently unable to use OpenSC support with the latest openssh ebuilds.
Thanks!
Comment 12 SpanKY gentoo-dev 2007-09-29 07:25:58 UTC
got an updated version for 4.7_p1 ?
Comment 13 Alon Bar-Lev (RETIRED) gentoo-dev 2007-09-29 08:31:18 UTC
Created attachment 132152 [details, diff]
openssh-4.7_p1-r1.ebuild.diff

Sure!
But I having trouble with keywording the pkcs11-helper at bug#160285.
I think you can complete the missing keywords... :)
Next, I need to start stabilization cycle... But nobody can estimate how long these cycles takes at Gentoo dimention.
Comment 14 Alon Bar-Lev (RETIRED) gentoo-dev 2007-09-30 08:27:23 UTC
Created attachment 132218 [details, diff]
openssh-4.7_p1-r2.ebuild.diff
Comment 15 Alon Bar-Lev (RETIRED) gentoo-dev 2008-01-19 18:24:24 UTC
Created attachment 141317 [details, diff]
openssh-4.7_p1-r3.ebuild.diff
Comment 16 Alon Bar-Lev (RETIRED) gentoo-dev 2008-03-21 21:38:30 UTC
Created attachment 146787 [details, diff]
openssh-4.7_p1-r20.ebuild.diff
Comment 17 Alon Bar-Lev (RETIRED) gentoo-dev 2008-04-02 17:07:37 UTC
Created attachment 148108 [details, diff]
openssh-4.9_p1.ebuild.diff
Comment 18 SpanKY gentoo-dev 2008-04-02 21:04:52 UTC
Comment on attachment 148108 [details, diff]
openssh-4.9_p1.ebuild.diff

this bug is about pkcs11 only ... keep x509 and anything else out of it
Comment 19 SpanKY gentoo-dev 2008-04-02 21:09:33 UTC
also, the pks pkg needs to go stable before i'll add it to openssh depend
Comment 20 Alon Bar-Lev (RETIRED) gentoo-dev 2008-04-05 07:50:15 UTC
Created attachment 148710 [details, diff]
openssh-5.0_p1.ebuild.diff

Hi!
Someone added pkcs11-helper dependency for openssh in portage.
This should be removed as long as USE flag is not added.
Thanks!
Comment 21 SpanKY gentoo-dev 2008-04-06 22:44:27 UTC
hrm, it got added by accident while testing
Comment 22 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2008-12-07 02:40:34 UTC
Alon: want to update this for openssh-5.1 assuming that your upstream patches are still good?
Comment 23 Alon Bar-Lev 2008-12-07 05:45:28 UTC
Created attachment 174528 [details, diff]
openssh-5.1_p1-r2.ebuild.diff

Sure.
Comment 24 SpanKY gentoo-dev 2008-12-07 20:22:29 UTC
the only issue i see is the EPATCH_OPTS ... why do you need to force -p1 ?
Comment 25 Alon Bar-Lev 2008-12-08 05:52:25 UTC
-p1 is forced because the patch adds some new files, if I don't use this, it will create the first path component for the files located in the root.
Is there any other solution?
Comment 26 SpanKY gentoo-dev 2008-12-25 22:25:37 UTC
no that's fine ... next time i get around to a revbump, i'll add the patchset (or whoever revbumps openssh next time)

i'm assuming you've opened standard bugs upstream to try and get it merged
Comment 27 Alon Bar-Lev 2008-12-26 05:50:58 UTC
Yes, I opened a bug for this [1].

As for any new feature that does not come from core developers, no exiting news.

Upstream wish to add a feature for multi-agent into openssh, but without modifying the protocol to be more generic. This has two main issues:

1. Users that do not wish to use the agent or cannot (console mode) will not be able to use the new features.

2. The current protocol forces the tools to understand each agent command, so new commands and features cannot be used.

The OpenSC project will soon drop the support for libopensc which is used only by this application. All other known applications moved to PKCS#11.

So I guess I will maintain this as external patch for a while.

Thanks!

[1] https://bugzilla.mindrot.org/show_bug.cgi?id=1371
Comment 28 SpanKY gentoo-dev 2009-02-24 17:01:46 UTC
added to openssh-5.2_p1, but disabled since your patchset doesnt apply :)
Comment 29 Alon Bar-Lev 2009-02-24 18:04:58 UTC
Created attachment 183040 [details, diff]
openssh-5.2_p1.ebuild.diff

Thank you!!
I rebased.
Comment 30 SpanKY gentoo-dev 2009-02-25 18:06:14 UTC
why not build the pkcs files conditionally in the Makefile ?  then you wouldnt need to wrap the files in '#ifdef ENABLE_PKCS11' ...

some functions (like _pkcs11_ssh_pin_prompt) calls strlen() on the same unchanged string.  gcc will not optimize that away, so you should cache it yourself:
size_t phraselen;
...
phraselen = strlen(passphrase);

free() will gladly accept NULL pointers, so there is no need for constructs like these:
if (foo != NULL)
    free(foo);
Comment 31 Alon Bar-Lev 2009-02-25 18:16:00 UTC
Thank you for your feedback.

(In reply to comment #30)
> why not build the pkcs files conditionally in the Makefile ?  then you wouldnt
> need to wrap the files in '#ifdef ENABLE_PKCS11' ...

As no other component is conditioned in the Makefile, I thought it is a bad idea to break the convension used. I've duplicated the SMARTCARD usage.

> some functions (like _pkcs11_ssh_pin_prompt) calls strlen() on the same
> unchanged string.  gcc will not optimize that away, so you should cache it
> yourself:
> size_t phraselen;
> ...
> phraselen = strlen(passphrase);

This saldom happens... So optimization was not taken into account.
I will modify this next time I touch the code.

> free() will gladly accept NULL pointers, so there is no need for constructs
> like these:
> if (foo != NULL)
>     free(foo);

As far as I know it is not the case in every compiler.
Also upstream is using xfree wrapper, and if you look at xmalloc.c you see the following:

void
xfree(void *ptr)
{
        if (ptr == NULL)
                fatal("xfree: NULL pointer given as argument");
        free(ptr);
}

Thanks!
Comment 32 SpanKY gentoo-dev 2009-02-25 21:30:04 UTC
free(NULL) is a C library issue, not compiler.  POSIX requires free(NULL) to work.  even the gnulib guys (who are portable to every friggin platform) requires free(NULL) to work and it hasnt been an issue for them yet.

that said, i can see why the openssh guys would mark free(NULL) as a bug as they see it as a potential indicator that other pieces of code are broken somehow.