diff -ruN openssh-3.6.1p2/acconfig.h openssh-3.6.1p2+x509g1/acconfig.h --- openssh-3.6.1p2/acconfig.h 2003-03-10 02:38:10.000000000 +0200 +++ openssh-3.6.1p2+x509g1/acconfig.h 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -/* $Id: acconfig.h,v 1.149 2003/03/10 00:38:10 djm Exp $ */ +/* $Id$*/ #ifndef _CONFIG_H #define _CONFIG_H @@ -292,6 +292,9 @@ /* Specify default $PATH */ #undef USER_PATH +/* Specify location of ssh CA root */ +#undef SSHCADIR + /* Specify location of ssh.pid */ #undef _PATH_SSH_PIDDIR diff -ruN openssh-3.6.1p2/auth2-pubkey.c openssh-3.6.1p2+x509g1/auth2-pubkey.c --- openssh-3.6.1p2/auth2-pubkey.c 2002-06-06 23:27:56.000000000 +0300 +++ openssh-3.6.1p2+x509g1/auth2-pubkey.c 2003-04-30 09:06:01.000000000 +0300 @@ -1,5 +1,7 @@ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. + * X509 certificates support, + * Copyright (c) 2003 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,7 +25,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: auth2-pubkey.c,v 1.2 2002/05/31 11:35:15 markus Exp $"); +RCSID("$OpenBSD$"); #include "ssh2.h" #include "xmalloc.h" @@ -40,6 +42,7 @@ #include "auth-options.h" #include "canohost.h" #include "monitor_wrap.h" +#include "ssh-x509.h" /* import */ extern ServerOptions options; @@ -244,6 +247,13 @@ fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX); verbose("Found matching %s key: %s", key_type(found), fp); + if ((key->type == KEY_X509_RSA) || + (key->type == KEY_X509_DSA)) { + if (ssh_x509store_check(key->x509) != 1) { + found_key = 0; + verbose("x509store reject matching key"); + } + } xfree(fp); break; } diff -ruN openssh-3.6.1p2/authfd.c openssh-3.6.1p2+x509g1/authfd.c --- openssh-3.6.1p2/authfd.c 2003-01-24 02:36:23.000000000 +0200 +++ openssh-3.6.1p2+x509g1/authfd.c 2003-04-30 09:06:01.000000000 +0300 @@ -12,6 +12,8 @@ * * SSH2 implementation, * Copyright (c) 2000 Markus Friedl. All rights reserved. + * X509 certificate support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,7 +37,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: authfd.c,v 1.58 2003/01/23 13:50:27 markus Exp $"); +RCSID("$OpenBSD$"); #include @@ -474,6 +476,7 @@ buffer_put_cstring(b, key_ssh_name(key)); switch (key->type) { case KEY_RSA: + case KEY_X509_RSA: buffer_put_bignum2(b, key->rsa->n); buffer_put_bignum2(b, key->rsa->e); buffer_put_bignum2(b, key->rsa->d); @@ -482,6 +485,7 @@ buffer_put_bignum2(b, key->rsa->q); break; case KEY_DSA: + case KEY_X509_DSA: buffer_put_bignum2(b, key->dsa->p); buffer_put_bignum2(b, key->dsa->q); buffer_put_bignum2(b, key->dsa->g); @@ -489,6 +493,21 @@ buffer_put_bignum2(b, key->dsa->priv_key); break; } + if ((key->type == KEY_X509_RSA) || (key->type == KEY_X509_DSA)) { + int len; + void* str; + unsigned char *p; + + len = i2d_X509(key->x509, NULL); + str = xmalloc(len); + if (str == NULL) + { error("ssh_encode_identity_ssh2: out of memory"); return; } + + p = str; + i2d_X509(key->x509, &p); + buffer_put_string(b, str, len); + xfree(str); + } buffer_put_cstring(b, comment); } @@ -516,6 +535,8 @@ break; case KEY_RSA: case KEY_DSA: + case KEY_X509_RSA: + case KEY_X509_DSA: type = constrained ? SSH2_AGENTC_ADD_ID_CONSTRAINED : SSH2_AGENTC_ADD_IDENTITY; @@ -570,7 +591,7 @@ buffer_put_int(&msg, BN_num_bits(key->rsa->n)); buffer_put_bignum(&msg, key->rsa->e); buffer_put_bignum(&msg, key->rsa->n); - } else if (key->type == KEY_DSA || key->type == KEY_RSA) { + } else if (key->type == KEY_DSA || key->type == KEY_RSA || key->type == KEY_X509_DSA || key->type == KEY_X509_RSA ) { key_to_blob(key, &blob, &blen); buffer_put_char(&msg, SSH2_AGENTC_REMOVE_IDENTITY); buffer_put_string(&msg, blob, blen); diff -ruN openssh-3.6.1p2/authfile.c openssh-3.6.1p2+x509g1/authfile.c --- openssh-3.6.1p2/authfile.c 2003-03-15 02:36:18.000000000 +0200 +++ openssh-3.6.1p2+x509g1/authfile.c 2003-04-30 09:06:01.000000000 +0300 @@ -13,6 +13,8 @@ * * * Copyright (c) 2000 Markus Friedl. All rights reserved. + * X509 certificate support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,7 +38,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: authfile.c,v 1.52 2003/03/13 11:42:18 markus Exp $"); +RCSID("$OpenBSD$"); #include #include @@ -51,6 +53,7 @@ #include "log.h" #include "authfile.h" #include "rsa.h" +#include "ssh-x509.h" /* Version identification string for SSH v1 identity files. */ static const char authfile_id_string[] = @@ -195,6 +198,10 @@ success = PEM_write_RSAPrivateKey(fp, key->rsa, cipher, passphrase, len, NULL, NULL); break; + case KEY_X509_RSA: + case KEY_X509_DSA: + success = x509key_save_pem(fp, key, cipher, passphrase, len); + break; } fclose(fp); return success; @@ -211,6 +218,8 @@ break; case KEY_DSA: case KEY_RSA: + case KEY_X509_RSA: + case KEY_X509_DSA: return key_save_private_pem(key, filename, passphrase, comment); break; @@ -447,6 +456,7 @@ Key *prv = NULL; char *name = ""; + debug("read PEM private key begin"); fp = fdopen(fd, "r"); if (fp == NULL) { error("fdopen failed: %s", strerror(errno)); @@ -484,6 +494,8 @@ error("PEM_read_PrivateKey: mismatch or " "unknown EVP_PKEY save_type %d", pk->save_type); } + if (prv) + x509key_load_cert(prv, fp); fclose(fp); if (pk != NULL) EVP_PKEY_free(pk); @@ -629,6 +641,7 @@ Key *pub; char file[MAXPATHLEN]; + debug3("key_load_public(%.200s,...)", filename); pub = key_load_public_type(KEY_RSA1, filename, commentp); if (pub != NULL) return pub; diff -ruN openssh-3.6.1p2/config.h.in openssh-3.6.1p2+x509g1/config.h.in --- openssh-3.6.1p2/config.h.in 2003-04-29 12:37:27.000000000 +0300 +++ openssh-3.6.1p2+x509g1/config.h.in 2003-04-30 09:06:01.000000000 +0300 @@ -1,5 +1,5 @@ /* config.h.in. Generated from configure.ac by autoheader. */ -/* $Id: acconfig.h,v 1.149 2003/03/10 00:38:10 djm Exp $ */ +/* $Id$*/ #ifndef _CONFIG_H #define _CONFIG_H @@ -292,6 +292,9 @@ /* Specify default $PATH */ #undef USER_PATH +/* Specify location of ssh CA root */ +#undef SSHCADIR + /* Specify location of ssh.pid */ #undef _PATH_SSH_PIDDIR diff -ruN openssh-3.6.1p2/configure openssh-3.6.1p2+x509g1/configure --- openssh-3.6.1p2/configure 2003-04-29 12:37:28.000000000 +0300 +++ openssh-3.6.1p2+x509g1/configure 2003-04-30 09:06:02.000000000 +0300 @@ -308,7 +308,7 @@ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT build build_cpu build_vendor build_os host host_cpu host_vendor host_os CPP RANLIB ac_ct_RANLIB INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AR PERL SED ENT TEST_MINUS_S_SH SH LOGIN_PROGRAM_FALLBACK LD EGREP LIBWRAP LIBPAM INSTALL_SSH_RAND_HELPER SSH_PRIVSEP_USER PROG_LS PROG_NETSTAT PROG_ARP PROG_IFCONFIG PROG_JSTAT PROG_PS PROG_SAR PROG_W PROG_WHO PROG_LAST PROG_LASTLOG PROG_DF PROG_VMSTAT PROG_UPTIME PROG_IPCS PROG_TAIL INSTALL_SSH_PRNG_CMDS OPENSC_CONFIG PRIVSEP_PATH xauth_path STRIP_OPT XAUTH_PATH NROFF MANTYPE mansubdir user_path piddir LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT build build_cpu build_vendor build_os host host_cpu host_vendor host_os CPP RANLIB ac_ct_RANLIB INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA AR PERL SED ENT TEST_MINUS_S_SH SH LOGIN_PROGRAM_FALLBACK LD EGREP LIBWRAP LIBPAM INSTALL_SSH_RAND_HELPER SSH_PRIVSEP_USER PROG_LS PROG_NETSTAT PROG_ARP PROG_IFCONFIG PROG_JSTAT PROG_PS PROG_SAR PROG_W PROG_WHO PROG_LAST PROG_LASTLOG PROG_DF PROG_VMSTAT PROG_UPTIME PROG_IPCS PROG_TAIL INSTALL_SSH_PRNG_CMDS OPENSC_CONFIG PRIVSEP_PATH xauth_path STRIP_OPT XAUTH_PATH NROFF MANTYPE mansubdir user_path sshcadir piddir LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -891,6 +891,7 @@ --with-ipv4-default Use IPv4 by connections unless '-6' specified --with-4in6 Check for and convert IPv4 in IPv6 mapped addresses --with-bsd-auth Enable BSD auth support + --with-sshca-dir=PATH Specify location of ssh CA root --with-pid-dir=PATH Specify location of ssh.pid file --with-lastlog=FILE|DIR specify lastlog location common locations @@ -9714,6 +9715,73 @@ rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext fi +# Check vulnerable for ASN.1 encoding errors OpenSSL version. +# see http://www.openssl.org/news/secadv_20020730.txt +echo "$as_me:$LINENO: checking for ASN.1 encoding errors vulnerable OpenSSL version" >&5 +echo $ECHO_N "checking for ASN.1 encoding errors vulnerable OpenSSL version... $ECHO_C" >&6 +if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +#include + +int main(void) { + unsigned long ssl_ver = SSLeay(); + /* 0.9.6X where X > e */ + if ((0x0090606fL <= ssl_ver) && (ssl_ver <= 0x00906fffL)) + exit (0); + /* 0.9.7X where X > beta2 */ + if ((0x00907003L <= ssl_ver)) + exit (0); + exit (1); + return (1); +} + +_ACEOF +rm -f conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) + + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + { echo "$as_me:$LINENO: WARNING: Your OpenSSL library might is vulnerable for ASN.1 encoding errors" >&5 +echo "$as_me: WARNING: Your OpenSSL library might is vulnerable for ASN.1 encoding errors" >&2;} + + +fi +rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + # Some Linux systems (Slackware) need crypt() from libcrypt, *not* the # version in OpenSSL. Skip this for PAM if test "x$PAM_MSG" = "xno" -a "x$check_for_libcrypt_later" = "x1"; then @@ -17431,6 +17499,33 @@ fi; +# Where to place ssh CA root +sshcadir='${sysconfdir}/ca' +sshcadir=`eval echo ${sshcadir}` +sshcadir=`eval echo ${sshcadir}` +case $sshcadir in + NONE/*) sshcadir=`echo $sshcadir | sed "s~NONE~$ac_default_prefix~"` ;; +esac + + +# Check whether --with-sshca-dir or --without-sshca-dir was given. +if test "${with_sshca_dir+set}" = set; then + withval="$with_sshca_dir" + + if test "x$withval" != "xno" ; then + sshcadir=$withval + fi + + +fi; + +cat >>confdefs.h <<_ACEOF +#define SSHCADIR "$sshcadir" +_ACEOF + + + + # Where to place sshd.pid piddir=/var/run # make sure the directory exists @@ -17968,7 +18063,7 @@ fi - ac_config_files="$ac_config_files Makefile openbsd-compat/Makefile scard/Makefile ssh_prng_cmds" + ac_config_files="$ac_config_files Makefile openbsd-compat/Makefile scard/Makefile ssh_prng_cmds tests/CA/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -18498,6 +18593,7 @@ "openbsd-compat/Makefile" ) CONFIG_FILES="$CONFIG_FILES openbsd-compat/Makefile" ;; "scard/Makefile" ) CONFIG_FILES="$CONFIG_FILES scard/Makefile" ;; "ssh_prng_cmds" ) CONFIG_FILES="$CONFIG_FILES ssh_prng_cmds" ;; + "tests/CA/Makefile" ) CONFIG_FILES="$CONFIG_FILES tests/CA/Makefile" ;; "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} @@ -18643,6 +18739,7 @@ s,@MANTYPE@,$MANTYPE,;t t s,@mansubdir@,$mansubdir,;t t s,@user_path@,$user_path,;t t +s,@sshcadir@,$sshcadir,;t t s,@piddir@,$piddir,;t t s,@LIBOBJS@,$LIBOBJS,;t t s,@LTLIBOBJS@,$LTLIBOBJS,;t t @@ -19123,6 +19220,7 @@ echo " User binaries: $B" echo " System binaries: $C" echo " Configuration files: $D" +echo " CA root: $sshcadir" echo " Askpass program: $E" echo " Manual pages: $F" echo " PID file: $G" diff -ruN openssh-3.6.1p2/configure.ac openssh-3.6.1p2+x509g1/configure.ac --- openssh-3.6.1p2/configure.ac 2003-04-29 12:12:08.000000000 +0300 +++ openssh-3.6.1p2+x509g1/configure.ac 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -# $Id: configure.ac,v 1.113.2.1 2003/04/29 09:12:08 djm Exp $ +# $Id$ AC_INIT AC_CONFIG_SRCDIR([ssh.c]) @@ -909,6 +909,35 @@ ] ) +# Check vulnerable for ASN.1 encoding errors OpenSSL version. +# see http://www.openssl.org/news/secadv_20020730.txt +AC_MSG_CHECKING([for ASN.1 encoding errors vulnerable OpenSSL version]) +AC_TRY_RUN( + [ +#include +#include + +int main(void) { + unsigned long ssl_ver = SSLeay(); + /* 0.9.6X where X > e */ + if ((0x0090606fL <= ssl_ver) && (ssl_ver <= 0x00906fffL)) + exit (0); + /* 0.9.7X where X > beta2 */ + if ((0x00907003L <= ssl_ver)) + exit (0); + exit (1); + return (1); +} + ], + [ + AC_MSG_RESULT(no) + ], + [ + AC_MSG_RESULT(yes) + AC_MSG_WARN(Your OpenSSL library might is vulnerable for ASN.1 encoding errors) + ] +) + # Some Linux systems (Slackware) need crypt() from libcrypt, *not* the # version in OpenSSL. Skip this for PAM if test "x$PAM_MSG" = "xno" -a "x$check_for_libcrypt_later" = "x1"; then @@ -2231,6 +2260,27 @@ ] ) +# Where to place ssh CA root +sshcadir='${sysconfdir}/ca' +sshcadir=`eval echo ${sshcadir}` +sshcadir=`eval echo ${sshcadir}` +case $sshcadir in + NONE/*) sshcadir=`echo $sshcadir | sed "s~NONE~$ac_default_prefix~"` ;; +esac + +AC_ARG_WITH(sshca-dir, + [ --with-sshca-dir=PATH Specify location of ssh CA root], + [ + if test "x$withval" != "xno" ; then + sshcadir=$withval + fi + ] +) + +AC_DEFINE_UNQUOTED(SSHCADIR, "$sshcadir") +AC_SUBST(sshcadir) + + # Where to place sshd.pid piddir=/var/run # make sure the directory exists @@ -2491,7 +2541,7 @@ fi AC_EXEEXT -AC_CONFIG_FILES([Makefile openbsd-compat/Makefile scard/Makefile ssh_prng_cmds]) +AC_CONFIG_FILES([Makefile openbsd-compat/Makefile scard/Makefile ssh_prng_cmds tests/CA/Makefile]) AC_OUTPUT # Print summary of options @@ -2513,6 +2563,7 @@ echo " User binaries: $B" echo " System binaries: $C" echo " Configuration files: $D" +echo " CA root: $sshcadir" echo " Askpass program: $E" echo " Manual pages: $F" echo " PID file: $G" diff -ruN openssh-3.6.1p2/hostfile.c openssh-3.6.1p2+x509g1/hostfile.c --- openssh-3.6.1p2/hostfile.c 2002-08-01 04:21:57.000000000 +0300 +++ openssh-3.6.1p2+x509g1/hostfile.c 2003-04-30 09:06:01.000000000 +0300 @@ -13,6 +13,8 @@ * * Copyright (c) 1999, 2000 Markus Friedl. All rights reserved. * Copyright (c) 1999 Niels Provos. All rights reserved. + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,13 +38,14 @@ */ #include "includes.h" -RCSID("$OpenBSD: hostfile.c,v 1.30 2002/07/24 16:11:18 markus Exp $"); +RCSID("$OpenBSD$"); #include "packet.h" #include "match.h" #include "key.h" #include "hostfile.h" #include "log.h" +#include "ssh-x509.h" /* * Parses an RSA (number of bits, e, n) or DSA key from a string. Moves the @@ -221,7 +224,13 @@ if (!f) return 0; fprintf(f, "%s ", host); - if (key_write(key, f)) { + if ((key->type == KEY_X509_RSA) || (key->type == KEY_X509_DSA)) { + /* key_write will print x509 certificate in blob format :-( */ + success = x509key_write_subject(key, f); + } else { + success = key_write(key, f); + } + if (success) { success = 1; } else { error("add_host_to_hostfile: saving key in %s failed", filename); diff -ruN openssh-3.6.1p2/key.c openssh-3.6.1p2+x509g1/key.c --- openssh-3.6.1p2/key.c 2003-02-24 03:01:41.000000000 +0200 +++ openssh-3.6.1p2+x509g1/key.c 2003-04-30 09:06:01.000000000 +0300 @@ -10,6 +10,8 @@ * * * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,13 +34,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: key.c,v 1.51 2003/02/12 09:33:04 markus Exp $"); +RCSID("$OpenBSD$"); #include #include "xmalloc.h" #include "key.h" #include "rsa.h" +#include "ssh-x509.h" #include "uuencode.h" #include "buffer.h" #include "bufaux.h" @@ -55,9 +58,11 @@ k->flags = 0; k->dsa = NULL; k->rsa = NULL; + k->x509 = NULL; switch (k->type) { case KEY_RSA1: case KEY_RSA: + case KEY_X509_RSA: if ((rsa = RSA_new()) == NULL) fatal("key_new: RSA_new failed"); if ((rsa->n = BN_new()) == NULL) @@ -65,8 +70,13 @@ if ((rsa->e = BN_new()) == NULL) fatal("key_new: BN_new failed"); k->rsa = rsa; + if (k->type == KEY_X509_RSA) { + if ((k->x509 = X509_new()) == NULL) + fatal("key_new: X509_new failed"); + } break; case KEY_DSA: + case KEY_X509_DSA: if ((dsa = DSA_new()) == NULL) fatal("key_new: DSA_new failed"); if ((dsa->p = BN_new()) == NULL) @@ -78,6 +88,10 @@ if ((dsa->pub_key = BN_new()) == NULL) fatal("key_new: BN_new failed"); k->dsa = dsa; + if (k->type == KEY_X509_DSA) { + if ((k->x509 = X509_new()) == NULL) + fatal("key_new: X509_new failed"); + } break; case KEY_UNSPEC: break; @@ -95,6 +109,7 @@ switch (k->type) { case KEY_RSA1: case KEY_RSA: + case KEY_X509_RSA: if ((k->rsa->d = BN_new()) == NULL) fatal("key_new_private: BN_new failed"); if ((k->rsa->iqmp = BN_new()) == NULL) @@ -107,10 +122,25 @@ fatal("key_new_private: BN_new failed"); if ((k->rsa->dmp1 = BN_new()) == NULL) fatal("key_new_private: BN_new failed"); + if (k->type == KEY_X509_RSA) { + debug3("key_new_private: X509(rsa) MORE ...?"); + /* + if ((k->x509 = X509_new()) == NULL) + fatal("key_new: X509_new failed"); + */ + } break; case KEY_DSA: + case KEY_X509_DSA: if ((k->dsa->priv_key = BN_new()) == NULL) fatal("key_new_private: BN_new failed"); + if (k->type == KEY_X509_DSA) { + debug3("key_new_private: X509(dsa) MORE ...?"); + /* + if ((k->x509 = X509_new()) == NULL) + fatal("key_new: X509_new failed"); + */ + } break; case KEY_UNSPEC: break; @@ -135,6 +165,21 @@ DSA_free(k->dsa); k->dsa = NULL; break; + case KEY_X509_RSA: + case KEY_X509_DSA: + if (k->dsa != NULL) { + DSA_free(k->dsa); + k->dsa = NULL; + } + if (k->rsa != NULL) { + RSA_free(k->rsa); + k->rsa = NULL; + } + if (k->x509 != NULL) { + X509_free(k->x509); + k->x509 = NULL; + } + break; case KEY_UNSPEC: break; default: @@ -143,6 +188,7 @@ } xfree(k); } + int key_equal(Key *a, Key *b) { @@ -162,6 +208,10 @@ BN_cmp(a->dsa->g, b->dsa->g) == 0 && BN_cmp(a->dsa->pub_key, b->dsa->pub_key) == 0; break; + case KEY_X509_RSA: + case KEY_X509_DSA: + return ssh_x509_equal(a, b) == 0; + break; default: fatal("key_equal: bad key type %d", a->type); break; @@ -203,6 +253,8 @@ break; case KEY_DSA: case KEY_RSA: + case KEY_X509_RSA: + case KEY_X509_DSA: key_to_blob(k, &blob, &len); break; case KEY_UNSPEC: @@ -406,6 +458,8 @@ case KEY_UNSPEC: case KEY_RSA: case KEY_DSA: + case KEY_X509_RSA: + case KEY_X509_DSA: space = strchr(cp, ' '); if (space == NULL) { debug3("key_read: missing whitespace"); @@ -430,6 +484,9 @@ debug3("key_read: type mismatch"); return -1; } + k = x509key_from_subject(type, cp); + if(k != NULL) + goto noblob; len = 2*strlen(cp); blob = xmalloc(len); n = uudecode(cp, blob, len); @@ -449,7 +506,30 @@ key_free(k); return -1; } +noblob: /*XXXX*/ + if (ret->type == KEY_X509_RSA || + ret->type == KEY_X509_DSA ) { + if (ret->rsa != NULL) + RSA_free(ret->rsa); + ret->rsa = k->rsa; + k->rsa = NULL; + if (ret->dsa != NULL) + DSA_free(ret->dsa); + ret->dsa = k->dsa; + k->dsa = NULL; + if (ret->x509 != NULL) + X509_free(ret->x509); + ret->x509 = k->x509; + k->x509 = NULL; +#ifdef DEBUG_PK + if (ret->type == KEY_X509_RSA) + RSA_print_fp(stderr, ret->rsa, 8); + else + DSA_print_fp(stderr, ret->dsa, 8); +#endif + success = 1; + } else if (ret->type == KEY_RSA) { if (ret->rsa != NULL) RSA_free(ret->rsa); @@ -516,6 +596,8 @@ } xfree(blob); xfree(uu); + } else if ( (key->type == KEY_X509_RSA) || (key->type == KEY_X509_DSA) ) { + success = x509key_write(key, f); } return success; } @@ -533,6 +615,14 @@ case KEY_DSA: return "DSA"; break; + case KEY_X509_RSA: + if(k->rsa) return "RSA+cert"; + return "X509(rsa)"; + break; + case KEY_X509_DSA: + if(k->dsa) return "DSA+cert"; + return "X509(dsa)"; + break; } return "unknown"; } @@ -547,6 +637,12 @@ case KEY_DSA: return "ssh-dss"; break; + case KEY_X509_RSA: + return "x509v3-sign-rsa"; + break; + case KEY_X509_DSA: + return "x509v3-sign-dss"; + break; } return "ssh-unknown"; } @@ -562,6 +658,10 @@ case KEY_DSA: return BN_num_bits(k->dsa->p); break; + case KEY_X509_RSA: + case KEY_X509_DSA: + return ssh_x509_key_size(k); + break; } return 0; } @@ -636,6 +736,7 @@ int key_type_from_name(char *name) { + debug3("call key_type_from_name(%.200s) ...", name); if (strcmp(name, "rsa1") == 0) { return KEY_RSA1; } else if (strcmp(name, "rsa") == 0) { @@ -646,6 +747,10 @@ return KEY_RSA; } else if (strcmp(name, "ssh-dss") == 0) { return KEY_DSA; + } else if (strcmp(name, "x509v3-sign-rsa") == 0) { + return KEY_X509_RSA; + } else if (strcmp(name, "x509v3-sign-dss") == 0) { + return KEY_X509_DSA; } debug2("key_type_from_name: unknown key type '%s'", name); return KEY_UNSPEC; @@ -680,14 +785,19 @@ char *ktype; int rlen, type; Key *key = NULL; + debug3("key_from_blob(..., %d)", blen); #ifdef DEBUG_PK dump_base64(stderr, blob, blen); #endif + if ((key = x509key_from_blob(blob, blen)) != NULL) { + return key; + } buffer_init(&b); buffer_append(&b, blob, blen); ktype = buffer_get_string(&b, NULL); type = key_type_from_name(ktype); + debug3("key_from_blob(..., ...) ktype=%.30s", ktype); switch (type) { case KEY_RSA: @@ -747,6 +857,11 @@ buffer_put_bignum2(&b, key->rsa->e); buffer_put_bignum2(&b, key->rsa->n); break; + case KEY_X509_RSA: + case KEY_X509_DSA: + if (!x509key_to_blob(key, &b)) + return 0; + break; default: error("key_to_blob: unsupported key type %d", key->type); buffer_free(&b); @@ -777,6 +892,10 @@ case KEY_RSA: return ssh_rsa_sign(key, sigp, lenp, data, datalen); break; + case KEY_X509_RSA: + case KEY_X509_DSA: + return ssh_x509_sign(key, sigp, lenp, data, datalen); + break; default: error("key_sign: illegal key type %d", key->type); return -1; @@ -804,6 +923,10 @@ case KEY_RSA: return ssh_rsa_verify(key, signature, signaturelen, data, datalen); break; + case KEY_X509_RSA: + case KEY_X509_DSA: + return ssh_x509_verify(key, signature, signaturelen, data, datalen); + break; default: error("key_verify: illegal key type %d", key->type); return -1; @@ -826,6 +949,7 @@ switch (k->type) { case KEY_RSA1: case KEY_RSA: + case KEY_X509_RSA: if ((pk->rsa = RSA_new()) == NULL) fatal("key_demote: RSA_new failed"); if ((pk->rsa->e = BN_dup(k->rsa->e)) == NULL) @@ -834,6 +958,7 @@ fatal("key_demote: BN_dup failed"); break; case KEY_DSA: + case KEY_X509_DSA: if ((pk->dsa = DSA_new()) == NULL) fatal("key_demote: DSA_new failed"); if ((pk->dsa->p = BN_dup(k->dsa->p)) == NULL) @@ -846,9 +971,19 @@ fatal("key_demote: BN_dup failed"); break; default: - fatal("key_free: bad key type %d", k->type); + fatal("key_demote: bad key type %d", k->type); break; } + switch (k->type) { + case KEY_X509_RSA: + case KEY_X509_DSA: + if(k->x509) { + if ((pk->x509 = X509_dup(k->x509)) == NULL) + fatal("key_demote: X509_dup failed"); + } else + fatal("key_demote: no X509 data"); + break; + } return (pk); } diff -ruN openssh-3.6.1p2/key.h openssh-3.6.1p2+x509g1/key.h --- openssh-3.6.1p2/key.h 2003-02-24 03:01:41.000000000 +0200 +++ openssh-3.6.1p2+x509g1/key.h 2003-04-30 09:06:00.000000000 +0300 @@ -1,7 +1,9 @@ -/* $OpenBSD: key.h,v 1.20 2003/02/12 09:33:04 markus Exp $ */ +/* $OpenBSD$ */ /* * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,12 +30,15 @@ #include #include +#include typedef struct Key Key; enum types { KEY_RSA1, KEY_RSA, KEY_DSA, + KEY_X509_RSA, + KEY_X509_DSA, KEY_UNSPEC }; enum fp_type { @@ -53,6 +58,7 @@ int flags; RSA *rsa; DSA *dsa; + X509 *x509; }; Key *key_new(int); diff -ruN openssh-3.6.1p2/log.c openssh-3.6.1p2+x509g1/log.c --- openssh-3.6.1p2/log.c 2003-01-14 13:22:43.000000000 +0200 +++ openssh-3.6.1p2+x509g1/log.c 2003-04-30 09:06:01.000000000 +0300 @@ -34,7 +34,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: log.c,v 1.25 2003/01/11 18:29:43 markus Exp $"); +RCSID("$OpenBSD$"); #include "log.h" #include "xmalloc.h" @@ -334,6 +334,11 @@ } } +LogLevel +get_log_level(void) { + return log_level; +} + #define MSGBUFSIZ 1024 void diff -ruN openssh-3.6.1p2/log.h openssh-3.6.1p2+x509g1/log.h --- openssh-3.6.1p2/log.h 2002-07-24 00:01:57.000000000 +0300 +++ openssh-3.6.1p2+x509g1/log.h 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.8 2002/07/19 15:43:33 markus Exp $ */ +/* $OpenBSD$ */ /* * Author: Tatu Ylonen @@ -49,6 +49,7 @@ } LogLevel; void log_init(char *, LogLevel, SyslogFacility, int); +LogLevel get_log_level(void); SyslogFacility log_facility_number(char *); LogLevel log_level_number(char *); diff -ruN openssh-3.6.1p2/Makefile.in openssh-3.6.1p2+x509g1/Makefile.in --- openssh-3.6.1p2/Makefile.in 2003-04-29 12:12:08.000000000 +0300 +++ openssh-3.6.1p2+x509g1/Makefile.in 2003-04-30 09:06:01.000000000 +0300 @@ -1,4 +1,4 @@ -# $Id: Makefile.in,v 1.228.2.1 2003/04/29 09:12:08 djm Exp $ +# $Id$ # uncomment if you run a non bourne compatable shell. Ie. csh #SHELL = @SH@ @@ -14,6 +14,7 @@ mandir=@mandir@ mansubdir=@mansubdir@ sysconfdir=@sysconfdir@ +sshcadir=@sshcadir@ piddir=@piddir@ srcdir=@srcdir@ top_srcdir=@top_srcdir@ @@ -30,6 +31,7 @@ STRIP_OPT=@STRIP_OPT@ PATHS= -DSSHDIR=\"$(sysconfdir)\" \ + -DSSHCADIR=\"$(sshcadir)\" \ -D_PATH_SSH_PROGRAM=\"$(SSH_PROGRAM)\" \ -D_PATH_SSH_ASKPASS_DEFAULT=\"$(ASKPASS_PROGRAM)\" \ -D_PATH_SFTP_SERVER=\"$(SFTP_SERVER)\" \ @@ -58,6 +60,8 @@ INSTALL_SSH_PRNG_CMDS=@INSTALL_SSH_PRNG_CMDS@ INSTALL_SSH_RAND_HELPER=@INSTALL_SSH_RAND_HELPER@ +X509_OBJS=ssh-x509.o x509store.o + TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) ssh-rand-helper${EXEEXT} sftp-server$(EXEEXT) sftp$(EXEEXT) LIBSSH_OBJS=authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o \ @@ -67,7 +71,7 @@ key.o dispatch.o kex.o mac.o uuencode.o misc.o \ rijndael.o ssh-dss.o ssh-rsa.o dh.o kexdh.o kexgex.o \ kexdhc.o kexgexc.o scard.o msg.o progressmeter.o \ - entropy.o + entropy.o $(X509_OBJS) SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \ sshconnect.o sshconnect1.o sshconnect2.o @@ -100,6 +104,10 @@ -e 's|/etc/ssh/ssh_host_key|$(sysconfdir)/ssh_host_key|g' \ -e 's|/etc/ssh/ssh_host_dsa_key|$(sysconfdir)/ssh_host_dsa_key|g' \ -e 's|/etc/ssh/ssh_host_rsa_key|$(sysconfdir)/ssh_host_rsa_key|g' \ + -e 's|/etc/ssh/ca/ca-bundle.crt|$(sshcadir)/ca-bundle.crt|g' \ + -e 's|/etc/ssh/ca/crt|$(sshcadir)/crt|g' \ + -e 's|/etc/ssh/ca/ca-bundle.crl|$(sshcadir)/ca-bundle.crl|g' \ + -e 's|/etc/ssh/ca/crl|$(sshcadir)/crl|g' \ -e 's|/var/run/sshd.pid|$(piddir)/sshd.pid|g' \ -e 's|/etc/ssh/moduli|$(sysconfdir)/moduli|g' \ -e 's|/etc/sshrc|$(sysconfdir)/sshrc|g' \ @@ -184,6 +192,7 @@ rm -f *.o *.a $(TARGETS) logintest config.cache config.log rm -f *.out core (cd openbsd-compat && $(MAKE) clean) + (cd tests/CA && $(MAKE) clean) distclean: rm -f *.o *.a $(TARGETS) logintest config.cache config.log @@ -192,6 +201,7 @@ rm -rf autom4te.cache (cd openbsd-compat && $(MAKE) distclean) (cd scard && $(MAKE) distclean) + (cd tests/CA && $(MAKE) distclean) veryclean: rm -f configure config.h.in *.0 @@ -200,6 +210,7 @@ rm -f Makefile config.h config.status ssh_prng_cmds *~ (cd openbsd-compat && $(MAKE) distclean) (cd scard && $(MAKE) distclean) + (cd tests/CA && $(MAKE) distclean) mrproper: distclean @@ -233,6 +244,8 @@ $(srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/$(mansubdir)5 $(srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/$(mansubdir)8 $(srcdir)/mkinstalldirs $(DESTDIR)$(libexecdir) + $(srcdir)/mkinstalldirs $(DESTDIR)$(sshcadir) + $(srcdir)/mkinstalldirs $(DESTDIR)$(piddir) (umask 022 ; $(srcdir)/mkinstalldirs $(DESTDIR)$(PRIVSEP_PATH)) $(INSTALL) -m 0755 $(STRIP_OPT) ssh $(DESTDIR)$(bindir)/ssh $(INSTALL) -m 0755 $(STRIP_OPT) scp $(DESTDIR)$(bindir)/scp @@ -359,3 +372,23 @@ -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8 -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1 + + +check: $(TARGETS) check-certs + +check-certs: + @if test ! -d "tests/CA"; then \ + mkdir -p "tests/CA" || exit 1; \ + fi + @BUILDDIR="`pwd`"; \ + ( cd "tests/CA" && \ + $(MAKE) \ + TEST_SSH_SSH="$${BUILDDIR}/ssh" \ + TEST_SSH_SSHD="$${BUILDDIR}/sshd" \ + TEST_SSH_SSHAGENT="$${BUILDDIR}/ssh-agent" \ + TEST_SSH_SSHADD="$${BUILDDIR}/ssh-add" \ + TEST_SSH_SSHKEYGEN="$${BUILDDIR}/ssh-keygen" \ + TEST_SSH_SSHKEYSCAN="$${BUILDDIR}/ssh-keyscan" \ + TEST_SSH_SFTP="$${BUILDDIR}/sftp" \ + TEST_SSH_SFTPSERVER="$${BUILDDIR}/sftp-server" \ + $@ ) diff -ruN openssh-3.6.1p2/myproposal.h openssh-3.6.1p2+x509g1/myproposal.h --- openssh-3.6.1p2/myproposal.h 2002-04-05 01:10:39.000000000 +0300 +++ openssh-3.6.1p2+x509g1/myproposal.h 2003-04-30 09:06:00.000000000 +0300 @@ -1,7 +1,9 @@ -/* $OpenBSD: myproposal.h,v 1.14 2002/04/03 09:26:11 markus Exp $ */ +/* $OpenBSD$ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -24,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define KEX_DEFAULT_KEX "diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1" -#define KEX_DEFAULT_PK_ALG "ssh-rsa,ssh-dss" +#define KEX_DEFAULT_PK_ALG "x509v3-sign-rsa,x509v3-sign-dss,ssh-rsa,ssh-dss" #define KEX_DEFAULT_ENCRYPT \ "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour," \ "aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se" diff -ruN openssh-3.6.1p2/pathnames.h openssh-3.6.1p2+x509g1/pathnames.h --- openssh-3.6.1p2/pathnames.h 2002-06-06 22:57:34.000000000 +0300 +++ openssh-3.6.1p2+x509g1/pathnames.h 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -/* $OpenBSD: pathnames.h,v 1.13 2002/05/23 19:24:30 markus Exp $ */ +/* $OpenBSD$ */ /* * Author: Tatu Ylonen @@ -10,6 +10,29 @@ * software must be clearly marked as such, and if the derived work is * incompatible with the protocol description in the RFC file, it must be * called by a name other than "ssh" or "Secure Shell". + * + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define ETCDIR "/etc" @@ -167,3 +190,20 @@ #ifndef ASKPASS_PROGRAM #define ASKPASS_PROGRAM "/usr/lib/ssh/ssh-askpass" #endif /* ASKPASS_PROGRAM */ + + +#ifndef SSHCADIR +#define SSHCADIR SSHDIR "/ca" +#endif + +/* x509 user store */ +#define _PATH_USERCA_CERTIFICATE_FILE "~/" _PATH_SSH_USER_DIR "/ca-bundle.crt" +#define _PATH_USERCA_CERTIFICATE_PATH "~/" _PATH_SSH_USER_DIR "/crt" +#define _PATH_USERCA_REVOCATION_FILE "~/" _PATH_SSH_USER_DIR "/ca-bundle.crl" +#define _PATH_USERCA_REVOCATION_PATH "~/" _PATH_SSH_USER_DIR "/crl" + +/* x509 global store */ +#define _PATH_CA_CERTIFICATE_FILE SSHCADIR "/ca-bundle.crt" +#define _PATH_CA_CERTIFICATE_PATH SSHCADIR "/crt" +#define _PATH_CA_REVOCATION_FILE SSHCADIR "/ca-bundle.crl" +#define _PATH_CA_REVOCATION_PATH SSHCADIR "/crl" diff -ruN openssh-3.6.1p2/readconf.c openssh-3.6.1p2+x509g1/readconf.c --- openssh-3.6.1p2/readconf.c 2003-04-01 14:43:39.000000000 +0300 +++ openssh-3.6.1p2+x509g1/readconf.c 2003-04-30 09:06:01.000000000 +0300 @@ -9,10 +9,33 @@ * software must be clearly marked as such, and if the derived work is * incompatible with the protocol description in the RFC file, it must be * called by a name other than "ssh" or "Secure Shell". + * + * X509 certificate store support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: readconf.c,v 1.104 2003/04/01 10:22:21 markus Exp $"); +RCSID("$OpenBSD$"); #include "ssh.h" #include "xmalloc.h" @@ -25,6 +48,7 @@ #include "misc.h" #include "kex.h" #include "mac.h" +#include "tildexpand.h" /* Format of the configuration file: @@ -114,6 +138,11 @@ oDynamicForward, oPreferredAuthentications, oHostbasedAuthentication, oHostKeyAlgorithms, oBindAddress, oSmartcardDevice, oClearAllForwardings, oNoHostAuthenticationForLocalhost, + sAllowedServerCertPurpose, + sCACertificateFile, sCACertificatePath, + sCARevocationFile, sCARevocationPath, + sUserCACertificateFile, sUserCACertificatePath, + sUserCARevocationFile, sUserCARevocationPath, oEnableSSHKeysign, oDeprecated } OpCodes; @@ -188,6 +217,15 @@ { "clearallforwardings", oClearAllForwardings }, { "enablesshkeysign", oEnableSSHKeysign }, { "nohostauthenticationforlocalhost", oNoHostAuthenticationForLocalhost }, + { "allowedcertpurpose", sAllowedServerCertPurpose }, + { "cacertificatefile", sCACertificateFile }, + { "cacertificatepath", sCACertificatePath }, + { "carevocationfile", sCARevocationFile }, + { "carevocationpath", sCARevocationPath }, + { "usercacertificatefile", sUserCACertificateFile }, + { "usercacertificatepath", sUserCACertificatePath }, + { "usercarevocationfile", sUserCARevocationFile }, + { "usercarevocationpath", sUserCARevocationPath }, { NULL, oBadOption } }; @@ -670,6 +708,58 @@ intptr = &options->enable_ssh_keysign; goto parse_flag; + case sAllowedServerCertPurpose: + arg = strdelim(&s); + if (arg && *arg) { + if (strcasecmp(arg, "skip") == 0) goto skip_purpose; + + { /* convert string to OpenSSL index */ + int purpose_index; + purpose_index = sshserver_cert_purpose (arg); + if (purpose_index < 0) + fatal("config error: unsupported purpose '%.30s' in file %s line %d.", arg, filename, linenum); + + options->allowedcertpurpose = purpose_index; + } + } else { +skip_purpose: + options->allowedcertpurpose = -2; + verbose("config warning: option is set to don`t check certificate purpose in file %s line %d.", filename, linenum); + } + break; + + case sCACertificateFile: + case sCACertificatePath: + case sCARevocationFile: + case sCARevocationPath: + case sUserCACertificateFile: + case sUserCACertificatePath: + case sUserCARevocationFile: + case sUserCARevocationPath: + arg = strdelim(&s); + if (!arg || *arg == '\0') + fatal("%s line %d: Missing argument.", filename, linenum); + switch (opcode) { + case sCACertificateFile: + options->ca.certificate_file = xstrdup(arg); break; + case sCACertificatePath: + options->ca.certificate_path = xstrdup(arg); break; + case sCARevocationFile: + options->ca.revocation_file = xstrdup(arg); break; + case sCARevocationPath: + options->ca.revocation_path = xstrdup(arg); break; + case sUserCACertificateFile: + options->userca.certificate_file = xstrdup(arg); break; + case sUserCACertificatePath: + options->userca.certificate_path = xstrdup(arg); break; + case sUserCARevocationFile: + options->userca.revocation_file = xstrdup(arg); break; + case sUserCARevocationPath: + options->userca.revocation_path = xstrdup(arg); break; + default: + } + break; + case oDeprecated: debug("%s line %d: Deprecated option \"%s\"", filename, linenum, keyword); @@ -795,6 +885,44 @@ options->smartcard_device = NULL; options->enable_ssh_keysign = - 1; options->no_host_authentication_for_localhost = - 1; + options->allowedcertpurpose = -1; + options->ca.certificate_file = NULL; + options->ca.certificate_path = NULL; + options->ca.revocation_file = NULL; + options->ca.revocation_path = NULL; + options->userca.certificate_file = NULL; + options->userca.certificate_path = NULL; + options->userca.revocation_file = NULL; + options->userca.revocation_path = NULL; +} + +static int +ssh_x509store_init (Options *options) { + int x509_store_loaded = 0; + + ssh_x509store_setpurpose(options->allowedcertpurpose); + + if(ssh_x509store_addlocations(&options->userca)) { + x509_store_loaded = 1; + } + if(ssh_x509store_addlocations(&options->ca)) { + x509_store_loaded = 1; + } + + return x509_store_loaded; +} + +static void +tilde_expand_filename2(char **_fn, char* _default) { + extern uid_t original_real_uid; + + if (*_fn == NULL) { + *_fn = tilde_expand_filename(_default, original_real_uid); + } else { + char *p = *_fn; + *_fn = tilde_expand_filename(*_fn, original_real_uid); + xfree(p); + } } /* @@ -916,4 +1044,22 @@ /* options->hostname will be set in the main program if appropriate */ /* options->host_key_alias should not be set by default */ /* options->preferred_authentications will be set in ssh */ + + if (options->allowedcertpurpose == -1) + options->allowedcertpurpose = sshserver_cert_purpose("sslserver"); + if (options->ca.certificate_file == NULL) + options->ca.certificate_file = _PATH_CA_CERTIFICATE_FILE; + if (options->ca.certificate_path == NULL) + options->ca.certificate_path = _PATH_CA_CERTIFICATE_PATH; + if (options->ca.revocation_file == NULL) + options->ca.revocation_file = _PATH_CA_REVOCATION_FILE; + if (options->ca.revocation_path == NULL) + options->ca.revocation_path = _PATH_CA_REVOCATION_PATH; + + tilde_expand_filename2(&options->userca.certificate_file, _PATH_USERCA_CERTIFICATE_FILE); + tilde_expand_filename2(&options->userca.certificate_path, _PATH_USERCA_CERTIFICATE_PATH); + tilde_expand_filename2(&options->userca.revocation_file , _PATH_USERCA_REVOCATION_FILE ); + tilde_expand_filename2(&options->userca.revocation_path , _PATH_USERCA_REVOCATION_PATH ); + + ssh_x509store_init(options); } diff -ruN openssh-3.6.1p2/readconf.h openssh-3.6.1p2+x509g1/readconf.h --- openssh-3.6.1p2/readconf.h 2003-04-01 14:43:40.000000000 +0300 +++ openssh-3.6.1p2+x509g1/readconf.h 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -/* $OpenBSD: readconf.h,v 1.46 2003/04/01 10:22:21 markus Exp $ */ +/* $OpenBSD$*/ /* * Author: Tatu Ylonen @@ -11,12 +11,36 @@ * software must be clearly marked as such, and if the derived work is * incompatible with the protocol description in the RFC file, it must be * called by a name other than "ssh" or "Secure Shell". + * + * X509 certificate store support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef READCONF_H #define READCONF_H #include "key.h" +#include "x509store.h" /* Data structure for representing a forwarding request. */ @@ -102,6 +126,13 @@ int enable_ssh_keysign; int no_host_authentication_for_localhost; + + /* allowed server certificate purpose */ + int allowedcertpurpose; + /* sshd PKI(X509) global store */ + X509StoreOptions ca; + /* sshd PKI(X509) user store */ + X509StoreOptions userca; } Options; diff -ruN openssh-3.6.1p2/README.x509v3 openssh-3.6.1p2+x509g1/README.x509v3 --- openssh-3.6.1p2/README.x509v3 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/README.x509v3 2003-04-30 09:06:00.000000000 +0300 @@ -0,0 +1,315 @@ + Roumen Petrov + Sofia, Bulgaria + Wed Apr 30 2003 + +How to use X.509 certificates with OpenSSH? + + +Identity or hostkey file for protocol version 2 can contain private key +plus x509 certificate in PEM format. Note that protocol version 2 keys +are in PEM format. To use X.509 certificate as identity or hostkey user +should convert certificate in PEM format and append to file. After this +with "ssh-keygen -y ..." user must update "pub" file. +File (identity or hostkey) with X.509 certificate (RSA key): +-----BEGIN RSA PRIVATE KEY----- +..... +-----END RSA PRIVATE KEY----- +-----BEGIN CERTIFICATE----- +..... +-----END CERTIFICATE----- +Note that to use X.509 certificates in OpenSSH files must contain +private key followed by certificate. + + +1.) server configuration: +1.1.) .../sshd_config +1.1.1.) "X509 store". "X509 store" is used to verify client keys. +AllowedCertPurpose sslclient + The intended use off the X509 client certificate. + +CACertificateFile /etc/ssh/ca/ca-bundle.crt + This file contain multiple certificates of certificate signers in PEM +format concatenated together. You can get a copy from openssl, apache, +KDE, mutt, etc. packages. Original file might is exported from Netscape +certificate database and one download URL is: + http://www.modssl.org/contrib/ca-bundle.crt.tar.gz + +CACertificatePath /etc/ssh/ca/crt + "Hash dir" with certificates of certificate signers. Each certificate +should be stored in separate file with name [HASH].[NUMBER], where +[HASH] is certificate hash value and [NUMBER] is an integer starting +from zero. Hash is result from command like this: +$ openssl x509 -in certificate_file_name -noout -hash + +CARevocationFile /etc/ssh/ca/ca-bundle.crl + This file contain multiple "Certificate Revocation List" (CRL) of +certificate signers in PEM format concatenated together. + +CARevocationPath /etc/ssh/ca/crl + "Hash dir" with "Certificate Revocation List" (CRL) of certificate +signers. Each CRL should be stored in separate file with name +[HASH].r[NUMBER], where [HASH] is CRL hash value and [NUMBER] is an +integer starting from zero. Hash is result from command like this: +$ openssl crl -in crl_file_name -noout -hash + +1.1.2.) HostKey files... + Host key for protocol version 2 can contain private key plus x509 +certificate in PEM format. + + +1.2.) append in USER_HOME/.ssh/authorized_keys a record with following +format: + +where: +KEY_TYPE:=x509v3-sign-rsa|x509v3-sign-dss (case sensitive !) +WORDDN:={Distinguished Name| + Distinguished-Name| + Distinguished_Name| + DistinguishedName| + DN| + Subject} +WORDDNSUFF:='='|':'|'' +NOTES: +- WORDDN is case insensitive ! + +- is like output from command: +$ openssl x509 -noout -subject -in A_CERTIFICATE_FILE + +- can be in RFC2253 format like output from command: +$ openssl x509 -noout -subject -in A_CERTIFICATE_FILE -nameopt RFC2253 + +- Order of items in is not important and separator +can be symbol "/", "," or mixed. All following subjects are equal: +a)CN=OpenSSH RSA test certificate(dsa),OU=OpenSSH Testers,O=OpenSSH Test Team,ST=World,C=XX +b)/C=XX/ST=World/O=OpenSSH Test Team/OU=OpenSSH Testers/CN=OpenSSH RSA test certificate(dsa) +c)/O=OpenSSH Test Team/OU=OpenSSH Testers/C=XX/ST=World/CN=OpenSSH RSA test certificate(dsa) +d)O=OpenSSH Test Team,OU=OpenSSH Testers/C=XX,ST=World/CN=OpenSSH RSA test certificate(dsa) + + +Shell sample: +$ printf 'x509v3-sign-rsa '; + openssl x509 -noout -subject \ + -in A_OPENSSH_CERT_FILE \ + >> $HOME/.ssh/authorized_keys + +NOTES: +- adjust user authorized_keys file ownership - user must have at least +read access. +- SecSH x509v3 key type is "x509v3-sign-rsa" or "x509v3-sign-dss". + + +2.) client settings: +2.1.) IdentityFile + Depends from client. To use X.509 certificate "OpenSSH id-file" must +contain both sections - private key and certificate in PEM format: +Note: Don't forget to update public key file with command: +$ ssh-keygen -y -f KEY_FILE_NAME > KEY_FILE_NAME.pub +Command ssh-add use public key file! + +2.2.) global ssh_config or $HOME/.ssh/config + Check options AllowedCertPurpose, [User]CACertificatePath, +[User]CACertificateFile, [User]CARevocationFile and +[User]CARevocationPath. See p. 1.1.1. All nine options are for "x509 +store". "x509 store" is used to verify server hostkey. + +Note: When we use own CA we must import CA certificate[s] to +"x509 store". More info on: + http://roumenpetrov.info/domino_CA/#dca2bundle + + + +3.) test x509 certificates. + +3.1.) In openssh build dir run "make check". +If x509 test scripts fail edit file OPENSSH_SOURCE_PATH/tests/CA/config +or set some environment variables. +Output from make check is in color and when is redirected to file later +we can see content best with command "less -r ...". +When script run a test command print star '*' followed by simple +information about command. When command succeed script print at right +"done" in GREEN(!) otherwise "failed" in RED(!). After failed command +script show on next lines in RED(!) response, skip execution of next +command/script, print message like this: +.... +Testing OpenSSH client with certificates finished. + status: failed +.... +Note that failed is in RED(!) and exit code is NONZERO(!). +Some command in a test script must fail. Part of "simple information" +about command expected to fail is in RED(!). When command fail script +print "done" (THIS IS CORRECT - COMMAND MUST FAIL) and on next lines +print in GREEN(!) response. Usualy this occur when server reject logon. +WHEN ALL TESTS SUCCEED output is: +.... +Testing OpenSSH client with certificates finished. + status: done +.... +Note that "done" is in GREEN(!) and exit code is ZERO(!). + + + +3.1.1.) Description of variables in Makefile file: + - SHELL + Used shell to run tests. For example: + make check SHELL=/bin/zsh + +3.1.2.) Description of variables in config file: + +3.1.2.1.) main variables: + - SUDO + (only in config) + on some system sshd must be started as root. + If necessary set variable to sudo and configure sudo'ers. + - TMPDIR + (environment or config) + directory for temporary files. If not set its value is selected + from /tmp, /var/tmp or /usr/tmp. + - SSH_X509TESTS + (environment or config) + list with test scripts. A test script is in file with following + name: test-.sh.inc. + +3.1.2.2.) openssl: + - OPENSSL + (environment or config) + path to openssl binary. The default is result from command: + `which openssl`. + - RSA_DIGEST_LIST + (environment or config) + list with RSA digests in support of openssl. The default value is + build at run time from following digest list "md5 sha1 md2 md4 + rmd160" and contain only supported from openssl. + +3.1.2.3.) server section: + Read sshd_config.5 manual page for valid values. + - SSHD_PORT + (environment or config) + specifies the port number that server listens on and client connect + to on localhost. The default is 20022. + - SSHD_LISTENADDRESS + (only in config) + Same as sshd option "ListenAddress" but without(!) port number. + The default is "127.0.0.1". + - SSHSERVER_USEPRIVILEGESEPARATION="yes": + (only in config) + sshd "UsePrivilegeSeparation" option. + if necessary set to "no", to disable privilege separation. + - SSHSERVER_SYSLOGFACILITY=AUTH + (only in config) + sshd "SyslogFacility" option. + - SSHSERVER_LOGLEVEL=INFO + (only in config) + sshd 'LogLevel' option. + +3.1.2.4.) certificates: + - Variables related to test certificates and CA. + (only in config) + +3.1.3.) Sample commands to run tests: +$ OPENSSL=/usr/local/ssl/bin/openssl make check +$ SSHD_PORT=1122 SSH_X509TESTS="agent blob_auth" make check +$ RSA_DIGEST_LIST="md5 sha1" make check +$ make check SHELL=/bin/ksh +When check fail see "Troubleshooting" later in document. + + +3.2.) Current test scripts uses only rsa as server hostkey. + To test sshd with x509 certificate please find in file +openssh_tests.sh variable TEST_SSHD_HOSTKEY and change it. Sample: +TEST_SSH_HOSTKEY="${CWD}/testhostkey_rsa-rsa_md5" + + +3.3.) Test SecSH from "Microsoft Windows OSes". + This is not part of document. +Tips: use created after make check files: +- convert OPENSSH_BUILD_PATH/tests/CA/ca-test/crt/*crt.pem CA + certificates from PEM to DER format and import in + "Windows keystore" +- import OPENSSH_BUILD_PATH/tests/CA/testid_*.p12 in + "Windows keystore" +- setup your client to use certificate[s](see SecSH client manuals). +DON'T FORGET TO REMOVE entries from "Windows keystore" after test! + + +3.4.) Go to OPENSSH_BUILD_PATH/tests/CA and run command "make clean" to +remove all client/server and CA files. + + +3.5.) files in OPENSSH_SOURCE_PATH/tests/CA directory: +config : configuration file + +1-cre_cadb.sh: + create "Test CA" directories and files. + +2-cre_cakeys.sh: + create "Test CA" private keys and certificates. + +3-cre_certs.sh: + create client/server certificates. + this command create files with mask + "PATH_TO_KEYFILEn-[.]" + , where is in format "rsa_" or "dsa". + DIGEST are form variable "RSA_DIGEST_LIST" specified in "config" + file. Files without extention are openssh identity or hostkey files. + File with .pub extention contain openssh public key (BLOB format). + File with .crt extention contain openssl "text output" for identity + files. File with .p12 extention are for "Microsoft Windows keystore". + + +verify.sh: + to check certificates against "Test CA". Note: check only + testid_*.crt and testhostkey_*.crt files in current directory. + +functions: + common usefull functions + +openssh_tests.sh: + main test script - call other testscripts. + +test-blob_auth.sh.inc, +test-dn_auth_file.sh.inc, +test-dn_auth_path.sh.inc, +test-agent.sh.inc, +test-crl.sh.inc: + see DESCRIPTION in each file. + +Note that hostbased authentication we cannot test without to install. +Generated testhostkey_* certificates are with sslserver and sslclient +purposes and you can use them to test manualy hostbased authentication. + + +4.) Troubleshooting +make check fails on: + +4.1.) "... 1-cre_cadb.sh: local: not found" +run: [ENVSETTINGS] make check SHELL=/bin/ksh + +4.2.) "generating a new ... private key for the TEST CA ..." +Usially this happen on system without /dev/{u}random. +In file [BUILDDIR]/tests/CA/openssh_ca-2.log we can see a message: +"... PRNG not seeded ...". +Read again WARNING.RNG from OpenSSH sourcedir and/or +http://www.openssl.org/support/faq.html + +4.2.1.) reconfigure your system and/or openssl +4.2.2.) or do next +4.2.2.1.) install OpenSSH :-( otherwise later "make check" +(ssh-keygen) fail with message: +"couldn't exec '.../libexec/ssh-rand-helper': ..." +and second ./ssh-rand-helper fail with message: +"couldn't read entropy commands file ../ssh_prng_cmds: ..." +Tip: configure OpenSSH with prefix for example $HOME/test + +4.2.2.2.) run: +ssh-rand-helper +rm -f $HOME/.rnd +ln -s .ssh/prng_seed $HOME/.rnd + +4.2.2.3.) test openssl with command: +/usr/local/ssl/bin/openssl genrsa -des3 -passout pass:change_it +Tip: before to create every key with OpenSSL run ssh-rand-helper ! + +4.2.2.4.) run againg "... make check ..." + + +Enjoy ;-) diff -ruN openssh-3.6.1p2/scp.0 openssh-3.6.1p2+x509g1/scp.0 --- openssh-3.6.1p2/scp.0 2003-04-29 12:37:29.000000000 +0300 +++ openssh-3.6.1p2+x509g1/scp.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SCP(1) BSD General Commands Manual SCP(1) +SCP(1) System General Commands Manual SCP(1) NAME scp - secure copy (remote file copy program) @@ -55,7 +55,7 @@ -P port Specifies the port to connect to on the remote host. Note that - this option is written with a capital M-bM-^@M-^XPM-bM-^@M-^Y, because -p is already + this option is written with a capital `P', because -p is already reserved for preserving the times and modes of the file in rcp(1). diff -ruN openssh-3.6.1p2/servconf.c openssh-3.6.1p2+x509g1/servconf.c --- openssh-3.6.1p2/servconf.c 2003-02-24 03:04:34.000000000 +0200 +++ openssh-3.6.1p2+x509g1/servconf.c 2003-04-30 09:06:01.000000000 +0300 @@ -7,10 +7,33 @@ * software must be clearly marked as such, and if the derived work is * incompatible with the protocol description in the RFC file, it must be * called by a name other than "ssh" or "Secure Shell". + * + * X509 certificate store support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: servconf.c,v 1.116 2003/02/21 09:05:53 markus Exp $"); +RCSID("$OpenBSD$"); #if defined(KRB4) #include @@ -123,11 +146,29 @@ options->client_alive_count_max = -1; options->authorized_keys_file = NULL; options->authorized_keys_file2 = NULL; + options->allowedcertpurpose = -1; + options->ca.certificate_file = NULL; + options->ca.certificate_path = NULL; + options->ca.revocation_file = NULL; + options->ca.revocation_path = NULL; /* Needs to be accessable in many places */ use_privsep = -1; } +static int +sshd_x509store_init (ServerOptions *options) { + int x509_store_loaded = 0; + + ssh_x509store_setpurpose(options->allowedcertpurpose); + + if(ssh_x509store_addlocations(&options->ca)) { + x509_store_loaded = 1; + } + + return x509_store_loaded; +} + void fill_default_server_options(ServerOptions *options) { @@ -256,6 +297,17 @@ if (options->authorized_keys_file == NULL) options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS; + if (options->allowedcertpurpose == -1) + options->allowedcertpurpose = sshclient_cert_purpose("sslclient"); + if (options->ca.certificate_file == NULL) + options->ca.certificate_file = _PATH_CA_CERTIFICATE_FILE; + if (options->ca.certificate_path == NULL) + options->ca.certificate_path = _PATH_CA_CERTIFICATE_PATH; + if (options->ca.revocation_file == NULL) + options->ca.revocation_file = _PATH_CA_REVOCATION_FILE; + if (options->ca.revocation_path == NULL) + options->ca.revocation_path = _PATH_CA_REVOCATION_PATH; + /* Turn privilege separation on by default */ if (use_privsep == -1) use_privsep = 1; @@ -269,6 +321,7 @@ } #endif + sshd_x509store_init(options); } /* Keyword tokens. */ @@ -302,6 +355,9 @@ sHostbasedUsesNameFromPacketOnly, sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2, sUsePrivilegeSeparation, + sAllowedClientCertPurpose, + sCACertificateFile, sCACertificatePath, + sCARevocationFile, sCARevocationPath, sDeprecated } ServerOpCodes; @@ -380,6 +436,11 @@ { "authorizedkeysfile", sAuthorizedKeysFile }, { "authorizedkeysfile2", sAuthorizedKeysFile2 }, { "useprivilegeseparation", sUsePrivilegeSeparation}, + { "allowedcertpurpose", sAllowedClientCertPurpose }, + { "cacertificatefile", sCACertificateFile }, + { "cacertificatepath", sCACertificatePath }, + { "carevocationfile", sCARevocationFile }, + { "carevocationpath", sCARevocationPath }, { NULL, sBadOption } }; @@ -909,6 +970,47 @@ intptr = &options->client_alive_count_max; goto parse_int; + case sAllowedClientCertPurpose: + arg = strdelim(&cp); + if (arg && *arg) { + if (strcasecmp(arg, "skip") == 0) goto skip_purpose; + + { /* convert string to OpenSSL index */ + int purpose_index; + purpose_index = sshclient_cert_purpose (arg); + if (purpose_index < 0) + fatal("config error: unsupported purpose '%.30s' in file %s line %d.", arg, filename, linenum); + + options->allowedcertpurpose = purpose_index; + } + } else { +skip_purpose: + options->allowedcertpurpose = -2; + verbose("config warning: option is set to don`t check certificate purpose in file %s line %d.", filename, linenum); + } + break; + + + case sCACertificateFile: + case sCACertificatePath: + case sCARevocationFile: + case sCARevocationPath: + arg = strdelim(&cp); + if (!arg || *arg == '\0') + fatal("%s line %d: Missing argument.", filename, linenum); + switch (opcode) { + case sCACertificateFile: + options->ca.certificate_file = xstrdup(arg); break; + case sCACertificatePath: + options->ca.certificate_path = xstrdup(arg); break; + case sCARevocationFile: + options->ca.revocation_file = xstrdup(arg); break; + case sCARevocationPath: + options->ca.revocation_path = xstrdup(arg); break; + default: + } + break; + case sDeprecated: log("%s line %d: Deprecated option %s", filename, linenum, arg); diff -ruN openssh-3.6.1p2/servconf.h openssh-3.6.1p2+x509g1/servconf.h --- openssh-3.6.1p2/servconf.h 2002-08-01 04:28:39.000000000 +0300 +++ openssh-3.6.1p2+x509g1/servconf.h 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -/* $OpenBSD: servconf.h,v 1.59 2002/07/30 17:03:55 markus Exp $ */ +/* $OpenBSD$ */ /* * Author: Tatu Ylonen @@ -11,11 +11,36 @@ * software must be clearly marked as such, and if the derived work is * incompatible with the protocol description in the RFC file, it must be * called by a name other than "ssh" or "Secure Shell". + * + * X509 certificate store support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef SERVCONF_H #define SERVCONF_H +#include "x509store.h" + #define MAX_PORTS 256 /* Max # ports. */ #define MAX_ALLOW_USERS 256 /* Max # users on allow list. */ @@ -132,6 +157,11 @@ char *authorized_keys_file; /* File containing public keys */ char *authorized_keys_file2; int pam_authentication_via_kbd_int; + + /* allowed client certificate purpose */ + int allowedcertpurpose; + /* sshd PKI(X509) global store */ + X509StoreOptions ca; } ServerOptions; void initialize_server_options(ServerOptions *); diff -ruN openssh-3.6.1p2/sftp.0 openssh-3.6.1p2+x509g1/sftp.0 --- openssh-3.6.1p2/sftp.0 2003-04-29 12:37:31.000000000 +0300 +++ openssh-3.6.1p2+x509g1/sftp.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SFTP(1) BSD General Commands Manual SFTP(1) +SFTP(1) System General Commands Manual SFTP(1) NAME sftp - Secure file transfer program @@ -33,7 +33,7 @@ will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd and lmkdir. Termination on error can be suppressed on a - command by command basis by prefixing the command with a M-bM-^@M-^M-bM-^@M-^Y-M-bM-^@M-^M-bM-^@M-^Y + command by command basis by prefixing the command with a '-' character (For example, -rm /tmp/blah* ). -o ssh_option @@ -55,7 +55,7 @@ files. Larger buffers require fewer round trips at the cost of higher memory consumption. The default is 32768 bytes. - -C Enables compression (via sshM-bM-^@M-^Ys -C flag). + -C Enables compression (via ssh's -C flag). -F ssh_config Specifies an alternative per-user configuration file for ssh. @@ -104,7 +104,7 @@ Retrieve the remote-path and store it on the local machine. If the local path name is not specified, it is given the same name it has on the remote machine. If the -P flag is specified, then - the fileM-bM-^@M-^Ys full permission and access time are copied too. + the file's full permission and access time are copied too. help Display help text. @@ -139,7 +139,7 @@ Upload local-path and store it on the remote machine. If the remote path name is not specified, it is given the same name it has on the local machine. If the -P flag is specified, then the - fileM-bM-^@M-^Ys full permission and access time are copied too. + file's full permission and access time are copied too. pwd Display remote working directory. diff -ruN openssh-3.6.1p2/sftp-server.0 openssh-3.6.1p2+x509g1/sftp-server.0 --- openssh-3.6.1p2/sftp-server.0 2003-04-29 12:37:30.000000000 +0300 +++ openssh-3.6.1p2+x509g1/sftp-server.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SFTP-SERVER(8) BSD System ManagerM-bM-^@M-^Ys Manual SFTP-SERVER(8) +SFTP-SERVER(8) System Manager's Manual SFTP-SERVER(8) NAME sftp-server - SFTP server subsystem diff -ruN openssh-3.6.1p2/ssh.0 openssh-3.6.1p2+x509g1/ssh.0 --- openssh-3.6.1p2/ssh.0 2003-04-29 12:37:30.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH(1) BSD General Commands Manual SSH(1) +SSH(1) System General Commands Manual SSH(1) NAME ssh - OpenSSH SSH client (remote login program) @@ -23,10 +23,11 @@ depending on the protocol version used: SSH protocol version 1 + First, if the machine the user logs in from is listed in /etc/hosts.equiv or /etc/shosts.equiv on the remote machine, and the user names are the same on both sides, the user is immediately permitted to log in. Second, - if .rhosts or .shosts exists in the userM-bM-^@M-^Ys home directory on the remote + if .rhosts or .shosts exists in the user's home directory on the remote machine and contains a line containing the name of the client machine and the name of the user on that machine, the user is permitted to log in. This form of authentication alone is normally not allowed by the server @@ -35,7 +36,7 @@ The second authentication method is the rhosts or hosts.equiv method com- bined with RSA-based host authentication. It means that if the login would be permitted by $HOME/.rhosts, $HOME/.shosts, /etc/hosts.equiv, or - /etc/shosts.equiv, and if additionally the server can verify the clientM-bM-^@M-^Ys + /etc/shosts.equiv, and if additionally the server can verify the client's host key (see /etc/ssh/ssh_known_hosts and $HOME/.ssh/known_hosts in the FILES section), only then login is permitted. This authentication method closes security holes due to IP spoofing, DNS spoofing and routing spoof- @@ -55,15 +56,15 @@ which key pair it would like to use for authentication. The server checks if this key is permitted, and if so, sends the user (actually the ssh program running on behalf of the user) a challenge, a random number, - encrypted by the userM-bM-^@M-^Ys public key. The challenge can only be decrypted - using the proper private key. The userM-bM-^@M-^Ys client then decrypts the chal- + encrypted by the user's public key. The challenge can only be decrypted + using the proper private key. The user's client then decrypts the chal- lenge using the private key, proving that he/she knows the private key but without disclosing it to the server. ssh implements the RSA authentication protocol automatically. The user creates his/her RSA key pair by running ssh-keygen(1). This stores the private key in $HOME/.ssh/identity and the public key in - $HOME/.ssh/identity.pub in the userM-bM-^@M-^Ys home directory. The user should + $HOME/.ssh/identity.pub in the user's home directory. The user should then copy the identity.pub to $HOME/.ssh/authorized_keys in his/her home directory on the remote machine (the authorized_keys file corresponds to the conventional $HOME/.rhosts file, and has one key per line, though the @@ -80,6 +81,7 @@ someone listening on the network. SSH protocol version 2 + When a user connects using protocol version 2 similar authentication methods are available. Using the default values for PreferredAuthentications, the client will try to authenticate first using @@ -89,16 +91,19 @@ The public key method is similar to RSA authentication described in the previous section and allows the RSA or DSA algorithm to be used: The - client uses his private key, $HOME/.ssh/id_dsa or $HOME/.ssh/id_rsa, to - sign the session identifier and sends the result to the server. The - server checks whether the matching public key is listed in + client uses his private key, $HOME/.ssh/id_dsa or $HOME/.ssh/id_rsa, + which can contain a x509 certificate in addition to key to sign the ses- + sion identifier and sends the result to the server. The server checks + whether the matching public key or certificate is listed in $HOME/.ssh/authorized_keys and grants access if both the key is found and - the signature is correct. The session identifier is derived from a - shared Diffie-Hellman value and is only known to the client and the - server. + the signature is correct. In case with x509 certificate server perform + additional verification of that certificate through database with cer- + tificates and CRLs of certificate signers. The session identifier is + derived from a shared Diffie-Hellman value and is only known to the + client and the server. If public key authentication fails or is not available a password can be - sent encrypted to the remote host for proving the userM-bM-^@M-^Ys identity. + sent encrypted to the remote host for proving the user's identity. Additionally, ssh supports hostbased or challenge response authentica- tion. @@ -109,7 +114,8 @@ ensuring the integrity of the connection. Login session and remote execution - When the userM-bM-^@M-^Ys identity has been accepted by the server, the server + + When the user's identity has been accepted by the server, the server either executes the given command, or logs into the machine and gives the user a normal shell on the remote machine. All communication with the remote command or shell will be automatically encrypted. @@ -119,14 +125,15 @@ If no pseudo tty has been allocated, the session is transparent and can be used to reliably transfer binary data. On most systems, setting the - escape character to M-bM-^@M-^\noneM-bM-^@M-^] will also make the session transparent even if - a tty is used. + escape character to ``none'' will also make the session transparent even + if a tty is used. The session terminates when the command or shell on the remote machine exits and all X11 and TCP/IP connections have been closed. The exit sta- tus of the remote program is returned as the exit status of ssh. Escape Characters + When a pseudo terminal has been requested, ssh supports a number of func- tions through the use of an escape character. @@ -136,7 +143,7 @@ ter can be changed in configuration files using the EscapeChar configura- tion directive or on the command line by the -e option. - The supported escapes (assuming the default M-bM-^@M-^X~M-bM-^@M-^Y) are: + The supported escapes (assuming the default `~') are: ~. Disconnect @@ -156,7 +163,8 @@ version 2 and if the peer supports it) X11 and TCP forwarding - If the ForwardX11 variable is set to M-bM-^@M-^\yesM-bM-^@M-^] (or, see the description of + + If the ForwardX11 variable is set to ``yes'' (or, see the description of the -X and -x options described later) and the user is using X11 (the DISPLAY environment variable is set), the connection to the X11 display is automatically forwarded to the remote side in such a way that any X11 @@ -168,7 +176,7 @@ The DISPLAY value set by ssh will point to the server machine, but with a display number greater than zero. This is normal, and happens because - ssh creates a M-bM-^@M-^\proxyM-bM-^@M-^] X server on the server machine for forwarding the + ssh creates a ``proxy'' X server on the server machine for forwarding the connections over the encrypted channel. ssh will also automatically set up Xauthority data on the server machine. @@ -178,10 +186,10 @@ is opened. The real authentication cookie is never sent to the server machine (and no cookies are sent in the plain). - If the ForwardAgent variable is set to M-bM-^@M-^\yesM-bM-^@M-^] (or, see the description of - the -A and -a options described later) and the user is using an authenti- - cation agent, the connection to the agent is automatically forwarded to - the remote side. + If the ForwardAgent variable is set to ``yes'' (or, see the description + of the -A and -a options described later) and the user is using an + authentication agent, the connection to the agent is automatically for- + warded to the remote side. Forwarding of arbitrary TCP/IP connections over the secure channel can be specified either on the command line or in a configuration file. One @@ -189,13 +197,14 @@ electronic purse; another is going through firewalls. Server authentication + ssh automatically maintains and checks a database containing identifica- tions for all hosts it has ever been used with. Host keys are stored in - $HOME/.ssh/known_hosts in the userM-bM-^@M-^Ys home directory. Additionally, the + $HOME/.ssh/known_hosts in the user's home directory. Additionally, the file /etc/ssh/ssh_known_hosts is automatically checked for known hosts. - Any new hosts are automatically added to the userM-bM-^@M-^Ys file. If a hostM-bM-^@M-^Ys + Any new hosts are automatically added to the user's file. If a host's identification ever changes, ssh warns about this and disables password - authentication to prevent a trojan horse from getting the userM-bM-^@M-^Ys pass- + authentication to prevent a trojan horse from getting the user's pass- word. Another purpose of this mechanism is to prevent man-in-the-middle attacks which could otherwise be used to circumvent the encryption. The StrictHostKeyChecking option can be used to prevent logins to machines @@ -211,7 +220,7 @@ Agent forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the - agentM-bM-^@M-^Ys Unix-domain socket) can access the local agent through + agent's Unix-domain socket) can access the local agent through the forwarded connection. An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into @@ -237,12 +246,12 @@ more information. -e ch|^ch|none - Sets the escape character for sessions with a pty (default: M-bM-^@M-^X~M-bM-^@M-^Y). + Sets the escape character for sessions with a pty (default: `~'). The escape character is only recognized at the beginning of a - line. The escape character followed by a dot (M-bM-^@M-^X.M-bM-^@M-^Y) closes the + line. The escape character followed by a dot (`.') closes the connection, followed by control-Z suspends the connection, and followed by itself sends the escape character once. Setting the - character to M-bM-^@M-^\noneM-bM-^@M-^] disables any escapes and makes the session + character to ``none'' disables any escapes and makes the session fully transparent. -f Requests ssh to go to background just before command execution. @@ -257,15 +266,16 @@ Selects a file from which the identity (private key) for RSA or DSA authentication is read. The default is $HOME/.ssh/identity for protocol version 1, and $HOME/.ssh/id_rsa and - $HOME/.ssh/id_dsa for protocol version 2. Identity files may - also be specified on a per-host basis in the configuration file. - It is possible to have multiple -i options (and multiple identi- - ties specified in configuration files). + $HOME/.ssh/id_dsa for protocol version 2. For protocol version 2 + is possible identity to contain in addition a x509 certificate. + Identity files may also be specified on a per-host basis in the + configuration file. It is possible to have multiple -i options + (and multiple identities specified in configuration files). -I smartcard_device Specifies which smartcard device to use. The argument is the device ssh should use to communicate with a smartcard used for - storing the userM-bM-^@M-^Ys private RSA key. + storing the user's private RSA key. -k Disables forwarding of Kerberos tickets and AFS tokens. This may also be specified on a per-host basis in the configuration file. @@ -329,15 +339,15 @@ X11 forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the - userM-bM-^@M-^Ys X authorization database) can access the local X11 display + user's X authorization database) can access the local X11 display through the forwarded connection. An attacker may then be able to perform activities such as keystroke monitoring. -C Requests compression of all data (including stdin, stdout, stderr, and data for forwarded X11 and TCP/IP connections). The compression algorithm is the same used by gzip(1), and the - M-bM-^@M-^\levelM-bM-^@M-^] can be controlled by the CompressionLevel option for pro- - tocol version 1. Compression is desirable on modem lines and + ``level'' can be controlled by the CompressionLevel option for + protocol version 1. Compression is desirable on modem lines and other slow connections, but will only slow down things on fast networks. The default value can be set on a host-by-host basis in the configuration files; see the Compression option. @@ -372,7 +382,7 @@ syntax: port/host/hostport -D port - Specifies a local M-bM-^@M-^\dynamicM-bM-^@M-^] application-level port forwarding. + Specifies a local ``dynamic'' application-level port forwarding. This works by allocating a socket to listen to port on the local side, and whenever a connection is made to this port, the connec- tion is forwarded over the secure channel, and the application @@ -401,20 +411,20 @@ DISPLAY The DISPLAY variable indicates the location of the X11 server. It is automatically set by ssh to point to a value of the form - M-bM-^@M-^\hostname:nM-bM-^@M-^] where hostname indicates the host where the shell + ``hostname:n'' where hostname indicates the host where the shell runs, and n is an integer >= 1. ssh uses this special value to forward X11 connections over the secure channel. The user should normally not set DISPLAY explicitly, as that will render the X11 connection insecure (and will require the user to manually copy any required authorization cookies). - HOME Set to the path of the userM-bM-^@M-^Ys home directory. + HOME Set to the path of the user's home directory. LOGNAME Synonym for USER; set for compatibility with systems that use this variable. - MAIL Set to the path of the userM-bM-^@M-^Ys mailbox. + MAIL Set to the path of the user's mailbox. PATH Set to the default PATH, as specified when compiling ssh. @@ -454,9 +464,9 @@ USER Set to the name of the user logging in. Additionally, ssh reads $HOME/.ssh/environment, and adds lines of the - format M-bM-^@M-^\VARNAME=valueM-bM-^@M-^] to the environment if the file exists and if users - are allowed to change their environment. See the PermitUserEnvironment - option in sshd_config(5). + format ``VARNAME=value'' to the environment if the file exists and if + users are allowed to change their environment. See the + PermitUserEnvironment option in sshd_config(5). FILES $HOME/.ssh/known_hosts @@ -466,23 +476,29 @@ $HOME/.ssh/identity, $HOME/.ssh/id_dsa, $HOME/.ssh/id_rsa Contains the authentication identity of the user. They are for protocol 1 RSA, protocol 2 DSA, and protocol 2 RSA, respectively. - These files contain sensitive data and should be readable by the - user but not accessible by others (read/write/execute). Note - that ssh ignores a private key file if it is accessible by oth- - ers. It is possible to specify a passphrase when generating the - key; the passphrase will be used to encrypt the sensitive part of - this file using 3DES. + It is possible protocol version 2 identity to contain identity + plus x509 certificate. These files contain sensitive data and + should be readable by the user but not accessible by others + (read/write/execute). Note that ssh ignores a private key file + if it is accessible by others. It is possible to specify a + passphrase when generating the key; the passphrase will be used + to encrypt the sensitive part of this file using 3DES. $HOME/.ssh/identity.pub, $HOME/.ssh/id_dsa.pub, $HOME/.ssh/id_rsa.pub Contains the public key for authentication (public part of the - identity file in human-readable form). The contents of the + identity file in human-readable form). Note that protocol ver- + sion 2 while a identity contain private key and x509 certificate + this file must contain that certificate. The contents of the $HOME/.ssh/identity.pub file should be added to $HOME/.ssh/authorized_keys on all machines where the user wishes to log in using protocol version 1 RSA authentication. The con- tents of the $HOME/.ssh/id_dsa.pub and $HOME/.ssh/id_rsa.pub file should be added to $HOME/.ssh/authorized_keys on all machines where the user wishes to log in using protocol version 2 DSA/RSA - authentication. These files are not sensitive and can (but need + authentication. In case with x509 certificates user can use + ``new style''. Instead to add content of file to authorized_keys + user can write certificate ``Distinguished Name''. See sshd(8) + manual page. These files are not sensitive and can (but need not) be readable by anyone. These files are never used automati- cally and are not necessary; they are only provided for the con- venience of the user. @@ -492,12 +508,12 @@ configuration options are described in ssh_config(5). $HOME/.ssh/authorized_keys - Lists the public keys (RSA/DSA) that can be used for logging in - as this user. The format of this file is described in the - sshd(8) manual page. In the simplest form the format is the same - as the .pub identity files. This file is not highly sensitive, - but the recommended permissions are read/write for the user, and - not accessible by others. + Lists the public keys (RSA/DSA) or certificates that can be used + for logging in as this user. The format of this file is + described in the sshd(8) manual page. In the simplest form the + format is the same as the .pub identity files. This file is not + highly sensitive, but the recommended permissions are read/write + for the user, and not accessible by others. /etc/ssh/ssh_known_hosts Systemwide list of known host keys. This file should be prepared @@ -505,10 +521,12 @@ all machines in the organization. This file should be world- readable. This file contains public keys, one per line, in the following format (fields separated by spaces): system name, pub- - lic key and optional comment field. When different names are - used for the same machine, all such names should be listed, sepa- - rated by commas. The format is described on the sshd(8) manual - page. + lic key and optional comment field. When a x509 certificate is + used as host key instead of public key line contain certificate + (old style) or certificate ``Distinguished Name''. When differ- + ent names are used for the same machine, all such names should be + listed, separated by commas. The format is described on the + sshd(8) manual page. The canonical system name (as returned by name servers) is used by sshd(8) to verify the client host when logging in; other names @@ -525,12 +543,39 @@ /etc/ssh/ssh_host_rsa_key These three files contain the private parts of the host keys and are used for RhostsRSAAuthentication and HostbasedAuthentication. - If the protocol version 1 RhostsRSAAuthentication method is used, - ssh must be setuid root, since the host key is readable only by - root. For protocol version 2, ssh uses ssh-keysign(8) to access - the host keys for HostbasedAuthentication. This eliminates the - requirement that ssh be setuid root when that authentication - method is used. By default ssh is not setuid root. + It is possible files to contain private part plus x509 certifi- + cate for protocol version 2 keys. If the protocol version 1 + RhostsRSAAuthentication method is used, ssh must be setuid root, + since the host key is readable only by root. For protocol ver- + sion 2, ssh uses ssh-keysign(8) to access the host keys for + HostbasedAuthentication. This eliminates the requirement that + ssh be setuid root when that authentication method is used. By + default ssh is not setuid root. When a certificate is used as + host key for hostbased authentication that certificate must have + client purpose too or server configuration must permit connection + without client purpose. For allowed client certificate purposes + see sshd_config(5). + + /etc/ssh/ca/ca-bundle.crt and /etc/ssh/ca/ca-bundle.crl + Part of systemwide ``X509 store''. The first file contain multi- + ple certificates and the second ``Certificate Revocation List'' + (CRLs) of certificate signers in PEM format concatenated + together. Used in verification of server host key certificate. + + /etc/ssh/ca/crt and /etc/ssh/ca/crl + Part of systemwide ``X509 store''. ``Hash dirs'' with certifi- + cates, the first file or CLRs, the second of certificate signers. + Each certificate should be stored in separate file with name + [HASH].[NUMBER] or [HASH].r[NUMBER] for the CRL, where [HASH] is + certificate or CRL hash value and [NUMBER] is an integer starting + from zero. Used in verification of server host key certificate. + + ~/.ssh/ca/ca-bundle.crt and ~/.ssh/ca/ca-bundle.crl + Part of user ``X509 store''. Same as above systemwide files. + + ~/.ssh/ca/crt and ~/.ssh/ca/crl + Part of user ``X509 store''. Same as above systemwide directo- + ries. $HOME/.rhosts This file is used in .rhosts authentication to list the host/user @@ -539,7 +584,7 @@ Each line of the file contains a host name (in the canonical form returned by name servers), and then a user name on that host, separated by a space. On some machines this file may need to be - world-readable if the userM-bM-^@M-^Ys home directory is on a NFS parti- + world-readable if the user's home directory is on a NFS parti- tion, because sshd(8) reads it as root. Additionally, this file must be owned by the user, and must not have write permissions for anyone else. The recommended permission for most machines is @@ -548,7 +593,7 @@ Note that by default sshd(8) will be installed so that it requires successful RSA host authentication before permitting .rhosts authentication. If the server machine does not have the - clientM-bM-^@M-^Ys host key in /etc/ssh/ssh_known_hosts, it can be stored + client's host key in /etc/ssh/ssh_known_hosts, it can be stored in $HOME/.ssh/known_hosts. The easiest way to do this is to con- nect back to the client from the server machine using ssh; this will automatically add the host key to $HOME/.ssh/known_hosts. @@ -574,12 +619,12 @@ /etc/ssh/sshrc Commands in this file are executed by ssh when the user logs in - just before the userM-bM-^@M-^Ys shell (or command) is started. See the + just before the user's shell (or command) is started. See the sshd(8) manual page for more information. $HOME/.ssh/rc Commands in this file are executed by ssh when the user logs in - just before the userM-bM-^@M-^Ys shell (or command) is started. See the + just before the user's shell (or command) is started. See the sshd(8) manual page for more information. $HOME/.ssh/environment @@ -595,7 +640,8 @@ Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and cre- ated OpenSSH. Markus Friedl contributed the support for SSH protocol - versions 1.5 and 2.0. + versions 1.5 and 2.0. Roumen Petrov contributed support for x509 cer- + tificates. SEE ALSO rsh(1), scp(1), sftp(1), ssh-add(1), ssh-agent(1), ssh-keygen(1), diff -ruN openssh-3.6.1p2/ssh.1 openssh-3.6.1p2+x509g1/ssh.1 --- openssh-3.6.1p2/ssh.1 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh.1 2003-04-30 09:06:00.000000000 +0300 @@ -13,6 +13,7 @@ .\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. .\" Copyright (c) 1999 Aaron Campbell. All rights reserved. .\" Copyright (c) 1999 Theo de Raadt. All rights reserved. +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -34,7 +35,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $OpenBSD: ssh.1,v 1.168 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .Dd September 25, 1999 .Dt SSH 1 .Os @@ -226,10 +227,15 @@ .Pa $HOME/.ssh/id_dsa or .Pa $HOME/.ssh/id_rsa , +which can contain a x509 certificate in addition to key to sign the session identifier and sends the result to the server. -The server checks whether the matching public key is listed in +The server checks whether the matching public key or certificate +is listed in .Pa $HOME/.ssh/authorized_keys and grants access if both the key is found and the signature is correct. +In case with x509 certificate server perform additional verification of +that certificate through database with certificates and CRLs of certificate +signers. The session identifier is derived from a shared Diffie-Hellman value and is only known to the client and the server. .Pp @@ -478,6 +484,8 @@ and .Pa $HOME/.ssh/id_dsa for protocol version 2. +For protocol version 2 is possible identity to contain in addition +a x509 certificate. Identity files may also be specified on a per-host basis in the configuration file. It is possible to have multiple @@ -777,6 +785,8 @@ .It Pa $HOME/.ssh/identity, $HOME/.ssh/id_dsa, $HOME/.ssh/id_rsa Contains the authentication identity of the user. They are for protocol 1 RSA, protocol 2 DSA, and protocol 2 RSA, respectively. +It is possible protocol version 2 identity to contain identity plus +x509 certificate. These files contain sensitive data and should be readable by the user but not accessible by others (read/write/execute). @@ -789,6 +799,8 @@ .It Pa $HOME/.ssh/identity.pub, $HOME/.ssh/id_dsa.pub, $HOME/.ssh/id_rsa.pub Contains the public key for authentication (public part of the identity file in human-readable form). +Note that protocol version 2 while a identity contain private key and +x509 certificate this file must contain that certificate. The contents of the .Pa $HOME/.ssh/identity.pub file should be added to @@ -803,6 +815,14 @@ .Pa $HOME/.ssh/authorized_keys on all machines where the user wishes to log in using protocol version 2 DSA/RSA authentication. +In case with x509 certificates user can use +.Dq "new style" . +Instead to add content of file to authorized_keys user can write +certificate +.Dq "Distinguished Name" . +See +.Xr sshd 8 +manual page. These files are not sensitive and can (but need not) be readable by anyone. These files are @@ -813,7 +833,8 @@ The file format and configuration options are described in .Xr ssh_config 5 . .It Pa $HOME/.ssh/authorized_keys -Lists the public keys (RSA/DSA) that can be used for logging in as this user. +Lists the public keys (RSA/DSA) or certificates that can be used for +logging in as this user. The format of this file is described in the .Xr sshd 8 manual page. @@ -830,6 +851,9 @@ This file contains public keys, one per line, in the following format (fields separated by spaces): system name, public key and optional comment field. +When a x509 certificate is used as host key instead of public key line +contain certificate (old style) or certificate +.Dq "Distinguished Name" . When different names are used for the same machine, all such names should be listed, separated by commas. @@ -854,6 +878,8 @@ .Cm RhostsRSAAuthentication and .Cm HostbasedAuthentication . +It is possible files to contain private part plus x509 certificate for +protocol version 2 keys. If the protocol version 1 .Cm RhostsRSAAuthentication method is used, @@ -871,6 +897,37 @@ By default .Nm is not setuid root. +When a certificate is used as host key for hostbased authentication +that certificate must have client purpose too or server configuration +must permit connection without client purpose. For allowed client +certificate purposes see +.Xr sshd_config 5 . +.It Pa "/etc/ssh/ca/ca-bundle.crt" and "/etc/ssh/ca/ca-bundle.crl" +Part of systemwide +.Dq "X509 store" . +The first file contain multiple certificates and the second +.Dq "Certificate Revocation List" +(CRLs) of certificate signers in PEM format concatenated together. +Used in verification of server host key certificate. +.It Pa "/etc/ssh/ca/crt" and Pa "/etc/ssh/ca/crl" +Part of systemwide +.Dq "X509 store" . +.Dq "Hash dirs" +with certificates, the first file or CLRs, the second of +certificate signers. +Each certificate should be stored in separate file with name +[HASH].[NUMBER] or [HASH].r[NUMBER] for the CRL, where [HASH] is +certificate or CRL hash value and [NUMBER] is an integer starting +from zero. +Used in verification of server host key certificate. +.It Pa "~/.ssh/ca/ca-bundle.crt" and "~/.ssh/ca/ca-bundle.crl" +Part of user +.Dq "X509 store" . +Same as above systemwide files. +.It Pa "~/.ssh/ca/crt" and Pa "~/.ssh/ca/crl" +Part of user +.Dq "X509 store" . +Same as above systemwide directories. .It Pa $HOME/.rhosts This file is used in .Pa \&.rhosts @@ -967,6 +1024,7 @@ created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. +Roumen Petrov contributed support for x509 certificates. .Sh SEE ALSO .Xr rsh 1 , .Xr scp 1 , diff -ruN openssh-3.6.1p2/ssh-add.0 openssh-3.6.1p2+x509g1/ssh-add.0 --- openssh-3.6.1p2/ssh-add.0 2003-04-29 12:37:29.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-add.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH-ADD(1) BSD General Commands Manual SSH-ADD(1) +SSH-ADD(1) System General Commands Manual SSH-ADD(1) NAME ssh-add - adds RSA or DSA identities to the authentication agent @@ -14,7 +14,7 @@ $HOME/.ssh/id_rsa, $HOME/.ssh/id_dsa and $HOME/.ssh/identity. Alterna- tive file names can be given on the command line. If any file requires a passphrase, ssh-add asks for the passphrase from the user. The - passphrase is read from the userM-bM-^@M-^Ys tty. ssh-add retries the last + passphrase is read from the user's tty. ssh-add retries the last passphrase if multiple identity files are given. The authentication agent must be running and must be an ancestor of the @@ -61,11 +61,13 @@ $HOME/.ssh/id_dsa Contains the protocol version 2 DSA authentication identity of - the user. + the user. It is possible to contain identity plus x509 certifi- + cate. $HOME/.ssh/id_rsa Contains the protocol version 2 RSA authentication identity of - the user. + the user. It is possible to contain identity plus x509 certifi- + cate. Identity files should not be readable by anyone but the user. Note that ssh-add ignores identity files if they are accessible by others. @@ -94,7 +96,8 @@ Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and cre- ated OpenSSH. Markus Friedl contributed the support for SSH protocol - versions 1.5 and 2.0. + versions 1.5 and 2.0. Roumen Petrov contributed support for x509 cer- + tificates. SEE ALSO ssh(1), ssh-agent(1), ssh-keygen(1), sshd(8) diff -ruN openssh-3.6.1p2/ssh-add.1 openssh-3.6.1p2+x509g1/ssh-add.1 --- openssh-3.6.1p2/ssh-add.1 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-add.1 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ssh-add.1,v 1.38 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .\" .\" -*- nroff -*- .\" @@ -16,6 +16,7 @@ .\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. .\" Copyright (c) 1999 Aaron Campbell. All rights reserved. .\" Copyright (c) 1999 Theo de Raadt. All rights reserved. +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -115,8 +116,10 @@ Contains the protocol version 1 RSA authentication identity of the user. .It Pa $HOME/.ssh/id_dsa Contains the protocol version 2 DSA authentication identity of the user. +It is possible to contain identity plus x509 certificate. .It Pa $HOME/.ssh/id_rsa Contains the protocol version 2 RSA authentication identity of the user. +It is possible to contain identity plus x509 certificate. .El .Pp Identity files should not be readable by anyone but the user. @@ -166,6 +169,7 @@ created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. +Roumen Petrov contributed support for x509 certificates. .Sh SEE ALSO .Xr ssh 1 , .Xr ssh-agent 1 , diff -ruN openssh-3.6.1p2/ssh-add.c openssh-3.6.1p2+x509g1/ssh-add.c --- openssh-3.6.1p2/ssh-add.c 2003-03-10 02:21:18.000000000 +0200 +++ openssh-3.6.1p2+x509g1/ssh-add.c 2003-04-30 09:06:01.000000000 +0300 @@ -12,6 +12,8 @@ * * SSH2 implementation, * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,7 +37,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-add.c,v 1.66 2003/03/05 22:33:43 markus Exp $"); +RCSID("$OpenBSD$"); #include @@ -49,6 +51,7 @@ #include "pathnames.h" #include "readpass.h" #include "misc.h" +#include "ssh-x509.h" #ifdef HAVE___PROGNAME extern char *__progname; @@ -234,9 +237,16 @@ key_size(key), fp, comment, key_type(key)); xfree(fp); } else { - if (!key_write(key, stdout)) - fprintf(stderr, "key_write failed"); - fprintf(stdout, " %s\n", comment); + if ((key->type == KEY_X509_RSA) || (key->type == KEY_X509_DSA)) { + /* key_write will print x509 certificate in blob format :-( */ + if(!x509key_write_subject(key, stdout)) + fprintf(stderr, "x509key_write_subject failed"); + fprintf(stdout, "\n"); + } else { + if (!key_write(key, stdout)) + fprintf(stderr, "key_write failed"); + fprintf(stdout, " %s\n", comment); + } } key_free(key); xfree(comment); diff -ruN openssh-3.6.1p2/ssh-agent.0 openssh-3.6.1p2+x509g1/ssh-agent.0 --- openssh-3.6.1p2/ssh-agent.0 2003-04-29 12:37:29.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-agent.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH-AGENT(1) BSD General Commands Manual SSH-AGENT(1) +SSH-AGENT(1) System General Commands Manual SSH-AGENT(1) NAME ssh-agent - authentication agent @@ -22,10 +22,10 @@ default is /tmp/ssh-XXXXXXXX/agent.. -c Generate C-shell commands on stdout. This is the default if - SHELL looks like itM-bM-^@M-^Ys a csh style of shell. + SHELL looks like it's a csh style of shell. -s Generate Bourne shell commands on stdout. This is the default if - SHELL does not look like itM-bM-^@M-^Ys a csh style of shell. + SHELL does not look like it's a csh style of shell. -k Kill the current agent (given by the SSH_AGENT_PID environment variable). @@ -53,7 +53,7 @@ these identities. ssh-add -l displays the identities currently held by the agent. - The idea is that the agent is run in the userM-bM-^@M-^Ys local PC, laptop, or ter- + The idea is that the agent is run in the user's local PC, laptop, or ter- minal. Authentication data need not be stored on any other machine, and authentication passphrases never go over the network. However, the con- nection to the agent is forwarded over SSH remote logins, and the user @@ -77,7 +77,7 @@ only to the current user. This method is easily abused by root or another instance of the same user. - The SSH_AGENT_PID environment variable holds the agentM-bM-^@M-^Ys process ID. + The SSH_AGENT_PID environment variable holds the agent's process ID. The agent exits automatically when the command given on the command line terminates. @@ -89,11 +89,13 @@ $HOME/.ssh/id_dsa Contains the protocol version 2 DSA authentication identity of - the user. + the user. It is possible to contain identity plus x509 certifi- + cate. $HOME/.ssh/id_rsa Contains the protocol version 2 RSA authentication identity of - the user. + the user. It is possible to contain identity plus x509 certifi- + cate. /tmp/ssh-XXXXXXXX/agent. Unix-domain sockets used to contain the connection to the authen- @@ -106,7 +108,8 @@ Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and cre- ated OpenSSH. Markus Friedl contributed the support for SSH protocol - versions 1.5 and 2.0. + versions 1.5 and 2.0. Roumen Petrov contributed support for x509 cer- + tificates. SEE ALSO ssh(1), ssh-add(1), ssh-keygen(1), sshd(8) diff -ruN openssh-3.6.1p2/ssh-agent.1 openssh-3.6.1p2+x509g1/ssh-agent.1 --- openssh-3.6.1p2/ssh-agent.1 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-agent.1 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ssh-agent.1,v 1.37 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .\" .\" Author: Tatu Ylonen .\" Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -13,6 +13,7 @@ .\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. .\" Copyright (c) 1999 Aaron Campbell. All rights reserved. .\" Copyright (c) 1999 Theo de Raadt. All rights reserved. +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -171,8 +172,10 @@ Contains the protocol version 1 RSA authentication identity of the user. .It Pa $HOME/.ssh/id_dsa Contains the protocol version 2 DSA authentication identity of the user. +It is possible to contain identity plus x509 certificate. .It Pa $HOME/.ssh/id_rsa Contains the protocol version 2 RSA authentication identity of the user. +It is possible to contain identity plus x509 certificate. .It Pa /tmp/ssh-XXXXXXXX/agent. Unix-domain sockets used to contain the connection to the authentication agent. @@ -188,6 +191,7 @@ created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. +Roumen Petrov contributed support for x509 certificates. .Sh SEE ALSO .Xr ssh 1 , .Xr ssh-add 1 , diff -ruN openssh-3.6.1p2/ssh-agent.c openssh-3.6.1p2+x509g1/ssh-agent.c --- openssh-3.6.1p2/ssh-agent.c 2003-03-15 02:37:09.000000000 +0200 +++ openssh-3.6.1p2+x509g1/ssh-agent.c 2003-04-30 09:06:01.000000000 +0300 @@ -11,6 +11,8 @@ * called by a name other than "ssh" or "Secure Shell". * * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,7 +37,7 @@ #include "includes.h" #include "openbsd-compat/sys-queue.h" -RCSID("$OpenBSD: ssh-agent.c,v 1.108 2003/03/13 11:44:50 markus Exp $"); +RCSID("$OpenBSD$"); #include #include @@ -50,6 +52,7 @@ #include "authfd.h" #include "compat.h" #include "log.h" +#include "ssh-x509.h" #include "readpass.h" #include "misc.h" @@ -458,6 +461,7 @@ xfree(type_name); switch (type) { case KEY_DSA: + case KEY_X509_DSA: k = key_new_private(type); buffer_get_bignum2(&e->request, k->dsa->p); buffer_get_bignum2(&e->request, k->dsa->q); @@ -466,6 +470,7 @@ buffer_get_bignum2(&e->request, k->dsa->priv_key); break; case KEY_RSA: + case KEY_X509_RSA: k = key_new_private(type); buffer_get_bignum2(&e->request, k->rsa->n); buffer_get_bignum2(&e->request, k->rsa->e); @@ -481,6 +486,24 @@ buffer_clear(&e->request); goto send; } + switch (type) { + case KEY_X509_RSA: + case KEY_X509_DSA: { + u_char *blob = NULL; + u_int blen = 0; + Key *key = NULL; + + blob = buffer_get_string(&e->request, &blen); + key = x509key_from_blob(blob, blen); + if(key == NULL) { + fatal("process_add_identity() x509key_from_blob fail"); + } + k->x509 = key->x509; + key->x509 = NULL; + key_free(key); + } + break; + } break; } /* enable blinding */ diff -ruN openssh-3.6.1p2/ssh_config openssh-3.6.1p2+x509g1/ssh_config --- openssh-3.6.1p2/ssh_config 2002-07-04 03:19:41.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh_config 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -# $OpenBSD: ssh_config,v 1.16 2002/07/03 14:21:05 markus Exp $ +# $OpenBSD$ # This is the ssh client system-wide configuration file. See # ssh_config(5) for more information. This file provides defaults for @@ -34,3 +34,12 @@ # Cipher 3des # Ciphers aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc # EscapeChar ~ +# AllowedCertPurpose sslserver +# CACertificateFile /etc/ssh/ca/ca-bundle.crt +# CACertificatePath /etc/ssh/ca/crt +# CARevocationFile /etc/ssh/ca/ca-bundle.crl +# CARevocationPath /etc/ssh/ca/crl +# UserCACertificateFile ~/.ssh/ca-bundle.crt +# UserCACertificatePath ~/.ssh/crt +# UserCARevocationFile ~/.ssh/ca-bundle.crl +# UserCARevocationPath ~/.ssh/crl diff -ruN openssh-3.6.1p2/ssh_config.0 openssh-3.6.1p2+x509g1/ssh_config.0 --- openssh-3.6.1p2/ssh_config.0 2003-04-29 12:37:32.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh_config.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH_CONFIG(5) BSD File Formats Manual SSH_CONFIG(5) +SSH_CONFIG(5) System File Formats Manual SSH_CONFIG(5) NAME ssh_config - OpenSSH SSH client configuration files @@ -11,11 +11,11 @@ ssh obtains configuration data from the following sources in the follow- ing order: 1. command-line options - 2. userM-bM-^@M-^Ys configuration file ($HOME/.ssh/config) + 2. user's configuration file ($HOME/.ssh/config) 3. system-wide configuration file (/etc/ssh/ssh_config) For each parameter, the first obtained value will be used. The configu- - ration files contain sections bracketed by M-bM-^@M-^\HostM-bM-^@M-^] specifications, and + ration files contain sections bracketed by ``Host'' specifications, and that section is only applied for hosts that match one of the patterns given in the specification. The matched host name is the one given on the command line. @@ -26,11 +26,11 @@ The configuration file has the following format: - Empty lines and lines starting with M-bM-^@M-^X#M-bM-^@M-^Y are comments. + Empty lines and lines starting with `#' are comments. - Otherwise a line is of the format M-bM-^@M-^\keyword argumentsM-bM-^@M-^]. Configuration + Otherwise a line is of the format ``keyword arguments''. Configuration options may be separated by whitespace or optional whitespace and exactly - one M-bM-^@M-^X=M-bM-^@M-^Y; the latter format is useful to avoid the need to quote whites- + one `='; the latter format is useful to avoid the need to quote whites- pace when specifying configuration options using the ssh, scp and sftp -o option. @@ -39,54 +39,87 @@ Host Restricts the following declarations (up to the next Host key- word) to be only for those hosts that match one of the patterns - given after the keyword. M-bM-^@M-^X*M-bM-^@M-^Y and M-bM-^@M-^XM-bM-^@M-^Y? can be used as wildcards - in the patterns. A single M-bM-^@M-^X*M-bM-^@M-^Y as a pattern can be used to pro- + given after the keyword. `*' and `'? can be used as wildcards + in the patterns. A single `*' as a pattern can be used to pro- vide global defaults for all hosts. The host is the hostname argument given on the command line (i.e., the name is not con- verted to a canonicalized host name before matching). AFSTokenPassing Specifies whether to pass AFS tokens to remote host. The argu- - ment to this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. This option applies - to protocol version 1 only. + ment to this keyword must be ``yes'' or ``no''. This option + applies to protocol version 1 only. + + AllowedCertPurpose + The intended use for the X509 server certificate. Without this + option no chain verification will be done. Currently accepted + uses are case insensitive: + - `sslserver' , `SSL server' , `SSL_server' or `server' + - `any' , `Any Purpose' , `Any_Purpose' or `AnyPurpose' + - `skip' or `' (empty): do not check purpose. + + The default is ``sslserver''. BatchMode - If set to M-bM-^@M-^\yesM-bM-^@M-^], passphrase/password querying will be disabled. + If set to ``yes'', passphrase/password querying will be disabled. This option is useful in scripts and other batch jobs where no user is present to supply the password. The argument must be - M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. + ``yes'' or ``no''. The default is ``no''. BindAddress Specify the interface to transmit from on machines with multiple interfaces or aliased addresses. Note that this option does not - work if UsePrivilegedPort is set to M-bM-^@M-^\yesM-bM-^@M-^]. + work if UsePrivilegedPort is set to ``yes''. + + CACertificateFile + This file contain multiple certificates of certificate signers in + PEM format concatenated together. The default is + /etc/ssh/ca/ca-bundle.crt + + CACertificatePath + ``Hash dir'' with certificates of certificate signers. Each cer- + tificate should be stored in separate file with name [HASH].[NUM- + BER], where [HASH] is certificate hash value and [NUMBER] is an + integer starting from zero. The default is /etc/ssh/ca/crt + + CARevocationFile + This file contain multiple ``Certificate Revocation List'' (CRL) + of certificate signers in PEM format concatenated together. The + default is /etc/ssh/ca/ca-bundle.crl + + CARevocationPath + ``Hash dir'' with ``Certificate Revocation List'' (CRL) of cer- + tificate signers. Each CRL should be stored in separate file with + name [HASH].r[NUMBER], where [HASH] is CRL hash value and [NUM- + BER] is an integer starting from zero. The default is + /etc/ssh/ca/crl ChallengeResponseAuthentication Specifies whether to use challenge response authentication. The - argument to this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is - M-bM-^@M-^\yesM-bM-^@M-^]. + argument to this keyword must be ``yes'' or ``no''. The default + is ``yes''. CheckHostIP - If this flag is set to M-bM-^@M-^\yesM-bM-^@M-^], ssh will additionally check the + If this flag is set to ``yes'', ssh will additionally check the host IP address in the known_hosts file. This allows ssh to detect if a host key changed due to DNS spoofing. If the option - is set to M-bM-^@M-^\noM-bM-^@M-^], the check will not be executed. The default is - M-bM-^@M-^\yesM-bM-^@M-^]. + is set to ``no'', the check will not be executed. The default is + ``yes''. Cipher Specifies the cipher to use for encrypting the session in proto- - col version 1. Currently, M-bM-^@M-^\blowfishM-bM-^@M-^], M-bM-^@M-^\3desM-bM-^@M-^], and M-bM-^@M-^\desM-bM-^@M-^] are sup- - ported. des is only supported in the ssh client for interoper- - ability with legacy protocol 1 implementations that do not sup- - port the 3des cipher. Its use is strongly discouraged due to - cryptographic weaknesses. The default is M-bM-^@M-^\3desM-bM-^@M-^]. + col version 1. Currently, ``blowfish'', ``3des'', and ``des'' + are supported. des is only supported in the ssh client for + interoperability with legacy protocol 1 implementations that do + not support the 3des cipher. Its use is strongly discouraged due + to cryptographic weaknesses. The default is ``3des''. Ciphers Specifies the ciphers allowed for protocol version 2 in order of preference. Multiple ciphers must be comma-separated. The default is - M-bM-^@M-^XM-bM-^@M-^Xaes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour, - aes192-cbc,aes256-cbcM-bM-^@M-^YM-bM-^@M-^Y + ``aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour, + aes192-cbc,aes256-cbc'' ClearAllForwardings Specifies that all local, remote and dynamic port forwardings @@ -94,11 +127,11 @@ cleared. This option is primarily useful when used from the ssh command line to clear port forwardings set in configuration files, and is automatically set by scp(1) and sftp(1). The argu- - ment must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. + ment must be ``yes'' or ``no''. The default is ``no''. Compression - Specifies whether to use compression. The argument must be M-bM-^@M-^\yesM-bM-^@M-^] - or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. + Specifies whether to use compression. The argument must be + ``yes'' or ``no''. The default is ``no''. CompressionLevel Specifies the compression level to use if compression is enabled. @@ -123,20 +156,20 @@ leged ports. EscapeChar - Sets the escape character (default: M-bM-^@M-^X~M-bM-^@M-^Y). The escape character + Sets the escape character (default: `~'). The escape character can also be set on the command line. The argument should be a - single character, M-bM-^@M-^X^M-bM-^@M-^Y followed by a letter, or M-bM-^@M-^\noneM-bM-^@M-^] to disable - the escape character entirely (making the connection transparent - for binary data). + single character, `^' followed by a letter, or ``none'' to dis- + able the escape character entirely (making the connection trans- + parent for binary data). ForwardAgent Specifies whether the connection to the authentication agent (if any) will be forwarded to the remote machine. The argument must - be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. + be ``yes'' or ``no''. The default is ``no''. Agent forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the - agentM-bM-^@M-^Ys Unix-domain socket) can access the local agent through + agent's Unix-domain socket) can access the local agent through the forwarded connection. An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into @@ -145,11 +178,11 @@ ForwardX11 Specifies whether X11 connections will be automatically redi- rected over the secure channel and DISPLAY set. The argument - must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. + must be ``yes'' or ``no''. The default is ``no''. X11 forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the - userM-bM-^@M-^Ys X authorization database) can access the local X11 display + user's X authorization database) can access the local X11 display through the forwarded connection. An attacker may then be able to perform activities such as keystroke monitoring. @@ -160,7 +193,8 @@ necting to forwarded ports. GatewayPorts can be used to specify that ssh should bind local port forwardings to the wildcard address, thus allowing remote hosts to connect to forwarded - ports. The argument must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. + ports. The argument must be ``yes'' or ``no''. The default is + ``no''. GlobalKnownHostsFile Specifies a file to use for the global host key database instead @@ -168,14 +202,14 @@ HostbasedAuthentication Specifies whether to try rhosts based authentication with public - key authentication. The argument must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The - default is M-bM-^@M-^\noM-bM-^@M-^]. This option applies to protocol version 2 only - and is similar to RhostsRSAAuthentication. + key authentication. The argument must be ``yes'' or ``no''. The + default is ``no''. This option applies to protocol version 2 + only and is similar to RhostsRSAAuthentication. HostKeyAlgorithms Specifies the protocol version 2 host key algorithms that the client wants to use in order of preference. The default for this - option is: M-bM-^@M-^\ssh-rsa,ssh-dssM-bM-^@M-^]. + option is: ``x509v3-sign-rsa,x509v3-sign-dss,ssh-rsa,ssh-dss''. HostKeyAlias Specifies an alias that should be used instead of the real host @@ -191,15 +225,16 @@ tions). IdentityFile - Specifies a file from which the userM-bM-^@M-^Ys RSA or DSA authentication + Specifies a file from which the user's RSA or DSA authentication identity is read. The default is $HOME/.ssh/identity for protocol version 1, and $HOME/.ssh/id_rsa and $HOME/.ssh/id_dsa for proto- - col version 2. Additionally, any identities represented by the - authentication agent will be used for authentication. The file - name may use the tilde syntax to refer to a userM-bM-^@M-^Ys home direc- - tory. It is possible to have multiple identity files specified - in configuration files; all these identities will be tried in - sequence. + col version 2. For version 2 is possible identity file to con- + tain key plus x509 certificate. Additionally, any identities + represented by the authentication agent will be used for authen- + tication. The file name may use the tilde syntax to refer to a + user's home directory. It is possible to have multiple identity + files specified in configuration files; all these identities will + be tried in sequence. KeepAlive Specifies whether the system should send TCP keepalive messages @@ -208,20 +243,21 @@ this means that connections will die if the route is down tem- porarily, and some people find it annoying. - The default is M-bM-^@M-^\yesM-bM-^@M-^] (to send keepalives), and the client will + The default is ``yes'' (to send keepalives), and the client will notice if the network goes down or the remote host dies. This is important in scripts, and many users want it too. - To disable keepalives, the value should be set to M-bM-^@M-^\noM-bM-^@M-^]. + To disable keepalives, the value should be set to ``no''. KerberosAuthentication Specifies whether Kerberos authentication will be used. The - argument to this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. + argument to this keyword must be ``yes'' or ``no''. KerberosTgtPassing Specifies whether a Kerberos TGT will be forwarded to the server. This will only work if the Kerberos server is actually an AFS - kaserver. The argument to this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. + kaserver. The argument to this keyword must be ``yes'' or + ``no''. LocalForward Specifies that a TCP/IP port on the local machine be forwarded @@ -243,7 +279,7 @@ order of preference. The MAC algorithm is used in protocol ver- sion 2 for data integrity protection. Multiple algorithms must be comma-separated. The default is - M-bM-^@M-^\hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96M-bM-^@M-^]. + ``hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96''. NoHostAuthenticationForLocalhost This option can be used if the home directory is shared across @@ -251,7 +287,7 @@ machine on each of the machines and the user will get many warn- ings about changed host keys. However, this option disables host authentication for localhost. The argument to this keyword must - be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is to check the host key for + be ``yes'' or ``no''. The default is to check the host key for localhost. NumberOfPasswordPrompts @@ -260,7 +296,8 @@ PasswordAuthentication Specifies whether to use password authentication. The argument - to this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\yesM-bM-^@M-^]. + to this keyword must be ``yes'' or ``no''. The default is + ``yes''. Port Specifies the port number to connect on the remote host. Default is 22. @@ -270,33 +307,33 @@ authentication methods. This allows a client to prefer one method (e.g. keyboard-interactive) over another method (e.g. password) The default for this option is: - M-bM-^@M-^\hostbased,publickey,keyboard-interactive,passwordM-bM-^@M-^]. + ``hostbased,publickey,keyboard-interactive,password''. Protocol Specifies the protocol versions ssh should support in order of - preference. The possible values are M-bM-^@M-^\1M-bM-^@M-^] and M-bM-^@M-^\2M-bM-^@M-^]. Multiple ver- - sions must be comma-separated. The default is M-bM-^@M-^\2,1M-bM-^@M-^]. This means - that ssh tries version 2 and falls back to version 1 if version 2 - is not available. + preference. The possible values are ``1'' and ``2''. Multiple + versions must be comma-separated. The default is ``2,1''. This + means that ssh tries version 2 and falls back to version 1 if + version 2 is not available. ProxyCommand Specifies the command to use to connect to the server. The com- mand string extends to the end of the line, and is executed with - /bin/sh. In the command string, M-bM-^@M-^X%hM-bM-^@M-^Y will be substituted by the - host name to connect and M-bM-^@M-^X%pM-bM-^@M-^Y by the port. The command can be + /bin/sh. In the command string, `%h' will be substituted by the + host name to connect and `%p' by the port. The command can be basically anything, and should read from its standard input and write to its standard output. It should eventually connect an sshd(8) server running on some machine, or execute sshd -i some- where. Host key management will be done using the HostName of the host being connected (defaulting to the name typed by the - user). Setting the command to M-bM-^@M-^\noneM-bM-^@M-^] disables this option + user). Setting the command to ``none'' disables this option entirely. Note that CheckHostIP is not available for connects with a proxy command. PubkeyAuthentication Specifies whether to try public key authentication. The argument - to this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\yesM-bM-^@M-^]. - This option applies to protocol version 2 only. + to this keyword must be ``yes'' or ``no''. The default is + ``yes''. This option applies to protocol version 2 only. RemoteForward Specifies that a TCP/IP port on the remote machine be forwarded @@ -312,51 +349,52 @@ this declaration only affects the client side and has no effect whatsoever on security. Most servers do not permit RhostsAuthen- tication because it is not secure (see RhostsRSAAuthentication). - The argument to this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default - is M-bM-^@M-^\noM-bM-^@M-^]. This option applies to protocol version 1 only and - requires ssh to be setuid root and UsePrivilegedPort to be set to - M-bM-^@M-^\yesM-bM-^@M-^]. + The argument to this keyword must be ``yes'' or ``no''. The + default is ``no''. This option applies to protocol version 1 + only and requires ssh to be setuid root and UsePrivilegedPort to + be set to ``yes''. RhostsRSAAuthentication Specifies whether to try rhosts based authentication with RSA - host authentication. The argument must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The - default is M-bM-^@M-^\noM-bM-^@M-^]. This option applies to protocol version 1 only - and requires ssh to be setuid root. + host authentication. The argument must be ``yes'' or ``no''. + The default is ``no''. This option applies to protocol version 1 + only and requires ssh to be setuid root. RSAAuthentication Specifies whether to try RSA authentication. The argument to - this keyword must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. RSA authentication will only - be attempted if the identity file exists, or an authentication - agent is running. The default is M-bM-^@M-^\yesM-bM-^@M-^]. Note that this option - applies to protocol version 1 only. + this keyword must be ``yes'' or ``no''. RSA authentication will + only be attempted if the identity file exists, or an authentica- + tion agent is running. The default is ``yes''. Note that this + option applies to protocol version 1 only. SmartcardDevice Specifies which smartcard device to use. The argument to this keyword is the device ssh should use to communicate with a smart- - card used for storing the userM-bM-^@M-^Ys private RSA key. By default, no + card used for storing the user's private RSA key. By default, no device is specified and smartcard support is not activated. StrictHostKeyChecking - If this flag is set to M-bM-^@M-^\yesM-bM-^@M-^], ssh will never automatically add + If this flag is set to ``yes'', ssh will never automatically add host keys to the $HOME/.ssh/known_hosts file, and refuses to con- nect to hosts whose host key has changed. This provides maximum protection against trojan horse attacks, however, can be annoying when the /etc/ssh/ssh_known_hosts file is poorly maintained, or connections to new hosts are frequently made. This option forces the user to manually add all new hosts. If this flag is set to - M-bM-^@M-^\noM-bM-^@M-^], ssh will automatically add new host keys to the user known - hosts files. If this flag is set to M-bM-^@M-^\askM-bM-^@M-^], new host keys will be - added to the user known host files only after the user has con- - firmed that is what they really want to do, and ssh will refuse - to connect to hosts whose host key has changed. The host keys of - known hosts will be verified automatically in all cases. The - argument must be M-bM-^@M-^\yesM-bM-^@M-^], M-bM-^@M-^\noM-bM-^@M-^] or M-bM-^@M-^\askM-bM-^@M-^]. The default is M-bM-^@M-^\askM-bM-^@M-^]. + ``no'', ssh will automatically add new host keys to the user + known hosts files. If this flag is set to ``ask'', new host keys + will be added to the user known host files only after the user + has confirmed that is what they really want to do, and ssh will + refuse to connect to hosts whose host key has changed. The host + keys of known hosts will be verified automatically in all cases. + The argument must be ``yes'', ``no'' or ``ask''. The default is + ``ask''. UsePrivilegedPort Specifies whether to use a privileged port for outgoing connec- - tions. The argument must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. - If set to M-bM-^@M-^\yesM-bM-^@M-^] ssh must be setuid root. Note that this option - must be set to M-bM-^@M-^\yesM-bM-^@M-^] if RhostsAuthentication and + tions. The argument must be ``yes'' or ``no''. The default is + ``no''. If set to ``yes'' ssh must be setuid root. Note that + this option must be set to ``yes'' if RhostsAuthentication and RhostsRSAAuthentication authentications are needed with older servers. @@ -365,6 +403,18 @@ trouble of having to remember to give the user name on the com- mand line. + UserCACertificateFile + User CACertificateFile , the default is ~/.ssh/ca-bundle.crt + + UserCACertificatePath + User CACertificatePath , the default is ~/.ssh/crt + + UserCARevocationFile + User CARevocationFile , the default is ~/.ssh/ca-bundle.crl + + UserCARevocationPath + User CARevocationPath , the default is ~/.ssh/crl + UserKnownHostsFile Specifies a file to use for the user host key database instead of $HOME/.ssh/known_hosts. @@ -383,7 +433,7 @@ /etc/ssh/ssh_config Systemwide configuration file. This file provides defaults for - those values that are not specified in the userM-bM-^@M-^Ys configuration + those values that are not specified in the user's configuration file, and for those users who do not have a configuration file. This file must be world-readable. @@ -392,7 +442,8 @@ Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and cre- ated OpenSSH. Markus Friedl contributed the support for SSH protocol - versions 1.5 and 2.0. + versions 1.5 and 2.0. Roumen Petrov contributed support for x509 cer- + tificates. SEE ALSO ssh(1) diff -ruN openssh-3.6.1p2/ssh_config.5 openssh-3.6.1p2+x509g1/ssh_config.5 --- openssh-3.6.1p2/ssh_config.5 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh_config.5 2003-04-30 09:06:00.000000000 +0300 @@ -13,6 +13,7 @@ .\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. .\" Copyright (c) 1999 Aaron Campbell. All rights reserved. .\" Copyright (c) 1999 Theo de Raadt. All rights reserved. +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -34,7 +35,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $OpenBSD: ssh_config.5,v 1.7 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .Dd September 25, 1999 .Dt SSH_CONFIG 5 .Os @@ -122,6 +123,35 @@ or .Dq no . This option applies to protocol version 1 only. +.It Cm AllowedCertPurpose +The intended use for the X509 server certificate. Without this option +no chain verification will be done. Currently accepted uses are case +insensitive: + - +.Sq sslserver +, +.Sq SSL server +, +.Sq SSL_server +or +.Sq server + - +.Sq any +, +.Sq Any Purpose +, +.Sq Any_Purpose +or +.Sq AnyPurpose + - +.Sq skip +or +.Sq +.. +(empty): do not check purpose. +.Pp +The default is +.Dq sslserver . .It Cm BatchMode If set to .Dq yes , @@ -141,6 +171,35 @@ .Cm UsePrivilegedPort is set to .Dq yes . +.Pp +.It Cm CACertificateFile +This file contain multiple certificates of certificate signers in +PEM format concatenated together. The default is +.Pa /etc/ssh/ca/ca-bundle.crt +.Pp +.It Cm CACertificatePath +.Dq "Hash dir" +with certificates of certificate signers. Each certificate should be +stored in separate file with name [HASH].[NUMBER], where [HASH] is +certificate hash value and [NUMBER] is an integer starting from zero. +The default is +.Pa /etc/ssh/ca/crt +.Pp +.It Cm CARevocationFile +This file contain multiple +.Dq "Certificate Revocation List" +(CRL) of certificate signers in PEM format concatenated together. +The default is +.Pa /etc/ssh/ca/ca-bundle.crl +.Pp +.It Cm CARevocationPath +.Dq "Hash dir" +with +.Dq "Certificate Revocation List" +(CRL) of certificate signers. Each CRL should be stored in separate +file with name [HASH].r[NUMBER], where [HASH] is CRL hash value and +[NUMBER] is an integer starting from zero. The default is +.Pa /etc/ssh/ca/crl .It Cm ChallengeResponseAuthentication Specifies whether to use challenge response authentication. The argument to this keyword must be @@ -323,7 +382,7 @@ Specifies the protocol version 2 host key algorithms that the client wants to use in order of preference. The default for this option is: -.Dq ssh-rsa,ssh-dss . +.Dq x509v3-sign-rsa,x509v3-sign-dss,ssh-rsa,ssh-dss . .It Cm HostKeyAlias Specifies an alias that should be used instead of the real host name when looking up or saving the host key @@ -346,6 +405,7 @@ and .Pa $HOME/.ssh/id_dsa for protocol version 2. +For version 2 is possible identity file to contain key plus x509 certificate. Additionally, any identities represented by the authentication agent will be used for authentication. The file name may use the tilde @@ -614,6 +674,30 @@ This can be useful when a different user name is used on different machines. This saves the trouble of having to remember to give the user name on the command line. +.Pp +.It Cm UserCACertificateFile +User +.Cm CACertificateFile +, the default is +.Pa ~/.ssh/ca-bundle.crt +.Pp +.It Cm UserCACertificatePath +User +.Cm CACertificatePath +, the default is +.Pa ~/.ssh/crt +.Pp +.It Cm UserCARevocationFile +User +.Cm CARevocationFile +, the default is +.Pa ~/.ssh/ca-bundle.crl +.Pp +.It Cm UserCARevocationPath +User +.Cm CARevocationPath +, the default is +.Pa ~/.ssh/crl .It Cm UserKnownHostsFile Specifies a file to use for the user host key database instead of @@ -652,5 +736,6 @@ created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. +Roumen Petrov contributed support for x509 certificates. .Sh SEE ALSO .Xr ssh 1 diff -ruN openssh-3.6.1p2/sshconnect.c openssh-3.6.1p2+x509g1/sshconnect.c --- openssh-3.6.1p2/sshconnect.c 2002-12-23 04:06:20.000000000 +0200 +++ openssh-3.6.1p2+x509g1/sshconnect.c 2003-04-30 09:06:01.000000000 +0300 @@ -10,10 +10,13 @@ * software must be clearly marked as such, and if the derived work is * incompatible with the protocol description in the RFC file, it must be * called by a name other than "ssh" or "Secure Shell". + * + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. */ #include "includes.h" -RCSID("$OpenBSD: sshconnect.c,v 1.137 2002/11/21 23:03:51 deraadt Exp $"); +RCSID("$OpenBSD$"); #include @@ -32,6 +35,7 @@ #include "atomicio.h" #include "misc.h" #include "readpass.h" +#include "ssh-x509.h" char *client_version_string = NULL; char *server_version_string = NULL; @@ -498,6 +502,7 @@ char msg[1024]; int len, host_line, ip_line, has_keys; const char *host_file = NULL, *ip_file = NULL; + char extramsg[1024], *subject = NULL; /* * Force accepting of the host key for loopback/localhost. The @@ -643,16 +648,30 @@ has_keys = show_other_keys(host, host_key); /* The default */ fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX); + if ((host_key->type == KEY_X509_RSA) || (host_key->type == KEY_X509_DSA)) { + subject = x509key_subject(host_key); + snprintf(extramsg, sizeof(extramsg), + "Distinguished name is %.*s.\n", + X509KEY_SUBJECT_MAXLEN, subject); + } else { + subject = NULL; + *extramsg = '\0'; + } snprintf(msg, sizeof(msg), "The authenticity of host '%.200s (%s)' can't be " "established%s\n" "%s key fingerprint is %s.\n" + "%s" "Are you sure you want to continue connecting " "(yes/no)? ", host, ip, has_keys ? ",\nbut keys of different type are already " "known for this host." : ".", - type, fp); + type, fp, extramsg); + if(subject != NULL) { + xfree(subject); + subject = NULL; + } xfree(fp); if (!confirm(msg)) goto fail; @@ -704,6 +723,13 @@ error("It is also possible that the %s host key has just been changed.", type); error("The fingerprint for the %s key sent by the remote host is\n%s.", type, fp); + if ((host_key->type == KEY_X509_RSA) || (host_key->type == KEY_X509_DSA)) { + subject = x509key_subject(host_key); + error("Distinguished name sent by remote host is\n%.*s.", + X509KEY_SUBJECT_MAXLEN, subject); + xfree(subject); + subject = NULL; + } error("Please contact your system administrator."); error("Add correct host key in %.100s to get rid of this message.", user_hostfile); @@ -896,7 +922,8 @@ static int show_other_keys(const char *host, Key *key) { - int type[] = { KEY_RSA1, KEY_RSA, KEY_DSA, -1}; + int type[] = { KEY_RSA1, KEY_RSA, KEY_DSA, KEY_X509_RSA, KEY_X509_DSA, -1}; + int i, found = 0; for (i = 0; type[i] != -1; i++) { diff -ruN openssh-3.6.1p2/sshd.0 openssh-3.6.1p2+x509g1/sshd.0 --- openssh-3.6.1p2/sshd.0 2003-04-29 12:37:30.000000000 +0300 +++ openssh-3.6.1p2+x509g1/sshd.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSHD(8) BSD System ManagerM-bM-^@M-^Ys Manual SSHD(8) +SSHD(8) System Manager's Manual SSHD(8) NAME sshd - OpenSSH SSH daemon @@ -21,6 +21,7 @@ sshd works as follows: SSH protocol version 1 + Each host has a host-specific RSA key (normally 1024 bits) used to iden- tify the host. Additionally, when the daemon starts, it generates a server RSA key (normally 768 bits). This key is normally regenerated @@ -48,11 +49,12 @@ abled (thus completely disabling rlogin and rsh into the machine). SSH protocol version 2 + Version 2 works similarly: Each host has a host-specific key (RSA or DSA) - used to identify the host. However, when the daemon starts, it does not - generate a server key. Forward security is provided through a Diffie- - Hellman key agreement. This key agreement results in a shared session - key. + used to identify the host. It is possible host key to contain key plus + x509 certificate. However, when the daemon starts, it does not generate + a server key. Forward security is provided through a Diffie-Hellman key + agreement. This key agreement results in a shared session key. The rest of the session is encrypted using a symmetric cipher, currently 128 bit AES, Blowfish, 3DES, CAST128, Arcfour, 192 bit AES, or 256 bit @@ -67,6 +69,7 @@ ods. Command execution and data forwarding + If the client successfully authenticates itself, a dialog for preparing the session is entered. At this time the client may request things like allocating a pseudo-tty, forwarding X11 connections, forwarding TCP/IP @@ -123,7 +126,9 @@ /etc/ssh/ssh_host_key for protocol version 1, and /etc/ssh/ssh_host_rsa_key and /etc/ssh/ssh_host_dsa_key for pro- tocol version 2. It is possible to have multiple host key files - for the different protocol versions and host key algorithms. + for the different protocol versions and host key algorithms. It + is possible host key for protocol version 2 to contain key plus + x509 certificate. -i Specifies that sshd is being run from inetd(8). sshd is normally not run from inetd because it needs to generate the server key @@ -207,23 +212,25 @@ allowed to change their environment. See the PermitUserEnvironment option in sshd_config(5). - 7. Changes to userM-bM-^@M-^Ys home directory. + 7. Changes to user's home directory. 8. If $HOME/.ssh/rc exists, runs it; else if /etc/ssh/sshrc - exists, runs it; otherwise runs xauth. The M-bM-^@M-^\rcM-bM-^@M-^] files are + exists, runs it; otherwise runs xauth. The ``rc'' files are given the X11 authentication protocol and cookie in standard input. - 9. Runs userM-bM-^@M-^Ys shell or command. + 9. Runs user's shell or command. AUTHORIZED_KEYS FILE FORMAT $HOME/.ssh/authorized_keys is the default file that lists the public keys that are permitted for RSA authentication in protocol version 1 and for public key authentication (PubkeyAuthentication) in protocol version 2. - AuthorizedKeysFile may be used to specify an alternative file. + It is posible for protocol version 2 to contain x509 certificate or cer- + tificate ``Distinguished Name''. AuthorizedKeysFile may be used to spec- + ify an alternative file. Each line of the file contains one key (empty lines and lines starting - with a M-bM-^@M-^X#M-bM-^@M-^Y are ignored as comments). Each RSA public key consists of the + with a `#' are ignored as comments). Each RSA public key consists of the following fields, separated by spaces: options, bits, exponent, modulus, comment. Each protocol version 2 public key consists of: options, key- type, base64 encoded key, comment. The options field is optional; its @@ -231,11 +238,19 @@ (the options field never starts with a number). The bits, exponent, mod- ulus and comment fields give the RSA key for protocol version 1; the com- ment field is not used for anything (but may be convenient for the user - to identify the key). For protocol version 2 the keytype is M-bM-^@M-^\ssh-dssM-bM-^@M-^] or - M-bM-^@M-^\ssh-rsaM-bM-^@M-^]. + to identify the key). For protocol version 2 the keytype is ``ssh-dss'' + or ``ssh-rsa''. In addition for protocol version 2 user can use x509 + certificates. In that case keytype is ``x509v3-sign-rsa'' or + ``x509v3-sign-dss''. Instead of ``base64 encoded key'' line must contain + base64 encoded certicate (old style) or a keyword (new style), optional + followed by symbol equal `=' or colon , zero or more spaces and certifi- + cate ``Distinguished Name'' (Subject). Keyword is case insensitive and + can be one of `Subject' , `Distinguished Name' , `Distinguished-Name' , + `Distinguished_Name' , `DistinguishedName' or `DN'. Separator of Subject + items can be slash `/' , comma or mixed and order is not important. Note that lines in this file are usually several hundred bytes long - (because of the size of the public key encoding). You donM-bM-^@M-^Yt want to type + (because of the size of the public key encoding). You don't want to type them in; instead, copy the identity.pub, id_dsa.pub or the id_rsa.pub file and edit it. @@ -250,9 +265,9 @@ from="pattern-list" Specifies that in addition to public key authentication, the canonical name of the remote host must be present in the comma- - separated list of patterns (M-bM-^@M-^X*M-bM-^@M-^Y and M-bM-^@M-^XM-bM-^@M-^Y? serve as wildcards). + separated list of patterns (`*' and `'? serve as wildcards). The list may also contain patterns negated by prefixing them with - M-bM-^@M-^XM-bM-^@M-^Y!; if the canonical host name matches a negated pattern, the + `'!; if the canonical host name matches a negated pattern, the key is not accepted. The purpose of this option is to optionally increase security: public key authentication by itself does not trust the network or name servers or anything (but the key); how- @@ -301,7 +316,7 @@ no-pty Prevents tty allocation (a request to allocate a pty will fail). permitopen="host:port" - Limit local M-bM-^@M-^XM-bM-^@M-^Xssh -LM-bM-^@M-^YM-bM-^@M-^Y port forwarding such that it may only con- + Limit local ``ssh -L'' port forwarding such that it may only con- nect to the specified host and port. IPv6 addresses can be spec- ified with an alternative syntax: host/port. Multiple permitopen options may be applied separated by commas. No pattern matching @@ -318,20 +333,23 @@ permitopen="10.2.1.55:80",permitopen="10.2.1.56:25" 1024 33 23...2323 + x509v3-sign-dss subject= /C=XX/ST=World/O=OpenSSH Test Team... + SSH_KNOWN_HOSTS FILE FORMAT The /etc/ssh/ssh_known_hosts and $HOME/.ssh/known_hosts files contain - host public keys for all known hosts. The global file should be prepared - by the administrator (optional), and the per-user file is maintained - automatically: whenever the user connects from an unknown host its key is - added to the per-user file. + host public keys, certificates (old style) or certificate ``Distinguished + Name'' for all known hosts. The global file should be prepared by the + administrator (optional), and the per-user file is maintained automati- + cally: whenever the user connects from an unknown host its key is added + to the per-user file. Each line in these files contains the following fields: hostnames, bits, exponent, modulus, comment. The fields are separated by spaces. - Hostnames is a comma-separated list of patterns (M-bM-^@M-^Y*M-bM-^@M-^Y and M-bM-^@M-^Y?M-bM-^@M-^Y act as wild- + Hostnames is a comma-separated list of patterns ('*' and '?' act as wild- cards); each pattern in turn is matched against the canonical host name (when authenticating a client) or against the user-supplied name (when - authenticating a server). A pattern may also be preceded by M-bM-^@M-^XM-bM-^@M-^Y! to + authenticating a server). A pattern may also be preceded by `'! to indicate negation: if the host name matches a negated pattern, it is not accepted (by that line) even if it matched another pattern on the line. @@ -339,7 +357,7 @@ they can be obtained, e.g., from /etc/ssh/ssh_host_key.pub. The optional comment field continues to the end of the line, and is not used. - Lines starting with M-bM-^@M-^X#M-bM-^@M-^Y and empty lines are ignored as comments. + Lines starting with `#' and empty lines are ignored as comments. When performing host authentication, authentication is accepted if any matching line has the proper key. It is thus permissible (but not recom- @@ -350,13 +368,15 @@ be found from either file. Note that the lines in these files are typically hundreds of characters - long, and you definitely donM-bM-^@M-^Yt want to type in the host keys by hand. + long, and you definitely don't want to type in the host keys by hand. Rather, generate them by a script or by taking /etc/ssh/ssh_host_key.pub and adding the host names at the front. Examples + closenet,...,130.233.208.41 1024 37 159...93 closenet.hut.fi cvs.openbsd.org,199.185.137.3 ssh-rsa AAAA1234.....= + x509host x509v3-sign-rsa Subject:/C=XX..... FILES /etc/ssh/sshd_config @@ -365,19 +385,22 @@ /etc/ssh/ssh_host_key, /etc/ssh/ssh_host_dsa_key, /etc/ssh/ssh_host_rsa_key - These three files contain the private parts of the host keys. - These files should only be owned by root, readable only by root, - and not accessible to others. Note that sshd does not start if - this file is group/world-accessible. + These three files contain the private parts of the host keys. It + is possible to contain private part plus x509 certificate for + protocol version 2 keys. These files should only be owned by + root, readable only by root, and not accessible to others. Note + that sshd does not start if this file is group/world-accessible. /etc/ssh/ssh_host_key.pub, /etc/ssh/ssh_host_dsa_key.pub, /etc/ssh/ssh_host_rsa_key.pub These three files contain the public parts of the host keys. These files should be world-readable but writable only by root. - Their contents should match the respective private parts. These - files are not really used for anything; they are provided for the - convenience of the user so their contents can be copied to known - hosts files. These files are created using ssh-keygen(1). + Their contents should match the respective private parts. Note + that when corresponding host key contain a certificate in addi- + tion these file must contains that certificate. These files are + not really used for anything; they are provided for the conve- + nience of the user so their contents can be copied to known hosts + files. These files are created using ssh-keygen(1). /etc/moduli Contains Diffie-Hellman groups used for the "Diffie-Hellman Group @@ -397,25 +420,40 @@ able. $HOME/.ssh/authorized_keys - Lists the public keys (RSA or DSA) that can be used to log into - the userM-bM-^@M-^Ys account. This file must be readable by root (which - may on some machines imply it being world-readable if the userM-bM-^@M-^Ys - home directory resides on an NFS volume). It is recommended that - it not be accessible by others. The format of this file is - described above. Users will place the contents of their + Lists the public keys (RSA or DSA), certificates or certificate + ``Distinguished Names'' (recommendet) that can be used to log + into the user's account. This file must be readable by root + (which may on some machines imply it being world-readable if the + user's home directory resides on an NFS volume). It is recom- + mended that it not be accessible by others. The format of this + file is described above. Users will place the contents of their identity.pub, id_dsa.pub and/or id_rsa.pub files into this file, as described in ssh-keygen(1). /etc/ssh/ssh_known_hosts and $HOME/.ssh/known_hosts These files are consulted when using rhosts with RSA host authen- tication or protocol version 2 hostbased authentication to check - the public key of the host. The key must be listed in one of - these files to be accepted. The client uses the same files to - verify that it is connecting to the correct remote host. These - files should be writable only by root/the owner. + the public key or certificate of the host. The key must be + listed in one of these files to be accepted. The client uses the + same files to verify that it is connecting to the correct remote + host. These files should be writable only by root/the owner. /etc/ssh/ssh_known_hosts should be world-readable, and $HOME/.ssh/known_hosts can, but need not be, world-readable. + /etc/ssh/ca/ca-bundle.crt and /etc/ssh/ca/ca-bundle.crl + The first file contain multiple certificates and the second + ``Certificate Revocation List'' (CRLs) of certificate signers in + PEM format concatenated together. Used to verify client certifi- + cate. + + /etc/ssh/ca/crt and /etc/ssh/ca/crl + ``Hash dirs'' with certificates, the first directory or CLRs, the + second of certificate signers. Each certificate should be stored + in separate file with name [HASH].[NUMBER] or [HASH].r[NUMBER] + for the CRL, where [HASH] is certificate or CRL hash value and + [NUMBER] is an integer starting from zero. Used to verify client + certificate. + /etc/nologin If this file exists, sshd refuses to let anyone except root log in. The contents of the file are displayed to anyone trying to @@ -449,8 +487,8 @@ they have the same user name on both machines. The host name may also be followed by a user name; such users are permitted to log in as any user on this machine (except root). Additionally, the - syntax M-bM-^@M-^\+@groupM-bM-^@M-^] can be used to specify netgroups. Negated - entries start with M-bM-^@M-^X-M-bM-^@M-^Y. + syntax ``+@group'' can be used to specify netgroups. Negated + entries start with `-'. If the client host/user is successfully matched in this file, login is automatically permitted provided the client and server @@ -476,14 +514,14 @@ $HOME/.ssh/environment This file is read into the environment at login (if it exists). It can only contain empty lines, comment lines (that start with - M-bM-^@M-^X#M-bM-^@M-^Y), and assignment lines of the form name=value. The file + `#'), and assignment lines of the form name=value. The file should be writable only by the user; it need not be readable by anyone else. Environment processing is disabled by default and is controlled via the PermitUserEnvironment option. $HOME/.ssh/rc If this file exists, it is run with /bin/sh after reading the - environment files but before starting the userM-bM-^@M-^Ys shell or com- + environment files but before starting the user's shell or com- mand. It must not produce any output on stdout; stderr must be used instead. If X11 forwarding is in use, it will receive the "proto cookie" pair in its standard input (and DISPLAY in its @@ -491,7 +529,7 @@ not run xauth automatically to add X11 cookies. The primary purpose of this file is to run any initialization - routines which may be needed before the userM-bM-^@M-^Ys home directory + routines which may be needed before the user's home directory becomes accessible; AFS is a particular example of such an envi- ronment. @@ -499,10 +537,10 @@ by something similar to: if read proto cookie && [ -n "$DISPLAY" ]; then - if [ M-bM-^@M-^Xecho $DISPLAY | cut -c1-10M-bM-^@M-^X = M-bM-^@M-^Ylocalhost:M-bM-^@M-^Y ]; then + if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then # X11UseLocalhost=yes - echo add unix:M-bM-^@M-^Xecho $DISPLAY | - cut -c11-M-bM-^@M-^X $proto $cookie + echo add unix:`echo $DISPLAY | + cut -c11-` $proto $cookie else # X11UseLocalhost=no echo add $DISPLAY $proto $cookie @@ -526,7 +564,8 @@ de Raadt and Dug Song removed many bugs, re-added newer features and cre- ated OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Niels Provos and Markus Friedl contributed support - for privilege separation. + for privilege separation. Roumen Petrov contributed support for x509 + certificates. SEE ALSO scp(1), sftp(1), ssh(1), ssh-add(1), ssh-agent(1), ssh-keygen(1), diff -ruN openssh-3.6.1p2/sshd.8 openssh-3.6.1p2+x509g1/sshd.8 --- openssh-3.6.1p2/sshd.8 2003-02-24 02:52:27.000000000 +0200 +++ openssh-3.6.1p2+x509g1/sshd.8 2003-04-30 09:06:00.000000000 +0300 @@ -13,6 +13,7 @@ .\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. .\" Copyright (c) 1999 Aaron Campbell. All rights reserved. .\" Copyright (c) 1999 Theo de Raadt. All rights reserved. +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -34,7 +35,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $OpenBSD: sshd.8,v 1.194 2003/01/31 21:54:40 jmc Exp $ +.\" $OpenBSD$ .Dd September 25, 1999 .Dt SSHD 8 .Os @@ -132,6 +133,7 @@ .Pp Version 2 works similarly: Each host has a host-specific key (RSA or DSA) used to identify the host. +It is possible host key to contain key plus x509 certificate. However, when the daemon starts, it does not generate a server key. Forward security is provided through a Diffie-Hellman key agreement. This key agreement results in a shared session key. @@ -226,6 +228,8 @@ for protocol version 2. It is possible to have multiple host key files for the different protocol versions and host key algorithms. +It is possible host key for protocol version 2 to contain key plus x509 +certificate. .It Fl i Specifies that .Nm @@ -382,6 +386,9 @@ permitted for RSA authentication in protocol version 1 and for public key authentication (PubkeyAuthentication) in protocol version 2. +It is posible for protocol version 2 to contain x509 certificate +or certificate +.Dq "Distinguished Name" . .Cm AuthorizedKeysFile may be used to specify an alternative file. .Pp @@ -405,6 +412,38 @@ .Dq ssh-dss or .Dq ssh-rsa . +In addition for protocol version 2 user can use x509 certificates. +In that case keytype is +.Dq x509v3-sign-rsa +or +.Dq x509v3-sign-dss . +Instead of +.Dq "base64 encoded key" +line must contain base64 encoded certicate (old style) or +a keyword (new style), optional followed by symbol equal +.Sq = +or colon +.\" .roumen:howto quote colon ? +.\" .Sq : work only in man2html +.\" .Sq \N'58' work only in GNU nroff +.\" +, zero or more spaces and certificate +.Dq "Distinguished Name" +(Subject). Keyword is case insensitive and can be one of +.Sq Subject +, +.Sq "Distinguished Name" +, +.Sq Distinguished-Name +, +.Sq Distinguished_Name +, +.Sq DistinguishedName +or +.Sq DN . +Separator of Subject items can be slash +.Sq / +, comma or mixed and order is not important. .Pp Note that lines in this file are usually several hundred bytes long (because of the size of the public key encoding). @@ -509,12 +548,16 @@ command="dump /home",no-pty,no-port-forwarding 1024 33 23.\|.\|.\|2323 backup.hut.fi .Pp permitopen="10.2.1.55:80",permitopen="10.2.1.56:25" 1024 33 23.\|.\|.\|2323 +.Pp +x509v3-sign-dss subject= /C=XX/ST=World/O=OpenSSH Test Team.\|.\|.\| .Sh SSH_KNOWN_HOSTS FILE FORMAT The .Pa /etc/ssh/ssh_known_hosts and .Pa $HOME/.ssh/known_hosts -files contain host public keys for all known hosts. +files contain host public keys, certificates (old style) or certificate +.Dq "Distinguished Name" +for all known hosts. The global file should be prepared by the administrator (optional), and the per-user file is maintained automatically: whenever the user connects from an unknown host @@ -564,6 +607,7 @@ .Bd -literal closenet,.\|.\|.\|,130.233.208.41 1024 37 159.\|.\|.93 closenet.hut.fi cvs.openbsd.org,199.185.137.3 ssh-rsa AAAA1234.....= +x509host x509v3-sign-rsa Subject:/C=XX..... .Ed .Sh FILES .Bl -tag -width Ds @@ -574,6 +618,8 @@ .Xr sshd_config 5 . .It Pa /etc/ssh/ssh_host_key, /etc/ssh/ssh_host_dsa_key, /etc/ssh/ssh_host_rsa_key These three files contain the private parts of the host keys. +It is possible to contain private part plus x509 certificate for +protocol version 2 keys. These files should only be owned by root, readable only by root, and not accessible to others. Note that @@ -584,6 +630,8 @@ These files should be world-readable but writable only by root. Their contents should match the respective private parts. +Note that when corresponding host key contain a certificate +in addition these file must contains that certificate. These files are not really used for anything; they are provided for the convenience of the user so their contents can be copied to known hosts files. @@ -608,7 +656,10 @@ started last). The content of this file is not sensitive; it can be world-readable. .It Pa $HOME/.ssh/authorized_keys -Lists the public keys (RSA or DSA) that can be used to log into the user's account. +Lists the public keys (RSA or DSA), certificates or certificate +.Dq "Distinguished Names" +(recommendet) +that can be used to log into the user's account. This file must be readable by root (which may on some machines imply it being world-readable if the user's home directory resides on an NFS volume). @@ -624,7 +675,7 @@ .It Pa "/etc/ssh/ssh_known_hosts" and "$HOME/.ssh/known_hosts" These files are consulted when using rhosts with RSA host authentication or protocol version 2 hostbased authentication -to check the public key of the host. +to check the public key or certificate of the host. The key must be listed in one of these files to be accepted. The client uses the same files to verify that it is connecting to the correct remote host. @@ -633,6 +684,20 @@ should be world-readable, and .Pa $HOME/.ssh/known_hosts can, but need not be, world-readable. +.It Pa "/etc/ssh/ca/ca-bundle.crt" and "/etc/ssh/ca/ca-bundle.crl" +The first file contain multiple certificates and the second +.Dq "Certificate Revocation List" +(CRLs) of certificate signers in PEM format concatenated together. +Used to verify client certificate. +.It Pa "/etc/ssh/ca/crt" and Pa "/etc/ssh/ca/crl" +.Dq "Hash dirs" +with certificates, the first directory or CLRs, the second of +certificate signers. +Each certificate should be stored in separate file with name +[HASH].[NUMBER] or [HASH].r[NUMBER] for the CRL, where [HASH] is +certificate or CRL hash value and [NUMBER] is an integer starting +from zero. +Used to verify client certificate. .It Pa /etc/nologin If this file exists, .Nm @@ -778,6 +843,7 @@ protocol versions 1.5 and 2.0. Niels Provos and Markus Friedl contributed support for privilege separation. +Roumen Petrov contributed support for x509 certificates. .Sh SEE ALSO .Xr scp 1 , .Xr sftp 1 , diff -ruN openssh-3.6.1p2/sshd.c openssh-3.6.1p2+x509g1/sshd.c --- openssh-3.6.1p2/sshd.c 2003-03-10 02:38:10.000000000 +0200 +++ openssh-3.6.1p2+x509g1/sshd.c 2003-04-30 09:06:01.000000000 +0300 @@ -20,6 +20,9 @@ * Copyright (c) 2000, 2001, 2002 Markus Friedl. All rights reserved. * Copyright (c) 2002 Niels Provos. All rights reserved. * + * X509 certificates support: + * Copyright (c) 2002 Roumen Petrov. All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -42,7 +45,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: sshd.c,v 1.263 2003/02/16 17:09:57 markus Exp $"); +RCSID("$OpenBSD$"); #include #include @@ -695,6 +698,8 @@ switch (key->type) { case KEY_RSA: case KEY_DSA: + case KEY_X509_RSA: + case KEY_X509_DSA: if (buffer_len(&b) > 0) buffer_append(&b, ",", 1); p = key_ssh_name(key); @@ -1003,6 +1008,8 @@ break; case KEY_RSA: case KEY_DSA: + case KEY_X509_RSA: + case KEY_X509_DSA: sensitive_data.have_ssh2_key = 1; break; } @@ -1224,6 +1231,8 @@ if (f) { fprintf(f, "%ld\n", (long) getpid()); fclose(f); + } else { + error("Could not create pid file: %.400s", options.pid_file); } } diff -ruN openssh-3.6.1p2/sshd_config openssh-3.6.1p2+x509g1/sshd_config --- openssh-3.6.1p2/sshd_config 2002-09-27 06:21:58.000000000 +0300 +++ openssh-3.6.1p2+x509g1/sshd_config 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -# $OpenBSD: sshd_config,v 1.59 2002/09/25 11:17:16 markus Exp $ +# $OpenBSD$ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. @@ -21,6 +21,32 @@ #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key +# The intended use for the X509 client certificate. Without this option +# no chain verification will be done. Currently accepted uses are case +# insensitive: +# - "sslclient", "SSL client", "SSL_client" or "client" +# - "any", "Any Purpose", "Any_Purpose" or "AnyPurpose" +# - "skip" or ""(empty): don`t check purpose. +#AllowedCertPurpose sslclient + +# A file with multiple certificates of certificate signers +# in PEM format concatenated together. +#CACertificateFile /etc/ssh/ca/ca-bundle.crt + +# A directory with certificates of certificate signers. +# The certificates should have name of the form: [HASH].[NUMBER] +# or have symbolic links to them of this form. +#CACertificatePath /etc/ssh/ca/crt + +# A file with multiple CRL of certificate signers +# in PEM format concatenated together. +#CARevocationFile /etc/ssh/ca/ca-bundle.crl + +# A directory with CRL of certificate signers. +# The CRL should have name of the form: [HASH].r[NUMBER] +# or have symbolic links to them of this form. +#CARevocationPath /etc/ssh/ca/crl + # Lifetime and size of ephemeral version 1 server key #KeyRegenerationInterval 3600 #ServerKeyBits 768 diff -ruN openssh-3.6.1p2/sshd_config.0 openssh-3.6.1p2+x509g1/sshd_config.0 --- openssh-3.6.1p2/sshd_config.0 2003-04-29 12:37:31.000000000 +0300 +++ openssh-3.6.1p2+x509g1/sshd_config.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSHD_CONFIG(5) BSD File Formats Manual SSHD_CONFIG(5) +SSHD_CONFIG(5) System File Formats Manual SSHD_CONFIG(5) NAME sshd_config - OpenSSH SSH daemon configuration file @@ -9,7 +9,7 @@ DESCRIPTION sshd reads configuration data from /etc/ssh/sshd_config (or the file specified with -f on the command line). The file contains keyword-argu- - ment pairs, one per line. Lines starting with M-bM-^@M-^X#M-bM-^@M-^Y and empty lines are + ment pairs, one per line. Lines starting with `#' and empty lines are interpreted as comments. The possible keywords and their meanings are as follows (note that key- @@ -17,26 +17,36 @@ AFSTokenPassing Specifies whether an AFS token may be forwarded to the server. - Default is M-bM-^@M-^\noM-bM-^@M-^]. + Default is ``no''. + + AllowedCertPurpose + The intended use for the X509 client certificate. Without this + option no chain verification will be done. Currently accepted + uses are case insensitive: + - `sslclient' , `SSL client' , `SSL_client' or `client' + - `any' , `Any Purpose' , `Any_Purpose' or `AnyPurpose' + - `skip' or `' (empty): do not check purpose. + + The default is ``sslclient''. AllowGroups This keyword can be followed by a list of group name patterns, separated by spaces. If specified, login is allowed only for users whose primary group or supplementary group list matches one - of the patterns. M-bM-^@M-^X*M-bM-^@M-^Y and M-bM-^@M-^XM-bM-^@M-^Y? can be used as wildcards in the + of the patterns. `*' and `'? can be used as wildcards in the patterns. Only group names are valid; a numerical group ID is not recognized. By default, login is allowed for all groups. AllowTcpForwarding Specifies whether TCP forwarding is permitted. The default is - M-bM-^@M-^\yesM-bM-^@M-^]. Note that disabling TCP forwarding does not improve secu- - rity unless users are also denied shell access, as they can + ``yes''. Note that disabling TCP forwarding does not improve + security unless users are also denied shell access, as they can always install their own forwarders. AllowUsers This keyword can be followed by a list of user name patterns, separated by spaces. If specified, login is allowed only for - user names that match one of the patterns. M-bM-^@M-^X*M-bM-^@M-^Y and M-bM-^@M-^XM-bM-^@M-^Y? can be + user names that match one of the patterns. `*' and `'? can be used as wildcards in the patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed for all users. If the pattern takes the form USER@HOST @@ -48,11 +58,11 @@ for user authentication. AuthorizedKeysFile may contain tokens of the form %T which are substituted during connection set-up. The following tokens are defined: %% is replaced by a literal - M-bM-^@M-^Y%M-bM-^@M-^Y, %h is replaced by the home directory of the user being + '%', %h is replaced by the home directory of the user being authenticated and %u is replaced by the username of that user. After expansion, AuthorizedKeysFile is taken to be an absolute - path or one relative to the userM-bM-^@M-^Ys home directory. The default - is M-bM-^@M-^\.ssh/authorized_keysM-bM-^@M-^]. + path or one relative to the user's home directory. The default + is ``.ssh/authorized_keys''. Banner In some jurisdictions, sending a warning message before authenti- cation may be relevant for getting legal protection. The con- @@ -60,17 +70,40 @@ authentication is allowed. This option is only available for protocol version 2. By default, no banner is displayed. + CACertificateFile + This file contain multiple certificates of certificate signers in + PEM format concatenated together. The default is + /etc/ssh/ca/ca-bundle.crt + + CACertificatePath + ``Hash dir'' with certificates of certificate signers. Each cer- + tificate should be stored in separate file with name [HASH].[NUM- + BER], where [HASH] is certificate hash value and [NUMBER] is an + integer starting from zero. The default is /etc/ssh/ca/crt + + CARevocationFile + This file contain multiple ``Certificate Revocation List'' (CRL) + of certificate signers in PEM format concatenated together. The + default is /etc/ssh/ca/ca-bundle.crl + + CARevocationPath + ``Hash dir'' with ``Certificate Revocation List'' (CRL) of cer- + tificate signers. Each CRL should be stored in separate file with + name [HASH].r[NUMBER], where [HASH] is CRL hash value and [NUM- + BER] is an integer starting from zero. The default is + /etc/ssh/ca/crl + ChallengeResponseAuthentication Specifies whether challenge response authentication is allowed. All authentication styles from login.conf(5) are supported. The - default is M-bM-^@M-^\yesM-bM-^@M-^]. + default is ``yes''. Ciphers Specifies the ciphers allowed for protocol version 2. Multiple ciphers must be comma-separated. The default is - M-bM-^@M-^XM-bM-^@M-^Xaes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour, - aes192-cbc,aes256-cbcM-bM-^@M-^YM-bM-^@M-^Y + ``aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour, + aes192-cbc,aes256-cbc'' ClientAliveInterval Sets a timeout interval in seconds after which if no data has @@ -98,20 +131,20 @@ Compression Specifies whether compression is allowed. The argument must be - M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\yesM-bM-^@M-^]. + ``yes'' or ``no''. The default is ``yes''. DenyGroups This keyword can be followed by a list of group name patterns, separated by spaces. Login is disallowed for users whose primary group or supplementary group list matches one of the patterns. - M-bM-^@M-^X*M-bM-^@M-^Y and M-bM-^@M-^XM-bM-^@M-^Y? can be used as wildcards in the patterns. Only + `*' and `'? can be used as wildcards in the patterns. Only group names are valid; a numerical group ID is not recognized. By default, login is allowed for all groups. DenyUsers This keyword can be followed by a list of user name patterns, separated by spaces. Login is disallowed for user names that - match one of the patterns. M-bM-^@M-^X*M-bM-^@M-^Y and M-bM-^@M-^XM-bM-^@M-^Y? can be used as wildcards + match one of the patterns. `*' and `'? can be used as wildcards in the patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed for all users. If the pattern takes the form USER@HOST then USER and HOST are @@ -125,15 +158,15 @@ hosts from connecting to forwarded ports. GatewayPorts can be used to specify that sshd should bind remote port forwardings to the wildcard address, thus allowing remote hosts to connect to - forwarded ports. The argument must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The - default is M-bM-^@M-^\noM-bM-^@M-^]. + forwarded ports. The argument must be ``yes'' or ``no''. The + default is ``no''. HostbasedAuthentication Specifies whether rhosts or /etc/hosts.equiv authentication together with successful public key client host authentication is allowed (hostbased authentication). This option is similar to RhostsRSAAuthentication and applies to protocol version 2 only. - The default is M-bM-^@M-^\noM-bM-^@M-^]. + The default is ``no''. HostKey Specifies a file containing a private host key used by SSH. The @@ -141,8 +174,9 @@ /etc/ssh/ssh_host_rsa_key and /etc/ssh/ssh_host_dsa_key for pro- tocol version 2. Note that sshd will refuse to use a file if it is group/world-accessible. It is possible to have multiple host - key files. M-bM-^@M-^\rsa1M-bM-^@M-^] keys are used for version 1 and M-bM-^@M-^\dsaM-bM-^@M-^] or M-bM-^@M-^\rsaM-bM-^@M-^] - are used for version 2 of the SSH protocol. + key files. ``rsa1'' keys are used for version 1 and ``dsa'' or + ``rsa'' are used for version 2 of the SSH protocol. It is possi- + ble host key to contain key plus x509 certificate for version 2. IgnoreRhosts Specifies that .rhosts and .shosts files will not be used in @@ -150,12 +184,12 @@ HostbasedAuthentication. /etc/hosts.equiv and /etc/shosts.equiv are still used. The - default is M-bM-^@M-^\yesM-bM-^@M-^]. + default is ``yes''. IgnoreUserKnownHosts - Specifies whether sshd should ignore the userM-bM-^@M-^Ys + Specifies whether sshd should ignore the user's $HOME/.ssh/known_hosts during RhostsRSAAuthentication or - HostbasedAuthentication. The default is M-bM-^@M-^\noM-bM-^@M-^]. + HostbasedAuthentication. The default is ``no''. KeepAlive Specifies whether the system should send TCP keepalive messages @@ -164,35 +198,35 @@ this means that connections will die if the route is down tem- porarily, and some people find it annoying. On the other hand, if keepalives are not sent, sessions may hang indefinitely on the - server, leaving M-bM-^@M-^\ghostM-bM-^@M-^] users and consuming server resources. + server, leaving ``ghost'' users and consuming server resources. - The default is M-bM-^@M-^\yesM-bM-^@M-^] (to send keepalives), and the server will + The default is ``yes'' (to send keepalives), and the server will notice if the network goes down or the client host crashes. This avoids infinitely hanging sessions. - To disable keepalives, the value should be set to M-bM-^@M-^\noM-bM-^@M-^]. + To disable keepalives, the value should be set to ``no''. KerberosAuthentication Specifies whether Kerberos authentication is allowed. This can be in the form of a Kerberos ticket, or if PasswordAuthentication is yes, the password provided by the user will be validated through the Kerberos KDC. To use this option, the server needs a - Kerberos servtab which allows the verification of the KDCM-bM-^@M-^Ys iden- - tity. Default is M-bM-^@M-^\noM-bM-^@M-^]. + Kerberos servtab which allows the verification of the KDC's iden- + tity. Default is ``no''. KerberosOrLocalPasswd If set then if password authentication through Kerberos fails then the password will be validated via any additional local - mechanism such as /etc/passwd. Default is M-bM-^@M-^\yesM-bM-^@M-^]. + mechanism such as /etc/passwd. Default is ``yes''. KerberosTgtPassing Specifies whether a Kerberos TGT may be forwarded to the server. - Default is M-bM-^@M-^\noM-bM-^@M-^], as this only works when the Kerberos KDC is + Default is ``no'', as this only works when the Kerberos KDC is actually an AFS kaserver. KerberosTicketCleanup - Specifies whether to automatically destroy the userM-bM-^@M-^Ys ticket - cache file on logout. Default is M-bM-^@M-^\yesM-bM-^@M-^]. + Specifies whether to automatically destroy the user's ticket + cache file on logout. Default is ``yes''. KeyRegenerationInterval In protocol version 1, the ephemeral server key is automatically @@ -233,7 +267,7 @@ rithms. The MAC algorithm is used in protocol version 2 for data integrity protection. Multiple algorithms must be comma-sepa- rated. The default is - M-bM-^@M-^\hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96M-bM-^@M-^]. + ``hmac-md5,hmac-sha1,hmac-ripemd160,hmac-sha1-96,hmac-md5-96''. MaxStartups Specifies the maximum number of concurrent unauthenticated con- @@ -242,12 +276,12 @@ expires for a connection. The default is 10. Alternatively, random early drop can be enabled by specifying the - three colon separated values M-bM-^@M-^\start:rate:fullM-bM-^@M-^] (e.g., + three colon separated values ``start:rate:full'' (e.g., "10:30:60"). sshd will refuse connection attempts with a proba- - bility of M-bM-^@M-^\rate/100M-bM-^@M-^] (30%) if there are currently M-bM-^@M-^\startM-bM-^@M-^] (10) - unauthenticated connections. The probability increases linearly - and all connection attempts are refused if the number of unau- - thenticated connections reaches M-bM-^@M-^\fullM-bM-^@M-^] (60). + bility of ``rate/100'' (30%) if there are currently ``start'' + (10) unauthenticated connections. The probability increases lin- + early and all connection attempts are refused if the number of + unauthenticated connections reaches ``full'' (60). PAMAuthenticationViaKbdInt Specifies whether PAM challenge response authentication is @@ -257,35 +291,35 @@ PasswordAuthentication Specifies whether password authentication is allowed. The - default is M-bM-^@M-^\yesM-bM-^@M-^]. + default is ``yes''. PermitEmptyPasswords When password authentication is allowed, it specifies whether the server allows login to accounts with empty password strings. The - default is M-bM-^@M-^\noM-bM-^@M-^]. + default is ``no''. PermitRootLogin Specifies whether root can login using ssh(1). The argument must - be M-bM-^@M-^\yesM-bM-^@M-^], M-bM-^@M-^\without-passwordM-bM-^@M-^], M-bM-^@M-^\forced-commands-onlyM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. - The default is M-bM-^@M-^\yesM-bM-^@M-^]. + be ``yes'', ``without-password'', ``forced-commands-only'' or + ``no''. The default is ``yes''. - If this option is set to M-bM-^@M-^\without-passwordM-bM-^@M-^] password authentica- - tion is disabled for root. + If this option is set to ``without-password'' password authenti- + cation is disabled for root. - If this option is set to M-bM-^@M-^\forced-commands-onlyM-bM-^@M-^] root login with + If this option is set to ``forced-commands-only'' root login with public key authentication will be allowed, but only if the command option has been specified (which may be useful for taking remote backups even if root login is normally not allowed). All other authentication methods are disabled for root. - If this option is set to M-bM-^@M-^\noM-bM-^@M-^] root is not allowed to login. + If this option is set to ``no'' root is not allowed to login. PermitUserEnvironment Specifies whether ~/.ssh/environment and environment= options in ~/.ssh/authorized_keys are processed by sshd. The default is - M-bM-^@M-^\noM-bM-^@M-^]. Enabling environment processing may enable users to bypass - access restrictions in some configurations using mechanisms such - as LD_PRELOAD. + ``no''. Enabling environment processing may enable users to + bypass access restrictions in some configurations using mecha- + nisms such as LD_PRELOAD. PidFile Specifies the file that contains the process ID of the sshd dae- @@ -297,25 +331,25 @@ PrintLastLog Specifies whether sshd should print the date and time when the - user last logged in. The default is M-bM-^@M-^\yesM-bM-^@M-^]. + user last logged in. The default is ``yes''. PrintMotd Specifies whether sshd should print /etc/motd when a user logs in interactively. (On some systems it is also printed by the shell, - /etc/profile, or equivalent.) The default is M-bM-^@M-^\yesM-bM-^@M-^]. + /etc/profile, or equivalent.) The default is ``yes''. Protocol Specifies the protocol versions sshd supports. The possible val- - ues are M-bM-^@M-^\1M-bM-^@M-^] and M-bM-^@M-^\2M-bM-^@M-^]. Multiple versions must be comma-separated. - The default is M-bM-^@M-^\2,1M-bM-^@M-^]. Note that the order of the protocol list - does not indicate preference, because the client selects among - multiple protocol versions offered by the server. Specifying - M-bM-^@M-^\2,1M-bM-^@M-^] is identical to M-bM-^@M-^\1,2M-bM-^@M-^]. + ues are ``1'' and ``2''. Multiple versions must be comma-sepa- + rated. The default is ``2,1''. Note that the order of the pro- + tocol list does not indicate preference, because the client + selects among multiple protocol versions offered by the server. + Specifying ``2,1'' is identical to ``1,2''. PubkeyAuthentication Specifies whether public key authentication is allowed. The - default is M-bM-^@M-^\yesM-bM-^@M-^]. Note that this option applies to protocol ver- - sion 2 only. + default is ``yes''. Note that this option applies to protocol + version 2 only. RhostsAuthentication Specifies whether authentication using rhosts or /etc/hosts.equiv @@ -323,17 +357,18 @@ ted because it is insecure. RhostsRSAAuthentication should be used instead, because it performs RSA-based host authentication in addition to normal rhosts or /etc/hosts.equiv authentication. - The default is M-bM-^@M-^\noM-bM-^@M-^]. This option applies to protocol version 1 + The default is ``no''. This option applies to protocol version 1 only. RhostsRSAAuthentication Specifies whether rhosts or /etc/hosts.equiv authentication together with successful RSA host authentication is allowed. The - default is M-bM-^@M-^\noM-bM-^@M-^]. This option applies to protocol version 1 only. + default is ``no''. This option applies to protocol version 1 + only. RSAAuthentication Specifies whether pure RSA authentication is allowed. The - default is M-bM-^@M-^\yesM-bM-^@M-^]. This option applies to protocol version 1 + default is ``yes''. This option applies to protocol version 1 only. ServerKeyBits @@ -342,17 +377,17 @@ StrictModes Specifies whether sshd should check file modes and ownership of - the userM-bM-^@M-^Ys files and home directory before accepting login. This + the user's files and home directory before accepting login. This is normally desirable because novices sometimes accidentally leave their directory or files world-writable. The default is - M-bM-^@M-^\yesM-bM-^@M-^]. + ``yes''. Subsystem Configures an external subsystem (e.g., file transfer daemon). Arguments should be a subsystem name and a command to execute upon subsystem request. The command sftp-server(8) implements - the M-bM-^@M-^\sftpM-bM-^@M-^] file transfer subsystem. By default no subsystems are - defined. Note that this option applies to protocol version 2 + the ``sftp'' file transfer subsystem. By default no subsystems + are defined. Note that this option applies to protocol version 2 only. SyslogFacility @@ -363,7 +398,7 @@ UseLogin Specifies whether login(1) is used for interactive login ses- - sions. The default is M-bM-^@M-^\noM-bM-^@M-^]. Note that login(1) is never used + sions. The default is ``no''. Note that login(1) is never used for remote command execution. Note also, that if this is enabled, X11Forwarding will be disabled because login(1) does not know how to handle xauth(1) cookies. If UsePrivilegeSeparation @@ -376,21 +411,21 @@ that has the privilege of the authenticated user. The goal of privilege separation is to prevent privilege escalation by con- taining any corruption within the unprivileged processes. The - default is M-bM-^@M-^\yesM-bM-^@M-^]. + default is ``yes''. VerifyReverseMapping Specifies whether sshd should try to verify the remote host name and check that the resolved host name for the remote IP address - maps back to the very same IP address. The default is M-bM-^@M-^\noM-bM-^@M-^]. + maps back to the very same IP address. The default is ``no''. X11DisplayOffset - Specifies the first display number available for sshdM-bM-^@M-^Ys X11 for- + Specifies the first display number available for sshd's X11 for- warding. This prevents sshd from interfering with real X11 servers. The default is 10. X11Forwarding Specifies whether X11 forwarding is permitted. The argument must - be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default is M-bM-^@M-^\noM-bM-^@M-^]. + be ``yes'' or ``no''. The default is ``no''. When X11 forwarding is enabled, there may be additional exposure to the server and to client displays if the sshd proxy display is @@ -398,12 +433,12 @@ below), however this is not the default. Additionally, the authentication spoofing and authentication data verification and substitution occur on the client side. The security risk of - using X11 forwarding is that the clientM-bM-^@M-^Ys X11 display server may + using X11 forwarding is that the client's X11 display server may be exposed to attack when the ssh client requests forwarding (see the warnings for ForwardX11 in ssh_config(5) ). A system adminis- trator may have a stance in which they want to protect clients that may expose themselves to attack by unwittingly requesting - X11 forwarding, which can warrant a M-bM-^@M-^\noM-bM-^@M-^] setting. + X11 forwarding, which can warrant a ``no'' setting. Note that disabling X11 forwarding does not prevent users from forwarding X11 traffic, as users can always install their own @@ -415,18 +450,19 @@ the loopback address or to the wildcard address. By default, sshd binds the forwarding server to the loopback address and sets the hostname part of the DISPLAY environment variable to - M-bM-^@M-^\localhostM-bM-^@M-^]. This prevents remote hosts from connecting to the + ``localhost''. This prevents remote hosts from connecting to the proxy display. However, some older X11 clients may not function - with this configuration. X11UseLocalhost may be set to M-bM-^@M-^\noM-bM-^@M-^] to + with this configuration. X11UseLocalhost may be set to ``no'' to specify that the forwarding server should be bound to the wild- - card address. The argument must be M-bM-^@M-^\yesM-bM-^@M-^] or M-bM-^@M-^\noM-bM-^@M-^]. The default - is M-bM-^@M-^\yesM-bM-^@M-^]. + card address. The argument must be ``yes'' or ``no''. The + default is ``yes''. XAuthLocation Specifies the full pathname of the xauth(1) program. The default is /usr/X11R6/bin/xauth. Time Formats + sshd command-line arguments and configuration file options that specify time may be expressed using a sequence of the form: time[qualifier], where time is a positive integer value and qualifier is one of the fol- @@ -460,7 +496,8 @@ de Raadt and Dug Song removed many bugs, re-added newer features and cre- ated OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Niels Provos and Markus Friedl contributed support - for privilege separation. + for privilege separation. Roumen Petrov contributed support for x509 + certificates. SEE ALSO sshd(8) diff -ruN openssh-3.6.1p2/sshd_config.5 openssh-3.6.1p2+x509g1/sshd_config.5 --- openssh-3.6.1p2/sshd_config.5 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/sshd_config.5 2003-04-30 09:06:00.000000000 +0300 @@ -13,6 +13,7 @@ .\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. .\" Copyright (c) 1999 Aaron Campbell. All rights reserved. .\" Copyright (c) 1999 Theo de Raadt. All rights reserved. +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -34,7 +35,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $OpenBSD: sshd_config.5,v 1.15 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .Dd September 25, 1999 .Dt SSHD_CONFIG 5 .Os @@ -65,6 +66,36 @@ Specifies whether an AFS token may be forwarded to the server. Default is .Dq no . +.It Cm AllowedCertPurpose +The intended use for the X509 client certificate. Without this option +no chain verification will be done. Currently accepted uses are case +insensitive: + - +.Sq sslclient +, +.Sq SSL client +, +.Sq SSL_client +or +.Sq client + - +.Sq any +, +.Sq Any Purpose +, +.Sq Any_Purpose +or +.Sq AnyPurpose + - +.Sq skip +or +.Sq +.. +(empty): do not check purpose. +.Pp +The default is +.Dq sslclient . +.Pp .It Cm AllowGroups This keyword can be followed by a list of group name patterns, separated by spaces. @@ -124,6 +155,35 @@ This option is only available for protocol version 2. By default, no banner is displayed. .Pp +.It Cm CACertificateFile +This file contain multiple certificates of certificate signers in +PEM format concatenated together. The default is +.Pa /etc/ssh/ca/ca-bundle.crt +.Pp +.It Cm CACertificatePath +.Dq "Hash dir" +with certificates of certificate signers. Each certificate should be +stored in separate file with name [HASH].[NUMBER], where [HASH] is +certificate hash value and [NUMBER] is an integer starting from zero. +The default is +.Pa /etc/ssh/ca/crt +.Pp +.It Cm CARevocationFile +This file contain multiple +.Dq "Certificate Revocation List" +(CRL) of certificate signers in PEM format concatenated together. +The default is +.Pa /etc/ssh/ca/ca-bundle.crl +.Pp +.It Cm CARevocationPath +.Dq "Hash dir" +with +.Dq "Certificate Revocation List" +(CRL) of certificate signers. Each CRL should be stored in separate +file with name [HASH].r[NUMBER], where [HASH] is CRL hash value and +[NUMBER] is an integer starting from zero. The default is +.Pa /etc/ssh/ca/crl +.Pp .It Cm ChallengeResponseAuthentication Specifies whether challenge response authentication is allowed. All authentication styles from @@ -253,6 +313,8 @@ or .Dq rsa are used for version 2 of the SSH protocol. +It is possible host key to contain key plus x509 certificate +for version 2. .It Cm IgnoreRhosts Specifies that .Pa .rhosts @@ -759,5 +821,6 @@ protocol versions 1.5 and 2.0. Niels Provos and Markus Friedl contributed support for privilege separation. +Roumen Petrov contributed support for x509 certificates. .Sh SEE ALSO .Xr sshd 8 diff -ruN openssh-3.6.1p2/ssh-keygen.0 openssh-3.6.1p2+x509g1/ssh-keygen.0 --- openssh-3.6.1p2/ssh-keygen.0 2003-04-29 12:37:29.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-keygen.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH-KEYGEN(1) BSD General Commands Manual SSH-KEYGEN(1) +SSH-KEYGEN(1) System General Commands Manual SSH-KEYGEN(1) NAME ssh-keygen - authentication key generation, management and conversion @@ -29,7 +29,7 @@ Normally this program generates the key and asks for a file in which to store the private key. The public key is stored in a file with the same - name but M-bM-^@M-^\.pubM-bM-^@M-^] appended. The program also asks for a passphrase. The + name but ``.pub'' appended. The program also asks for a passphrase. The passphrase may be empty to indicate no passphrase (host keys must have an empty passphrase), or it may be a string of arbitrary length. A passphrase is similar to a password, except it can be a phrase with a @@ -48,8 +48,8 @@ For RSA1 keys, there is also a comment field in the key file that is only for convenience to the user to help identify the key. The comment can tell what the key is for, or whatever is useful. The comment is initial- - ized to M-bM-^@M-^\user@hostM-bM-^@M-^] when the key is created, but can be changed using the - -c option. + ized to ``user@host'' when the key is created, but can be changed using + the -c option. After a key is generated, instructions below detail where the keys should be placed to be activated. @@ -67,7 +67,7 @@ the passphrase if the key has one, and for the new comment. -e This option will read a private or public OpenSSH key file and - print the key in a M-bM-^@M-^XSECSH Public Key File FormatM-bM-^@M-^Y to stdout. + print the key in a `SECSH Public Key File Format' to stdout. This option allows exporting keys for use by several commercial SSH implementations. @@ -76,8 +76,8 @@ -i This option will read an unencrypted private (or public) key file in SSH2-compatible format and print an OpenSSH compatible private - (or public) key to stdout. ssh-keygen also reads the M-bM-^@M-^XSECSH - Public Key File FormatM-bM-^@M-^Y. This option allows importing keys from + (or public) key to stdout. ssh-keygen also reads the `SECSH + Public Key File Format'. This option allows importing keys from several commercial SSH implementations. -l Show fingerprint of specified public key file. Private RSA1 keys @@ -96,8 +96,8 @@ -t type Specifies the type of the key to create. The possible values are - M-bM-^@M-^\rsa1M-bM-^@M-^] for protocol version 1 and M-bM-^@M-^\rsaM-bM-^@M-^] or M-bM-^@M-^\dsaM-bM-^@M-^] for protocol - version 2. + ``rsa1'' for protocol version 1 and ``rsa'' or ``dsa'' for proto- + col version 2. -B Show the bubblebabble digest of specified private or public key file. @@ -136,10 +136,11 @@ $HOME/.ssh/id_dsa Contains the protocol version 2 DSA authentication identity of - the user. This file should not be readable by anyone but the - user. It is possible to specify a passphrase when generating the - key; that passphrase will be used to encrypt the private part of - this file using 3DES. This file is not automatically accessed by + the user. It is possible to contain identity plus x509 certifi- + cate. This file should not be readable by anyone but the user. + It is possible to specify a passphrase when generating the key; + that passphrase will be used to encrypt the private part of this + file using 3DES. This file is not automatically accessed by ssh-keygen but it is offered as the default file for the private key. ssh(1) will read this file when a login attempt is made. @@ -148,14 +149,21 @@ tion. The contents of this file should be added to $HOME/.ssh/authorized_keys on all machines where the user wishes to log in using public key authentication. There is no need to - keep the contents of this file secret. + keep the contents of this file secret. When file + $HOME/.ssh/id_dsa contain DSA identity plus X509 certificate this + file must contain user certificate! Use ssh-keygen(1) with option + -y to regenerate its content. Note in case with X509 certificate + you can append content to $HOME/.ssh/authorized_keys or to add + certificate ``Distinguished Name'' / ``Subject'' in corresponding + format to ``authorized keys'' file. See sshd(8). $HOME/.ssh/id_rsa Contains the protocol version 2 RSA authentication identity of - the user. This file should not be readable by anyone but the - user. It is possible to specify a passphrase when generating the - key; that passphrase will be used to encrypt the private part of - this file using 3DES. This file is not automatically accessed by + the user. It is possible to contain identity plus x509 certifi- + cate. This file should not be readable by anyone but the user. + It is possible to specify a passphrase when generating the key; + that passphrase will be used to encrypt the private part of this + file using 3DES. This file is not automatically accessed by ssh-keygen but it is offered as the default file for the private key. ssh(1) will read this file when a login attempt is made. @@ -164,14 +172,21 @@ tion. The contents of this file should be added to $HOME/.ssh/authorized_keys on all machines where the user wishes to log in using public key authentication. There is no need to - keep the contents of this file secret. + keep the contents of this file secret. When file + $HOME/.ssh/id_rsa contain RSA identity plus X509 certificate this + file must contain user certificate! Use ssh-keygen(1) with option + -y to regenerate its content. Note in case with X509 certificate + you can append content to $HOME/.ssh/authorized_keys or to add + certificate ``Distinguished Name'' / ``Subject'' in corresponding + format to ``authorized keys'' file. See sshd(8). AUTHORS OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and cre- ated OpenSSH. Markus Friedl contributed the support for SSH protocol - versions 1.5 and 2.0. + versions 1.5 and 2.0. Roumen Petrov contributed support for x509 cer- + tificates. SEE ALSO ssh(1), ssh-add(1), ssh-agent(1), sshd(8) diff -ruN openssh-3.6.1p2/ssh-keygen.1 openssh-3.6.1p2+x509g1/ssh-keygen.1 --- openssh-3.6.1p2/ssh-keygen.1 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-keygen.1 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ssh-keygen.1,v 1.56 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .\" .\" -*- nroff -*- .\" @@ -16,6 +16,7 @@ .\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. .\" Copyright (c) 1999 Aaron Campbell. All rights reserved. .\" Copyright (c) 1999 Theo de Raadt. All rights reserved. +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -241,6 +242,7 @@ There is no need to keep the contents of this file secret. .It Pa $HOME/.ssh/id_dsa Contains the protocol version 2 DSA authentication identity of the user. +It is possible to contain identity plus x509 certificate. This file should not be readable by anyone but the user. It is possible to specify a passphrase when generating the key; that passphrase will be @@ -257,8 +259,25 @@ on all machines where the user wishes to log in using public key authentication. There is no need to keep the contents of this file secret. +When file +.Pa $HOME/.ssh/id_dsa +contain DSA identity plus X509 certificate this file must contain +user certificate! Use +.Xr ssh-keygen 1 +with option -y to regenerate its content. +Note in case with X509 certificate you can append content to +.Pa $HOME/.ssh/authorized_keys +or to add certificate +.Dq Distinguished Name +/ +.Dq Subject +in corresponding format to +.Dq authorized keys +file. See +.Xr sshd 8 . .It Pa $HOME/.ssh/id_rsa Contains the protocol version 2 RSA authentication identity of the user. +It is possible to contain identity plus x509 certificate. This file should not be readable by anyone but the user. It is possible to specify a passphrase when generating the key; that passphrase will be @@ -275,6 +294,22 @@ on all machines where the user wishes to log in using public key authentication. There is no need to keep the contents of this file secret. +When file +.Pa $HOME/.ssh/id_rsa +contain RSA identity plus X509 certificate this file must contain +user certificate! Use +.Xr ssh-keygen 1 +with option -y to regenerate its content. +Note in case with X509 certificate you can append content to +.Pa $HOME/.ssh/authorized_keys +or to add certificate +.Dq Distinguished Name +/ +.Dq Subject +in corresponding format to +.Dq authorized keys +file. See +.Xr sshd 8 . .El .Sh AUTHORS OpenSSH is a derivative of the original and free @@ -285,6 +320,7 @@ created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. +Roumen Petrov contributed support for x509 certificates. .Sh SEE ALSO .Xr ssh 1 , .Xr ssh-add 1 , diff -ruN openssh-3.6.1p2/ssh-keyscan.0 openssh-3.6.1p2+x509g1/ssh-keyscan.0 --- openssh-3.6.1p2/ssh-keyscan.0 2003-04-29 12:37:29.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-keyscan.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH-KEYSCAN(1) BSD General Commands Manual SSH-KEYSCAN(1) +SSH-KEYSCAN(1) System General Commands Manual SSH-KEYSCAN(1) NAME ssh-keyscan - gather ssh public keys @@ -34,9 +34,11 @@ -t type Specifies the type of the key to fetch from the scanned hosts. - The possible values are M-bM-^@M-^\rsa1M-bM-^@M-^] for protocol version 1 and M-bM-^@M-^\rsaM-bM-^@M-^] - or M-bM-^@M-^\dsaM-bM-^@M-^] for protocol version 2. Multiple values may be speci- - fied by separating them with commas. The default is M-bM-^@M-^\rsa1M-bM-^@M-^]. + The possible values are ``rsa1'' for protocol version 1 and + ``rsa'' or ``ssh-rsa'' , ``dsa'' or ``ssh-rsa'' , + ``x509v3-sign-rsa'' or ``x509v3-sign-dss'' for protocol version + 2. Multiple values may be specified by separating them with com- + mas. The default is ``rsa1''. -f filename Read hosts or addrlist namelist pairs from this file, one per @@ -65,7 +67,7 @@ Find all hosts from the file ssh_hosts which have new or different keys from those in the sorted file ssh_known_hosts: - $ ssh-keyscan -t rsa,dsa -f ssh_hosts | \ + $ ssh-keyscan -t x509v3-sign-rsa,x509v3-sign-dss,rsa,dsa -f ssh_hosts | \ sort -u - ssh_known_hosts | diff ssh_known_hosts - FILES @@ -81,7 +83,13 @@ host-or-namelist keytype base64-encoded-key - Where keytype is either M-bM-^@M-^\ssh-rsaM-bM-^@M-^] or M-bM-^@M-^\ssh-dsaM-bM-^@M-^]. + Where keytype is either ``ssh-rsa'' or ``ssh-dsa''. + + Output format for rsa and dsa keys with x509 certificates: + + host-or-namelist keytype distinguished-name + + Where keytype is either ``x509v3-sign-rsa'' or ``x509v3-sign-dss''. /etc/ssh/ssh_known_hosts @@ -97,6 +105,6 @@ AUTHORS David Mazieres wrote the initial version, and Wayne Davison added support for protocol version - 2. + 2. Roumen Petrov contributed support for x509 certificates. BSD January 1, 1996 BSD diff -ruN openssh-3.6.1p2/ssh-keyscan.1 openssh-3.6.1p2+x509g1/ssh-keyscan.1 --- openssh-3.6.1p2/ssh-keyscan.1 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-keyscan.1 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ssh-keyscan.1,v 1.15 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .\" .\" Copyright 1995, 1996 by David Mazieres . .\" @@ -6,6 +6,29 @@ .\" permitted provided that due credit is given to the author and the .\" OpenBSD project by leaving this copyright notice intact. .\" +.\" X509 certificates support, +.\" Copyright (c) 2002 Roumen Petrov. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" .Dd January 1, 1996 .Dt SSH-KEYSCAN 1 .Os @@ -63,7 +86,15 @@ for protocol version 1 and .Dq rsa or +.Dq ssh-rsa +, .Dq dsa +or +.Dq ssh-rsa +, +.Dq x509v3-sign-rsa +or +.Dq x509v3-sign-dss for protocol version 2. Multiple values may be specified by separating them with commas. The default is @@ -118,7 +149,7 @@ which have new or different keys from those in the sorted file .Pa ssh_known_hosts : .Bd -literal -$ ssh-keyscan -t rsa,dsa -f ssh_hosts | \e\ +$ ssh-keyscan -t x509v3-sign-rsa,x509v3-sign-dss,rsa,dsa -f ssh_hosts | \e\ sort -u - ssh_known_hosts | diff ssh_known_hosts - .Ed .Sh FILES @@ -144,6 +175,18 @@ or .Dq ssh-dsa . .Pp +.Pa Output format for rsa and dsa keys with x509 certificates: +.Bd -literal +host-or-namelist keytype distinguished-name +.Ed +.Pp +Where +.Pa keytype +is either +.Dq x509v3-sign-rsa +or +.Dq x509v3-sign-dss . +.Pp .Pa /etc/ssh/ssh_known_hosts .Sh BUGS It generates "Connection closed by remote host" messages on the consoles @@ -158,3 +201,4 @@ wrote the initial version, and Wayne Davison added support for protocol version 2. +Roumen Petrov contributed support for x509 certificates. diff -ruN openssh-3.6.1p2/ssh-keyscan.c openssh-3.6.1p2+x509g1/ssh-keyscan.c --- openssh-3.6.1p2/ssh-keyscan.c 2003-02-24 03:03:03.000000000 +0200 +++ openssh-3.6.1p2+x509g1/ssh-keyscan.c 2003-04-30 09:06:01.000000000 +0300 @@ -4,10 +4,33 @@ * Modification and redistribution in source and binary forms is * permitted provided that due credit is given to the author and the * OpenBSD project by leaving this copyright notice intact. + * + * X509 certificates support, + * Copyright (c) 2002 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: ssh-keyscan.c,v 1.41 2003/02/16 17:09:57 markus Exp $"); +RCSID("$OpenBSD$"); #include "openbsd-compat/sys-queue.h" @@ -42,6 +65,8 @@ #define KT_RSA1 1 #define KT_DSA 2 #define KT_RSA 4 +#define KT_X509DSA 8 +#define KT_X509RSA 16 int get_keytypes = KT_RSA1; /* Get only RSA1 keys by default */ @@ -79,7 +104,8 @@ int c_plen; /* Packet length field for ssh packet */ int c_len; /* Total bytes which must be read. */ int c_off; /* Length of data read so far. */ - int c_keytype; /* Only one of KT_RSA1, KT_DSA, or KT_RSA */ + int c_keytype; /* Only one of KT_RSA1, KT_DSA, KT_RSA, + KT_X509DSA or KT_X509RSA */ char *c_namebase; /* Address to free for c_name and c_namelist */ char *c_name; /* Hostname of connection for errors */ char *c_namelist; /* Pointer to other possible addresses */ @@ -351,8 +377,23 @@ packet_set_connection(c->c_fd, c->c_fd); enable_compat20(); +/* myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = c->c_keytype == KT_DSA? "ssh-dss": "ssh-rsa"; +*/ + { + Key k; + switch (c->c_keytype) { + case KT_DSA: k.type = KEY_DSA; break; + case KT_RSA: k.type = KEY_RSA; break; + case KT_X509DSA: k.type = KEY_X509_RSA; break; + case KT_X509RSA: k.type = KEY_X509_DSA; break; + default: + fprintf(stderr, "keygrab_ssh2:Invalid keytype!\n"); + exit(1); + } + myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = key_ssh_name(&k); + } c->c_kex = kex_setup(myproposal); c->c_kex->kex[KEX_DH_GRP1_SHA1] = kexdh_client; c->c_kex->kex[KEX_DH_GEX_SHA1] = kexgex_client; @@ -379,7 +420,12 @@ return; fprintf(stdout, "%s ", c->c_output_name ? c->c_output_name : c->c_name); - key_write(key, stdout); + if ((key->type == KEY_X509_RSA) || (key->type == KEY_X509_DSA)) { + /* key_write will print x509 certificate in blob format :-( */ + x509key_write_subject(key, stdout); + } else { + key_write(key, stdout); + } fputs("\n", stdout); } @@ -659,7 +705,7 @@ if (name == NULL) return; - for (j = KT_RSA1; j <= KT_RSA; j *= 2) { + for (j = KT_RSA1; j <= KT_X509RSA; j *= 2) { if (get_keytypes & j) { while (ncon >= MAXCON) conloop(); @@ -755,6 +801,12 @@ case KEY_RSA: get_keytypes |= KT_RSA; break; + case KEY_X509_DSA: + get_keytypes |= KT_X509DSA; + break; + case KEY_X509_RSA: + get_keytypes |= KT_X509RSA; + break; case KEY_UNSPEC: fatal("unknown key type %s", tname); } diff -ruN openssh-3.6.1p2/ssh-keysign.0 openssh-3.6.1p2+x509g1/ssh-keysign.0 --- openssh-3.6.1p2/ssh-keysign.0 2003-04-29 12:37:31.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-keysign.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH-KEYSIGN(8) BSD System ManagerM-bM-^@M-^Ys Manual SSH-KEYSIGN(8) +SSH-KEYSIGN(8) System Manager's Manual SSH-KEYSIGN(8) NAME ssh-keysign - ssh helper program for hostbased authentication @@ -13,7 +13,7 @@ ssh-keysign is disabled by default and can only be enabled in the global client configuration file /etc/ssh/ssh_config by setting EnableSSHKeysign - to M-bM-^@M-^\yesM-bM-^@M-^]. + to ``yes''. ssh-keysign is not intended to be invoked by the user, but from ssh(1). See ssh(1) and sshd(8) for more information about hostbased authentica- @@ -28,7 +28,8 @@ generate the digital signature. They should be owned by root, readable only by root, and not accessible to others. Since they are readable only by root, ssh-keysign must be set-uid root if - hostbased authentication is used. + hostbased authentication is used. It is possible host key to + contain private parts plus x509 certificate. SEE ALSO ssh(1), ssh-keygen(1), ssh_config(5), sshd(8) diff -ruN openssh-3.6.1p2/ssh-keysign.8 openssh-3.6.1p2+x509g1/ssh-keysign.8 --- openssh-3.6.1p2/ssh-keysign.8 2003-04-01 14:42:14.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-keysign.8 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ssh-keysign.8,v 1.6 2003/03/28 10:11:43 jmc Exp $ +.\" $OpenBSD$ .\" .\" Copyright (c) 2002 Markus Friedl. All rights reserved. .\" @@ -68,6 +68,7 @@ Since they are readable only by root, .Nm must be set-uid root if hostbased authentication is used. +It is possible host key to contain private parts plus x509 certificate. .El .Sh SEE ALSO .Xr ssh 1 , diff -ruN openssh-3.6.1p2/ssh-rand-helper.0 openssh-3.6.1p2+x509g1/ssh-rand-helper.0 --- openssh-3.6.1p2/ssh-rand-helper.0 2003-04-29 12:37:31.000000000 +0300 +++ openssh-3.6.1p2+x509g1/ssh-rand-helper.0 2003-04-30 09:06:00.000000000 +0300 @@ -1,4 +1,4 @@ -SSH-RAND-HELPER(8) BSD System ManagerM-bM-^@M-^Ys Manual SSH-RAND-HELPER(8) +SSH-RAND-HELPER(8) System Manager's Manual SSH-RAND-HELPER(8) NAME ssh-rand-helper - Random number gatherer for OpenSSH diff -ruN openssh-3.6.1p2/ssh-x509.c openssh-3.6.1p2+x509g1/ssh-x509.c --- openssh-3.6.1p2/ssh-x509.c 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/ssh-x509.c 2003-03-19 18:00:58.000000000 +0200 @@ -0,0 +1,1060 @@ +/* + * Copyright (c) 2002-2003 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "ssh-x509.h" +#include "log.h" +#include +#include "xmalloc.h" +#include "uuencode.h" +#include +#include "bufaux.h" +#include "x509store.h" + + +static char* +x509key_find_subject(int _keytype, char* _cp) { + static char *keywords[] = { + "subject", + "distinguished name", + "distinguished-name", + "distinguished_name", + "distinguishedname", + "dn", + NULL + }; + char **q, *p; + size_t len; + + if (_keytype != KEY_X509_RSA && + _keytype != KEY_X509_DSA) { + debug3("x509key_find_subject: %d is not x509 key ", _keytype); + return 0; + } + for (q=keywords; *q; q++) { + len = strlen(*q); + if (strncasecmp(_cp, *q, len) == 0) { + for (p = _cp + len; *p && isspace((int)*p); p++) + {} + if (!*p) { + error("x509key_find_subject: no data"); + return NULL; + } + if (*p == ':' || *p == '=') + p++; + for (; *p && isspace((int)*p); p++) + {} + if (!*p) { + error("x509key_find_subject: no data"); + return NULL; + } + if (*p == '/') + p++; + return p; + } + } + return NULL; +} + + +static int +x509key_str2X509NAME(char* _str, X509_NAME *_name) { + int ret = 1; + char *p, *q, *token; + char ch; + + p = _str; + while (*p) { + int nid; + for (; *p && isspace((int)*p); p++) + {} + if (!*p) break; + + /* get shortest token */ + { + char *tokenA = strchr(p, ','); + char *tokenB = strchr(p, '/'); + + if (tokenA == NULL) { + token = tokenB; + } else if (tokenB == NULL) { + token = tokenA; + } else { + token = (tokenA < tokenB) ? tokenA : tokenB; + } + } + if (token) { + ch = *token; + *token = 0; + } else { + ch = 0; + token = p + strlen(p); + } + q = strchr(p, '='); + if (!q) { + error("x509key_str2X509NAME: cannot parse '%.200s' ...", p); + ret = 0; + break; + } + *q = 0; + nid = OBJ_txt2nid(p); + *q = '='; + if (nid == NID_undef) { + error("x509key_str2X509NAME: cannot get nid from string '%.200s'", p); + ret = 0; + } else { + p = q + 1; + if(!*p) { + error("x509key_str2X509NAME: no data"); + ret = 0; + } else { /* add */ + char save; + for(q = token - 1; (q >= p) && isspace((int)*q); q--) + {/*skip unexpected \n,etc. from end*/} + + save = *++q; + *q = 0; + ret = X509_NAME_add_entry_by_NID(_name, nid, MBSTRING_ASC, p, q - p, -1, 0); + if(ret <= 0) { + int ecode = ERR_get_error(); + error("x509key_str2X509NAME: X509_NAME_add_entry_by_NID" + " fail with errormsg='%.200s'" + " for nid=%d/%.32s" + " and data='%.128s'" + , ERR_error_string(ecode, NULL) + , nid, OBJ_nid2ln(nid) + , p); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + } + *q = save; + } + } + *token = ch; + if(ret <= 0) { + break; + } + p = token; + if(*p) p++; + } + debug3("x509key_str2X509NAME: return %d", ret); + return ret; +} + + +Key* +x509key_from_subject(int _keytype, char* _cp) { + int ret = 1; + Key* key = NULL; + X509_NAME *subj; + char *subject; + + debug3("x509key_from_subject(%d, [%.200s]) called ", _keytype, _cp); + subject = x509key_find_subject(_keytype, _cp); + if(subject == NULL) + return NULL; + + debug3("x509key_from_subject: subject=[%.200s]", subject); + key = key_new(_keytype); + if (key == NULL) { + error("x509key_from_subject: out of memory"); + return NULL; + } + + if (ret > 0) { + subj = X509_get_subject_name(key->x509); + if (subj == NULL) { + error("x509key_from_subject: new x509 key without subject"); + ret = 0; + } + } + + if (ret > 0) { + ret = x509key_str2X509NAME(subject, subj); + } + + if (ret <= 0) { + if (key) { + key_free(key); + key = NULL; + } + } + debug3("x509key_from_subject: return %p", key); + return key; +} + + +static Key* +x509_to_key(X509 *x509) { + Key *key = NULL; + EVP_PKEY *env_pkey; + + env_pkey = X509_get_pubkey(x509); + + if (env_pkey == NULL) { + int ecode = ERR_get_error(); + error("x509_to_key: X509_get_pubkey fail %.200s", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + return key; + } + else { + debug3("x509_to_key: X509_get_pubkey done!"); + } + + switch(env_pkey->type) { + case EVP_PKEY_RSA: + key = key_new(KEY_UNSPEC); + key->x509 = x509; + key->rsa = EVP_PKEY_get1_RSA(env_pkey); + key->type = KEY_X509_RSA; +#ifdef DEBUG_PK + RSA_print_fp(stderr, key->rsa, 8); +#endif + break; + + case EVP_PKEY_DSA: + key = key_new(KEY_UNSPEC); + key->x509 = x509; + key->dsa = EVP_PKEY_get1_DSA(env_pkey); + key->type = KEY_X509_DSA; +#ifdef DEBUG_PK + DSA_print_fp(stderr, key->dsa, 8); +#endif + break; + + default: + debug3("x509_to_key: unspec key" ); + } + + return key; +} + + +Key* +x509key_from_blob( + u_char *blob, + int blen +) { + Key* key = NULL; + BIO *mbio; + + /* convert blob data to BIO certificate data */ + mbio=BIO_new(BIO_s_mem()); + if (mbio == NULL) return NULL; + BIO_write(mbio,blob,blen); + BIO_flush(mbio); + + debug3("x509key_from_blob:We have %d bytes available in BIO",BIO_pending(mbio)); + + { /* read X509 certificate from BIO data */ + X509* x509 = NULL; + x509 = d2i_X509_bio(mbio,NULL); + if (x509 == NULL) { + int ecode = ERR_get_error(); + /* We will print only debug info !!! + * This method is used in place where we can only check incomming data. + * If data contain x506 certificate blob we will return a key otherwise NULL. + */ + debug3("x509key_from_blob: read X509 from BIO fail %.200s", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + } + else { + key = x509_to_key(x509); + if (key == NULL) + X509_free(x509); + } + } + + /* This call will walk the chain freeing all the BIOs */ + BIO_free_all(mbio); + return key; +} + + +static int +x509key_check(char* method, Key *key) { + if (key == NULL) + { error("%.50s: no key", method); return 0; } + + if (key->type != KEY_X509_RSA && + key->type != KEY_X509_DSA ) + { error("%.50s: cannot handle key type %d", method, key->type); return 0; } + + if (key->x509 == NULL) + { error("%.50s: no X509 key", method); return 0; } + + return 1; +} + + +int +x509key_to_blob( + Key *key, + Buffer *b +) { + int len; + void* str; + unsigned char *p; + + if (!x509key_check("x509key_to_blob", key)) + return 0; + + len = i2d_X509(key->x509, NULL); + str = xmalloc(len); + if (str == NULL) + { error("x509key_to_blob: out of memory"); return 0; } + + p = str; + i2d_X509(key->x509, &p); + buffer_append(b, str, len); + xfree(str); + return 1; +} + + +char* +x509key_subject(Key *key) { + char *buf = NULL; + if (!x509key_check("x509key_subject", key)) + return buf; + buf = xmalloc(X509KEY_SUBJECT_MAXLEN); /* xmalloc exit if cannot allocate memory */ + X509_NAME_oneline(X509_get_subject_name(key->x509), buf, X509KEY_SUBJECT_MAXLEN); + return buf; +} + + +int +x509key_write( + Key *key, + FILE *f +) { + int ret = 0; + Buffer b; + int n; + + if (!x509key_check("x509key_write_blob", key)) + return ret; + + buffer_init(&b); + ret = x509key_to_blob(key,&b); + if (ret) { + /* write ssh key name */ + char * ktype = key_ssh_name(key); + n = strlen(ktype); + ret = ( fwrite(ktype, 1, n, f) == n ) && + ( fwrite(" " , 1, 1, f) == 1 ); + } + if (ret) { + u_char uu[1<<12]; /* 4096 bytes */ + + n = uuencode(buffer_ptr(&b), buffer_len(&b), uu, sizeof(uu)); + ret = n > 0; + if (ret) { + ret = (fwrite(uu, 1, n, f) == n); + } + } + buffer_free(&b); + return ret; +} + + +int +x509key_write_subject( + Key *key, + FILE *f +) { + BIO *out=NULL; + char buf[X509KEY_SUBJECT_MAXLEN]; + + if (!x509key_check("x509key_write_subject", key)) + return 0; + + out=BIO_new_fp(f, BIO_NOCLOSE); +#ifdef VMS + { + BIO *tmpbio = BIO_new(BIO_f_linebuffer()); + out = BIO_push(tmpbio, out); + } +#endif + + BIO_puts(out, key_ssh_name(key)); + BIO_puts(out, " Subject:"); + X509_NAME_oneline(X509_get_subject_name(key->x509), buf, sizeof(buf)); + BIO_puts(out, buf); + + BIO_free_all(out); + return 1; +} + + +Key* +x509key_load_cert( + Key *key, + FILE *fp +) { + if (!key) return NULL; + + if ( (key->type == KEY_RSA) || + (key->type == KEY_DSA) ) { + key->x509 = PEM_read_X509(fp, NULL, NULL, NULL); + if (key->x509 == NULL) { + int ecode = ERR_get_error(); + debug3("x509key_load_cert: PEM_read_X509 fail %.200s", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + } + else { + key->type = (key->type == KEY_RSA) ? KEY_X509_RSA : KEY_X509_DSA; + debug("read X509 certificate done: type %.40s", + key ? key_type(key) : ""); + } + } + return key; +} + + +static int +x509key_save_cert( + FILE *fp, + X509 *x509 +) { + int ret = 0; + BIO *out=NULL; + char buf[X509KEY_SUBJECT_MAXLEN]; + + out=BIO_new_fp(fp, BIO_NOCLOSE); +#ifdef VMS + { + BIO *tmpbio = BIO_new(BIO_f_linebuffer()); + out = BIO_push(tmpbio, out); + } +#endif + + BIO_puts(out, "issuer= "); + X509_NAME_oneline(X509_get_issuer_name(x509), buf, sizeof(buf)); + BIO_puts(out, buf); + BIO_puts(out, "\n"); + + BIO_puts(out, "subject= "); + X509_NAME_oneline(X509_get_subject_name(x509), buf, sizeof(buf)); + BIO_puts(out, buf); + BIO_puts(out, "\n"); + { + unsigned char *alstr; + alstr = X509_alias_get0(x509, NULL); + if (!alstr) alstr = ""; + BIO_puts(out,alstr); + BIO_puts(out, "\n"); + } + ret = PEM_write_bio_X509(out, x509); + if (!ret) { + int ecode = ERR_get_error(); + error("x509key_save_cert: PEM_write_bio_X509 fail %.200s", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + } + + BIO_free_all(out); + return ret; +} + + +int +x509key_save_pem( + FILE *fp, + Key *key, + const EVP_CIPHER *cipher, + u_char *passphrase, + int len +) { + if (!x509key_check("x509key_save_pem", key)) + return 0; + + switch (key->type) { + case KEY_X509_DSA: + if(PEM_write_DSAPrivateKey(fp, key->dsa, cipher, passphrase, len, NULL, NULL)) + return x509key_save_cert(fp, key->x509); + break; + case KEY_X509_RSA: + if(PEM_write_RSAPrivateKey(fp, key->rsa, cipher, passphrase, len, NULL, NULL)) + return x509key_save_cert(fp, key->x509); + break; + } + return 0; +} + + +static int +ssh_ASN1_OBJECT_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b) { + int lmin = MIN(a->length, b->length); + + int ret = memcmp(a->data, b->data, lmin); + + return (ret == 0) + ? (b->length - a->length) + : ret; +} + + +static int +ssh_ASN1_STRING_casecmp(const ASN1_STRING *a, const ASN1_STRING *b) +{ + int lmin = MIN(M_ASN1_STRING_length(a), M_ASN1_STRING_length(b)); + + int ret = strncasecmp(M_ASN1_STRING_data(a), M_ASN1_STRING_data(b), lmin); + + return (ret != 0) + ? (M_ASN1_STRING_length(b) - M_ASN1_STRING_length(a)) + : ret; +} + + +/* from RFC2459 + (d) attribute values in PrintableString are compared after + removing leading and trailing white space and converting internal + substrings of one or more consecutive white space characters to a + single space. +*/ + +static int +ssh_ASN1_PRINTABLESTRING_casecmp(const ASN1_STRING *a, const ASN1_STRING *b) +{ + int la = M_ASN1_STRING_length(a); + u_char *pa = M_ASN1_STRING_data(a); + int lb = M_ASN1_STRING_length(b); + u_char *pb = M_ASN1_STRING_data(b); + + /* skip leading spaces */ + for (; la > 0 && isspace(*pa); la--, pa++); + for (; lb > 0 && isspace(*pb); lb--, pb++); + + /* skip trailing spaces */ + { + u_char *p; + for (p = pa + la - 1; la > 0 && isspace(*p); la--, p--); + for (p = pb + lb - 1; lb > 0 && isspace(*p); lb--, p--); + } + + while (la > 0 && lb > 0) + { + int chA = tolower(*pa); + int chB = tolower(*pb); + + if (chA != chB) + return (chB - chA); + + pa++; pb++; + la--; lb--; + if (isspace(chA)) { + for (; la > 0 && isspace(*pa); la--, pa++); + for (; lb > 0 && isspace(*pb); lb--, pb++); + } + } + return (lb - la); +} + + +/* +1.) + Since version 0.9.7.beta4 and 0.9.6h OpenSSL function X509_NAME_cmp + is more restrictive but more correct (!). + Problem is that some x509 implementation set X509_NAME entry + incorrectly to "Printable String" :-[ . + O.K. when one entry is "Printable String" we will compare + to corresponding entry as "Printable String". +2.) + OpenSSL functions X509_NAME_cmp check nids order in X509_NAME. + i.e. X509_NAME{"/C=XX/O=YY"} is not equal to X509_NAME{"/O=YY/C=XX"} +*/ +static int +ssh_X509_NAME_cmp(X509_NAME *_a, X509_NAME *_b) { + int k, n; + X509_NAME *b; + + + k = sk_X509_NAME_ENTRY_num(_a->entries); + n = sk_X509_NAME_ENTRY_num(_b->entries); + + if (k != n) + return (n - k); + + b = X509_NAME_dup(_b); + n = 0; + for (--k; k >= 0; k--) { + X509_NAME_ENTRY *neA; + ASN1_STRING *nvA; + int nid; + X509_NAME_ENTRY *neB; + ASN1_STRING *nvB; + int loc; + + neA = sk_X509_NAME_ENTRY_value(_a->entries, k); + nvA = neA->value; + nid = OBJ_obj2nid(neA->object); + loc = X509_NAME_get_index_by_NID(b, nid, -1); + if (loc < 0) { + char buf1[X509KEY_SUBJECT_MAXLEN]; + char buf2[X509KEY_SUBJECT_MAXLEN]; + + X509_NAME_oneline(_a, buf1, sizeof(buf1)); + X509_NAME_oneline(_b, buf2, sizeof(buf2)); + debug3("ssh_X509_NAME_cmp: insufficient entries with nid=%d(%.40s) in second name." + " na=%.*s, nb=%.*s", + nid, OBJ_nid2ln(nid), + (int) sizeof(buf1), buf1, + (int) sizeof(buf1), buf2); + n = -1; + break; + } +trynextentry: + neB = sk_X509_NAME_ENTRY_value(b->entries, loc); + nvB = neB->value; +#ifdef SSHX509TEST +{ + int la = M_ASN1_STRING_length(nvA); + u_char *pa = M_ASN1_STRING_data (nvA); + int lb = M_ASN1_STRING_length(nvB); + u_char *pb = M_ASN1_STRING_data (nvB); + + log("nvA='%*s', nvB='%*s'", la, pa, lb, pb); +} +#endif + + if (nid == NID_pkcs9_emailAddress) { + int tag; + + tag = M_ASN1_STRING_type(nvA); + if (tag != V_ASN1_IA5STRING) { + /* to be strict and return nonzero or ... ? XXX + n = -1; + break; + */ + error("ssh_X509_NAME_cmp: incorrect type for emailAddress(a) %d(%.30s)", tag, ASN1_tag2str(tag)); + } + + tag = M_ASN1_STRING_type(nvB); + if (tag != V_ASN1_IA5STRING) { + /* to be strict and return nonzero or ... ? XXX + n = 1; + break; + */ + error("ssh_X509_NAME_cmp: incorrect type for emailAddress(b) %d(%.30s)", tag, ASN1_tag2str(tag)); + } + + n = ssh_ASN1_STRING_casecmp(nvA, nvB); + if (n == 0) goto entryisok; + + goto getnextentry; + } + if ((M_ASN1_STRING_type(nvA) == V_ASN1_PRINTABLESTRING) || + (M_ASN1_STRING_type(nvB) == V_ASN1_PRINTABLESTRING) ) { + int tag; + + tag = M_ASN1_STRING_type(nvA); + if (tag != V_ASN1_PRINTABLESTRING) + debug("ssh_X509_NAME_cmp: X509_NAME_ENTRY(a)->type=%d(%.30s) is not PrintableString", tag, ASN1_tag2str(tag)); + + tag = M_ASN1_STRING_type(nvB); + if (tag != V_ASN1_PRINTABLESTRING) + debug("ssh_X509_NAME_cmp: X509_NAME_ENTRY(b)->type=%d(%.30s) is not PrintableString", tag, ASN1_tag2str(tag)); + + n = ssh_ASN1_PRINTABLESTRING_casecmp(nvA, nvB); + if (n == 0) goto entryisok; + + goto getnextentry; + } + + n = M_ASN1_STRING_length(nvA) - M_ASN1_STRING_length(nvB); + if (n != 0) goto getnextentry; + + n = M_ASN1_STRING_length(nvA); + n = memcmp(nvA->data, nvB->data, n); + if (n != 0) goto getnextentry; + + /* openssl check object too */ + n = ssh_ASN1_OBJECT_cmp(neA->object, neB->object); + if (n != 0) goto getnextentry; + +entryisok: + { + X509_NAME_ENTRY *ne = X509_NAME_delete_entry(b, loc); + X509_NAME_ENTRY_free(ne); + } + continue; +getnextentry: + loc = X509_NAME_get_index_by_NID(b, nid, loc); + if (loc < 0) { + break; + } + goto trynextentry; + } + + X509_NAME_free(b); + return n; +} + +/* we can check only by Subject (Distinguished Name): + - sshd receive from client only x509 certificate !!! + - sshadd -d ... send only x509 certificate !!! + - otherwise Key might contain private key +*/ +int +ssh_x509_equal(Key *a, Key *b) { + if (!x509key_check("ssh_x509_equal", a)) + return 1; + if (!x509key_check("ssh_x509_equal", b)) + return -1; + +#if 1 +/* We must use own method to compare two X509_NAMEs + instead of OpenSSL function[s] ! See notes before + body of "ssh_X509_NAME_cmp()" . +*/ + { + X509_NAME *nameA = X509_get_subject_name(a->x509); + X509_NAME *nameB = X509_get_subject_name(b->x509); + return ssh_X509_NAME_cmp(nameA, nameB); + } +#else + return X509_subject_name_cmp(a->x509, b->x509); +#endif +} + + +int +ssh_x509_sign( + Key * key, + u_char **psignature, u_int *psignaturelen, + u_char *data, u_int datalen +) { + int ret = -1; + u_char sigret[256]; + u_int siglen; + + if (!x509key_check("ssh_x509_sign", key)) + return ret; + if((key->rsa == NULL) && (key->dsa == NULL)) { + error("ssh_x509_sign: missing private key"); + return ret; + } + + debug3("ssh_x509_sign: key_type=%.20s, key_ssh_name=%.40s", key_type(key), key_ssh_name(key)); + ret = 1; + { + EVP_PKEY* privkey = NULL; + + privkey = EVP_PKEY_new(); + if (!privkey) { + error("ssh_x509_sign: out of memory"); + ret = -1; + } + else { + ret = (key->rsa) + ? EVP_PKEY_set1_RSA(privkey, key->rsa) + : EVP_PKEY_set1_DSA(privkey, key->dsa); + + if (ret <= 0) { + int ecode = ERR_get_error(); + error("ssh_x509_sign: EVP_PKEY_set1_XXX: failed %.200s", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + } + } + + if (ret > 0) { + EVP_MD_CTX ctx; + const EVP_MD *evp_md = (key->rsa) ? EVP_md5() : EVP_dss1(); + debug3("ssh_x509_sign: evp_md { %d, %d, %d, ... }", evp_md->type, evp_md->pkey_type, evp_md->md_size); + + EVP_SignInit(&ctx,evp_md); + EVP_SignUpdate(&ctx,data,datalen); + + if (ret > 0) { + ret = EVP_SignFinal(&ctx,sigret,&siglen,privkey); + if (ret <= 0) { + int ecode = ERR_get_error(); + error("ssh_x509_sign: digest failed: %.200s", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + } + } + } + EVP_PKEY_free(privkey); + } + if (ret > 0) { + Buffer b; + + buffer_init(&b); + buffer_put_cstring(&b, key_ssh_name(key)); + buffer_put_string(&b, sigret, siglen); + + { + u_int len = buffer_len(&b); + if (psignaturelen != NULL) + *psignaturelen = len; + + if (psignature != NULL) { + *psignature = xmalloc(len); + memcpy(*psignature, buffer_ptr(&b), len); + } + } + buffer_free(&b); + } + ret = ret > 0 ? 0 : -1; + debug3("ssh_x509_sign: return %d", ret); + return ret; +} + + +int ssh_x509_verify( + Key *key, + u_char *signature, u_int signaturelen, + u_char *data, u_int datalen) +{ + int ret = -1; + u_char *sigblob = NULL; + uint len = 0; + + if (!x509key_check("ssh_x509_verify", key)) + return ret; + + { /* get signature data only */ + Buffer b; + buffer_init(&b); + buffer_append(&b, signature, signaturelen); + + { /* check signature key type */ + char *ktype = buffer_get_string(&b, NULL); + debug3("ssh_x509_verify: signature key type = %.40s", ktype ); + ret = strcmp("x509v3-sign-rsa", ktype) == 0 || + strcmp("x509v3-sign-dss", ktype) == 0; + if (!ret) { + error("ssh_x509_verify: cannot handle signature key type %.40s", ktype); + } + xfree(ktype); + } + + if (ret > 0) { + sigblob = buffer_get_string(&b, &len); + } + + if (ret > 0) { + int rlen = buffer_len(&b); + if (rlen != 0) { + error("ssh_x509_verify: remaining bytes in signature %d", rlen); + ret = -1; + } + } + buffer_free(&b); + } + + if (ret > 0 ) { + EVP_PKEY* pubkey; + + pubkey = X509_get_pubkey(key->x509); + if (!pubkey) { + error("ssh_x509_verify: no 'X509 Public Key'"); + ret = -1; + } + + if (ret > 0) { + EVP_MD_CTX ctx; + const EVP_MD *evp_md = (key->rsa) ? EVP_md5() : EVP_dss1(); + debug3("ssh_x509_verify: evp_md { %d, %d, %d, ... }", evp_md->type, evp_md->pkey_type, evp_md->md_size); + + EVP_VerifyInit(&ctx,evp_md); + EVP_VerifyUpdate(&ctx,data,datalen); + ret = EVP_VerifyFinal(&ctx,sigblob,len,pubkey); + if (ret <= 0) { + int ecode = ERR_get_error(); + error("ssh_x509_verify: verify failed: %.200s", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + ret = 0; + } + } + } + if (ret > 0) { + ret = ssh_x509store_check(key->x509); + } + if (sigblob) { + memset(sigblob, 's', len); + xfree(sigblob); + } + ret = ret > 0 ? 1 : (ret < 0 ? -1 : 0); + debug3("ssh_x509_verify return %d", ret); + return ret; +} + + +u_int +ssh_x509_key_size(Key *key) { + EVP_PKEY *pkey=NULL; + int k = 0; + + if (!x509key_check("key_size", key)) + return 0; + + pkey=X509_get_pubkey(key->x509); + if (pkey != NULL) { + if (pkey->type == EVP_PKEY_RSA) + { + /* BN_num_bits return int (!): XXX */ + k = BN_num_bits(pkey->pkey.rsa->n); + } + if (pkey->type == EVP_PKEY_DSA) + { + /*OpenSSH like this*/ + k = BN_num_bits(pkey->pkey.dsa->p); + } + } + EVP_PKEY_free(pkey); + return (u_int) k; +} + + +#ifdef SSHX509TEST + +#ifdef HAVE___PROGNAME +extern char *__progname; +#else +char *__progname; +#endif + + +#define DATA "test_certificate" +#define DATA2 "Test_Certificate" + +int +main (int argc, char *argv[]) { + X509_NAME* name; + + __progname = get_progname(argv[0]); + log_init(__progname, SYSLOG_LEVEL_DEBUG3, SYSLOG_FACILITY_AUTH, 1); + + name = X509_NAME_new(); + X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, DATA, -1, -1, 0); + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "CN", V_ASN1_PRINTABLESTRING, DATA, -1, -1, 0); + fprintf(stderr, "A1.1:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "CN", V_ASN1_PRINTABLESTRING, " " DATA " ", -1, -1, 0); + fprintf(stderr, "A1.2:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "CN", V_ASN1_PRINTABLESTRING, " " DATA2 " ", -1, -1, 0); + fprintf(stderr, "A1.3:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "OU", V_ASN1_PRINTABLESTRING, " " DATA2 " ", -1, -1, 0); + fprintf(stderr, "A1.4:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "CN", MBSTRING_ASC, " " DATA2 " ", -1, -1, 0); + fprintf(stderr, "A1.5:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + X509_NAME_free(name); + + + name = X509_NAME_new(); + X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_ASC, DATA, -1, -1, 0); + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "emailAddress", V_ASN1_TELETEXSTRING, DATA2, -1, -1, 0); + fprintf(stderr, "A2.1:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "emailAddress", V_ASN1_IA5STRING, DATA2, -1, -1, 0); + fprintf(stderr, "A2.2:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + X509_NAME_free(name); + + name = X509_NAME_new(); + X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_ASC, DATA "-e", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, DATA "-cn", -1, -1, 0); + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "CN", V_ASN1_PRINTABLESTRING, " " DATA2 "-cn ", -1, -1, 0); + X509_NAME_add_entry_by_txt(x, "emailAddress", V_ASN1_IA5STRING, DATA2 "-e", -1, -1, 0); + fprintf(stderr, "A3 :ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + X509_NAME_free(name); + + name = X509_NAME_new(); + X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_ASC, DATA "1", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_ASC, DATA "2", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_ASC, DATA "3", -1, -1, 0); + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "1", -1, -1, 0); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "3", -1, -1, 0); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "2", -1, -1, 0); + fprintf(stderr, "A4.1:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "2", -1, -1, 0); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "1", -1, -1, 0); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "2", -1, -1, 0); + fprintf(stderr, "A4.2:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + { + X509_NAME* x = X509_NAME_new(); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "2", -1, -1, 0); + X509_NAME_add_entry_by_txt(x, "O" , MBSTRING_ASC, DATA "2", -1, -1, 0); + X509_NAME_add_entry_by_txt(x, "OU", MBSTRING_ASC, DATA "3", -1, -1, 0); + fprintf(stderr, "A4.3:ssh_X509_NAME_cmp return %d\n", ssh_X509_NAME_cmp(name, x)); + X509_NAME_free(x); + } + X509_NAME_free(name); + + exit(0); + return 0; +} +#endif diff -ruN openssh-3.6.1p2/ssh-x509.h openssh-3.6.1p2+x509g1/ssh-x509.h --- openssh-3.6.1p2/ssh-x509.h 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/ssh-x509.h 2003-03-19 18:00:53.000000000 +0200 @@ -0,0 +1,60 @@ +#ifndef SSH_X509_H +#define SSH_X509_H +/* + * Copyright (c) 2002-2003 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "includes.h" +#include "key.h" +#include "buffer.h" + + /* + * This method return a key(x509) only with "Subject"("Distinguished Name") ! + */ +Key* x509key_from_subject(int _keytype, char* _cp); + + +Key* x509key_from_blob(u_char *blob, int blen); +int x509key_to_blob(Key *key, Buffer *b); + +#define X509KEY_SUBJECT_MAXLEN 512 +char* x509key_subject(Key *key); + + /* write x509 certificate as blob */ +int x509key_write(Key *key, FILE *f); + /* write x509 certificate subject */ +int x509key_write_subject(Key *key, FILE *f); + +Key* x509key_load_cert(Key *key, FILE *fp); + +int x509key_save_pem(FILE *fp, Key *key, const EVP_CIPHER *cipher, u_char *passphrase, int len); + + +int ssh_x509_equal(Key *a, Key *b); +int ssh_x509_sign(Key *, u_char **, u_int *, u_char *, u_int); +int ssh_x509_verify(Key *key, u_char *signature, u_int signaturelen, u_char *data, u_int datalen); +u_int ssh_x509_key_size(Key *key); + + +#endif /* SSH_X509_H */ diff -ruN openssh-3.6.1p2/tests/CA/1-cre_cadb.sh openssh-3.6.1p2+x509g1/tests/CA/1-cre_cadb.sh --- openssh-3.6.1p2/tests/CA/1-cre_cadb.sh 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/1-cre_cadb.sh 2003-03-19 18:12:17.000000000 +0200 @@ -0,0 +1,226 @@ +#!/bin/sh +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Create a new certificate authority config and database. +# + +CWD=`pwd` +SCRIPTDIR=`echo $0 | sed 's/1-cre_cadb.sh$//'` +. "${SCRIPTDIR}shell.rc" +. "${SCRIPTDIR}functions" +. "${SCRIPTDIR}config" + + +# === +echo_CA_common_options () { + local type="$1" + +cat < "$1" +[ ca ] +default_ca = CA_OpenSSH_rsa_md5 + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +[ req ] +default_bits = 1024 +distinguished_name = req_distinguished_name +attributes = req_attributes +#prompt = no + +# The extensions to add to a certificate request: +#???req_extensions = usr_cert + + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = $SSH_DN_C +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +stateOrProvinceName_default = $SSH_DN_ST + +localityName = Locality Name (eg, city) + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = $SSH_DN_O + +0.organizationalUnitName = Organizational Unit1 Name (eg, section1) +0.organizationalUnitName_default = ${SSH_DN_OU}-1 + +1.organizationalUnitName = Organizational Unit2 Name (eg, section2) +1.organizationalUnitName_default = ${SSH_DN_OU}-2 + +2.organizationalUnitName = Organizational Unit3 Name (eg, section3) +2.organizationalUnitName_default = ${SSH_DN_OU}-3 + +commonName = Common Name (eg, YOUR name) +commonName_min = 2 +commonName_max = 64 + +emailAddress = Email Address (optional) +emailAddress_max = 40 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +[ usr_cert ] +# These extensions are added when 'ca' signs a request. +basicConstraints=CA:FALSE +nsCertType = client, email + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Client Test Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer:always + +[ srv_cert ] +# These extensions are added when 'ca' signs a request. +basicConstraints = CA:FALSE + +# To test OpenSSH hostbased authentication we need +# following certificate purposes: +nsCertType = server,client +# Normal for server certificate is: +#nsCertType = server +# but in last case me must disable check of certificate purposes +# in sshd_config otherwise hostbased fail. + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Server Test Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer:always + +EOF + + +for DIGEST in ${RSA_DIGEST_LIST}; do +( cat << EOF + + +[ CA_OpenSSH_rsa_${DIGEST} ] +EOF + echo_CA_common_options "rsa_${DIGEST}" + cat << EOF +# which md to use: +default_md = ${DIGEST} + +# The private key (!) +private_key = "${SSH_CAKEYDIR}/${RSA_BASENAME}.key" + +#The CA certificate (!) +certificate = "${SSH_CACERTDIR}/${RSA_BASENAME}_${DIGEST}.crt.pem" +EOF +) >> "$1" +done + +( cat << EOF + + +[ CA_OpenSSH_dsa ] +EOF + echo_CA_common_options "dsa" + cat << EOF +# which md to use: +default_md = sha1 + +# The private key (!) +private_key = "${SSH_CAKEYDIR}/${DSA_BASENAME}.key" + +#The CA certificate (!) +certificate = "${SSH_CACERTDIR}/${DSA_BASENAME}.crt.pem" +EOF +) >> "$1" +} + + +# === +cre_db () { + local var="${SSH_CAROOT}" + if test ! -d "$var"; then + mkdir -p "$var" || return $? + else + count=`getNextDirName "${var}"` || return $? + if test -d "${var}"; then + printf '%s' "saving old directoty as ${attn}${var}.${warn}${count}${norm} ... " + mv "${var}" "${var}.${count}"; show_status $? || return $? + fi + fi + mkdir -p "$var" && + mkdir "$var/crt" && + mkdir "$var/crl" && + for DIGEST in ${RSA_DIGEST_LIST}; do + cp /dev/null "$var/index-rsa_${DIGEST}.txt" + done && + cp /dev/null "$var/index-dsa.txt" && + mkdir "$var/newcerts" && + echo '01' > "$var/serial" +} + + +# === + +cre_config "${TMPDIR}/${CACONFIG}" && +cre_db && +update_file "${TMPDIR}/${CACONFIG}" "${SSH_CACFGFILE}"; retval=$? + +show_status $retval "${extd}Creating a new ${warn}TEST${norm} ${attn}Certificate Authority Database${norm} ..." diff -ruN openssh-3.6.1p2/tests/CA/2-cre_cakeys.sh openssh-3.6.1p2+x509g1/tests/CA/2-cre_cakeys.sh --- openssh-3.6.1p2/tests/CA/2-cre_cakeys.sh 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/2-cre_cakeys.sh 2003-03-19 18:54:04.000000000 +0200 @@ -0,0 +1,250 @@ +#!/bin/sh +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Create "Test Certificate Authority" private keys and certificates. +# + +CWD=`pwd` +SCRIPTDIR=`echo $0 | sed 's/2-cre_cakeys.sh$//'` +. "${SCRIPTDIR}shell.rc" +. "${SCRIPTDIR}functions" +. "${SCRIPTDIR}config" + + +OPENSSH_LOG="$CWD/openssh_ca-2.log" +cat /dev/null > .delmy +update_file .delmy "$OPENSSH_LOG" > /dev/null || exit $? + + +# === +SSH_DN_OU="OpenSSH Test CA Root" +SSH_DN_CN_BASE="OpenSSH Test CA key" + + +echo_SSH_CA_DN () { +cat </dev/null + +$OPENSSL genrsa ${RSA_OPT} \ + -passout pass:${KEY_PASS} \ + -out "${TMPDIR}/${RSA_BASENAME}.key" 1024 \ + 2>> "$OPENSSH_LOG" \ +; show_status $? "${extd}generating a new ${attn}rsa ${norm} private key for the ${warn}TEST${norm}${extd} ${attn}CA${norm} ..." \ +|| return $? + +for DIGEST in ${RSA_DIGEST_LIST}; do + +rm -f "${TMPDIR}/${RSA_BASENAME}_${DIGEST}.crt" 2>/dev/null + +echo_SSH_CA_DN "rsa_${DIGEST}" | +$OPENSSL req -new -x509 \ + -days $SSH_CACERTDAYS \ + -passin pass:${KEY_PASS} \ + -key "${TMPDIR}/${RSA_BASENAME}.key" \ + -${DIGEST} \ + -out "${TMPDIR}/${RSA_BASENAME}_${DIGEST}.crt" \ + 2>> "$OPENSSH_LOG" \ +; show_status $? "${extd}generating the new ${warn}TEST${norm}${extd} ${attn}CA${norm}/(${DIGEST} with rsa) ..." \ +|| return $? + +done + +return 0 +} + + +# === +gen_dsa () { +local DSA_OPT="" +if [ -f /etc/random-seed ]; then + DSA_OPT="${DSA_OPT} -rand /etc/random-seed" +fi + +rm -f "${TMPDIR}/${DSA_BASENAME}.prm" 2>/dev/null +$OPENSSL dsaparam ${DSA_OPT} \ + -out "${TMPDIR}/${DSA_BASENAME}.prm" 1024\ + 2>> "$OPENSSH_LOG";\ +show_status $? "${extd}generating a new ${attn}DSA parameter file${norm} ..." \ +|| return $? + +rm -f "${TMPDIR}/${DSA_BASENAME}.key" 2>/dev/null +DSA_OPT="${DSA_OPT} -des3" +$OPENSSL gendsa ${DSA_OPT} \ + -passout pass:${KEY_PASS} \ + -out "${TMPDIR}/${DSA_BASENAME}.key" \ + "${TMPDIR}/${DSA_BASENAME}.prm" \ + 2>> "$OPENSSH_LOG" \ +; show_status $? "${extd}generating a new ${attn}dsa${norm} private key for the ${warn}TEST${norm}${extd} ${attn}CA${norm} ..." \ +|| return $? + + +#request & ceritificate +rm -f "${TMPDIR}/${DSA_BASENAME}.crt" 2>/dev/null + +echo_SSH_CA_DN "dsa" | +$OPENSSL req -new -x509 \ + -days $SSH_CACERTDAYS \ + -passin pass:${KEY_PASS} \ + -key "${TMPDIR}/${DSA_BASENAME}.key" \ + -out "${TMPDIR}/${DSA_BASENAME}.crt" \ + 2>> "$OPENSSH_LOG" \ +; show_status $? "${extd}generating the new ${warn}TEST${norm}${extd} ${attn}CA${norm}/(sha1 with dsa) ..." \ +|| return $? + +return 0 +} + + +# === +crt2bundle () { + local val="$1" + test -z "${val}" && { echo ${warn}missing DN${norm} 1>&2; return 1; } + + echo + echo ${val} + echo ${val} | sed -e 's/./=/g' + $OPENSSL x509 -inform PEM -in "${2}" -fingerprint -noout || return $? + echo PEM data: + $OPENSSL x509 -inform PEM -in "${2}" -trustout || return $? + echo Certificate Ingredients: + $OPENSSL x509 -inform PEM -in "${2}" -text -noout || return $? + + return 0 +} + + +# === +install () { + local F + + for D in \ + "${SSH_CAROOT}" \ + "${SSH_CAKEYDIR}" \ + "${SSH_CACERTDIR}" \ + ;do + test ! -d "$D" && mkdir -p "${D}" + done + + update_file "${TMPDIR}/${DSA_BASENAME}.prm" "${SSH_CAROOT}/${DSA_BASENAME}.prm" \ +&& + chmod 700 "${SSH_CAKEYDIR}" \ +&& + update_file "${TMPDIR}/${RSA_BASENAME}.key" "${SSH_CAKEYDIR}/${RSA_BASENAME}.key" && + chmod 400 "${SSH_CAKEYDIR}/${RSA_BASENAME}.key" \ +&& + update_file "${TMPDIR}/${DSA_BASENAME}.key" "${SSH_CAKEYDIR}/${DSA_BASENAME}.key" && + chmod 400 "${SSH_CAKEYDIR}/${DSA_BASENAME}.key" \ +|| return $? + + +for DIGEST in ${RSA_DIGEST_LIST}; do + F="${RSA_BASENAME}_${DIGEST}" + update_file "${TMPDIR}/${F}.crt" "${SSH_CACERTDIR}/${F}.crt.pem" || return $? +done + F="${DSA_BASENAME}" + update_file "${TMPDIR}/${F}.crt" "${SSH_CACERTDIR}/${F}.crt.pem" || return $? + + +printf '%s' "" > "${TMPDIR}/${CACERTFILE}" +for DIGEST in ${RSA_DIGEST_LIST}; do + F="${SSH_CACERTDIR}/${RSA_BASENAME}_${DIGEST}.crt.pem" + crt2bundle "$SSH_DN_OU" "${F}" >> "${TMPDIR}/${CACERTFILE}" || return $? +done + F="${SSH_CACERTDIR}/${DSA_BASENAME}.crt.pem" + crt2bundle "$SSH_DN_OU" "${F}" >> "${TMPDIR}/${CACERTFILE}" || return $? + +update_file "${TMPDIR}/${CACERTFILE}" "${SSH_CAROOT}/${CACERTFILE}" +} + + +# === +cre_hash_link () { + local HASH + local NAME + +#option -noout problem: +#exit code from .../openssl ... -noout ... is sometime nonzero !!! +#might only by .../openssl x509 ... -noout ... exit code is zero +#sample: +#a) exit code is one - INCORRECT +# .../openssl crl -in a_crl_file -hash -noout +#b) exit code is zero - correct +# .../openssl crl -in a_crl_file -hash -out /dev/null +# +#work around might is to use -out /dev/null :-/ + HASH=`$OPENSSL x509 -in "$1" -noout -hash` || return $? + NAME=`getNextFreeName ${HASH}.` || return $? + + echo "creating link ${attn}${NAME}${norm} to ${attn}$1${norm}" + rm -f "${NAME}" && + ln -s "$1" "${NAME}" || return $? + #link might never fail ;-( + test -h "${NAME}" +} + + +cre_hashs () { +#(!) openssl script "c_rehash" is missing in some installations :-( +# c_rehash "${SSH_CACERTDIR}" +( cd "${SSH_CACERTDIR}" || exit $? + for F in [0-9a-f]*.[0-9]; do + # we must use test -L, but on ?-OSes ... :-( + if test -h $F; then + rm "$F" || exit $? + fi + done + + for DIGEST in ${RSA_DIGEST_LIST}; do + cre_hash_link "${RSA_BASENAME}_${DIGEST}.crt.pem" || exit $? + done + cre_hash_link "${DSA_BASENAME}.crt.pem" || exit $? +) +} + + +# === + +gen_rsa && +gen_dsa && +install && +cre_hashs; retval=$? + +show_status $retval "${extd}Creating a new ${warn}TEST${norm} ${attn}Certificate Authority${norm} ..." +echo "${warn}password for all private keys is ${attn}${KEY_PASS}${norm}" +exit $retval diff -ruN openssh-3.6.1p2/tests/CA/3-cre_certs.sh openssh-3.6.1p2+x509g1/tests/CA/3-cre_certs.sh --- openssh-3.6.1p2/tests/CA/3-cre_certs.sh 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/3-cre_certs.sh 2003-03-19 18:05:34.000000000 +0200 @@ -0,0 +1,277 @@ +#!/bin/sh +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Create certificate(s). +# + +CWD=`pwd` +SCRIPTDIR=`echo $0 | sed 's/3-cre_certs.sh$//'` +. "${SCRIPTDIR}shell.rc" +. "${SCRIPTDIR}functions" +. "${SCRIPTDIR}config" + +usage () { + cat < + -f[ile] [ssh]key_file_name + -t[ype] certificate type: client or server + -n[ame] "base" common name +EOF + exit 1 +} + +test "x$TEST_SSH_SSHKEYGEN" = "x" && { echo "Please define TEST_SSH_SSHKEYGEN"; exit 1; } +test -z "$1" && usage + +while ! test -z "$1"; do + case $1 in + -f|\ + -file) + shift + if test -z "$1"; then + usage + fi + if ! test -z "${SSH_BASE_KEY}"; then + usage + fi + SSH_BASE_KEY="$1" + shift + ;; + + -t|\ + -type) + shift + if test -z "$1"; then + usage + fi + if ! test -z "$SSH_CERT_TYPE"; then + usage + fi + SSH_CERT_TYPE="$1" + shift + case $SSH_CERT_TYPE in + client) + SSH_X509V3_EXTENSIONS="usr_cert" + ;; + server) + SSH_X509V3_EXTENSIONS="srv_cert" + ;; + *) + echo "${warn}wrong type${norm}" + usage + ;; + esac + ;; + + -n|\ + -name) + shift + if test -z "$1"; then + usage + fi + if ! test -z "${SSH_BASE_DN_CN}"; then + usage + fi + SSH_BASE_DN_CN="$1" + shift + ;; + + *) + usage + ;; + esac +done + +test -z "${SSH_BASE_KEY}" && usage +test ! -r "${SSH_BASE_KEY}" && { error_file_not_readable; exit 1; } +test -z "${SSH_BASE_DN_CN}" && usage +test -z "${SSH_CERT_TYPE}" && usage + + +OPENSSH_LOG="$CWD/openssh_ca-3.log" +cat /dev/null > .delmy +update_file .delmy "$OPENSSH_LOG" > /dev/null || exit $? + + +# === +cre_csr () { + local type="$1" + local subtype="$2" + + echo "=== create a new CSR ===" >> "$OPENSSH_LOG" + ( cat <> "$OPENSSH_LOG" \ + ; show_status $? "creating new ${extd}CSR${norm} for ${attn}${SSH_BASE_DN_CN}(${type}${subtype})${norm} ..." || return $? + + sync + return 0 +} + + +# === +cre_crt () { + local type="$1" + local subtype="$2" + + echo "=== create a new CRT ===" >> "$OPENSSH_LOG" + $OPENSSL ca -config "${SSH_CACFGFILE}" \ + -batch \ + -in "${TMPDIR}/${SSH_X509V3_EXTENSIONS}-${type}${subtype}.csr" \ + -name "CA_OpenSSH_${type}" \ + -passin pass:$KEY_PASS \ + -out "${TMPDIR}/${SSH_X509V3_EXTENSIONS}-${type}${subtype}.crt" \ + -extensions ${SSH_X509V3_EXTENSIONS} \ + 2>> "$OPENSSH_LOG" \ + ; show_status $? "creating new ${extd}CRT${norm} for ${attn}${SSH_BASE_DN_CN}(${type}${subtype})${norm} ..." || + { retval=$? + printf '%s' "${warn}" + grep 'ERROR:' "$OPENSSH_LOG" + printf '%s' "${norm}" + return $retval + } + + sync + $OPENSSL verify \ + -CAfile "${SSH_CACERTDIR}/${CAKEY_PREFIX}-${type}.crt.pem" \ + "${TMPDIR}/${SSH_X509V3_EXTENSIONS}-${type}${subtype}.crt" && + rm -f "${TMPDIR}/${SSH_X509V3_EXTENSIONS}-${type}${subtype}.csr" && + update_file \ + "${TMPDIR}/${SSH_X509V3_EXTENSIONS}-${type}${subtype}.crt" \ + "${SSH_BASE_KEY}-${type}${subtype}.crt" +} + + +# === + +cre_OpenSSH_Crt () { + local type="$1" + local subtype="$2" + + printf '%s' "creating ${extd}OpenSSH certificate${norm} with signature ${attn}${type}${norm}${subtype} ..." + ( cat "${SSH_BASE_KEY}" + $OPENSSL x509 -in "${SSH_BASE_KEY}-${type}${subtype}.crt" -subject -issuer -alias + ) > "${SSH_BASE_KEY}-${type}${subtype}" && + chmod 600 "${SSH_BASE_KEY}-${type}${subtype}" \ + ; show_status $? +} + +cre_OpenSSH_PubKey () { + local type="$1" + local subtype="$2" + + printf '%s' "creating ${extd}OpenSSH public key for certificate${norm} with signature ${attn}${type}${norm}${subtype} ..." + "$TEST_SSH_SSHKEYGEN" -y -f "${SSH_BASE_KEY}-${type}${subtype}" \ + > "${SSH_BASE_KEY}-${type}${subtype}.pub" \ + ; show_status $? +} + +cre_P12_Crt () { + local type="$1" + local subtype="$2" + + printf '%s' "creating ${extd}p12 certificate${norm} with signature ${attn}${type}${norm}${subtype} ..." + $OPENSSL pkcs12 \ + -passin pass:"" \ + -passout pass:"" \ + -in "${SSH_BASE_KEY}-${type}${subtype}" \ + -out "${SSH_BASE_KEY}-${type}${subtype}".p12 \ + -export \ + ; show_status $? +} + + +revoke_crt () { + local type="$1" + local subtype="$2" + + echo "=== revoke a CRT ===" >> "$OPENSSH_LOG" + printf '%s' "revoke ${extd}certificate${norm} with signature ${attn}${type}${norm}${subtype} ..." + $OPENSSL ca -config "${SSH_CACFGFILE}" \ + -name "CA_OpenSSH_${type}" \ + -passin pass:$KEY_PASS \ + -revoke "${SSH_BASE_KEY}-${type}${subtype}" \ + 2>> "$OPENSSH_LOG" \ + ; show_status $? +} + + +# === +cre_all2 () { + local type="$1" + cre_csr "${type}" && + cre_crt "${type}" && + cre_OpenSSH_Crt "${type}" && + cre_OpenSSH_PubKey "${type}" && + cre_P12_Crt "${type}" +} + + +# === +cre_all3 () { + local type="$1" + + cre_csr "${type}" "-revoked" && + cre_crt "${type}" "-revoked" && + cre_OpenSSH_Crt "${type}" "-revoked" && + cre_OpenSSH_PubKey "${type}" "-revoked" && + cre_P12_Crt "${type}" "-revoked" && + revoke_crt "${type}" "-revoked" +} + + +# === +cre_all () { + for DIGEST in ${RSA_DIGEST_LIST}; do + cre_all2 "rsa_${DIGEST}" || return $? + done + cre_all2 dsa || return $? + +if test "$SSH_X509V3_EXTENSIONS" = "usr_cert"; then + for DIGEST in ${RSA_DIGEST_LIST}; do + cre_all3 "rsa_${DIGEST}" || return $? + done + cre_all3 dsa || return $? +fi + + return 0 +} + +# === + +cre_all; retval=$? + +show_status $retval "${extd}Creating ${warn}TEST certificates${norm} ${extd}wich common name:${norm}${attn}${SSH_BASE_DN_CN}${norm} ..." diff -ruN openssh-3.6.1p2/tests/CA/4-cre_crls.sh openssh-3.6.1p2+x509g1/tests/CA/4-cre_crls.sh --- openssh-3.6.1p2/tests/CA/4-cre_crls.sh 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/4-cre_crls.sh 2003-03-19 18:05:18.000000000 +0200 @@ -0,0 +1,117 @@ +#!/bin/sh +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Create "Test Certificate Authority" CRLs. +# + +CWD=`pwd` +SCRIPTDIR=`echo $0 | sed 's/4-cre_crls.sh$//'` +. "${SCRIPTDIR}shell.rc" +. "${SCRIPTDIR}functions" +. "${SCRIPTDIR}config" + + +OPENSSH_LOG="$CWD/openssh_ca-4.log" +cat /dev/null > .delmy +update_file .delmy "$OPENSSH_LOG" > /dev/null || exit $? + + +# === +cre_crlfile() { + local type="$1" + local retval=0 + +( cd "${SSH_CACRLDIR}" || exit $? + + FILE="${CAKEY_PREFIX}-${type}.crl.pem" + + printf '%s' "creating ${extd}CA CRL file${norm} for ${attn}${type}${norm} certificates..." + ${OPENSSL} ca -config "${SSH_CACFGFILE}" \ + -name "CA_OpenSSH_${type}" \ + -passin pass:$KEY_PASS \ + -gencrl \ + -out "${FILE}" \ + 2>> "$OPENSSH_LOG" \ + ; show_status $? || exit $? + + HASH=`${OPENSSL} crl -out /dev/null -in "${FILE}" -hash 2>> "$OPENSSH_LOG"` || exit $? + + NAME=`getNextFreeName "${HASH}.r"` || exit $? + + ln -s "${FILE}" "${NAME}" + #link might never fail :-( + test -h "${NAME}" +) +} + + +# === +cre_crlindir () { + echo "=== create a new CRL ===" >> "$OPENSSH_LOG" + rm -f "${SSH_CACRLDIR}"/* 2>/dev/null + + for DIGEST in ${RSA_DIGEST_LIST}; do + cre_crlfile "rsa_${DIGEST}" || return $? + done + cre_crlfile "dsa" || return $? + + return 0 +} + + +# === +cre_CAcrlfile () { + local crlfile="${SSH_CAROOT}/${CACRLFILE}" + + cp /dev/null "${crlfile}" && + for DIGEST in ${RSA_DIGEST_LIST}; do + ( ${OPENSSL} crl \ + -in "${SSH_CACRLDIR}/${CAKEY_PREFIX}-rsa_${DIGEST}.crl.pem" \ + -text \ + 2>> "$OPENSSH_LOG" + echo; echo + ) >> "${crlfile}" || return $? + done + ( ${OPENSSL} crl \ + -in "${SSH_CACRLDIR}/${CAKEY_PREFIX}-dsa.crl.pem" \ + -text \ + 2>> "$OPENSSH_LOG" + echo; echo + ) >> "${crlfile}" || return $? + + return 0 +} + + +# === +cre_all () { + cre_crlindir || return $? + + printf '%s' "creating ${extd}CA CRL file${norm}..." + cre_CAcrlfile; show_status $? + +} + + +# === +cre_all; retval=$? + +show_status $retval "${extd}Creating ${warn}TEST${norm} ${attn}Certificate Authority${norm} CRL files ..." diff -ruN openssh-3.6.1p2/tests/CA/config openssh-3.6.1p2+x509g1/tests/CA/config --- openssh-3.6.1p2/tests/CA/config 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/config 2003-03-07 01:59:20.000000000 +0200 @@ -0,0 +1,145 @@ +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: OpenSSH CA configuration. +# + + +# === main variables: +# on some system (with pam?, AIX?, when port is below 1024, etc.) we +# might use sudo command to start sshd when current user isn`t root or +# to run tests as root. +# Prefered user for tests is NOT root :-) ! +SUDO= +#SUDO=sudo + + +#Old BSD shells, including the Ultrix `sh', don't accept the colon +#for any shell substitution, and complain and die. +##TMPDIR="${TMPDIR:-/tmp}" + +if test -n "$TMPDIR"; then + if test ! -d "$TMPDIR"; then + echo "error: $TMPDIR is not directory" + exit 1 + fi + if test ! -w "$TMPDIR"; then + echo "error: $TMPDIR is not writable" + exit 1 + fi +else + for D in /tmp /var/tmp /usr/tmp; do + test -d $D || continue + test -w $D || continue + TMPDIR=$D + break + done + if test -z "$TMPDIR"; then + echo "error: cannot set TMPDIR" + exit 1 + fi +fi + + +if test -z "${SSH_X509TESTS}"; then +SSH_X509TESTS="\ + blob_auth + dn_auth_file + dn_auth_path + agent + crl +" +fi + + +# === openssl: + +if test -z "${OPENSSL}"; then + OPENSSL=`which openssl 2>/dev/null` + if test -z "${OPENSSL}"; then + echo "error:cannot find openssl is your path !" 1>&2 + exit 1 + fi +fi + +printf 'OpenSSL executable version: ' +"${OPENSSL}" version || exit $? + +# These are the known patent issues with OpenSSL: +# name # expires +# mdc2: 4,908,861 13/03/2007 + +if test -z "${RSA_DIGEST_LIST}"; then + for DIGEST in md5 sha1 md2 md4 rmd160; do + if "${OPENSSL}" dgst -${DIGEST} "${OPENSSL}" >/dev/null 2>&1; then + RSA_DIGEST_LIST="${RSA_DIGEST_LIST} ${DIGEST}" + fi + done +fi +if test -z "${RSA_DIGEST_LIST}"; then + echo "RSA_DIGEST_LIST is empty" 1>&2 + exit 1 +fi +echo "RSA digest list: ${RSA_DIGEST_LIST}" + + +# === server section: + +if test -z "${SSHD_PORT}"; then + SSHD_PORT=20022 +fi + +SSHD_LISTENADDRESS=127.0.0.1 +#SSHD_LISTENADDRESS=::1 + +#"yes" or "no" +SSHSERVER_USEPRIVILEGESEPARATION="yes" + +SSHSERVER_SYSLOGFACILITY=AUTH +SSHSERVER_LOGLEVEL=INFO +#SSHSERVER_SYSLOGFACILITY=LOCAL3 +#SSHSERVER_LOGLEVEL=DEBUG3 + + +# === certificates: + +KEY_PASS="change_it" +CAKEY_PREFIX="catest" +RSA_BASENAME="${CAKEY_PREFIX}-rsa" +DSA_BASENAME="${CAKEY_PREFIX}-dsa" + +SSH_CAROOT="`pwd`/ca-test" +SSH_CAKEYDIR="${SSH_CAROOT}/keys" + +CACERTFILE="catest-bundle.crt" +CACRLFILE="catest-bundle.crl" + +SSH_CACERTDIR="${SSH_CAROOT}/crt" +SSH_CACRLDIR="${SSH_CAROOT}/crl" + +CACONFIG="catest.config" +SSH_CACFGFILE="${SSH_CAROOT}/${CACONFIG}" + +SSH_CACERTDAYS=60 + +SSH_DN_C="XX" +SSH_DN_ST="World" +SSH_DN_O="OpenSSH Test Team" +SSH_DN_OU="OpenSSH Testers" diff -ruN openssh-3.6.1p2/tests/CA/functions openssh-3.6.1p2+x509g1/tests/CA/functions --- openssh-3.6.1p2/tests/CA/functions 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/functions 2003-03-19 19:12:51.000000000 +0200 @@ -0,0 +1,262 @@ +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Usefull functions. +# + + +# === +# +# define colors and more for echo commands +# +# \033 ascii ESCape +# \033[G move to column (linux console, xterm, not vt100) +# \033[C move columns forward but only upto last column +# \033[D move columns backward but only upto first column +# \033[A move rows up +# \033[B move rows down +# \033[1m switch bold on +# \033[31m switch red on +# \033[32m switch green on +# \033[33m switch yellow on +# \033[m switch color/bold off +# \017 exit alternate mode (xterm, vt100, linux console) +# \033[10m exit alternate mode (linux console) +# \015 carriage return (without newline) +# + +if test -z "${LINES}" -o -z "${COLUMNS}" ; then + eval `stty size 2>/dev/null | (read L C; \ + if test x${L} = x; then L=24; fi; \ + if test x${C} = x; then C=80; fi; \ + echo LINES=${L} COLUMNS=${C} )` +fi +test ${LINES} -eq 0 && LINES=24 +test ${COLUMNS} -eq 0 && COLUMNS=80 +export LINES COLUMNS + +if test "${TERM}" != "dumb" ; then + esc=`printf '\033'` + extd="${esc}[1m" + warn="${esc}[1;31m" + done="${esc}[1;32m" + attn="${esc}[1;34m" + norm=`printf '%s\017' "${esc}[m"` + stat=`printf '\015%s' "${esc}[${COLUMNS}C${esc}[10D"` + + msg_done="${stat}${done}done${norm}" + msg_failed="${stat}${warn}failed${norm}" + +else + esc="" + extd="" + warn="" + done="" + attn="" + norm="" + stat="" + + msg_done="..done" + msg_failed="..failed" + +fi + + +# === +error_file_not_found () { + echo "${warn}file ${attn}${1}${warn} not found${norm}" + return 1 +} + + +# === +error_file_not_readable () { + echo "${warn}file ${attn}${1}${warn} not found or not readable${norm}" + return 1 +} + + +# === +error_dir_not_found () { + echo "${warn}directory ${attn}${1}${warn} not found${norm}" + return 1 +} + + +# === +printSeparator() { + echo "=======================================================================" +} + + +# === +show_status () { + if ! test -z "$2"; then + printf '%s' "$2" + fi + if test $1 -eq 0; then + echo "$msg_done" + else + echo "$msg_failed" + fi + return $1 +} + + +# === +getNextFreeName() { + local var="$1" + local limit="$2" + + if test -z "${limit}"; then + limit=10 + fi + + local count=0 + while true; do + test ! -f "${var}${count}" && break + count=`expr ${count} + 1` + if test ${count} -ge ${limit}; then + echo "getNextFreeName: ${warn}limit reached${norm} for file ${attn}${var}${norm}" 1>&2 + + echo "" + return 33 + fi + done + + echo "${var}${count}" + return 0 +} + + +# === +getNextDirName() { + local var="$1" + local count=0 + while true; do + test ! -d "${var}.${count}" && break + count=`expr ${count} + 1` + done + if test ${count} -ge 10; then + echo "${warn}please remove ${attn}${var}${warn} backup directories !${norm}" 1>&2 + return 33 + fi + echo $count + return 0 +} + + +# === +update_file () { + local var_new="$1" + local var_old="$2" + local backup + local not_writable + + if test ! -f "${var_old}"; then + printf '%s' "creating file ${attn}${var_old}${norm} ... " + mv "${var_new}" "${var_old}"; show_status $? + return $? + fi + test -r "${var_new}" || { error_file_not_readable "${var_new}"; return 1; } + + if diff "${var_old}" "${var_new}" >/dev/null 2>&1; then + echo "no changes in ${attn}${var_old}${norm}" + rm -f "${var_new}" + return 0 + fi + + backup=`getNextFreeName "${var_old}."` || return $? + printf '%s' "saving old file as ${attn}${backup}${norm} ... " + cp -p "${var_old}" "${backup}"; show_status $? || return $? + + printf '%s' "updating file ${attn}${var_old}${norm} ... " + if test ! -w "${var_old}"; then + chmod u+w "${var_old}" + not_writable="yes" + fi + cat "${var_new}" > "${var_old}"; show_status $? || return $? + if test "$not_writable" = "yes"; then + chmod u-w "${var_old}" + fi + rm -f "${var_new}" + return 0 +} + + +# === +getSSHkeyType () { + local identity_file="$1" + if test ! -r "$identity_file"; then + error_file_not_readable "${identity_file}" 1>&2; return $? + fi + + local sshkeytype="unspec" + local retval=0 + + sshkeytype=`"${TEST_SSH_SSHKEYGEN}" -f "${identity_file}" -y 2>/dev/null`; retval=$? + if test $retval -ne 0 ; then + echo "${warn}command${norm} ${TEST_SSH_SSHKEYGEN} ${warn}fail${norm}" 1>&2 + return $retval + fi + echo "${sshkeytype}" | cut -d ' ' -f 1 + return 0 +} + + +# === +getSubject () { + local identity_file="$1" +#rest of arguments passed to openssl + + if test ! -r "$identity_file"; then + error_file_not_readable "${identity_file}" 1>&2 + return 1 + fi + shift + + local retval=0 + +#bash bug or ?: when all is on only one line retval is always zero :-/ !!! +# local subject=`"${OPENSSL}" x509 -noout -subject -in "${identity_file}" $*`; retval=$? + local subject + subject=`"${OPENSSL}" x509 -noout -subject -in "${identity_file}" $* 2>/dev/null`; retval=$? + if test $retval -ne 0 ; then + echo "${warn}cannot get certificate subject${norm}" 1>&2 + return $retval + fi + echo "$subject" | cut -d ' ' -f 2- +} + + +#=== +creX509AuthorizedKeysFile () { + local identity_file="$1" + local sshkeytype + local subject + + sshkeytype=`getSSHkeyType "${identity_file}"` || return $? + subject=`getSubject "${identity_file}"` || return $? + echo "${sshkeytype} subject ${subject}" > "${AUTHORIZEDKEYSFILE}" +} + + +# === +FUNCTIONS_INCLUDED="yes" diff -ruN openssh-3.6.1p2/tests/CA/Makefile.in openssh-3.6.1p2+x509g1/tests/CA/Makefile.in --- openssh-3.6.1p2/tests/CA/Makefile.in 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/Makefile.in 2003-03-19 18:17:31.000000000 +0200 @@ -0,0 +1,70 @@ +srcdir=@srcdir@ + +all: + + +clean: + rm -f testhostkey_* testid_* + rm -fr ca-test/ + rm -f openssh_ca-?.log* + rm -f sshd_x509.log + +distclean: clean + rm -f Makefile + +# === + +check-certs: ca_files host_keys rsa_keys dsa_keys crl_files + $(SHELL) $(srcdir)/openssh_tests.sh + +# === +ca_files: ca-test/catest.config ca-test/catest-bundle.crt + +ca-test/catest.config: + $(SHELL) $(srcdir)/1-cre_cadb.sh + +ca-test/catest-bundle.crt: + $(SHELL) $(srcdir)/2-cre_cakeys.sh + + +# === +host_keys: testhostkey_rsa testhostkey_rsa-rsa_md5 testhostkey_dsa testhostkey_dsa-rsa_md5 + +testhostkey_rsa: + $(TEST_SSH_SSHKEYGEN) -t rsa -b 1024 -f $@ -N "" + +testhostkey_rsa-rsa_md5: testhostkey_rsa + $(SHELL) $(srcdir)/3-cre_certs.sh -f testhostkey_rsa -t server -n "localhost RSA" + +testhostkey_dsa: + $(TEST_SSH_SSHKEYGEN) -t dsa -b 1024 -f $@ -N "" + +testhostkey_dsa-rsa_md5: testhostkey_dsa + $(SHELL) $(srcdir)/3-cre_certs.sh -f testhostkey_dsa -t server -n "localhost DSA" + + +# === +rsa_keys: testid_rsa testid_rsa-rsa_md5 + +testid_rsa: + $(TEST_SSH_SSHKEYGEN) -t rsa -b 1024 -f $@ -N "" + +testid_rsa-rsa_md5: testid_rsa + $(SHELL) $(srcdir)/3-cre_certs.sh -f testid_rsa -t client -n "OpenSSH RSA test certificate" + + +# === +dsa_keys: testid_dsa testid_dsa-rsa_md5 + +testid_dsa: + $(TEST_SSH_SSHKEYGEN) -t dsa -b 1024 -f $@ -N "" + +testid_dsa-rsa_md5: testid_dsa + $(SHELL) $(srcdir)/3-cre_certs.sh -f testid_dsa -t client -n "OpenSSH DSA test certificate" + + +# === +crl_files: ca-test/catest-bundle.crl + +ca-test/catest-bundle.crl: + $(SHELL) $(srcdir)/4-cre_crls.sh diff -ruN openssh-3.6.1p2/tests/CA/openssh_tests.sh openssh-3.6.1p2+x509g1/tests/CA/openssh_tests.sh --- openssh-3.6.1p2/tests/CA/openssh_tests.sh 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/openssh_tests.sh 2003-03-19 19:12:37.000000000 +0200 @@ -0,0 +1,318 @@ +#!/bin/sh +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Test OpenSSH client and server with x509 certificates. +# + + +CWD=`pwd` +SCRIPTDIR=`echo $0 | sed 's/openssh_tests.sh//'` +. "${SCRIPTDIR}shell.rc" +. "${SCRIPTDIR}functions" +. "${SCRIPTDIR}config" + +test "x$TEST_SSH_SSH" = "x" && { echo "${warn}Please define ${attn}TEST_SSH_SSH${norm}" ; exit 1; } +test "x$TEST_SSH_SSHD" = "x" && { echo "${warn}Please define ${attn}TEST_SSH_SSHD${norm}" ; exit 1; } +test "x$TEST_SSH_SSHAGENT" = "x" && { echo "${warn}Please define ${attn}TEST_SSH_SSHAGENT${norm}" ; exit 1; } +test "x$TEST_SSH_SSHADD" = "x" && { echo "${warn}Please define ${attn}TEST_SSH_SSHADD${norm}" ; exit 1; } +#TEST_SSH_SSHKEYSCAN +#TEST_SSH_SFTP +#TEST_SSH_SFTPSERVER + + +SSHD_LOG="${CWD}/sshd_x509.log" +SSHD_PID="${CWD}/.sshd_x509.pid" +SSHD_CFG="${CWD}/sshd_config-certTests" +SSH_CFG="${CWD}/ssh_config-certTests" + +SSH_ERRLOG="${CWD}/.ssh_x509.err.log" +SSH_REPLY="${CWD}/.ssh_x509.reply" +SSH_EXTRA_OPTIONS="" + + +TEST_SSH_CLIENTKEYS="\ + testid_rsa + testid_dsa +" + +#TEST_SSHD_HOSTKEY="${CWD}/testhostkey_rsa-rsa_md5" +TEST_SSHD_HOSTKEY="${CWD}/testhostkey_rsa" + + +USERDIR="${HOME}/.ssh" +if test ! -d "${USERDIR}"; then + mkdir "${USERDIR}" || exit 1 +fi +chmod 700 "${USERDIR}" || exit 1 + +AUTHORIZEDKEYSFILE="${USERDIR}/authorized_keys-certTests" +USERKNOWNHOSTSFILE="${USERDIR}/known_hosts-certTests" + + +# === +runSSHdaemon() { + echo "=======================================================================" >> "${SSHD_LOG}" + + if test -f "${SSHD_PID}"; then + echo "${warn}sshd pid file exist!${norm}" 1>&2 + fi + + #NOTES: + #- without -d option sshd run in daemon mode and this command always return 0 !!! + #- bug or ?: with option -e no log to stderr in daemon mode + $SUDO "$TEST_SSH_SSHD" -f "${SSHD_CFG}" \ + -o PidFile="${SSHD_PID}" \ + -o SyslogFacility="${SSHSERVER_SYSLOGFACILITY}" \ + -o LogLevel="${SSHSERVER_LOGLEVEL}" \ + >> "${SSHD_LOG}" 2>&1 + + sleep 3 + if test ! -f "${SSHD_PID}"; then + printf "${warn}cannot start sshd:${norm} " 1>&2 + error_file_not_readable "${SSHD_PID}" + return 33 + fi +} + + +# === +killSSHdaemon() { + local K + $SUDO kill `cat "${SSHD_PID}" 2>/dev/null` > /dev/null 2>&1 + K=0 + while test $K -le 9; do + if test ! -f "${SSHD_PID}"; then + break + fi + sleep 1 + K=`expr $K + 1` + done + rm -f "${SSHD_CFG}" + if test -f "${SSHD_PID}"; then + $SUDO kill -9 `cat "${SSHD_PID}" 2>/dev/null` > /dev/null 2>&1 + sleep 1 + $SUDO rm -f "${SSHD_PID}" > /dev/null 2>&1 + return 0 + fi + return 0 +} + + +# === +testEND() { + ( echo + echo "*=- The END -=*" + ) >> "${SSHD_LOG}" + + rm -f "${SSH_ERRLOG}" + rm -f "${SSH_REPLY}" + rm -f "${AUTHORIZEDKEYSFILE}" + rm -f "${USERKNOWNHOSTSFILE}" + rm -f "${SSH_CFG}" +} + +testBREAK() { + ( echo + echo "*=- BREAK -=*" + ) >> "${SSHD_LOG}" + killSSHdaemon +} + +trap testBREAK INT QUIT ABRT KILL TERM || exit 1 +trap testEND EXIT || exit 1 + + +# === +creTestSSHDcfgFile() { + cat > "${SSHD_CFG}" < "${SSH_CFG}" < "${SSH_ERRLOG}" > "${SSH_REPLY}" +} + + +runTest () { + # + #linux ksh bugs (?): + # variables type, identity_file, info and must_fail + # must have uniq names in functions runTest and/or run_ssh !!! + #About type: + # let after first call its values is "AAA", after second call its + # value is "AAA BBB", next call "AAA BBB CCC". Because type is used + # only in echo comands only output look bad (test is auth_file). + #About identity_file: + # after first call to run_ssh with nonempty argument identity_file + # has value "-i XXXXX", is second call value is "-i -i XXXXX" and + # this break ssh and all tests. + #About info: + # crl tests output is not complete. + #About must_fail: + # bug break crl tests. + # + #Note that these problems cannot be reproduces in simple test scrips + # + local runTest_type="$1" + local runTest_identity_file="$2" + local runTest_info="$3" + local runTest_must_fail="$4" + local msg="OpenSSH Certificate TeSt-${runTest_type}" + local retval=0 + + case $runTest_must_fail in + Y|y|Yes|yes|YES|1) + runTest_must_fail=1;; + *) + runTest_must_fail=0;; + esac + + printf '%s' " * ${extd}${runTest_type}${norm} ${runTest_info}" + run_ssh "${runTest_identity_file}" "${msg}"; retval=$? + + if test "x$runTest_must_fail" = "x1"; then + if test $retval -ne 0; then + retval=0 + else + retval=1 + fi + fi + + show_status $retval + if test $retval -ne 0; then + printf '%s' "${warn}" + cat "${SSH_ERRLOG}"; printf '%s' "${norm}" + else + if test "x$runTest_must_fail" = "x1"; then + if ! fgrep 'Permission denied (publickey)' "${SSH_ERRLOG}" > /dev/null; then + retval=33 + printf '%s' "${warn}" + else + printf '%s' "${done}" + fi + cat "${SSH_ERRLOG}"; printf '%s' "${norm}" + else + if ! fgrep "$msg" "${SSH_REPLY}" > /dev/null; then + retval=33 + printf '%s' "${warn}" + cat "${SSH_REPLY}"; printf '%s' "${norm}" + fi + fi + fi + + return $retval +} + + +# === +do_all () { + printf '%s' "" > "${AUTHORIZEDKEYSFILE}" + chmod 644 "${AUTHORIZEDKEYSFILE}" || return $? + + printf '%s' "" > "${SSHD_LOG}" + if test ! -f "${TEST_SSHD_HOSTKEY}"; then + "$TEST_SSH_SSHKEYGEN" -t rsa -f "${TEST_SSHD_HOSTKEY}" -N "" + fi + if test ! -f "${TEST_SSHD_HOSTKEY}.pub"; then + echo "${warn}Public host file ${attn}${TEST_SSHD_HOSTKEY}.pub${warn} not found !${norm}" + return 3 + fi + ( printf '%s' "${SSHD_LISTENADDRESS} " + cat "${TEST_SSHD_HOSTKEY}.pub" + ) > "${USERKNOWNHOSTSFILE}" + chmod 644 "${USERKNOWNHOSTSFILE}" || return $? + + # call the test scripts + for LTEST in ${SSH_X509TESTS}; do + ( + . ${SCRIPTDIR}test-${LTEST}.sh.inc && + do_test + ) || return $? + done + + printSeparator + return 0 +} + + +# === +echo +echo "${extd}Testing OpenSSH client with certificates:${norm}" +printSeparator + +do_all; retval=$? + +echo +echo "${extd}Testing OpenSSH client with certificates finished.${norm}" +show_status $retval " ${extd}retval${norm}:" +echo + +exit $retval diff -ruN openssh-3.6.1p2/tests/CA/shell.rc openssh-3.6.1p2+x509g1/tests/CA/shell.rc --- openssh-3.6.1p2/tests/CA/shell.rc 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/shell.rc 2003-03-19 18:27:54.000000000 +0200 @@ -0,0 +1,55 @@ +# Copyright (c) 2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Shell settings. +# + + +# === zsh: +if test -n "$ZSH_NAME"; then + unsetopt NOMATCH + # NOMATCH (+3) + # If a pattern for filename generation has no matches, print an + # error, instead of leaving it unchanged in the argument list. This + # also applies to file expansion of an initial `~' or `='. + # Check results from sample script: + # #!/bin/zsh + # for F in *notfound; do + # echo F=$F + # done + + setopt SH_WORD_SPLIT + # SH_WORD_SPLIT (-y) + # Causes field splitting to be performed on unquoted parameter + # expansions. Note that this option has nothing to do with word + # splitting. + # Check results from sample script: + # #!/bin/zsh + # VAR=" + # v1 + # v2 + # " + # for V in ${VAR}; do + # echo V=$V + # done +fi + + +# === diff -ruN openssh-3.6.1p2/tests/CA/test-agent.sh.inc openssh-3.6.1p2+x509g1/tests/CA/test-agent.sh.inc --- openssh-3.6.1p2/tests/CA/test-agent.sh.inc 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/test-agent.sh.inc 2003-03-07 14:37:52.000000000 +0200 @@ -0,0 +1,141 @@ +# +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Test OpenSSH client authentication: +# - add a key to agent; +# - list agent keys; +# - try to connect with key from agent; +# - remove the key from agent. +# + + +# === +testAgent () { + local type="$1" + local identity_file="${SSH_CLIENTKEY}-${type}" + if test ! -r "${identity_file}"; then + error_file_not_readable "${identity_file}"; return $? + fi + + local sshkeytype + local subject + + sshkeytype=`getSSHkeyType "${identity_file}"` || return $? + subject=`getSubject "${identity_file}"` || return $? + + echo "${sshkeytype} Subject: ${subject}" > "${AUTHORIZEDKEYSFILE}" + +( +killAgent () { + "${TEST_SSH_SSHAGENT}" -k > /dev/null + sleep 1 + exit $1 +} + +checkEmptyListResponse () { + case $1 in + 1) return 0;; + 0) killAgent 99;; + *) killAgent $1;; + esac + return 33 +} + +showAgentMsg() { + show_status $1 "$2" + if test $1 -ne 0; then + printf '%s' "${warn}" + cat "${SSH_ERRLOG}" + printf '%s' "${norm}" + if test $1 -ne 2; then + killAgent $1 + fi + exit $1 + fi + + if test "x$3" != "x"; then + printf '%s' "${done}" + cat "$3" + printf '%s' "${norm}" + fi + return 0 +} + + eval `"${TEST_SSH_SSHAGENT}"` > /dev/null + + "${TEST_SSH_SSHADD}" -L >/dev/null; checkEmptyListResponse $? + + "${TEST_SSH_SSHADD}" "${identity_file}" 2> "${SSH_ERRLOG}" > "${SSH_REPLY}"; \ + showAgentMsg $? " add identity ${extd}${SSH_CLIENTKEY}-${attn}${type}${norm} to agent ..." + + "${TEST_SSH_SSHADD}" -L 2> "${SSH_ERRLOG}" > "${SSH_REPLY}"; \ + retval=$? + if test $retval -ne 0; then + showAgentMsg ${retval} + else + printf " ${done}-${norm} " + cat "${SSH_REPLY}" + fi + + runTest "${type}" \ + "use-only-key-from-agent" \ + "key from agent ..." || + killAgent $? + + "${TEST_SSH_SSHADD}" -d "${identity_file}".pub \ + 2> "${SSH_ERRLOG}" > "${SSH_REPLY}"; \ + showAgentMsg $? " remove identity ${extd}${SSH_CLIENTKEY}-${attn}${type}${norm} from agent ..." + + "${TEST_SSH_SSHADD}" -L > /dev/null; checkEmptyListResponse $? + + killAgent 0 +) || return $? + +} + +# === + +do_test () { + local retval=0 + echo + echo "* ${extd}against ${attn}CACertificateFile${norm} and x509 key from ${attn}agent${norm}:" + + creTestSSHDcfgFile + cat >> "$SSHD_CFG" </dev/null > "${AUTHORIZEDKEYSFILE}" || return $? + runTest "${type}" "${identity_file}"\ + "${extd}valid${norm} blob" || return $? + + local blob + blob=`cat "${AUTHORIZEDKEYSFILE}"` + echo $blob | cut -c 1-50 > "${AUTHORIZEDKEYSFILE}" + runTest "${type}" "${identity_file}"\ + "${warn}invalid${norm} blob" "Yes" || return $? + + return 0 +} + + +# === + +do_test () { + local retval=0 + echo + echo "* ${extd}against ${attn}CACertificateFile${norm} and autorization by x509 ${attn}blob${norm}:" + + creTestSSHDcfgFile + cat >> "$SSHD_CFG" <> "$SSHD_CFG" <> "$SSHD_CFG" <> "$SSHD_CFG" < /dev/null + local FILE="${SSH_CACRLDIR}/${CAKEY_PREFIX}-${crltype}.crl.pem" + local HASH + HASH=`${OPENSSL} crl -out /dev/null -in "${FILE}" -hash`; retval=$? + if test $retval -eq 0; then + hashfile="${CRL_TEST_DIR}/${HASH}.r0" + ln -s "${FILE}" "${hashfile}" + #link might never fail :-( + test -h "${hashfile}"; retval=$? + fi + #printf "${norm}" + show_status $retval || return $? + + if test $retval -eq 0; then + ( + for DIGEST in ${RSA_DIGEST_LIST}; do + test_crlbytype0 "${crltype}" "rsa_${DIGEST}" || exit $? + done + test_crlbytype0 "${crltype}" "dsa" || exit $? + ); retval=$? + fi + + if test $retval -eq 0; then + rm -f "${hashfile}"; retval=$? + else + rm -f "${hashfile}" + fi + return $retval +} + + +#=== +test_onlyonecrl () { + local retval=0 + local CRL_TEST_DIR="${SSH_CAROOT}/crl-test" + + printSeparator + echo "Begin test ${extd}with only ${attn}one CRL file${norm} in ${attn}CARevocationPath${norm}..." + + mkdir -p "${CRL_TEST_DIR}" || return $? + + creTestSSHDcfgFile + cat >> "$SSHD_CFG" < /dev/null + if test $retval -eq 0; then + rmdir "${CRL_TEST_DIR}"; retval=$? + else + rmdir "${CRL_TEST_DIR}" + fi + return $retval +} + + +#=== +do_test () { + + echo + echo "* ${extd}against ${attn}CA CRL${norm} file and/or hash-dir:" + + test_nocrl && + test_crlfile && + test_crldir && + test_onlyonecrl + + return $? +} diff -ruN openssh-3.6.1p2/tests/CA/test-dn_auth_file.sh.inc openssh-3.6.1p2+x509g1/tests/CA/test-dn_auth_file.sh.inc --- openssh-3.6.1p2/tests/CA/test-dn_auth_file.sh.inc 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/test-dn_auth_file.sh.inc 2003-03-07 14:35:42.000000000 +0200 @@ -0,0 +1,112 @@ +# +# Copyright (c) 2002-2003 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Test OpenSSH client authentication: +# - "IdentityFile" contain private key and x509 certificate; +# - "AuthorizedKeysFile" contain certificate "Distinguished Name"/ +# "Subject" in varios formats. +# + + +# === +testDNautorizations1 () { + local type="$1" + local identity_file="${SSH_CLIENTKEY}-${type}" + if test ! -r "$identity_file"; then + error_file_not_readable "${identity_file}"; return $? + fi + + local sshkeytype + local subject + + sshkeytype=`getSSHkeyType "${identity_file}"` || return $? + subject=`getSubject "${identity_file}"` || return $? + + for subtype in\ + "Subject:" \ + "SuBjecT=" \ + "sUbjecT" \ + "diStinguished name:" \ + "distiNguished-nAme:" \ + "distinguiShed_naMe:" \ + "disTinguishednamE:" \ + "dN:" \ + ; do + echo "${sshkeytype} ${subtype} ${subject}" > "${AUTHORIZEDKEYSFILE}" + runTest "${type} ${subtype}" "${identity_file}" "" || return $? + done + + subtype="subject" + subject=`getSubject "${identity_file}" -nameopt RFC2253` || return $? + echo "${sshkeytype} ${subtype} ${subject}" > "${AUTHORIZEDKEYSFILE}" + runTest "${type} ${subtype} in ${attn}RFC2253${norm} format" "${identity_file}" "" || return $? + + echo "${sshkeytype} ${subtype} ${subject}" | sed -e 's/,/\//'> "${AUTHORIZEDKEYSFILE}" + runTest "${type} ${subtype} and mixed tag-separator symbol" "${identity_file}" "" || return $? + + for subtype in\ + "Invalid" \ + "Subject-" \ + ; do + echo "${sshkeytype} ${subtype} ${subject}" > "${AUTHORIZEDKEYSFILE}" + runTest "${type} ${warn}${subtype}${norm}" "${identity_file}"\ + "autorization type" "Yes" || return $? + done + + subtype="Subject" + ( printf "${sshkeytype} ${subtype}" + echo "${subject}" | cut -c -40 + ) > "${AUTHORIZEDKEYSFILE}" + runTest "${type} ${warn}invalid${norm} ${subtype}" "${identity_file}"\ + "" "Yes" || return $? + + return 0 +} + + +# === + +do_test () { + local retval=0 + echo + echo "* ${extd}against ${attn}CACertificateFile${norm} and autorization by x509 ${attn}'Distinguished Name'${norm}:" + + creTestSSHDcfgFile + cat >> "$SSHD_CFG" <> "$SSHD_CFG" </dev/null + + for DIGEST in ${RSA_DIGEST_LIST}; do + if test $retval -eq 0; then + type="rsa_${DIGEST}" + HASH=`$OPENSSL x509 -in "${SSH_CACERTDIR}/${CAKEY_PREFIX}-${type}.crt.pem" -noout -hash` + ( cd "${CRT_TEST_DIR}" || exit $? + ln -s "${SSH_CACERTDIR}/${CAKEY_PREFIX}-${type}.crt.pem" "$HASH.0" + #link might never fail :-( + test -h "$HASH.0" + ) && + do_test_catype "${type}"; retval=$? + rm -f "${CRT_TEST_DIR}/$HASH.0" + fi + done + if test $retval -eq 0; then + type="dsa" + HASH=`$OPENSSL x509 -in "${SSH_CACERTDIR}/${CAKEY_PREFIX}-${type}.crt.pem" -noout -hash` + ( cd "${CRT_TEST_DIR}" || exit $? + ln -s "${SSH_CACERTDIR}/${CAKEY_PREFIX}-${type}.crt.pem" "$HASH.0" + #link might never fail :-( + test -h "$HASH.0" + ) && + do_test_catype "${type}"; retval=$? + rm -f "${CRT_TEST_DIR}/$HASH.0" + fi + + rmdir "${CRT_TEST_DIR}" + done + killSSHdaemon + return $retval +} diff -ruN openssh-3.6.1p2/tests/CA/verify.sh openssh-3.6.1p2+x509g1/tests/CA/verify.sh --- openssh-3.6.1p2/tests/CA/verify.sh 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/tests/CA/verify.sh 2003-03-06 13:45:28.000000000 +0200 @@ -0,0 +1,40 @@ +#!/bin/sh +# Copyright (c) 2002 Roumen Petrov, Sofia, Bulgaria +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# DESCRIPTION: Verify all testid_*.crt testhostkey_*.crt files in current +# directory agains openssh "Test CA". +# + +CWD=`pwd` +SCRIPTDIR=`echo $0 | sed 's/verify.sh//'` +. "${SCRIPTDIR}functions" +. "${SCRIPTDIR}config" + + +for VERIFY in \ + "${OPENSSL} verify -CAfile ${SSH_CAROOT}/${CACERTFILE}" \ + "${OPENSSL} verify -CApath ${SSH_CACERTDIR}" \ +; do + echo ${attn}${VERIFY} ....${norm} + for F in testid_*.crt testhostkey_*.crt; do + ${VERIFY} "$F" || exit 1 + done +done diff -ruN openssh-3.6.1p2/x509store.c openssh-3.6.1p2+x509g1/x509store.c --- openssh-3.6.1p2/x509store.c 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/x509store.c 2003-03-19 18:01:12.000000000 +0200 @@ -0,0 +1,567 @@ +/* + * Copyright (c) 2002-2003 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "x509store.h" +#include "log.h" +#include "xmalloc.h" +#include "openssl/e_os.h" +#include "openssl/err.h" +#include "openssl/x509v3.h" + + +/* allowed client certificate purpose */ +static int sshpurpose_index = -1; +static X509_STORE *x509store = NULL; +#define SSH_CHECK_REVOKED + + +#ifdef SSH_CHECK_REVOKED +static X509_STORE *x509revoked = NULL; +static int ssh_x509revoked_cb(int ok, X509_STORE_CTX *ctx); + + +static char * +ssh_ASN1_INTEGER_2_string(ASN1_INTEGER *_asni) { + BIO *bio; + int k; + char *p; + + bio = BIO_new(BIO_s_mem()); + if (bio == NULL) { + fatal("ssh_ASN1_INTEGER_2_string: out of memory"); + return NULL; /* ;-) */ + } + + i2a_ASN1_INTEGER(bio, _asni); + k = BIO_pending(bio); + p = xmalloc(k + 1); + k = BIO_read(bio, p, k); + p[k] = '\0'; + BIO_free_all(bio); + + return p; +} + + +static int +ssh_x509store_lookup(X509_STORE *store, int type, X509_NAME *name, X509_OBJECT *xobj) { + X509_STORE_CTX ctx; + int ret; + + X509_STORE_CTX_init(&ctx, store, NULL, NULL); + ret = X509_STORE_get_by_subject(&ctx, type, name, xobj); + X509_STORE_CTX_cleanup(&ctx); + + return ret; +} +#endif /*def SSH_CHECK_REVOKED*/ + + +static int MS_CALLBACK +ssh_x509store_cb(int ok, X509_STORE_CTX *ctx) { + if (!ok) { + char buf[512]; + X509_NAME_oneline( X509_get_subject_name(ctx->current_cert), buf, sizeof(buf)); + error("ssh_x509store_cb: subject='%.512s', error %d at %d depth lookup:%.200s\n", + buf, + ctx->error, + ctx->error_depth, + X509_verify_cert_error_string(ctx->error)); + +#if 0 + if (ctx->error == X509_V_ERR_CERT_HAS_EXPIRED) ok=1; + /* since we are just checking the certificates, it is + * ok if they are self signed. But we should still warn + * the user. + */ + if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) ok=1; + /* Continue after extension errors too */ + if (ctx->error == X509_V_ERR_INVALID_CA) ok=1; + if (ctx->error == X509_V_ERR_PATH_LENGTH_EXCEEDED) ok=1; + if (ctx->error == X509_V_ERR_INVALID_PURPOSE) ok=1; + if (ctx->error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) ok=1; +#endif + } +#ifdef SSH_CHECK_REVOKED + if (ok) { + ok = ssh_x509revoked_cb(ok, ctx); + } +#endif + return(ok); +} + + +typedef struct { + const char **synonyms; +} CertPurposes; + + +static const char *__purpose_any[] = { + "any", "any purpose", "any_purpose", "anypurpose", NULL +}; + + +static const char *__purpose_sslclient[] = { + "sslclient", "ssl client", "ssl_client", "client", NULL +}; + + +static const char *__purpose_sslserver[] = { + "sslserver", "ssl server", "ssl_server", "server", NULL +}; + + +static CertPurposes +sslclient_purposes[] = { + { __purpose_sslclient }, + { __purpose_any }, + { NULL } +}; + + +static CertPurposes +sslserver_purposes [] = { + { __purpose_sslserver }, + { __purpose_any }, + { NULL } +}; + + +static const char* +get_cert_purpose (const char* _purpose_synonym, CertPurposes *_purposes) { + int i; + + for (i = 0; _purposes[i].synonyms[0]; i++) { + const char *q = _purposes[i].synonyms[0]; + if (strcasecmp(_purpose_synonym, q) == 0 ) { + return q; + } else { + const char **p; + for (p = (_purposes[i].synonyms) + 1; *p; p++) { + if (strcasecmp(_purpose_synonym, *p) == 0 ) { + return q; + } + } + } + } + return NULL; +} + + + +int +sshclient_cert_purpose (const char* _purpose_synonym) { + const char * sslpurpose = get_cert_purpose(_purpose_synonym, sslclient_purposes); + if (sslpurpose != NULL) { + int purpose_index = X509_PURPOSE_get_by_sname((char*)sslpurpose); + if (purpose_index < 0) + fatal("client:X509_PURPOSE_get_by_sname fail for argument '%.30s(%.40s)'", sslpurpose, _purpose_synonym); + return purpose_index; + } + return -1; +} + + +int +sshserver_cert_purpose (const char* _purpose_synonym) { + const char * sslpurpose = get_cert_purpose(_purpose_synonym, sslserver_purposes); + if (sslpurpose != NULL) { + int purpose_index = X509_PURPOSE_get_by_sname((char*)sslpurpose); + if (purpose_index < 0) + fatal("server:X509_PURPOSE_get_by_sname fail for argument '%.30s(%.40s)'", sslpurpose, _purpose_synonym); + return purpose_index; + } + return -1; +} + + +void +ssh_x509store_setpurpose(int _sshpurpose_index) { + sshpurpose_index = _sshpurpose_index; +} + + +static void +ssh_x509store_initcontext() { + if (x509store == NULL) { + x509store = X509_STORE_new(); + if (x509store == NULL) { + fatal ("cannot create x509store context"); + } + X509_STORE_set_verify_cb_func(x509store, ssh_x509store_cb); + } +#ifdef SSH_CHECK_REVOKED + if (x509revoked == NULL) { + x509revoked = X509_STORE_new(); + if (x509revoked == NULL) { + fatal ("cannot create x509revoced context"); + } + } +#endif +} + + +int +ssh_x509store_addlocations (const X509StoreOptions *_locations) { + int flag = 0, flag2 = 0; + + if (_locations == NULL) { + error("ssh_x509store_addlocations: _locations is NULL"); + return 0; + } + if ((_locations->certificate_path == NULL) && + (_locations->certificate_file == NULL)) { + error("ssh_x509store_addlocations: certificate path and file are NULLs"); + return 0; + } +#ifdef SSH_CHECK_REVOKED + if ((_locations->revocation_path == NULL) && + (_locations->revocation_file == NULL)) { + error("ssh_x509store_addlocations: revocation path and file are NULLs"); + return 0; + } +#endif + ssh_x509store_initcontext(); + /* + Note: + After X509_LOOKUP_{add_dir|load_file} calls we must call + ERR_clear_error() otherwise when the first call to + X509_LOOKUP_XXXX fail the second call fail too ! + */ + if (_locations->certificate_path != NULL) { + X509_LOOKUP *lookup = X509_STORE_add_lookup(x509store, X509_LOOKUP_hash_dir()); + if (lookup == NULL) { + fatal("ssh_x509store_addlocations:cannot add hash dir lookup !"); + return 0; /* ;-) */ + } + if (X509_LOOKUP_add_dir(lookup, _locations->certificate_path, X509_FILETYPE_PEM)) { + debug2( "hash dir '%.400s' added to x509 store", _locations->certificate_path); + flag = 1; + } + ERR_clear_error(); + } + if (_locations->certificate_file != NULL) { + X509_LOOKUP *lookup = X509_STORE_add_lookup(x509store, X509_LOOKUP_file()); + if (lookup == NULL) { + fatal("ssh_x509store_addlocations:cannot add file lookup !"); + return 0; /* ;-) */ + } + if (X509_LOOKUP_load_file(lookup, _locations->certificate_file, X509_FILETYPE_PEM)) { + debug2( "file '%.400s' added to x509 store", _locations->certificate_file); + flag = 1; + } + ERR_clear_error(); + } +#ifdef SSH_CHECK_REVOKED + if (_locations->revocation_path != NULL) { + X509_LOOKUP *lookup = X509_STORE_add_lookup(x509revoked, X509_LOOKUP_hash_dir()); + if (lookup == NULL) { + fatal("ssh_x509store_addlocations:cannot add hash dir revocation lookup !"); + return 0; /* ;-) */ + } + if (X509_LOOKUP_add_dir(lookup, _locations->revocation_path, X509_FILETYPE_PEM)) { + debug2( "hash dir '%.400s' added to x509 revocation store", _locations->revocation_path); + flag2 = 1; + } + ERR_clear_error(); + } + if (_locations->revocation_file != NULL) { + X509_LOOKUP *lookup = X509_STORE_add_lookup(x509revoked, X509_LOOKUP_file()); + if (lookup == NULL) { + fatal("ssh_x509store_addlocations:cannot add file revocation lookup !"); + return 0; /* ;-) */ + } + if (X509_LOOKUP_load_file(lookup, _locations->revocation_file, X509_FILETYPE_PEM)) { + debug2( "file '%.400s' added to x509 revocation store", _locations->revocation_file); + flag2 = 1; + } + ERR_clear_error(); + } +#else + flag2 = 1; +#endif + return flag && flag2; +} + + +static int +ssh_verify_cert (X509_STORE_CTX *_csc, X509 *_cert) { + X509_STORE_CTX_init(_csc, x509store, _cert, NULL); + + if(sshpurpose_index >= 0) { + X509_PURPOSE *xptmp = X509_PURPOSE_get0(sshpurpose_index); + if (X509_STORE_CTX_set_purpose(_csc, X509_PURPOSE_get_id(xptmp)) == 0) { + int ecode = X509_STORE_CTX_get_error(_csc); + error("ssh_x509store_check: purpose error, code=%d, msg='%.200s'" + , ecode + , X509_verify_cert_error_string(ecode)); + return -1; + } + } + + /* + if(issuer_checks) + X509_STORE_CTX_set_flags(_csc, X509_V_FLAG_CB_ISSUER_CHECK); + */ + + if(X509_verify_cert(_csc) == 0) { + int ecode = X509_STORE_CTX_get_error(_csc); + error("ssh_x509store_check: verify error, code=%d, msg='%.200s'" + , ecode + , X509_verify_cert_error_string(ecode)); + return -1; + } + + return 1; +} + + +int +ssh_x509store_check(X509 *_cert) { + X509_STORE_CTX *csc; + int ret = 1; + + if (x509store == NULL) { + error("ssh_x509store_check: context is NULL\n"); + return -1; + } + + if (get_log_level() >= SYSLOG_LEVEL_DEBUG3) { + char buf[512]; + X509_NAME_oneline( X509_get_subject_name(_cert), buf, sizeof(buf)); + debug3("ssh_x509store_check: for '%.512s'", buf); + } + + csc = X509_STORE_CTX_new(); + if (csc == NULL) { + int ecode = ERR_get_error(); + error("ssh_x509store_check:X509_STORE_CTX_new failed with '%.200s'", ERR_error_string(ecode, NULL)); + + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + return -1; + } + + ret = ssh_verify_cert(csc, _cert); + X509_STORE_CTX_free(csc); + + debug3("ssh_x509store_check: return %d", ret); + return (ret); +} + + +#ifdef SSH_CHECK_REVOKED +static int +ssh_check_crl(X509_STORE_CTX *_ctx, X509_CRL *_crl) { + X509 *cert = NULL; + time_t *pcheck_time; + int k; + + if (_crl == NULL) { + return 1; + } + + cert = X509_STORE_CTX_get_current_cert(_ctx); + if (cert == NULL) { + error("ssh_check_crl: missing current certificate in x509store context"); + return 0; + } + + if (get_log_level() >= SYSLOG_LEVEL_DEBUG3) { + BIO *bio; + char buf[512]; + char *p; + + bio = BIO_new(BIO_s_mem()); + if (bio == NULL) { + fatal("ssh_check_crl: out of memory"); + return 0; /* ;-) */ + } + + X509_NAME_oneline( X509_CRL_get_issuer(_crl), buf, sizeof(buf)); + + BIO_printf(bio, ", Last Update: "); + ASN1_UTCTIME_print(bio, X509_CRL_get_lastUpdate(_crl)); + + BIO_printf(bio, ", Next Update: "); + ASN1_UTCTIME_print(bio, X509_CRL_get_nextUpdate(_crl)); + + k = BIO_pending(bio); + p = xmalloc(k + 1); + k = BIO_read(bio, p, k); + p[k] = '\0'; + + debug3("ssh_check_crl: Issuer: %s%s", buf, p); + + xfree(p); + BIO_free(bio); + } + + { + EVP_PKEY *pkey = X509_get_pubkey(cert); + if(pkey == NULL) { + error("ssh_check_crl:unable to devode public key"); + X509_STORE_CTX_set_error(_ctx, X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY); + return 0; + } + + if (X509_CRL_verify(_crl, pkey) <= 0) { + error("ssh_check_crl:CRL has invalid signature"); + X509_STORE_CTX_set_error(_ctx, X509_V_ERR_CRL_SIGNATURE_FAILURE); + return 0; + } + EVP_PKEY_free(pkey); + } + + + if (_ctx->flags & X509_V_FLAG_USE_CHECK_TIME) + pcheck_time = &_ctx->check_time; + else + pcheck_time = NULL; + + k = X509_cmp_time(X509_CRL_get_lastUpdate(_crl), pcheck_time); + if (k == 0) { + X509_STORE_CTX_set_error(_ctx, X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD); + error("ssh_check_crl:CRL has invalid lastUpdate field"); + return 0; + } + if (k > 0) { + X509_STORE_CTX_set_error(_ctx, X509_V_ERR_CRL_NOT_YET_VALID); + error("ssh_check_crl:CRL is not yet valid"); + return 0; + } + + k = X509_cmp_time(X509_CRL_get_nextUpdate(_crl), pcheck_time); + if (k == 0) { + error("ssh_check_crl:CRL has invalid nextUpdate field"); + X509_STORE_CTX_set_error(_ctx, X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD); + return 0; + } + if (k < 0) { + error("ssh_check_crl:CRL is expired"); + X509_STORE_CTX_set_error(_ctx, X509_V_ERR_CRL_HAS_EXPIRED); + return 0; + } + + return 1; +} + + +static int +ssh_check_crl_cert(X509_STORE_CTX *_ctx, X509_CRL *_crl, X509 *_cert) { + X509_REVOKED revoked; + int k; + char *p, buf1[512], buf2[512]; + + if (_crl == NULL) return 1; + revoked.serialNumber = X509_get_serialNumber(_cert); + k = sk_X509_REVOKED_find(_crl->crl->revoked, &revoked); + if (k < 0) return 1; + + X509_STORE_CTX_set_error(_ctx, X509_V_ERR_CERT_REVOKED); + /* yes, revoked. print log and ...*/ + p = ssh_ASN1_INTEGER_2_string(revoked.serialNumber); + X509_NAME_oneline(X509_get_subject_name(_cert), buf1, sizeof(buf1)); + X509_NAME_oneline(X509_CRL_get_issuer (_crl ), buf2, sizeof(buf2)); + + log ("certificate '%.512s' with serial '%.40s' revoked from issuer '%.512s'", + buf1, p, buf2); + xfree (p); + + return 0; +} + + +static int +ssh_x509revoked_cb(int ok, X509_STORE_CTX *ctx) { + X509 *cert; + X509_OBJECT xobj; + + if (!ok) return 0; + if (x509revoked == NULL) + return ok; /* XXX:hmm */ + + cert = X509_STORE_CTX_get_current_cert(ctx); + if (cert == NULL) { + error("ssh_x509revoked_cb: missing current certificate in x509store context"); + return 0; + } + + if (get_log_level() >= SYSLOG_LEVEL_DEBUG3) { + char buf[512]; + + X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf)); + debug3("ssh_x509revoked_cb:issuer =%.512s", buf); + + X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf)); + debug3("ssh_x509revoked_cb:subject=%.512s", buf); + } + + memset(&xobj, 0, sizeof(xobj)); + if (ssh_x509store_lookup( + x509revoked, X509_LU_CRL, + X509_get_subject_name(cert), + &xobj) > 0) { +/* + In callback we cannot check CRL signature at this point when we use + X509_get_issuer_name(), because we don't know issuer public key! + Of course we can get the public key from X509_STORE defined by + static variable "x509store". + Of course we can check revocation outside callback, but we should + try to find public key in X509_STORE[s]. + + At this point we can get easy public key of "current certificate"! + + Method: "look forward" + At this call we check CLR (signature and other) issued with "current + certificate" ("CertA"). If all is OK with "CertA" by next call of + callback method "current certificate" is signed from "CertA" and the + CRL issued from "CertA", if any is already verified - cool ;-). + + Note that when a certificate is revoked all signed form that + certificate are revoked automatically too. With method "look forward" + we already know that all issuers of "current certificate" aren't + revoked. +*/ + ok = ssh_check_crl(ctx, xobj.data.crl); + } + X509_OBJECT_free_contents(&xobj); + if (!ok) return 0; + + memset(&xobj, 0, sizeof(xobj)); + if (ssh_x509store_lookup( + x509revoked, X509_LU_CRL, + X509_get_issuer_name(cert), + &xobj) > 0) { + ok = ssh_check_crl_cert(ctx, xobj.data.crl, cert); + } + X509_OBJECT_free_contents(&xobj); + /* clear rest of errors in OpenSSL "error buffer" */ + ERR_clear_error(); + + if (!ok) return 0; + + /**/ + return ok; +} +#endif diff -ruN openssh-3.6.1p2/x509store.h openssh-3.6.1p2+x509g1/x509store.h --- openssh-3.6.1p2/x509store.h 1970-01-01 02:00:00.000000000 +0200 +++ openssh-3.6.1p2+x509g1/x509store.h 2003-03-19 18:01:09.000000000 +0200 @@ -0,0 +1,59 @@ +#ifndef X509STORE_H +#define X509STORE_H +/* + * Copyright (c) 2002-2003 Roumen Petrov. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "includes.h" +#include +#if 0 +/* Set 0 (above) to 1 for OpenSSL 0.9.7beta2/3 :-( or comment in openssl "des_old.h" all lines: + #define cript ... + This is commented in beta4 ;-) + */ +#ifdef crypt +# undef crypt +#endif +#endif + + +int ssh_x509store_check(X509 *_cert); + +/* return purpose index, not purpose id (!) */ +int sshclient_cert_purpose (const char* _purpose_synonym); +int sshserver_cert_purpose (const char* _purpose_synonym); + + +typedef struct { + /* ssh PKI(X509) store */ + char *certificate_file; + char *certificate_path; + char *revocation_file; + char *revocation_path; +} X509StoreOptions; + +void ssh_x509store_setpurpose(int _sshpurpose_index); +int ssh_x509store_addlocations (const X509StoreOptions *_locations); + +#endif /* X509STORE_H */