|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/authfd.c.nss-keys openssh-5.2p1/authfd.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/authfd.c.nss-keys 2006-09-01 07:38:36.000000000 +0200
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/authfd.c 2009-03-10 03:51:55.866208145 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -626,6 +626,45 @@ ssh_update_card(AuthenticationConnection
|
|
Jan F. Chadima |
a3ba41 |
return decode_reply(type);
|
|
Tomáš Mráz |
c9833c |
}
|
|
Tomáš Mráz |
c9833c |
|
|
Jan F. Chadima |
a3ba41 |
+int
|
|
Jan F. Chadima |
a3ba41 |
+ssh_update_nss_key(AuthenticationConnection *auth, int add,
|
|
Jan F. Chadima |
a3ba41 |
+ const char *tokenname, const char *keyname,
|
|
Jan F. Chadima |
a3ba41 |
+ const char *pass, u_int life, u_int confirm)
|
|
Tomáš Mráz |
c9833c |
+{
|
|
Jan F. Chadima |
a3ba41 |
+ Buffer msg;
|
|
Jan F. Chadima |
a3ba41 |
+ int type, constrained = (life || confirm);
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if (add) {
|
|
Jan F. Chadima |
a3ba41 |
+ type = constrained ?
|
|
Jan F. Chadima |
a3ba41 |
+ SSH_AGENTC_ADD_NSS_KEY_CONSTRAINED :
|
|
Jan F. Chadima |
a3ba41 |
+ SSH_AGENTC_ADD_NSS_KEY;
|
|
Jan F. Chadima |
a3ba41 |
+ } else
|
|
Jan F. Chadima |
a3ba41 |
+ type = SSH_AGENTC_REMOVE_NSS_KEY;
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_init(&msg;;
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_char(&msg, type);
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_cstring(&msg, tokenname);
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_cstring(&msg, keyname);
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_cstring(&msg, pass);
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if (constrained) {
|
|
Jan F. Chadima |
a3ba41 |
+ if (life != 0) {
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_char(&msg, SSH_AGENT_CONSTRAIN_LIFETIME);
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_int(&msg, life);
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ if (confirm != 0)
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_char(&msg, SSH_AGENT_CONSTRAIN_CONFIRM);
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if (ssh_request_reply(auth, &msg, &msg) == 0) {
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_free(&msg;;
|
|
Jan F. Chadima |
a3ba41 |
+ return 0;
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ type = buffer_get_char(&msg;;
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_free(&msg;;
|
|
Jan F. Chadima |
a3ba41 |
+ return decode_reply(type);
|
|
Tomáš Mráz |
c9833c |
+}
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
/*
|
|
Jan F. Chadima |
a3ba41 |
* Removes all identities from the agent. This call is not meant to be used
|
|
Jan F. Chadima |
a3ba41 |
* by normal applications.
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/authfd.h.nss-keys openssh-5.2p1/authfd.h
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/authfd.h.nss-keys 2006-08-05 04:39:39.000000000 +0200
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/authfd.h 2009-03-10 03:51:55.847449129 +0100
|
|
Tomáš Mráz |
c3274c |
@@ -49,6 +49,12 @@
|
|
Tomáš Mráz |
c3274c |
#define SSH2_AGENTC_ADD_ID_CONSTRAINED 25
|
|
Tomáš Mráz |
c3274c |
#define SSH_AGENTC_ADD_SMARTCARD_KEY_CONSTRAINED 26
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
+/* nss */
|
|
Tomáš Mráz |
c3274c |
+#define SSH_AGENTC_ADD_NSS_KEY 30
|
|
Tomáš Mráz |
c3274c |
+#define SSH_AGENTC_REMOVE_NSS_KEY 31
|
|
Tomáš Mráz |
c3274c |
+#define SSH_AGENTC_ADD_NSS_KEY_CONSTRAINED 32
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
#define SSH_AGENT_CONSTRAIN_LIFETIME 1
|
|
Tomáš Mráz |
c3274c |
#define SSH_AGENT_CONSTRAIN_CONFIRM 2
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
@@ -83,6 +89,8 @@ int ssh_remove_all_identities(Authentic
|
|
Tomáš Mráz |
c3274c |
int ssh_lock_agent(AuthenticationConnection *, int, const char *);
|
|
Tomáš Mráz |
c3274c |
int ssh_update_card(AuthenticationConnection *, int, const char *,
|
|
Tomáš Mráz |
c3274c |
const char *, u_int, u_int);
|
|
Tomáš Mráz |
c3274c |
+int ssh_update_nss_key(AuthenticationConnection *, int, const char *,
|
|
Tomáš Mráz |
c3274c |
+ const char *, const char *, u_int, u_int);
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
int
|
|
Tomáš Mráz |
c3274c |
ssh_decrypt_challenge(AuthenticationConnection *, Key *, BIGNUM *, u_char[16],
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/configure.ac.nss-keys openssh-5.2p1/configure.ac
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/configure.ac.nss-keys 2009-03-10 03:51:55.285821039 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/configure.ac 2009-03-10 03:51:55.850215090 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -3462,6 +3462,20 @@ AC_ARG_WITH(kerberos5,
|
|
Tomáš Mráz |
9e5c6e |
]
|
|
Tomáš Mráz |
c9833c |
)
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
+# Check whether user wants NSS support
|
|
Tomáš Mráz |
c3274c |
+LIBNSS_MSG="no"
|
|
Tomáš Mráz |
c3274c |
+AC_ARG_WITH(nss,
|
|
Tomáš Mráz |
c3274c |
+ [ --with-nss Enable NSS support],
|
|
Tomáš Mráz |
c3274c |
+ [ if test "x$withval" != "xno" ; then
|
|
Tomáš Mráz |
c3274c |
+ AC_DEFINE(HAVE_LIBNSS,1,[Define if you want NSS support.])
|
|
Tomáš Mráz |
c3274c |
+ LIBNSS_MSG="yes"
|
|
Tomáš Mráz |
c3274c |
+ CPPFLAGS="$CPPFLAGS -I/usr/include/nss3 -I/usr/include/nspr4"
|
|
Tomáš Mráz |
0092bb |
+ AC_CHECK_HEADERS(pk11pub.h)
|
|
Tomáš Mráz |
c9833c |
+ LIBS="$LIBS -lnss3"
|
|
Tomáš Mráz |
c3274c |
+ fi
|
|
Tomáš Mráz |
c3274c |
+ ])
|
|
Tomáš Mráz |
c3274c |
+AC_SUBST(LIBNSS)
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
9e5c6e |
# Looking for programs, paths and files
|
|
Tomáš Mráz |
9e5c6e |
|
|
Tomáš Mráz |
9e5c6e |
PRIVSEP_PATH=/var/empty
|
|
Jan F. Chadima |
a3ba41 |
@@ -4189,6 +4203,7 @@ echo " TCP Wrappers support
|
|
Tomáš Mráz |
9e5c6e |
echo " MD5 password support: $MD5_MSG"
|
|
Tomáš Mráz |
9e5c6e |
echo " libedit support: $LIBEDIT_MSG"
|
|
Tomáš Mráz |
9e5c6e |
echo " Solaris process contract support: $SPC_MSG"
|
|
Tomáš Mráz |
c3274c |
+echo " NSS support: $LIBNSS_MSG"
|
|
Tomáš Mráz |
9e5c6e |
echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
|
|
Tomáš Mráz |
9e5c6e |
echo " Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
|
|
Tomáš Mráz |
9e5c6e |
echo " BSD Auth support: $BSD_AUTH_MSG"
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/key.c.nss-keys openssh-5.2p1/key.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/key.c.nss-keys 2008-11-03 09:24:17.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/key.c 2009-03-10 03:51:55.840226575 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -96,6 +96,54 @@ key_new(int type)
|
|
Jan F. Chadima |
a3ba41 |
return k;
|
|
Jan F. Chadima |
a3ba41 |
}
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+Key *
|
|
Jan F. Chadima |
a3ba41 |
+key_new_nss(int type)
|
|
Jan F. Chadima |
a3ba41 |
+{
|
|
Jan F. Chadima |
a3ba41 |
+ Key *k = key_new(type);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ k->nss = xcalloc(1, sizeof(*k->nss));
|
|
Jan F. Chadima |
a3ba41 |
+ k->flags = KEY_FLAG_EXT | KEY_FLAG_NSS;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ return k;
|
|
Jan F. Chadima |
a3ba41 |
+}
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+Key *
|
|
Jan F. Chadima |
a3ba41 |
+key_new_nss_copy(int type, const Key *c)
|
|
Jan F. Chadima |
a3ba41 |
+{
|
|
Jan F. Chadima |
a3ba41 |
+ Key *k = key_new_nss(type);
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ switch (k->type) {
|
|
Jan F. Chadima |
a3ba41 |
+ case KEY_RSA:
|
|
Jan F. Chadima |
a3ba41 |
+ if ((BN_copy(k->rsa->n, c->rsa->n) == NULL) ||
|
|
Jan F. Chadima |
a3ba41 |
+ (BN_copy(k->rsa->e, c->rsa->e) == NULL))
|
|
Jan F. Chadima |
a3ba41 |
+ fatal("key_new_nss_copy: BN_copy failed");
|
|
Jan F. Chadima |
a3ba41 |
+ break;
|
|
Jan F. Chadima |
a3ba41 |
+ case KEY_DSA:
|
|
Jan F. Chadima |
a3ba41 |
+ if ((BN_copy(k->dsa->p, c->rsa->p) == NULL) ||
|
|
Jan F. Chadima |
a3ba41 |
+ (BN_copy(k->dsa->q, c->dsa->q) == NULL) ||
|
|
Jan F. Chadima |
a3ba41 |
+ (BN_copy(k->dsa->g, c->dsa->g) == NULL) ||
|
|
Jan F. Chadima |
a3ba41 |
+ (BN_copy(k->dsa->pub_key, c->dsa->pub_key) == NULL))
|
|
Jan F. Chadima |
a3ba41 |
+ fatal("key_new_nss_copy: BN_copy failed");
|
|
Jan F. Chadima |
a3ba41 |
+ break;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ k->nss->privk = SECKEY_CopyPrivateKey(c->nss->privk);
|
|
Jan F. Chadima |
a3ba41 |
+ if (k->nss->privk == NULL)
|
|
Jan F. Chadima |
a3ba41 |
+ fatal("key_new_nss_copy: SECKEY_CopyPrivateKey failed");
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ k->nss->pubk = SECKEY_CopyPublicKey(c->nss->pubk);
|
|
Jan F. Chadima |
a3ba41 |
+ if (k->nss->pubk == NULL)
|
|
Jan F. Chadima |
a3ba41 |
+ fatal("key_new_nss_copy: SECKEY_CopyPublicKey failed");
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if (c->nss->privk->wincx)
|
|
Jan F. Chadima |
a3ba41 |
+ k->nss->privk->wincx = xstrdup(c->nss->privk->wincx);
|
|
Tomáš Mráz |
c9833c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ return k;
|
|
Jan F. Chadima |
a3ba41 |
+}
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
Key *
|
|
Jan F. Chadima |
a3ba41 |
key_new_private(int type)
|
|
Jan F. Chadima |
a3ba41 |
{
|
|
Jan F. Chadima |
a3ba41 |
@@ -151,6 +199,19 @@ key_free(Key *k)
|
|
Jan F. Chadima |
a3ba41 |
fatal("key_free: bad key type %d", k->type);
|
|
Jan F. Chadima |
a3ba41 |
break;
|
|
Jan F. Chadima |
a3ba41 |
}
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ if (k->flags & KEY_FLAG_NSS) {
|
|
Jan F. Chadima |
a3ba41 |
+ if (k->nss->privk != NULL && k->nss->privk->wincx != NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ memset(k->nss->privk->wincx, 0,
|
|
Jan F. Chadima |
a3ba41 |
+ strlen(k->nss->privk->wincx));
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(k->nss->privk->wincx);
|
|
Jan F. Chadima |
a3ba41 |
+ k->nss->privk->wincx = NULL;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ SECKEY_DestroyPrivateKey(k->nss->privk);
|
|
Jan F. Chadima |
a3ba41 |
+ SECKEY_DestroyPublicKey(k->nss->pubk);
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(k->nss);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
xfree(k);
|
|
Jan F. Chadima |
a3ba41 |
}
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/key.h.nss-keys openssh-5.2p1/key.h
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/key.h.nss-keys 2008-06-12 20:40:35.000000000 +0200
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/key.h 2009-03-10 03:51:55.925279322 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -29,11 +29,17 @@
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/rsa.h>
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/dsa.h>
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+#include <nss.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <keyhi.h>
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
typedef struct Key Key;
|
|
Jan F. Chadima |
a3ba41 |
enum types {
|
|
Jan F. Chadima |
a3ba41 |
KEY_RSA1,
|
|
Jan F. Chadima |
a3ba41 |
KEY_RSA,
|
|
Jan F. Chadima |
a3ba41 |
KEY_DSA,
|
|
Jan F. Chadima |
a3ba41 |
+ KEY_NSS,
|
|
Jan F. Chadima |
a3ba41 |
KEY_UNSPEC
|
|
Jan F. Chadima |
a3ba41 |
};
|
|
Jan F. Chadima |
a3ba41 |
enum fp_type {
|
|
Jan F. Chadima |
a3ba41 |
@@ -48,16 +54,30 @@ enum fp_rep {
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
/* key is stored in external hardware */
|
|
Jan F. Chadima |
a3ba41 |
#define KEY_FLAG_EXT 0x0001
|
|
Jan F. Chadima |
a3ba41 |
+#define KEY_FLAG_NSS 0x0002
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+typedef struct NSSKey NSSKey;
|
|
Jan F. Chadima |
a3ba41 |
+struct NSSKey {
|
|
Jan F. Chadima |
a3ba41 |
+ SECKEYPrivateKey *privk;
|
|
Jan F. Chadima |
a3ba41 |
+ SECKEYPublicKey *pubk;
|
|
Jan F. Chadima |
a3ba41 |
+};
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Tomáš Mráz |
c3274c |
|
|
Jan F. Chadima |
a3ba41 |
struct Key {
|
|
Jan F. Chadima |
a3ba41 |
int type;
|
|
Jan F. Chadima |
a3ba41 |
int flags;
|
|
Jan F. Chadima |
a3ba41 |
RSA *rsa;
|
|
Jan F. Chadima |
a3ba41 |
DSA *dsa;
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ NSSKey *nss;
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
};
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
Key *key_new(int);
|
|
Jan F. Chadima |
a3ba41 |
Key *key_new_private(int);
|
|
Jan F. Chadima |
a3ba41 |
+Key *key_new_nss(int);
|
|
Jan F. Chadima |
a3ba41 |
+Key *key_new_nss_copy(int, const Key *);
|
|
Jan F. Chadima |
a3ba41 |
void key_free(Key *);
|
|
Jan F. Chadima |
a3ba41 |
Key *key_demote(const Key *);
|
|
Jan F. Chadima |
a3ba41 |
int key_equal(const Key *, const Key *);
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/Makefile.in.nss-keys openssh-5.2p1/Makefile.in
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/Makefile.in.nss-keys 2008-11-05 06:20:46.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/Makefile.in 2009-03-10 03:51:56.222702935 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -71,7 +71,7 @@ LIBSSH_OBJS=acss.o authfd.o authfile.o b
|
|
Jan F. Chadima |
a3ba41 |
atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \
|
|
Jan F. Chadima |
a3ba41 |
monitor_fdpass.o rijndael.o ssh-dss.o ssh-rsa.o dh.o kexdh.o \
|
|
Jan F. Chadima |
a3ba41 |
kexgex.o kexdhc.o kexgexc.o scard.o msg.o progressmeter.o dns.o \
|
|
Jan F. Chadima |
a3ba41 |
- entropy.o scard-opensc.o gss-genr.o umac.o jpake.o schnorr.o
|
|
Jan F. Chadima |
a3ba41 |
+ entropy.o scard-opensc.o gss-genr.o umac.o jpake.o schnorr.o nsskeys.o
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
|
|
Jan F. Chadima |
a3ba41 |
sshconnect.o sshconnect1.o sshconnect2.o mux.o
|
|
Jan F. Chadima |
a3ba41 |
@@ -134,28 +134,28 @@ libssh.a: $(LIBSSH_OBJS)
|
|
Jan F. Chadima |
a3ba41 |
$(RANLIB) $@
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS)
|
|
Jan F. Chadima |
a3ba41 |
- $(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
+ $(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
sshd$(EXEEXT): libssh.a $(LIBCOMPAT) $(SSHDOBJS)
|
|
Jan F. Chadima |
a3ba41 |
- $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
+ $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) -lfipscheck $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o
|
|
Jan F. Chadima |
a3ba41 |
$(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o
|
|
Jan F. Chadima |
a3ba41 |
- $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
+ $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
ssh-agent$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-agent.o
|
|
Jan F. Chadima |
a3ba41 |
- $(LD) -o $@ ssh-agent.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
+ $(LD) -o $@ ssh-agent.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
ssh-keygen$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keygen.o
|
|
Jan F. Chadima |
a3ba41 |
- $(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
+ $(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
ssh-keysign$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keysign.o
|
|
Jan F. Chadima |
a3ba41 |
- $(LD) -o $@ ssh-keysign.o readconf.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
+ $(LD) -o $@ ssh-keysign.o readconf.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o
|
|
Jan F. Chadima |
a3ba41 |
- $(LD) -o $@ ssh-keyscan.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
+ $(LD) -o $@ ssh-keyscan.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o sftp-server-main.o
|
|
Jan F. Chadima |
a3ba41 |
$(LD) -o $@ sftp-server.o sftp-common.o sftp-server-main.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
|
|
Jan F. Chadima |
a3ba41 |
diff -up /dev/null openssh-5.2p1/nsskeys.c
|
|
Jan F. Chadima |
a3ba41 |
--- /dev/null 2009-03-09 14:26:59.819020596 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/nsskeys.c 2009-03-10 03:51:56.251363837 +0100
|
|
Tomáš Mráz |
c3274c |
@@ -0,0 +1,327 @@
|
|
Tomáš Mráz |
c3274c |
+/*
|
|
Tomáš Mráz |
c3274c |
+ * Copyright (c) 2001 Markus Friedl. All rights reserved.
|
|
Tomáš Mráz |
c3274c |
+ * Copyright (c) 2007 Red Hat, Inc. All rights reserved.
|
|
Tomáš Mráz |
c3274c |
+ *
|
|
Tomáš Mráz |
c3274c |
+ * Redistribution and use in source and binary forms, with or without
|
|
Tomáš Mráz |
c3274c |
+ * modification, are permitted provided that the following conditions
|
|
Tomáš Mráz |
c3274c |
+ * are met:
|
|
Tomáš Mráz |
c3274c |
+ * 1. Redistributions of source code must retain the above copyright
|
|
Tomáš Mráz |
c3274c |
+ * notice, this list of conditions and the following disclaimer.
|
|
Tomáš Mráz |
c3274c |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
Tomáš Mráz |
c3274c |
+ * notice, this list of conditions and the following disclaimer in the
|
|
Tomáš Mráz |
c3274c |
+ * documentation and/or other materials provided with the distribution.
|
|
Tomáš Mráz |
c3274c |
+ *
|
|
Tomáš Mráz |
c3274c |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
Tomáš Mráz |
c3274c |
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
Tomáš Mráz |
c3274c |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
Tomáš Mráz |
c3274c |
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Tomáš Mráz |
c3274c |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
Tomáš Mráz |
c3274c |
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Tomáš Mráz |
c3274c |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Tomáš Mráz |
c3274c |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Tomáš Mráz |
c3274c |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
Tomáš Mráz |
c3274c |
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Tomáš Mráz |
c3274c |
+ */
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#include "includes.h"
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#include <sys/types.h>
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#include <stdarg.h>
|
|
Tomáš Mráz |
c3274c |
+#include <string.h>
|
|
Tomáš Mráz |
c3274c |
+#include <unistd.h>
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#include <openssl/evp.h>
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#include <nss.h>
|
|
Tomáš Mráz |
c3274c |
+#include <keyhi.h>
|
|
Tomáš Mráz |
c3274c |
+#include <pk11pub.h>
|
|
Tomáš Mráz |
c3274c |
+#include <cert.h>
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#include "xmalloc.h"
|
|
Tomáš Mráz |
c3274c |
+#include "key.h"
|
|
Tomáš Mráz |
c3274c |
+#include "log.h"
|
|
Tomáš Mráz |
c3274c |
+#include "misc.h"
|
|
Tomáš Mráz |
c3274c |
+#include "nsskeys.h"
|
|
Tomáš Mráz |
c3274c |
+#include "pathnames.h"
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+static char *
|
|
Tomáš Mráz |
c3274c |
+password_cb(PK11SlotInfo *slot, PRBool retry, void *arg)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ char *password = arg;
|
|
Tomáš Mráz |
c3274c |
+ if (retry || password == NULL)
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ return PL_strdup(password);
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+int
|
|
Tomáš Mráz |
c3274c |
+nss_init(PK11PasswordFunc pwfn)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ char *dbpath;
|
|
Tomáš Mráz |
c3274c |
+ char buf[MAXPATHLEN];
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (NSS_IsInitialized())
|
|
Tomáš Mráz |
c3274c |
+ return 0;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if ((dbpath=getenv("NSS_DB_PATH")) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ struct passwd *pw;
|
|
Tomáš Mráz |
c3274c |
+ if ((pw = getpwuid(getuid())) == NULL ||
|
|
Tomáš Mráz |
c3274c |
+ pw->pw_dir == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ return -1;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ snprintf(buf, sizeof(buf), "%s/%s", pw->pw_dir,
|
|
Tomáš Mráz |
c3274c |
+ _PATH_SSH_USER_DIR);
|
|
Tomáš Mráz |
c3274c |
+ dbpath = buf;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (NSS_Init(dbpath) != SECSuccess)
|
|
Tomáš Mráz |
c3274c |
+ return -1;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (pwfn == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ pwfn = password_cb;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ PK11_SetPasswordFunc(pwfn);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ return 0;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+static Key *
|
|
Tomáš Mráz |
c3274c |
+make_key_from_privkey(SECKEYPrivateKey *privk, char *password)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ Key *k;
|
|
Tomáš Mráz |
c3274c |
+ switch (SECKEY_GetPrivateKeyType(privk)) {
|
|
Tomáš Mráz |
c3274c |
+ case rsaKey:
|
|
Tomáš Mráz |
c3274c |
+ k = key_new_nss(KEY_RSA);
|
|
Tomáš Mráz |
c3274c |
+ break;
|
|
Tomáš Mráz |
c3274c |
+ case dsaKey:
|
|
Tomáš Mráz |
c3274c |
+ k = key_new_nss(KEY_DSA);
|
|
Tomáš Mráz |
c3274c |
+ break;
|
|
Tomáš Mráz |
c3274c |
+ default:
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ k->nss->pubk = SECKEY_ConvertToPublicKey(privk);
|
|
Tomáš Mráz |
c3274c |
+ if (k->nss->pubk != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ k->nss->privk = SECKEY_CopyPrivateKey(privk);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ if (k->nss->privk != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ if (password != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ k->nss->privk->wincx = xstrdup(password);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ return k;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ key_free(k);
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+static Key **
|
|
Tomáš Mráz |
c3274c |
+add_key_to_list(Key *k, Key **keys, size_t *i, size_t *allocated)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ if (*allocated < *i + 2) {
|
|
Tomáš Mráz |
c3274c |
+ *allocated += 16;
|
|
Tomáš Mráz |
c3274c |
+ keys = xrealloc(keys, *allocated, sizeof(k));
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ keys[*i] = k;
|
|
Tomáš Mráz |
c3274c |
+ (*i)++;
|
|
Tomáš Mráz |
c3274c |
+ keys[*i] = NULL;
|
|
Tomáš Mráz |
c3274c |
+ return keys;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+static int
|
|
Tomáš Mráz |
c3274c |
+nss_convert_pubkey(Key *k)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ u_char *n;
|
|
Tomáš Mráz |
c3274c |
+ unsigned int len;
|
|
Tomáš Mráz |
c3274c |
+ char *p;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ switch (k->type) {
|
|
Tomáš Mráz |
c3274c |
+ case KEY_RSA:
|
|
Tomáš Mráz |
c3274c |
+ n = k->nss->pubk->u.rsa.modulus.data;
|
|
Tomáš Mráz |
c3274c |
+ len = k->nss->pubk->u.rsa.modulus.len;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (BN_bin2bn(n, len, k->rsa->n) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ fatal("nss_convert_pubkey: BN_bin2bn failed");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ n = k->nss->pubk->u.rsa.publicExponent.data;
|
|
Tomáš Mráz |
c3274c |
+ len = k->nss->pubk->u.rsa.publicExponent.len;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (BN_bin2bn(n, len, k->rsa->e) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ fatal("nss_convert_pubkey: BN_bin2bn failed");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ break;
|
|
Tomáš Mráz |
c3274c |
+ case KEY_DSA:
|
|
Tomáš Mráz |
c3274c |
+ n = k->nss->pubk->u.dsa.params.prime.data;
|
|
Tomáš Mráz |
c3274c |
+ len = k->nss->pubk->u.dsa.params.prime.len;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (BN_bin2bn(n, len, k->dsa->p) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ fatal("nss_convert_pubkey: BN_bin2bn failed");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ n = k->nss->pubk->u.dsa.params.subPrime.data;
|
|
Tomáš Mráz |
c3274c |
+ len = k->nss->pubk->u.dsa.params.subPrime.len;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (BN_bin2bn(n, len, k->dsa->q) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ fatal("nss_convert_pubkey: BN_bin2bn failed");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ n = k->nss->pubk->u.dsa.params.base.data;
|
|
Tomáš Mráz |
c3274c |
+ len = k->nss->pubk->u.dsa.params.base.len;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (BN_bin2bn(n, len, k->dsa->g) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ fatal("nss_convert_pubkey: BN_bin2bn failed");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ n = k->nss->pubk->u.dsa.publicValue.data;
|
|
Tomáš Mráz |
c3274c |
+ len = k->nss->pubk->u.dsa.publicValue.len;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (BN_bin2bn(n, len, k->dsa->pub_key) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ fatal("nss_convert_pubkey: BN_bin2bn failed");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ break;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ p = key_fingerprint(k, SSH_FP_SHA1, SSH_FP_HEX);
|
|
Jan F. Chadima |
a3ba41 |
+ debug("SHA1 fingerprint %u %s", key_size(k), p);
|
|
Tomáš Mráz |
c3274c |
+ xfree(p);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ return 0;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+static Key **
|
|
Tomáš Mráz |
c3274c |
+nss_find_privkeys(const char *tokenname, const char *keyname,
|
|
Tomáš Mráz |
c3274c |
+ char *password)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ Key *k = NULL;
|
|
Tomáš Mráz |
c3274c |
+ Key **keys = NULL;
|
|
Tomáš Mráz |
c3274c |
+ PK11SlotList *slots;
|
|
Tomáš Mráz |
c3274c |
+ PK11SlotListElement *sle;
|
|
Tomáš Mráz |
c3274c |
+ size_t allocated = 0;
|
|
Tomáš Mráz |
c3274c |
+ size_t i = 0;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if ((slots=PK11_FindSlotsByNames(NULL, NULL, tokenname, PR_TRUE)) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ if (tokenname == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ debug("No NSS token found");
|
|
Tomáš Mráz |
c3274c |
+ } else {
|
|
Tomáš Mráz |
c3274c |
+ debug("NSS token not found: %s", tokenname);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ for (sle = slots->head; sle; sle = sle->next) {
|
|
Tomáš Mráz |
c3274c |
+ SECKEYPrivateKeyList *list;
|
|
Tomáš Mráz |
c3274c |
+ SECKEYPrivateKeyListNode *node;
|
|
Tomáš Mráz |
c3274c |
+ char *tmppass = password;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (PK11_NeedLogin(sle->slot)) {
|
|
Tomáš Mráz |
c3274c |
+ if (password == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ char *prompt;
|
|
Tomáš Mráz |
c3274c |
+ if (asprintf(&prompt, "Enter passphrase for token %s: ",
|
|
Tomáš Mráz |
c3274c |
+ PK11_GetTokenName(sle->slot)) < 0)
|
|
Tomáš Mráz |
c3274c |
+ fatal("password_cb: asprintf failed");
|
|
Tomáš Mráz |
c3274c |
+ tmppass = read_passphrase(prompt, RP_ALLOW_STDIN);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ PK11_Authenticate(sle->slot, PR_TRUE, tmppass);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ debug("Looking for: %s:%s", tokenname, keyname);
|
|
Tomáš Mráz |
c3274c |
+ list = PK11_ListPrivKeysInSlot(sle->slot, (char *)keyname,
|
|
Tomáš Mráz |
c3274c |
+ tmppass);
|
|
Tomáš Mráz |
c3274c |
+ if (list == NULL && keyname != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ char *fooname;
|
|
Tomáš Mráz |
c3274c |
+ /* NSS bug workaround */
|
|
Tomáš Mráz |
c3274c |
+ if (asprintf(&fooname, "%s~", keyname) < 0) {
|
|
Tomáš Mráz |
c3274c |
+ error("nss_find_privkey: asprintf failed");
|
|
Tomáš Mráz |
c3274c |
+ PK11_FreeSlotList(slots);
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ list = PK11_ListPrivKeysInSlot(sle->slot, fooname,
|
|
Tomáš Mráz |
c3274c |
+ tmppass);
|
|
Tomáš Mráz |
c3274c |
+ free(fooname);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ if (list == NULL && keyname != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ CERTCertificate *cert;
|
|
Tomáš Mráz |
c3274c |
+ SECKEYPrivateKey *privk;
|
|
Tomáš Mráz |
c3274c |
+ cert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(),
|
|
Tomáš Mráz |
c3274c |
+ (char *)keyname);
|
|
Tomáš Mráz |
c3274c |
+ if (cert == NULL)
|
|
Tomáš Mráz |
c3274c |
+ goto cleanup;
|
|
Tomáš Mráz |
c3274c |
+ privk = PK11_FindPrivateKeyFromCert(sle->slot, cert, tmppass);
|
|
Tomáš Mráz |
c3274c |
+ CERT_DestroyCertificate(cert);
|
|
Tomáš Mráz |
c3274c |
+ if (privk == NULL)
|
|
Tomáš Mráz |
c3274c |
+ goto cleanup;
|
|
Tomáš Mráz |
c3274c |
+ if ((k=make_key_from_privkey(privk, tmppass)) != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ nss_convert_pubkey(k);
|
|
Tomáš Mráz |
c3274c |
+ keys = add_key_to_list(k, keys, &i, &allocated);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ SECKEY_DestroyPrivateKey(privk);
|
|
Tomáš Mráz |
c3274c |
+ } else {
|
|
Tomáš Mráz |
c3274c |
+ if (list == NULL)
|
|
Tomáš Mráz |
c3274c |
+ goto cleanup;
|
|
Tomáš Mráz |
c3274c |
+ for (node=PRIVKEY_LIST_HEAD(list); !PRIVKEY_LIST_END(node, list);
|
|
Tomáš Mráz |
c3274c |
+ node=PRIVKEY_LIST_NEXT(node))
|
|
Tomáš Mráz |
c3274c |
+ if ((k=make_key_from_privkey(node->key, tmppass)) != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ nss_convert_pubkey(k);
|
|
Tomáš Mráz |
c3274c |
+ keys = add_key_to_list(k, keys, &i, &allocated);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ SECKEY_DestroyPrivateKeyList(list);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+cleanup:
|
|
Tomáš Mráz |
c3274c |
+ if (password == NULL && tmppass != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ memset(tmppass, 0, strlen(tmppass));
|
|
Tomáš Mráz |
c3274c |
+ xfree(tmppass);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ PK11_FreeSlotList(slots);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ return keys;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+Key **
|
|
Tomáš Mráz |
c3274c |
+nss_get_keys(const char *tokenname, const char *keyname,
|
|
Tomáš Mráz |
c3274c |
+ char *password)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ Key **keys;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (nss_init(NULL) == -1) {
|
|
Tomáš Mráz |
c3274c |
+ error("Failed to initialize NSS library");
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ keys = nss_find_privkeys(tokenname, keyname, password);
|
|
Tomáš Mráz |
c3274c |
+ if (keys == NULL && keyname != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ error("Cannot find key in nss, token removed");
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+#if 0
|
|
Tomáš Mráz |
c3274c |
+ keys = xcalloc(3, sizeof(Key *));
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (k->type == KEY_RSA) {
|
|
Tomáš Mráz |
c3274c |
+ n = key_new_nss_copy(KEY_RSA1, k);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ keys[0] = n;
|
|
Tomáš Mráz |
c3274c |
+ keys[1] = k;
|
|
Tomáš Mráz |
c3274c |
+ keys[2] = NULL;
|
|
Tomáš Mráz |
c3274c |
+ } else {
|
|
Tomáš Mráz |
c3274c |
+ keys[0] = k;
|
|
Tomáš Mráz |
c3274c |
+ keys[1] = NULL;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
+ return keys;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+char *
|
|
Tomáš Mráz |
c3274c |
+nss_get_key_label(Key *key)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ char *label, *nickname;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ nickname = PK11_GetPrivateKeyNickname(key->nss->privk);
|
|
Tomáš Mráz |
c3274c |
+ label = xstrdup(nickname);
|
|
Tomáš Mráz |
c3274c |
+ PORT_Free(nickname);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ return label;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#endif /* HAVE_LIBNSS */
|
|
Jan F. Chadima |
a3ba41 |
diff -up /dev/null openssh-5.2p1/nsskeys.h
|
|
Jan F. Chadima |
a3ba41 |
--- /dev/null 2009-03-09 14:26:59.819020596 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/nsskeys.h 2009-03-10 03:51:55.908243644 +0100
|
|
Tomáš Mráz |
c3274c |
@@ -0,0 +1,39 @@
|
|
Tomáš Mráz |
c3274c |
+/*
|
|
Tomáš Mráz |
c3274c |
+ * Copyright (c) 2001 Markus Friedl. All rights reserved.
|
|
Tomáš Mráz |
c3274c |
+ * Copyright (c) 2007 Red Hat, Inc. All rights reserved.
|
|
Tomáš Mráz |
c3274c |
+ *
|
|
Tomáš Mráz |
c3274c |
+ * Redistribution and use in source and binary forms, with or without
|
|
Tomáš Mráz |
c3274c |
+ * modification, are permitted provided that the following conditions
|
|
Tomáš Mráz |
c3274c |
+ * are met:
|
|
Tomáš Mráz |
c3274c |
+ * 1. Redistributions of source code must retain the above copyright
|
|
Tomáš Mráz |
c3274c |
+ * notice, this list of conditions and the following disclaimer.
|
|
Tomáš Mráz |
c3274c |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
Tomáš Mráz |
c3274c |
+ * notice, this list of conditions and the following disclaimer in the
|
|
Tomáš Mráz |
c3274c |
+ * documentation and/or other materials provided with the distribution.
|
|
Tomáš Mráz |
c3274c |
+ *
|
|
Tomáš Mráz |
c3274c |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
Tomáš Mráz |
c3274c |
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
Tomáš Mráz |
c3274c |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
Tomáš Mráz |
c3274c |
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Tomáš Mráz |
c3274c |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
Tomáš Mráz |
c3274c |
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Tomáš Mráz |
c3274c |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Tomáš Mráz |
c3274c |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Tomáš Mráz |
c3274c |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
Tomáš Mráz |
c3274c |
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Tomáš Mráz |
c3274c |
+ */
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#ifndef NSSKEYS_H
|
|
Tomáš Mráz |
c3274c |
+#define NSSKEYS_H
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+#include <pk11func.h>
|
|
Tomáš Mráz |
c3274c |
+#include <prtypes.h>
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+int nss_init(PK11PasswordFunc);
|
|
Tomáš Mráz |
c3274c |
+Key **nss_get_keys(const char *, const char *, char *);
|
|
Tomáš Mráz |
c3274c |
+char *nss_get_key_label(Key *);
|
|
Tomáš Mráz |
c3274c |
+/*void sc_close(void);*/
|
|
Tomáš Mráz |
c3274c |
+/*int sc_put_key(Key *, const char *);*/
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/readconf.c.nss-keys openssh-5.2p1/readconf.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/readconf.c.nss-keys 2009-02-14 06:28:21.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/readconf.c 2009-03-10 03:51:55.950217925 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -124,6 +124,7 @@ typedef enum {
|
|
Jan F. Chadima |
a3ba41 |
oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias,
|
|
Jan F. Chadima |
a3ba41 |
oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication,
|
|
Jan F. Chadima |
a3ba41 |
oHostKeyAlgorithms, oBindAddress, oSmartcardDevice,
|
|
Jan F. Chadima |
a3ba41 |
+ oUseNSS, oNSSToken,
|
|
Jan F. Chadima |
a3ba41 |
oClearAllForwardings, oNoHostAuthenticationForLocalhost,
|
|
Jan F. Chadima |
a3ba41 |
oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
|
|
Jan F. Chadima |
a3ba41 |
oAddressFamily, oGssAuthentication, oGssDelegateCreds,
|
|
Jan F. Chadima |
a3ba41 |
@@ -210,6 +211,13 @@ static struct {
|
|
Jan F. Chadima |
a3ba41 |
#else
|
|
Jan F. Chadima |
a3ba41 |
{ "smartcarddevice", oUnsupported },
|
|
Jan F. Chadima |
a3ba41 |
#endif
|
|
Tomáš Mráz |
c9833c |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ { "usenss", oUseNSS },
|
|
Jan F. Chadima |
a3ba41 |
+ { "nsstoken", oNSSToken },
|
|
Jan F. Chadima |
a3ba41 |
+#else
|
|
Jan F. Chadima |
a3ba41 |
+ { "usenss", oUnsupported },
|
|
Jan F. Chadima |
a3ba41 |
+ { "nsstoken", oNSSToken },
|
|
Tomáš Mráz |
c9833c |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
{ "clearallforwardings", oClearAllForwardings },
|
|
Jan F. Chadima |
a3ba41 |
{ "enablesshkeysign", oEnableSSHKeysign },
|
|
Jan F. Chadima |
a3ba41 |
{ "verifyhostkeydns", oVerifyHostKeyDNS },
|
|
Jan F. Chadima |
a3ba41 |
@@ -612,6 +620,14 @@ parse_string:
|
|
Jan F. Chadima |
a3ba41 |
charptr = &options->smartcard_device;
|
|
Jan F. Chadima |
a3ba41 |
goto parse_string;
|
|
Tomáš Mráz |
c9833c |
|
|
Jan F. Chadima |
a3ba41 |
+ case oUseNSS:
|
|
Jan F. Chadima |
a3ba41 |
+ intptr = &options->use_nss;
|
|
Jan F. Chadima |
a3ba41 |
+ goto parse_flag;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ case oNSSToken:
|
|
Jan F. Chadima |
a3ba41 |
+ charptr = &options->nss_token;
|
|
Jan F. Chadima |
a3ba41 |
+ goto parse_command;
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
case oProxyCommand:
|
|
Jan F. Chadima |
a3ba41 |
charptr = &options->proxy_command;
|
|
Jan F. Chadima |
a3ba41 |
parse_command:
|
|
Jan F. Chadima |
a3ba41 |
@@ -1047,6 +1063,8 @@ initialize_options(Options * options)
|
|
Jan F. Chadima |
a3ba41 |
options->preferred_authentications = NULL;
|
|
Jan F. Chadima |
a3ba41 |
options->bind_address = NULL;
|
|
Jan F. Chadima |
a3ba41 |
options->smartcard_device = NULL;
|
|
Jan F. Chadima |
a3ba41 |
+ options->use_nss = -1;
|
|
Jan F. Chadima |
a3ba41 |
+ options->nss_token = NULL;
|
|
Jan F. Chadima |
a3ba41 |
options->enable_ssh_keysign = - 1;
|
|
Jan F. Chadima |
a3ba41 |
options->no_host_authentication_for_localhost = - 1;
|
|
Jan F. Chadima |
a3ba41 |
options->identities_only = - 1;
|
|
Jan F. Chadima |
a3ba41 |
@@ -1177,6 +1195,8 @@ fill_default_options(Options * options)
|
|
Jan F. Chadima |
a3ba41 |
options->no_host_authentication_for_localhost = 0;
|
|
Jan F. Chadima |
a3ba41 |
if (options->identities_only == -1)
|
|
Jan F. Chadima |
a3ba41 |
options->identities_only = 0;
|
|
Jan F. Chadima |
a3ba41 |
+ if (options->use_nss == -1)
|
|
Jan F. Chadima |
a3ba41 |
+ options->use_nss = 0;
|
|
Jan F. Chadima |
a3ba41 |
if (options->enable_ssh_keysign == -1)
|
|
Jan F. Chadima |
a3ba41 |
options->enable_ssh_keysign = 0;
|
|
Jan F. Chadima |
a3ba41 |
if (options->rekey_limit == -1)
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/readconf.h.nss-keys openssh-5.2p1/readconf.h
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/readconf.h.nss-keys 2009-02-14 06:28:21.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/readconf.h 2009-03-10 03:51:55.868252768 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -85,6 +85,8 @@ typedef struct {
|
|
Jan F. Chadima |
a3ba41 |
char *preferred_authentications;
|
|
Jan F. Chadima |
a3ba41 |
char *bind_address; /* local socket address for connection to sshd */
|
|
Jan F. Chadima |
a3ba41 |
char *smartcard_device; /* Smartcard reader device */
|
|
Jan F. Chadima |
a3ba41 |
+ int use_nss; /* Use NSS library for keys */
|
|
Jan F. Chadima |
a3ba41 |
+ char *nss_token; /* Look for NSS keys on token */
|
|
Jan F. Chadima |
a3ba41 |
int verify_host_key_dns; /* Verify host key using DNS */
|
|
Tomáš Mráz |
c9833c |
|
|
Jan F. Chadima |
a3ba41 |
int num_identity_files; /* Number of files for RSA/DSA identities. */
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/ssh-add.c.nss-keys openssh-5.2p1/ssh-add.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/ssh-add.c.nss-keys 2008-02-28 09:13:52.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/ssh-add.c 2009-03-10 03:51:56.254252403 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -42,8 +42,18 @@
|
|
Jan F. Chadima |
a3ba41 |
#include <sys/param.h>
|
|
Tomáš Mráz |
c9833c |
|
|
Tomáš Mráz |
c3274c |
#include <openssl/evp.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <openssl/fips.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <fipscheck.h>
|
|
Tomáš Mráz |
ec5276 |
#include "openbsd-compat/openssl-compat.h"
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+#include <nss.h>
|
|
Tomáš Mráz |
c3274c |
+#include <secmod.h>
|
|
Tomáš Mráz |
c3274c |
+#include <pk11pub.h>
|
|
Tomáš Mráz |
c3274c |
+#include <keyhi.h>
|
|
Tomáš Mráz |
c3274c |
+#include <cert.h>
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
#include <fcntl.h>
|
|
Tomáš Mráz |
c3274c |
#include <pwd.h>
|
|
Tomáš Mráz |
c3274c |
#include <stdarg.h>
|
|
Jan F. Chadima |
a3ba41 |
@@ -57,6 +67,7 @@
|
|
Tomáš Mráz |
c3274c |
#include "rsa.h"
|
|
Tomáš Mráz |
c3274c |
#include "log.h"
|
|
Tomáš Mráz |
c3274c |
#include "key.h"
|
|
Tomáš Mráz |
c3274c |
+#include "nsskeys.h"
|
|
Tomáš Mráz |
c3274c |
#include "buffer.h"
|
|
Tomáš Mráz |
c3274c |
#include "authfd.h"
|
|
Tomáš Mráz |
c3274c |
#include "authfile.h"
|
|
Jan F. Chadima |
a3ba41 |
@@ -245,7 +256,7 @@ list_identities(AuthenticationConnection
|
|
Jan F. Chadima |
a3ba41 |
key = ssh_get_next_identity(ac, &comment, version)) {
|
|
Jan F. Chadima |
a3ba41 |
had_identities = 1;
|
|
Jan F. Chadima |
a3ba41 |
if (do_fp) {
|
|
Jan F. Chadima |
a3ba41 |
- fp = key_fingerprint(key, SSH_FP_MD5,
|
|
Jan F. Chadima |
a3ba41 |
+ fp = key_fingerprint(key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5,
|
|
Jan F. Chadima |
a3ba41 |
SSH_FP_HEX);
|
|
Jan F. Chadima |
a3ba41 |
printf("%d %s %s (%s)\n",
|
|
Jan F. Chadima |
a3ba41 |
key_size(key), fp, comment, key_type(key));
|
|
Jan F. Chadima |
a3ba41 |
@@ -307,6 +318,117 @@ do_file(AuthenticationConnection *ac, in
|
|
Tomáš Mráz |
c3274c |
return 0;
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+static char *
|
|
Tomáš Mráz |
c3274c |
+password_cb(PK11SlotInfo *slot, PRBool retry, void *arg)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ char **passcache = arg;
|
|
Tomáš Mráz |
c3274c |
+ char *password, *p2 = NULL;
|
|
Tomáš Mráz |
c3274c |
+ char *prompt;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (retry)
|
|
Tomáš Mráz |
c3274c |
+ return NULL;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (asprintf(&prompt, "Enter passphrase for token %s: ",
|
|
Tomáš Mráz |
c3274c |
+ PK11_GetTokenName(slot)) < 0)
|
|
Tomáš Mráz |
c3274c |
+ fatal("password_cb: asprintf failed");
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ password = read_passphrase(prompt, RP_ALLOW_STDIN);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (password != NULL && (p2=PL_strdup(password)) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ memset(password, 0, strlen(password));
|
|
Tomáš Mráz |
c3274c |
+ fatal("password_cb: PL_strdup failed");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (passcache != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ if (*passcache != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ memset(*passcache, 0, strlen(*passcache));
|
|
Tomáš Mráz |
c3274c |
+ xfree(*passcache);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ *passcache = password;
|
|
Tomáš Mráz |
c3274c |
+ } else {
|
|
Tomáš Mráz |
c3274c |
+ memset(password, 0, strlen(password));
|
|
Tomáš Mráz |
c3274c |
+ xfree(password);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ return p2;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+static int
|
|
Tomáš Mráz |
c3274c |
+add_slot_keys(AuthenticationConnection *ac, PK11SlotInfo *slot, int add)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ SECKEYPrivateKeyList *list;
|
|
Tomáš Mráz |
c3274c |
+ SECKEYPrivateKeyListNode *node;
|
|
Tomáš Mráz |
c3274c |
+ char *passcache = NULL;
|
|
Tomáš Mráz |
c3274c |
+ char *tokenname;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ int count = 0;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (PK11_NeedLogin(slot))
|
|
Tomáš Mráz |
c3274c |
+ PK11_Authenticate(slot, PR_TRUE, &passcache);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if ((list=PK11_ListPrivKeysInSlot(slot, NULL, NULL)) == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ return 0;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ tokenname = PK11_GetTokenName(slot);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ for (node=PRIVKEY_LIST_HEAD(list); !PRIVKEY_LIST_END(node, list);
|
|
Tomáš Mráz |
c3274c |
+ node=PRIVKEY_LIST_NEXT(node)) {
|
|
Tomáš Mráz |
c3274c |
+ char *keyname;
|
|
Tomáš Mráz |
c3274c |
+ SECKEYPublicKey *pub;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ keyname = PK11_GetPrivateKeyNickname(node->key);
|
|
Tomáš Mráz |
c3274c |
+ if (keyname == NULL || *keyname == '\0') {
|
|
Tomáš Mráz |
c3274c |
+ /* no nickname to refer to */
|
|
Tomáš Mráz |
c3274c |
+ CERTCertificate *cert;
|
|
Tomáš Mráz |
c3274c |
+ char *kn;
|
|
Tomáš Mráz |
c3274c |
+ cert = PK11_GetCertFromPrivateKey(node->key);
|
|
Tomáš Mráz |
c3274c |
+ if (cert == NULL)
|
|
Tomáš Mráz |
c3274c |
+ continue;
|
|
Tomáš Mráz |
c3274c |
+ kn = strchr(cert->nickname, ':');
|
|
Tomáš Mráz |
c3274c |
+ if (kn == NULL)
|
|
Tomáš Mráz |
c3274c |
+ kn = cert->nickname;
|
|
Tomáš Mráz |
c3274c |
+ else
|
|
Tomáš Mráz |
c3274c |
+ kn++;
|
|
Tomáš Mráz |
c3274c |
+ keyname = PORT_Strdup(kn);
|
|
Tomáš Mráz |
c3274c |
+ CERT_DestroyCertificate(cert);
|
|
Tomáš Mráz |
c3274c |
+ if (keyname == NULL)
|
|
Tomáš Mráz |
c3274c |
+ continue;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ pub = SECKEY_ConvertToPublicKey(node->key);
|
|
Tomáš Mráz |
c3274c |
+ if (pub == NULL) {
|
|
Tomáš Mráz |
c3274c |
+ fprintf(stderr, "No public key for: %s:%s\n",
|
|
Tomáš Mráz |
c3274c |
+ tokenname, keyname);
|
|
Tomáš Mráz |
c3274c |
+ continue; /* not possible to obtain public key */
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ SECKEY_DestroyPublicKey(pub);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (ssh_update_nss_key(ac, add, tokenname, keyname,
|
|
Tomáš Mráz |
c3274c |
+ passcache?passcache:"", lifetime, confirm)) {
|
|
Tomáš Mráz |
c3274c |
+ fprintf(stderr, "Key %s: %s:%s\n",
|
|
Tomáš Mráz |
c3274c |
+ add?"added":"removed", tokenname, keyname);
|
|
Tomáš Mráz |
c3274c |
+ count++;
|
|
Tomáš Mráz |
c3274c |
+ } else {
|
|
Tomáš Mráz |
c3274c |
+ fprintf(stderr, "Could not %s key: %s:%s\n",
|
|
Tomáš Mráz |
c3274c |
+ add?"add":"remove", tokenname, keyname);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ PORT_Free(keyname);
|
|
Tomáš Mráz |
c3274c |
+ count++;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (passcache != NULL) {
|
|
Tomáš Mráz |
c3274c |
+ memset(passcache, 0, strlen(passcache));
|
|
Tomáš Mráz |
c3274c |
+ xfree(passcache);
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ SECKEY_DestroyPrivateKeyList(list);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ return count;
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
static void
|
|
Tomáš Mráz |
c3274c |
usage(void)
|
|
Tomáš Mráz |
c3274c |
{
|
|
Jan F. Chadima |
a3ba41 |
@@ -334,16 +456,25 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
AuthenticationConnection *ac = NULL;
|
|
Tomáš Mráz |
c3274c |
char *sc_reader_id = NULL;
|
|
Tomáš Mráz |
c3274c |
int i, ch, deleting = 0, ret = 0;
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+ char *token_id = NULL;
|
|
Tomáš Mráz |
c3274c |
+ int use_nss = 0;
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
|
Tomáš Mráz |
c3274c |
sanitise_stdfd();
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
__progname = ssh_get_progname(argv[0]);
|
|
Jan F. Chadima |
a3ba41 |
+ SSLeay_add_all_algorithms();
|
|
Jan F. Chadima |
a3ba41 |
+ if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
|
|
Jan F. Chadima |
a3ba41 |
+ fprintf(stderr,
|
|
Jan F. Chadima |
a3ba41 |
+ "FIPS integrity verification test failed.\n");
|
|
Jan F. Chadima |
a3ba41 |
+ exit(3);
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
init_rng();
|
|
Jan F. Chadima |
a3ba41 |
seed_rng();
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
- SSLeay_add_all_algorithms();
|
|
Jan F. Chadima |
a3ba41 |
-
|
|
Jan F. Chadima |
a3ba41 |
/* At first, get a connection to the authentication agent. */
|
|
Jan F. Chadima |
a3ba41 |
ac = ssh_get_authentication_connection();
|
|
Jan F. Chadima |
a3ba41 |
if (ac == NULL) {
|
|
Jan F. Chadima |
a3ba41 |
@@ -351,7 +482,7 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
"Could not open a connection to your authentication agent.\n");
|
|
Tomáš Mráz |
c3274c |
exit(2);
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
- while ((ch = getopt(argc, argv, "lLcdDxXe:s:t:")) != -1) {
|
|
Tomáš Mráz |
c3274c |
+ while ((ch = getopt(argc, argv, "lLcdDnxXe:s:t:T:")) != -1) {
|
|
Tomáš Mráz |
c3274c |
switch (ch) {
|
|
Tomáš Mráz |
c3274c |
case 'l':
|
|
Tomáš Mráz |
c3274c |
case 'L':
|
|
Jan F. Chadima |
a3ba41 |
@@ -373,6 +504,11 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
if (delete_all(ac) == -1)
|
|
Tomáš Mráz |
c3274c |
ret = 1;
|
|
Tomáš Mráz |
c3274c |
goto done;
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+ case 'n':
|
|
Tomáš Mráz |
c3274c |
+ use_nss = 1;
|
|
Tomáš Mráz |
c3274c |
+ break;
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
case 's':
|
|
Tomáš Mráz |
c3274c |
sc_reader_id = optarg;
|
|
Tomáš Mráz |
c3274c |
break;
|
|
Jan F. Chadima |
a3ba41 |
@@ -387,6 +523,11 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
goto done;
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
break;
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+ case 'T':
|
|
Tomáš Mráz |
c9833c |
+ token_id = optarg;
|
|
Tomáš Mráz |
c9833c |
+ break;
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c9833c |
default:
|
|
Tomáš Mráz |
c9833c |
usage();
|
|
Tomáš Mráz |
c9833c |
ret = 1;
|
|
Jan F. Chadima |
a3ba41 |
@@ -400,6 +541,40 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c9833c |
ret = 1;
|
|
Tomáš Mráz |
c9833c |
goto done;
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ if (use_nss) {
|
|
Jan F. Chadima |
a3ba41 |
+ PK11SlotList *slots;
|
|
Jan F. Chadima |
a3ba41 |
+ PK11SlotListElement *sle;
|
|
Jan F. Chadima |
a3ba41 |
+ int count = 0;
|
|
Jan F. Chadima |
a3ba41 |
+ if (nss_init(password_cb) == -1) {
|
|
Jan F. Chadima |
a3ba41 |
+ fprintf(stderr, "Failed to initialize NSS library\n");
|
|
Jan F. Chadima |
a3ba41 |
+ ret = 1;
|
|
Jan F. Chadima |
a3ba41 |
+ goto done;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if ((slots=PK11_GetAllTokens(CKM_INVALID_MECHANISM, PR_FALSE, PR_FALSE,
|
|
Jan F. Chadima |
a3ba41 |
+ NULL)) == NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ fprintf(stderr, "No tokens found\n");
|
|
Jan F. Chadima |
a3ba41 |
+ ret = 1;
|
|
Jan F. Chadima |
a3ba41 |
+ goto nss_done;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ for (sle = slots->head; sle; sle = sle->next) {
|
|
Jan F. Chadima |
a3ba41 |
+ int rv;
|
|
Jan F. Chadima |
a3ba41 |
+ if ((rv=add_slot_keys(ac, sle->slot, !deleting)) == -1) {
|
|
Jan F. Chadima |
a3ba41 |
+ ret = 1;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ count += rv;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ if (count == 0) {
|
|
Jan F. Chadima |
a3ba41 |
+ ret = 1;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+nss_done:
|
|
Jan F. Chadima |
a3ba41 |
+ NSS_Shutdown();
|
|
Jan F. Chadima |
a3ba41 |
+ clear_pass();
|
|
Jan F. Chadima |
a3ba41 |
+ goto done;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
if (argc == 0) {
|
|
Jan F. Chadima |
a3ba41 |
char buf[MAXPATHLEN];
|
|
Jan F. Chadima |
a3ba41 |
struct passwd *pw;
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/ssh-agent.c.nss-keys openssh-5.2p1/ssh-agent.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/ssh-agent.c.nss-keys 2008-07-04 15:10:49.000000000 +0200
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/ssh-agent.c 2009-03-10 03:51:56.171221623 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -51,6 +51,8 @@
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/evp.h>
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/md5.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <openssl/fips.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <fipscheck.h>
|
|
Jan F. Chadima |
a3ba41 |
#include "openbsd-compat/openssl-compat.h"
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
#include <errno.h>
|
|
Jan F. Chadima |
a3ba41 |
@@ -80,6 +82,10 @@
|
|
Jan F. Chadima |
a3ba41 |
#include "scard.h"
|
|
Jan F. Chadima |
a3ba41 |
#endif
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+#include "nsskeys.h"
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
#if defined(HAVE_SYS_PRCTL_H)
|
|
Jan F. Chadima |
a3ba41 |
#include <sys/prctl.h> /* For prctl() and PR_SET_DUMPABLE */
|
|
Jan F. Chadima |
a3ba41 |
#endif
|
|
Jan F. Chadima |
a3ba41 |
@@ -196,9 +202,9 @@ confirm_key(Identity *id)
|
|
Jan F. Chadima |
a3ba41 |
char *p;
|
|
Jan F. Chadima |
a3ba41 |
int ret = -1;
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
- p = key_fingerprint(id->key, SSH_FP_MD5, SSH_FP_HEX);
|
|
Jan F. Chadima |
a3ba41 |
- if (ask_permission("Allow use of key %s?\nKey fingerprint %s.",
|
|
Jan F. Chadima |
a3ba41 |
- id->comment, p))
|
|
Jan F. Chadima |
a3ba41 |
+ p = key_fingerprint(id->key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
|
|
Jan F. Chadima |
a3ba41 |
+ if (ask_permission("Allow use of key %s?\nKey %sfingerprint %s.",
|
|
Jan F. Chadima |
a3ba41 |
+ id->comment, FIPS_mode() ? "SHA1 " : "", p))
|
|
Jan F. Chadima |
a3ba41 |
ret = 0;
|
|
Jan F. Chadima |
a3ba41 |
xfree(p);
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
@@ -714,6 +720,114 @@ send:
|
|
Jan F. Chadima |
a3ba41 |
}
|
|
Jan F. Chadima |
a3ba41 |
#endif /* SMARTCARD */
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+static void
|
|
Jan F. Chadima |
a3ba41 |
+process_add_nss_key (SocketEntry *e)
|
|
Jan F. Chadima |
a3ba41 |
+{
|
|
Jan F. Chadima |
a3ba41 |
+ char *tokenname = NULL, *keyname = NULL, *password = NULL;
|
|
Jan F. Chadima |
a3ba41 |
+ int i, version, success = 0, death = 0, confirm = 0;
|
|
Jan F. Chadima |
a3ba41 |
+ Key **keys, *k;
|
|
Jan F. Chadima |
a3ba41 |
+ Identity *id;
|
|
Jan F. Chadima |
a3ba41 |
+ Idtab *tab;
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ tokenname = buffer_get_string(&e->request, NULL);
|
|
Jan F. Chadima |
a3ba41 |
+ keyname = buffer_get_string(&e->request, NULL);
|
|
Jan F. Chadima |
a3ba41 |
+ password = buffer_get_string(&e->request, NULL);
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ while (buffer_len(&e->request)) {
|
|
Jan F. Chadima |
a3ba41 |
+ switch (buffer_get_char(&e->request)) {
|
|
Jan F. Chadima |
a3ba41 |
+ case SSH_AGENT_CONSTRAIN_LIFETIME:
|
|
Jan F. Chadima |
a3ba41 |
+ death = time(NULL) + buffer_get_int(&e->request);
|
|
Jan F. Chadima |
a3ba41 |
+ break;
|
|
Jan F. Chadima |
a3ba41 |
+ case SSH_AGENT_CONSTRAIN_CONFIRM:
|
|
Jan F. Chadima |
a3ba41 |
+ confirm = 1;
|
|
Jan F. Chadima |
a3ba41 |
+ break;
|
|
Jan F. Chadima |
a3ba41 |
+ default:
|
|
Jan F. Chadima |
a3ba41 |
+ break;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ if (lifetime && !death)
|
|
Jan F. Chadima |
a3ba41 |
+ death = time(NULL) + lifetime;
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ keys = nss_get_keys(tokenname, keyname, password);
|
|
Jan F. Chadima |
a3ba41 |
+ /* password is owned by keys[0] now */
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(tokenname);
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(keyname);
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if (keys == NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ memset(password, 0, strlen(password));
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(password);
|
|
Jan F. Chadima |
a3ba41 |
+ error("nss_get_keys failed");
|
|
Jan F. Chadima |
a3ba41 |
+ goto send;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ for (i = 0; keys[i] != NULL; i++) {
|
|
Jan F. Chadima |
a3ba41 |
+ k = keys[i];
|
|
Jan F. Chadima |
a3ba41 |
+ version = k->type == KEY_RSA1 ? 1 : 2;
|
|
Jan F. Chadima |
a3ba41 |
+ tab = idtab_lookup(version);
|
|
Jan F. Chadima |
a3ba41 |
+ if (lookup_identity(k, version) == NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ id = xmalloc(sizeof(Identity));
|
|
Jan F. Chadima |
a3ba41 |
+ id->key = k;
|
|
Jan F. Chadima |
a3ba41 |
+ id->comment = nss_get_key_label(k);
|
|
Jan F. Chadima |
a3ba41 |
+ id->death = death;
|
|
Jan F. Chadima |
a3ba41 |
+ id->confirm = confirm;
|
|
Jan F. Chadima |
a3ba41 |
+ TAILQ_INSERT_TAIL(&tab->idlist, id, next);
|
|
Jan F. Chadima |
a3ba41 |
+ tab->nentries++;
|
|
Jan F. Chadima |
a3ba41 |
+ success = 1;
|
|
Jan F. Chadima |
a3ba41 |
+ } else {
|
|
Jan F. Chadima |
a3ba41 |
+ key_free(k);
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ keys[i] = NULL;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(keys);
|
|
Jan F. Chadima |
a3ba41 |
+send:
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_int(&e->output, 1);
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_char(&e->output,
|
|
Jan F. Chadima |
a3ba41 |
+ success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
|
|
Jan F. Chadima |
a3ba41 |
+}
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+static void
|
|
Jan F. Chadima |
a3ba41 |
+process_remove_nss_key(SocketEntry *e)
|
|
Jan F. Chadima |
a3ba41 |
+{
|
|
Jan F. Chadima |
a3ba41 |
+ char *tokenname = NULL, *keyname = NULL, *password = NULL;
|
|
Jan F. Chadima |
a3ba41 |
+ int i, version, success = 0;
|
|
Jan F. Chadima |
a3ba41 |
+ Key **keys, *k = NULL;
|
|
Jan F. Chadima |
a3ba41 |
+ Identity *id;
|
|
Jan F. Chadima |
a3ba41 |
+ Idtab *tab;
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ tokenname = buffer_get_string(&e->request, NULL);
|
|
Jan F. Chadima |
a3ba41 |
+ keyname = buffer_get_string(&e->request, NULL);
|
|
Jan F. Chadima |
a3ba41 |
+ password = buffer_get_string(&e->request, NULL);
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ keys = nss_get_keys(tokenname, keyname, password);
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(tokenname);
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(keyname);
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(password);
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if (keys == NULL || keys[0] == NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ error("nss_get_keys failed");
|
|
Jan F. Chadima |
a3ba41 |
+ goto send;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ for (i = 0; keys[i] != NULL; i++) {
|
|
Jan F. Chadima |
a3ba41 |
+ k = keys[i];
|
|
Jan F. Chadima |
a3ba41 |
+ version = k->type == KEY_RSA1 ? 1 : 2;
|
|
Jan F. Chadima |
a3ba41 |
+ if ((id = lookup_identity(k, version)) != NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ tab = idtab_lookup(version);
|
|
Jan F. Chadima |
a3ba41 |
+ TAILQ_REMOVE(&tab->idlist, id, next);
|
|
Jan F. Chadima |
a3ba41 |
+ tab->nentries--;
|
|
Jan F. Chadima |
a3ba41 |
+ free_identity(id);
|
|
Jan F. Chadima |
a3ba41 |
+ success = 1;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ key_free(k);
|
|
Jan F. Chadima |
a3ba41 |
+ keys[i] = NULL;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(keys);
|
|
Jan F. Chadima |
a3ba41 |
+send:
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_int(&e->output, 1);
|
|
Jan F. Chadima |
a3ba41 |
+ buffer_put_char(&e->output,
|
|
Jan F. Chadima |
a3ba41 |
+ success ? SSH_AGENT_SUCCESS : SSH_AGENT_FAILURE);
|
|
Jan F. Chadima |
a3ba41 |
+}
|
|
Jan F. Chadima |
a3ba41 |
+#endif /* HAVE_LIBNSS */
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
/* dispatch incoming messages */
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
static void
|
|
Jan F. Chadima |
a3ba41 |
@@ -806,6 +920,15 @@ process_message(SocketEntry *e)
|
|
Jan F. Chadima |
a3ba41 |
process_remove_smartcard_key(e);
|
|
Jan F. Chadima |
a3ba41 |
break;
|
|
Jan F. Chadima |
a3ba41 |
#endif /* SMARTCARD */
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ case SSH_AGENTC_ADD_NSS_KEY:
|
|
Jan F. Chadima |
a3ba41 |
+ case SSH_AGENTC_ADD_NSS_KEY_CONSTRAINED:
|
|
Jan F. Chadima |
a3ba41 |
+ process_add_nss_key(e);
|
|
Jan F. Chadima |
a3ba41 |
+ break;
|
|
Jan F. Chadima |
a3ba41 |
+ case SSH_AGENTC_REMOVE_NSS_KEY:
|
|
Jan F. Chadima |
a3ba41 |
+ process_remove_nss_key(e);
|
|
Jan F. Chadima |
a3ba41 |
+ break;
|
|
Jan F. Chadima |
a3ba41 |
+#endif /* SMARTCARD */
|
|
Jan F. Chadima |
a3ba41 |
default:
|
|
Jan F. Chadima |
a3ba41 |
/* Unknown message. Respond with failure. */
|
|
Jan F. Chadima |
a3ba41 |
error("Unknown message %d", type);
|
|
Jan F. Chadima |
a3ba41 |
@@ -1075,6 +1198,11 @@ main(int ac, char **av)
|
|
Jan F. Chadima |
a3ba41 |
#endif
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
SSLeay_add_all_algorithms();
|
|
Jan F. Chadima |
a3ba41 |
+ if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
|
|
Jan F. Chadima |
a3ba41 |
+ fprintf(stderr,
|
|
Jan F. Chadima |
a3ba41 |
+ "FIPS integrity verification test failed.\n");
|
|
Jan F. Chadima |
a3ba41 |
+ exit(3);
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
__progname = ssh_get_progname(av[0]);
|
|
Jan F. Chadima |
a3ba41 |
init_rng();
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/ssh.c.nss-keys openssh-5.2p1/ssh.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/ssh.c.nss-keys 2009-02-14 06:28:21.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/ssh.c 2009-03-10 03:51:56.176206362 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -71,6 +71,8 @@
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/evp.h>
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/err.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <openssl/fips.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <fipscheck.h>
|
|
Jan F. Chadima |
a3ba41 |
#include "openbsd-compat/openssl-compat.h"
|
|
Jan F. Chadima |
a3ba41 |
#include "openbsd-compat/sys-queue.h"
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
@@ -104,6 +106,9 @@
|
|
Jan F. Chadima |
a3ba41 |
#ifdef SMARTCARD
|
|
Jan F. Chadima |
a3ba41 |
#include "scard.h"
|
|
Jan F. Chadima |
a3ba41 |
#endif
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+#include "nsskeys.h"
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
extern char *__progname;
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
@@ -217,6 +222,10 @@ main(int ac, char **av)
|
|
Jan F. Chadima |
a3ba41 |
sanitise_stdfd();
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
__progname = ssh_get_progname(av[0]);
|
|
Jan F. Chadima |
a3ba41 |
+ SSLeay_add_all_algorithms();
|
|
Jan F. Chadima |
a3ba41 |
+ if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
|
|
Jan F. Chadima |
a3ba41 |
+ fatal("FIPS integrity verification test failed.");
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
init_rng();
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
/*
|
|
Jan F. Chadima |
a3ba41 |
@@ -547,7 +556,6 @@ main(int ac, char **av)
|
|
Jan F. Chadima |
a3ba41 |
if (!host)
|
|
Jan F. Chadima |
a3ba41 |
usage();
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
- SSLeay_add_all_algorithms();
|
|
Jan F. Chadima |
a3ba41 |
ERR_load_crypto_strings();
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
/* Initialize the command to execute on remote host. */
|
|
Jan F. Chadima |
a3ba41 |
@@ -1231,9 +1239,11 @@ load_public_identity_files(void)
|
|
Jan F. Chadima |
a3ba41 |
int i = 0;
|
|
Jan F. Chadima |
a3ba41 |
Key *public;
|
|
Jan F. Chadima |
a3ba41 |
struct passwd *pw;
|
|
Jan F. Chadima |
a3ba41 |
-#ifdef SMARTCARD
|
|
Jan F. Chadima |
a3ba41 |
+#if defined(SMARTCARD) || defined(HAVE_LIBNSS)
|
|
Jan F. Chadima |
a3ba41 |
Key **keys;
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef SMARTCARD
|
|
Jan F. Chadima |
a3ba41 |
if (options.smartcard_device != NULL &&
|
|
Jan F. Chadima |
a3ba41 |
options.num_identity_files < SSH_MAX_IDENTITY_FILES &&
|
|
Jan F. Chadima |
a3ba41 |
(keys = sc_get_keys(options.smartcard_device, NULL)) != NULL) {
|
|
Jan F. Chadima |
a3ba41 |
@@ -1256,6 +1266,27 @@ load_public_identity_files(void)
|
|
Jan F. Chadima |
a3ba41 |
xfree(keys);
|
|
Jan F. Chadima |
a3ba41 |
}
|
|
Jan F. Chadima |
a3ba41 |
#endif /* SMARTCARD */
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ if (options.use_nss &&
|
|
Jan F. Chadima |
a3ba41 |
+ options.num_identity_files < SSH_MAX_IDENTITY_FILES &&
|
|
Jan F. Chadima |
a3ba41 |
+ (keys = nss_get_keys(options.nss_token, NULL, NULL)) != NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ int count;
|
|
Jan F. Chadima |
a3ba41 |
+ for (count = 0; keys[count] != NULL; count++) {
|
|
Jan F. Chadima |
a3ba41 |
+ memmove(&options.identity_files[1], &options.identity_files[0],
|
|
Jan F. Chadima |
a3ba41 |
+ sizeof(char *) * (SSH_MAX_IDENTITY_FILES - 1));
|
|
Jan F. Chadima |
a3ba41 |
+ memmove(&options.identity_keys[1], &options.identity_keys[0],
|
|
Jan F. Chadima |
a3ba41 |
+ sizeof(Key *) * (SSH_MAX_IDENTITY_FILES - 1));
|
|
Jan F. Chadima |
a3ba41 |
+ options.num_identity_files++;
|
|
Jan F. Chadima |
a3ba41 |
+ options.identity_keys[0] = keys[count];
|
|
Jan F. Chadima |
a3ba41 |
+ options.identity_files[0] = nss_get_key_label(keys[count]);
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ if (options.num_identity_files > SSH_MAX_IDENTITY_FILES)
|
|
Jan F. Chadima |
a3ba41 |
+ options.num_identity_files = SSH_MAX_IDENTITY_FILES;
|
|
Jan F. Chadima |
a3ba41 |
+ i += count;
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(keys);
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+#endif /* HAVE_LIBNSS */
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
if ((pw = getpwuid(original_real_uid)) == NULL)
|
|
Jan F. Chadima |
a3ba41 |
fatal("load_public_identity_files: getpwuid failed");
|
|
Jan F. Chadima |
a3ba41 |
pwname = xstrdup(pw->pw_name);
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/ssh-dss.c.nss-keys openssh-5.2p1/ssh-dss.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/ssh-dss.c.nss-keys 2006-11-07 13:14:42.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/ssh-dss.c 2009-03-10 03:51:55.843232632 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -39,6 +39,10 @@
|
|
Jan F. Chadima |
a3ba41 |
#include "log.h"
|
|
Jan F. Chadima |
a3ba41 |
#include "key.h"
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+#include <cryptohi.h>
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
#define INTBLOB_LEN 20
|
|
Jan F. Chadima |
a3ba41 |
#define SIGBLOB_LEN (2*INTBLOB_LEN)
|
|
Tomáš Mráz |
c3274c |
|
|
Jan F. Chadima |
a3ba41 |
@@ -57,6 +61,34 @@ ssh_dss_sign(const Key *key, u_char **si
|
|
Jan F. Chadima |
a3ba41 |
error("ssh_dss_sign: no DSA key");
|
|
Tomáš Mráz |
c3274c |
return -1;
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+ if (key->flags & KEY_FLAG_NSS) {
|
|
Tomáš Mráz |
c3274c |
+ SECItem sigitem;
|
|
Jan F. Chadima |
a3ba41 |
+ SECItem *rawsig;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ memset(&sigitem, 0, sizeof(sigitem));
|
|
Tomáš Mráz |
c3274c |
+ if (SEC_SignData(&sigitem, (u_char *)data, datalen, key->nss->privk,
|
|
Jan F. Chadima |
a3ba41 |
+ SEC_OID_ANSIX9_DSA_SIGNATURE_WITH_SHA1_DIGEST) != SECSuccess) {
|
|
Jan F. Chadima |
a3ba41 |
+ error("ssh_dss_sign: sign failed");
|
|
Tomáš Mráz |
c3274c |
+ return -1;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if ((rawsig=DSAU_DecodeDerSig(&sigitem)) == NULL) {
|
|
Jan F. Chadima |
a3ba41 |
+ error("ssh_dss_sign: der decode failed");
|
|
Tomáš Mráz |
c3274c |
+ SECITEM_ZfreeItem(&sigitem, PR_FALSE);
|
|
Tomáš Mráz |
c3274c |
+ return -1;
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c9833c |
+ SECITEM_ZfreeItem(&sigitem, PR_FALSE);
|
|
Jan F. Chadima |
a3ba41 |
+ if (rawsig->len != SIGBLOB_LEN) {
|
|
Jan F. Chadima |
a3ba41 |
+ error("ssh_dss_sign: unsupported signature length %d",
|
|
Jan F. Chadima |
a3ba41 |
+ rawsig->len);
|
|
Jan F. Chadima |
a3ba41 |
+ SECITEM_ZfreeItem(rawsig, PR_TRUE);
|
|
Jan F. Chadima |
a3ba41 |
+ return -1;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ memcpy(sigblob, rawsig->data, SIGBLOB_LEN);
|
|
Jan F. Chadima |
a3ba41 |
+ SECITEM_ZfreeItem(rawsig, PR_TRUE);
|
|
Tomáš Mráz |
c3274c |
+ } else {
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
EVP_DigestInit(&md, evp_md);
|
|
Tomáš Mráz |
c3274c |
EVP_DigestUpdate(&md, data, datalen);
|
|
Tomáš Mráz |
c3274c |
EVP_DigestFinal(&md, digest, &dlen);
|
|
Jan F. Chadima |
a3ba41 |
@@ -80,7 +112,9 @@ ssh_dss_sign(const Key *key, u_char **si
|
|
Jan F. Chadima |
a3ba41 |
BN_bn2bin(sig->r, sigblob+ SIGBLOB_LEN - INTBLOB_LEN - rlen);
|
|
Jan F. Chadima |
a3ba41 |
BN_bn2bin(sig->s, sigblob+ SIGBLOB_LEN - slen);
|
|
Jan F. Chadima |
a3ba41 |
DSA_SIG_free(sig);
|
|
Tomáš Mráz |
c3274c |
-
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
if (datafellows & SSH_BUG_SIGBLOB) {
|
|
Jan F. Chadima |
a3ba41 |
if (lenp != NULL)
|
|
Jan F. Chadima |
a3ba41 |
*lenp = SIGBLOB_LEN;
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/ssh-keygen.c.nss-keys openssh-5.2p1/ssh-keygen.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/ssh-keygen.c.nss-keys 2009-02-21 22:47:02.000000000 +0100
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/ssh-keygen.c 2009-03-10 03:51:56.249239228 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -21,6 +21,8 @@
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/evp.h>
|
|
Jan F. Chadima |
a3ba41 |
#include <openssl/pem.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <openssl/fips.h>
|
|
Jan F. Chadima |
a3ba41 |
+#include <fipscheck.h>
|
|
Jan F. Chadima |
a3ba41 |
#include "openbsd-compat/openssl-compat.h"
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
#include <errno.h>
|
|
Jan F. Chadima |
a3ba41 |
@@ -53,6 +55,11 @@
|
|
Tomáš Mráz |
c3274c |
#include "scard.h"
|
|
Tomáš Mráz |
c3274c |
#endif
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+#include <nss.h>
|
|
Tomáš Mráz |
c3274c |
+#include "nsskeys.h"
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
/* Number of bits in the RSA/DSA key. This value can be set on the command line. */
|
|
Tomáš Mráz |
c3274c |
#define DEFAULT_BITS 2048
|
|
Tomáš Mráz |
c3274c |
#define DEFAULT_BITS_DSA 1024
|
|
Jan F. Chadima |
a3ba41 |
@@ -501,6 +508,26 @@ do_download(struct passwd *pw, const cha
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
#endif /* SMARTCARD */
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+static void
|
|
Tomáš Mráz |
c3274c |
+do_nss_download(struct passwd *pw, const char *tokenname, const char *keyname)
|
|
Tomáš Mráz |
c3274c |
+{
|
|
Tomáš Mráz |
c3274c |
+ Key **keys = NULL;
|
|
Tomáš Mráz |
c3274c |
+ int i;
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ keys = nss_get_keys(tokenname, keyname, NULL);
|
|
Tomáš Mráz |
c3274c |
+ if (keys == NULL)
|
|
Tomáš Mráz |
c3274c |
+ fatal("cannot find public key in NSS");
|
|
Tomáš Mráz |
c3274c |
+ for (i = 0; keys[i]; i++) {
|
|
Tomáš Mráz |
c3274c |
+ key_write(keys[i], stdout);
|
|
Tomáš Mráz |
c3274c |
+ key_free(keys[i]);
|
|
Tomáš Mráz |
c3274c |
+ fprintf(stdout, "\n");
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
+ xfree(keys);
|
|
Tomáš Mráz |
c3274c |
+ exit(0);
|
|
Tomáš Mráz |
c3274c |
+}
|
|
Tomáš Mráz |
c3274c |
+#endif /* HAVE_LIBNSS */
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
static void
|
|
Tomáš Mráz |
c3274c |
do_fingerprint(struct passwd *pw)
|
|
Tomáš Mráz |
c3274c |
{
|
|
Jan F. Chadima |
a3ba41 |
@@ -512,7 +539,7 @@ do_fingerprint(struct passwd *pw)
|
|
Jan F. Chadima |
a3ba41 |
enum fp_type fptype;
|
|
Jan F. Chadima |
a3ba41 |
struct stat st;
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
- fptype = print_bubblebabble ? SSH_FP_SHA1 : SSH_FP_MD5;
|
|
Jan F. Chadima |
a3ba41 |
+ fptype = print_bubblebabble ? SSH_FP_SHA1 : FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5;
|
|
Jan F. Chadima |
a3ba41 |
rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_HEX;
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
if (!have_identity)
|
|
Jan F. Chadima |
a3ba41 |
@@ -1083,7 +1110,8 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
Key *private, *public;
|
|
Tomáš Mráz |
c3274c |
struct passwd *pw;
|
|
Tomáš Mráz |
c3274c |
struct stat st;
|
|
Tomáš Mráz |
c3274c |
- int opt, type, fd, download = 0;
|
|
Tomáš Mráz |
c3274c |
+ int opt, type, fd, download = 1;
|
|
Tomáš Mráz |
c3274c |
+ int use_nss = 0;
|
|
Tomáš Mráz |
c3274c |
u_int32_t memory = 0, generator_wanted = 0, trials = 100;
|
|
Tomáš Mráz |
c3274c |
int do_gen_candidates = 0, do_screen_candidates = 0;
|
|
Tomáš Mráz |
ec5276 |
BIGNUM *start = NULL;
|
|
Jan F. Chadima |
a3ba41 |
@@ -1099,6 +1127,12 @@ main(int argc, char **argv)
|
|
Jan F. Chadima |
a3ba41 |
__progname = ssh_get_progname(argv[0]);
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
SSLeay_add_all_algorithms();
|
|
Jan F. Chadima |
a3ba41 |
+ if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
|
|
Jan F. Chadima |
a3ba41 |
+ fprintf(stderr,
|
|
Jan F. Chadima |
a3ba41 |
+ "FIPS integrity verification test failed.\n");
|
|
Jan F. Chadima |
a3ba41 |
+ exit(3);
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1);
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
init_rng();
|
|
Jan F. Chadima |
a3ba41 |
@@ -1116,7 +1150,7 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
|
|
Tomáš Mráz |
c9833c |
while ((opt = getopt(argc, argv,
|
|
Tomáš Mráz |
c3274c |
- "degiqpclBHvxXyF:b:f:t:U:D:P:N:C:r:g:R:T:G:M:S:a:W:")) != -1) {
|
|
Tomáš Mráz |
c3274c |
+ "degiqpclnBHvxXyF:b:f:t:U:D:P:N:C:r:g:R:T:G:M:S:a:W:")) != -1) {
|
|
Tomáš Mráz |
c3274c |
switch (opt) {
|
|
Tomáš Mráz |
c3274c |
case 'b':
|
|
Tomáš Mráz |
c3274c |
bits = (u_int32_t)strtonum(optarg, 768, 32768, &errstr);
|
|
Jan F. Chadima |
a3ba41 |
@@ -1156,6 +1190,10 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
case 'g':
|
|
Tomáš Mráz |
c3274c |
print_generic = 1;
|
|
Tomáš Mráz |
c3274c |
break;
|
|
Tomáš Mráz |
c3274c |
+ case 'n':
|
|
Tomáš Mráz |
c3274c |
+ use_nss = 1;
|
|
Tomáš Mráz |
c3274c |
+ download = 1;
|
|
Tomáš Mráz |
c3274c |
+ break;
|
|
Tomáš Mráz |
c3274c |
case 'P':
|
|
Tomáš Mráz |
c3274c |
identity_passphrase = optarg;
|
|
Tomáš Mráz |
c3274c |
break;
|
|
Jan F. Chadima |
a3ba41 |
@@ -1187,10 +1225,10 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
case 't':
|
|
Tomáš Mráz |
c3274c |
key_type_name = optarg;
|
|
Tomáš Mráz |
c3274c |
break;
|
|
Tomáš Mráz |
c3274c |
- case 'D':
|
|
Tomáš Mráz |
c3274c |
- download = 1;
|
|
Tomáš Mráz |
c3274c |
- /*FALLTHROUGH*/
|
|
Tomáš Mráz |
c3274c |
case 'U':
|
|
Tomáš Mráz |
c3274c |
+ download = 0;
|
|
Tomáš Mráz |
c3274c |
+ /*FALLTHROUGH*/
|
|
Tomáš Mráz |
c3274c |
+ case 'D':
|
|
Tomáš Mráz |
c3274c |
reader_id = optarg;
|
|
Tomáš Mráz |
c3274c |
break;
|
|
Tomáš Mráz |
c3274c |
case 'v':
|
|
Jan F. Chadima |
a3ba41 |
@@ -1299,6 +1337,17 @@ main(int argc, char **argv)
|
|
Tomáš Mráz |
c3274c |
exit(0);
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Tomáš Mráz |
c3274c |
+ if (use_nss) {
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Tomáš Mráz |
c3274c |
+ if (download)
|
|
Tomáš Mráz |
c3274c |
+ do_nss_download(pw, reader_id, identity_file);
|
|
Tomáš Mráz |
c3274c |
+ else
|
|
Tomáš Mráz |
c3274c |
+ fatal("no support for NSS key upload.");
|
|
Tomáš Mráz |
c3274c |
+#else
|
|
Tomáš Mráz |
c3274c |
+ fatal("no support for NSS keys.");
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Tomáš Mráz |
c3274c |
+ }
|
|
Tomáš Mráz |
c3274c |
if (reader_id != NULL) {
|
|
Tomáš Mráz |
c3274c |
#ifdef SMARTCARD
|
|
Tomáš Mráz |
c3274c |
if (download)
|
|
Jan F. Chadima |
a3ba41 |
@@ -1465,14 +1514,15 @@ passphrase_again:
|
|
Jan F. Chadima |
a3ba41 |
fclose(f);
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
if (!quiet) {
|
|
Jan F. Chadima |
a3ba41 |
- char *fp = key_fingerprint(public, SSH_FP_MD5, SSH_FP_HEX);
|
|
Jan F. Chadima |
a3ba41 |
- char *ra = key_fingerprint(public, SSH_FP_MD5,
|
|
Jan F. Chadima |
a3ba41 |
+ int fips_on = FIPS_mode();
|
|
Jan F. Chadima |
a3ba41 |
+ char *fp = key_fingerprint(public, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
|
|
Jan F. Chadima |
a3ba41 |
+ char *ra = key_fingerprint(public, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5,
|
|
Jan F. Chadima |
a3ba41 |
SSH_FP_RANDOMART);
|
|
Jan F. Chadima |
a3ba41 |
printf("Your public key has been saved in %s.\n",
|
|
Jan F. Chadima |
a3ba41 |
identity_file);
|
|
Jan F. Chadima |
a3ba41 |
- printf("The key fingerprint is:\n");
|
|
Jan F. Chadima |
a3ba41 |
+ printf("The key %sfingerprint is:\n", fips_on ? "SHA1 " : "");
|
|
Jan F. Chadima |
a3ba41 |
printf("%s %s\n", fp, comment);
|
|
Jan F. Chadima |
a3ba41 |
- printf("The key's randomart image is:\n");
|
|
Jan F. Chadima |
a3ba41 |
+ printf("The key's %srandomart image is:\n", fips_on ? "SHA1 " :"");
|
|
Jan F. Chadima |
a3ba41 |
printf("%s\n", ra);
|
|
Jan F. Chadima |
a3ba41 |
xfree(ra);
|
|
Jan F. Chadima |
a3ba41 |
xfree(fp);
|
|
Jan F. Chadima |
a3ba41 |
diff -up openssh-5.2p1/ssh-rsa.c.nss-keys openssh-5.2p1/ssh-rsa.c
|
|
Jan F. Chadima |
a3ba41 |
--- openssh-5.2p1/ssh-rsa.c.nss-keys 2006-09-01 07:38:37.000000000 +0200
|
|
Jan F. Chadima |
a3ba41 |
+++ openssh-5.2p1/ssh-rsa.c 2009-03-10 03:51:55.930219040 +0100
|
|
Jan F. Chadima |
a3ba41 |
@@ -32,6 +32,10 @@
|
|
Jan F. Chadima |
a3ba41 |
#include "compat.h"
|
|
Jan F. Chadima |
a3ba41 |
#include "ssh.h"
|
|
Jan F. Chadima |
a3ba41 |
|
|
Tomáš Mráz |
c3274c |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+#include <cryptohi.h>
|
|
Tomáš Mráz |
c3274c |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
static int openssh_RSA_verify(int, u_char *, u_int, u_char *, u_int, RSA *);
|
|
Tomáš Mráz |
c3274c |
|
|
Jan F. Chadima |
a3ba41 |
/* RSASSA-PKCS1-v1_5 (PKCS #1 v2.0 signature) with SHA1 */
|
|
Jan F. Chadima |
a3ba41 |
@@ -50,6 +54,38 @@ ssh_rsa_sign(const Key *key, u_char **si
|
|
Jan F. Chadima |
a3ba41 |
error("ssh_rsa_sign: no RSA key");
|
|
Jan F. Chadima |
a3ba41 |
return -1;
|
|
Jan F. Chadima |
a3ba41 |
}
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+ slen = RSA_size(key->rsa);
|
|
Jan F. Chadima |
a3ba41 |
+ sig = xmalloc(slen);
|
|
Tomáš Mráz |
c3274c |
+
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ if (key->flags & KEY_FLAG_NSS) {
|
|
Jan F. Chadima |
a3ba41 |
+ SECItem sigitem;
|
|
Jan F. Chadima |
a3ba41 |
+ SECOidTag alg;
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ memset(&sigitem, 0, sizeof(sigitem));
|
|
Jan F. Chadima |
a3ba41 |
+ alg = (datafellows & SSH_BUG_RSASIGMD5) ?
|
|
Jan F. Chadima |
a3ba41 |
+ SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION :
|
|
Jan F. Chadima |
a3ba41 |
+ SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION;
|
|
Jan F. Chadima |
a3ba41 |
+
|
|
Jan F. Chadima |
a3ba41 |
+ if (SEC_SignData(&sigitem, (u_char *)data, datalen, key->nss->privk,
|
|
Jan F. Chadima |
a3ba41 |
+ alg) != SECSuccess) {
|
|
Jan F. Chadima |
a3ba41 |
+ error("ssh_rsa_sign: sign failed");
|
|
Jan F. Chadima |
a3ba41 |
+ return -1;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ if (sigitem.len > slen) {
|
|
Jan F. Chadima |
a3ba41 |
+ error("ssh_rsa_sign: slen %u slen2 %u", slen, sigitem.len);
|
|
Jan F. Chadima |
a3ba41 |
+ xfree(sig);
|
|
Jan F. Chadima |
a3ba41 |
+ SECITEM_ZfreeItem(&sigitem, PR_FALSE);
|
|
Jan F. Chadima |
a3ba41 |
+ return -1;
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ if (sigitem.len < slen) {
|
|
Jan F. Chadima |
a3ba41 |
+ memset(sig, 0, slen - sigitem.len);
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+ memcpy(sig+slen-sigitem.len, sigitem.data, sigitem.len);
|
|
Jan F. Chadima |
a3ba41 |
+ SECITEM_ZfreeItem(&sigitem, PR_FALSE);
|
|
Jan F. Chadima |
a3ba41 |
+ } else {
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
nid = (datafellows & SSH_BUG_RSASIGMD5) ? NID_md5 : NID_sha1;
|
|
Jan F. Chadima |
a3ba41 |
if ((evp_md = EVP_get_digestbynid(nid)) == NULL) {
|
|
Jan F. Chadima |
a3ba41 |
error("ssh_rsa_sign: EVP_get_digestbynid %d failed", nid);
|
|
Jan F. Chadima |
a3ba41 |
@@ -59,9 +95,6 @@ ssh_rsa_sign(const Key *key, u_char **si
|
|
Jan F. Chadima |
a3ba41 |
EVP_DigestUpdate(&md, data, datalen);
|
|
Jan F. Chadima |
a3ba41 |
EVP_DigestFinal(&md, digest, &dlen);
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
- slen = RSA_size(key->rsa);
|
|
Jan F. Chadima |
a3ba41 |
- sig = xmalloc(slen);
|
|
Jan F. Chadima |
a3ba41 |
-
|
|
Jan F. Chadima |
a3ba41 |
ok = RSA_sign(nid, digest, dlen, sig, &len, key->rsa);
|
|
Jan F. Chadima |
a3ba41 |
memset(digest, 'd', sizeof(digest));
|
|
Jan F. Chadima |
a3ba41 |
|
|
Jan F. Chadima |
a3ba41 |
@@ -83,6 +116,9 @@ ssh_rsa_sign(const Key *key, u_char **si
|
|
Jan F. Chadima |
a3ba41 |
xfree(sig);
|
|
Jan F. Chadima |
a3ba41 |
return -1;
|
|
Jan F. Chadima |
a3ba41 |
}
|
|
Jan F. Chadima |
a3ba41 |
+#ifdef HAVE_LIBNSS
|
|
Jan F. Chadima |
a3ba41 |
+ }
|
|
Jan F. Chadima |
a3ba41 |
+#endif
|
|
Jan F. Chadima |
a3ba41 |
/* encode signature */
|
|
Jan F. Chadima |
a3ba41 |
buffer_init(&b);
|
|
Jan F. Chadima |
a3ba41 |
buffer_put_cstring(&b, "ssh-rsa");
|