From 602f4beeeda5bb0eca181f8753d923a2997d0a51 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Tue, 9 Jan 2024 21:39:14 +0000 Subject: [PATCH 1/9] upstream: adapt ssh_api.c code for kex-strict from markus@ ok me OpenBSD-Commit-ID: 4d9f256852af2a5b882b12cae9447f8f00f933ac --- ssh_api.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ssh_api.c b/ssh_api.c index d3c661761..fadf2f4b1 100644 --- a/ssh_api.c +++ b/ssh_api.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh_api.c,v 1.27 2021/04/03 06:18:41 djm Exp $ */ +/* $OpenBSD: ssh_api.c,v 1.28 2024/01/09 21:39:14 djm Exp $ */ /* * Copyright (c) 2012 Markus Friedl. All rights reserved. * @@ -82,6 +82,7 @@ int ssh_init(struct ssh **sshp, int is_server, struct kex_params *kex_params) { char *myproposal[PROPOSAL_MAX] = { KEX_CLIENT }; + char *populated[PROPOSAL_MAX]; struct ssh *ssh; char **proposal; static int called; @@ -99,10 +100,19 @@ ssh_init(struct ssh **sshp, int is_server, struct kex_params *kex_params) /* Initialize key exchange */ proposal = kex_params ? kex_params->proposal : myproposal; - if ((r = kex_ready(ssh, proposal)) != 0) { + kex_proposal_populate_entries(ssh, populated, + proposal[PROPOSAL_KEX_ALGS], + proposal[PROPOSAL_ENC_ALGS_CTOS], + proposal[PROPOSAL_MAC_ALGS_CTOS], + proposal[PROPOSAL_COMP_ALGS_CTOS], + proposal[PROPOSAL_SERVER_HOST_KEY_ALGS]); + r = kex_ready(ssh, populated); + kex_proposal_free_entries(populated); + if (r != 0) { ssh_free(ssh); return r; } + ssh->kex->server = is_server; if (is_server) { #ifdef WITH_OPENSSL From b31b12d28de96e1d43581d32f34da8db27e11c03 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Tue, 9 Jan 2024 22:19:00 +0000 Subject: [PATCH 2/9] upstream: add a "global" ChannelTimeout type to ssh(1) and sshd(8) that watches all open channels and will close all open channels if there is no traffic on any of them for the specified interval. This is in addition to the existing per-channel timeouts added a few releases ago. This supports use-cases like having a session + x11 forwarding channel open where one may be idle for an extended period but the other is actively used. The global timeout would allow closing both channels when both have been idle for too long. ok dtucker@ OpenBSD-Commit-ID: 0054157d24d2eaa5dc1a9a9859afefc13d1d7eb3 --- channels.c | 74 +++++++++++++++++++++++++++++++++++++++------------ ssh_config.5 | 22 ++++++++++----- sshd_config.5 | 44 +++++++++++++++++------------- 3 files changed, 99 insertions(+), 41 deletions(-) diff --git a/channels.c b/channels.c index 20f31dadd..6862556be 100644 --- a/channels.c +++ b/channels.c @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.c,v 1.435 2023/12/18 14:47:20 djm Exp $ */ +/* $OpenBSD: channels.c,v 1.436 2024/01/09 22:19:00 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -214,6 +214,9 @@ struct ssh_channels { /* Channel timeouts by type */ struct ssh_channel_timeout *timeouts; size_t ntimeouts; + /* Global timeout for all OPEN channels */ + int global_deadline; + time_t lastused; }; /* helper */ @@ -316,6 +319,11 @@ channel_add_timeout(struct ssh *ssh, const char *type_pattern, { struct ssh_channels *sc = ssh->chanctxt; + if (strcmp(type_pattern, "global") == 0) { + debug2_f("global channel timeout %d seconds", timeout_secs); + sc->global_deadline = timeout_secs; + return; + } debug2_f("channel type \"%s\" timeout %d seconds", type_pattern, timeout_secs); sc->timeouts = xrecallocarray(sc->timeouts, sc->ntimeouts, @@ -376,6 +384,38 @@ channel_set_xtype(struct ssh *ssh, int id, const char *xctype) c->inactive_deadline); } +/* + * update "last used" time on a channel. + * NB. nothing else should update lastused except to clear it. + */ +static void +channel_set_used_time(struct ssh *ssh, Channel *c) +{ + ssh->chanctxt->lastused = monotime(); + if (c != NULL) + c->lastused = ssh->chanctxt->lastused; +} + +/* + * Get the time at which a channel is due to time out for inactivity. + * Returns 0 if the channel is not due to time out ever. + */ +static time_t +channel_get_expiry(struct ssh *ssh, Channel *c) +{ + struct ssh_channels *sc = ssh->chanctxt; + time_t expiry = 0, channel_expiry; + + if (sc->lastused != 0 && sc->global_deadline != 0) + expiry = sc->lastused + sc->global_deadline; + if (c->lastused != 0 && c->inactive_deadline != 0) { + channel_expiry = c->lastused + c->inactive_deadline; + if (expiry == 0 || channel_expiry < expiry) + expiry = channel_expiry; + } + return expiry; +} + /* * Register filedescriptors for a channel, used when allocating a channel or * when the channel consumer/producer is ready, e.g. shell exec'd @@ -441,6 +481,8 @@ channel_register_fds(struct ssh *ssh, Channel *c, int rfd, int wfd, int efd, if (efd != -1) set_nonblock(efd); } + /* channel might be entering a larval state, so reset global timeout */ + channel_set_used_time(ssh, NULL); } /* @@ -1197,7 +1239,7 @@ channel_set_fds(struct ssh *ssh, int id, int rfd, int wfd, int efd, channel_register_fds(ssh, c, rfd, wfd, efd, extusage, nonblock, is_tty); c->type = SSH_CHANNEL_OPEN; - c->lastused = monotime(); + channel_set_used_time(ssh, c); c->local_window = c->local_window_max = window_max; if ((r = sshpkt_start(ssh, SSH2_MSG_CHANNEL_WINDOW_ADJUST)) != 0 || @@ -1368,7 +1410,7 @@ channel_pre_x11_open(struct ssh *ssh, Channel *c) if (ret == 1) { c->type = SSH_CHANNEL_OPEN; - c->lastused = monotime(); + channel_set_used_time(ssh, c); channel_pre_open(ssh, c); } else if (ret == -1) { logit("X11 connection rejected because of wrong " @@ -2016,7 +2058,7 @@ channel_post_connecting(struct ssh *ssh, Channel *c) c->self, c->connect_ctx.host, c->connect_ctx.port); channel_connect_ctx_free(&c->connect_ctx); c->type = SSH_CHANNEL_OPEN; - c->lastused = monotime(); + channel_set_used_time(ssh, c); if (isopen) { /* no message necessary */ } else { @@ -2108,7 +2150,7 @@ channel_handle_rfd(struct ssh *ssh, Channel *c) goto rfail; } if (nr != 0) - c->lastused = monotime(); + channel_set_used_time(ssh, c); return 1; } @@ -2134,7 +2176,7 @@ channel_handle_rfd(struct ssh *ssh, Channel *c) } return -1; } - c->lastused = monotime(); + channel_set_used_time(ssh, c); if (c->input_filter != NULL) { if (c->input_filter(ssh, c, buf, len) == -1) { debug2("channel %d: filter stops", c->self); @@ -2215,7 +2257,7 @@ channel_handle_wfd(struct ssh *ssh, Channel *c) } return -1; } - c->lastused = monotime(); + channel_set_used_time(ssh, c); #ifndef BROKEN_TCGETATTR_ICANON if (c->isatty && dlen >= 1 && buf[0] != '\r') { if (tcgetattr(c->wfd, &tio) == 0 && @@ -2264,7 +2306,7 @@ channel_handle_efd_write(struct ssh *ssh, Channel *c) if ((r = sshbuf_consume(c->extended, len)) != 0) fatal_fr(r, "channel %i: consume", c->self); c->local_consumed += len; - c->lastused = monotime(); + channel_set_used_time(ssh, c); } return 1; } @@ -2291,7 +2333,7 @@ channel_handle_efd_read(struct ssh *ssh, Channel *c) channel_close_fd(ssh, c, &c->efd); return 1; } - c->lastused = monotime(); + channel_set_used_time(ssh, c); if (c->extended_usage == CHAN_EXTENDED_IGNORE) debug3("channel %d: discard efd", c->self); else if ((r = sshbuf_put(c->extended, buf, len)) != 0) @@ -2581,10 +2623,9 @@ channel_handler(struct ssh *ssh, int table, struct timespec *timeout) continue; } if (ftab[c->type] != NULL) { - if (table == CHAN_PRE && - c->type == SSH_CHANNEL_OPEN && - c->inactive_deadline != 0 && c->lastused != 0 && - now >= c->lastused + c->inactive_deadline) { + if (table == CHAN_PRE && c->type == SSH_CHANNEL_OPEN && + channel_get_expiry(ssh, c) != 0 && + now >= channel_get_expiry(ssh, c)) { /* channel closed for inactivity */ verbose("channel %d: closing after %u seconds " "of inactivity", c->self, @@ -2596,10 +2637,9 @@ channel_handler(struct ssh *ssh, int table, struct timespec *timeout) /* inactivity timeouts must interrupt poll() */ if (timeout != NULL && c->type == SSH_CHANNEL_OPEN && - c->lastused != 0 && - c->inactive_deadline != 0) { + channel_get_expiry(ssh, c) != 0) { ptimeout_deadline_monotime(timeout, - c->lastused + c->inactive_deadline); + channel_get_expiry(ssh, c)); } } else if (timeout != NULL) { /* @@ -3558,7 +3598,7 @@ channel_input_open_confirmation(int type, u_int32_t seq, struct ssh *ssh) c->open_confirm(ssh, c->self, 1, c->open_confirm_ctx); debug2_f("channel %d: callback done", c->self); } - c->lastused = monotime(); + channel_set_used_time(ssh, c); debug2("channel %d: open confirm rwindow %u rmax %u", c->self, c->remote_window, c->remote_maxpacket); return 0; diff --git a/ssh_config.5 b/ssh_config.5 index 4bbdfefd1..15ad012f8 100644 --- a/ssh_config.5 +++ b/ssh_config.5 @@ -33,8 +33,8 @@ .\" (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.391 2023/10/12 02:18:18 djm Exp $ -.Dd $Mdocdate: October 12 2023 $ +.\" $OpenBSD: ssh_config.5,v 1.392 2024/01/09 22:19:00 djm Exp $ +.Dd $Mdocdate: January 9 2024 $ .Dt SSH_CONFIG 5 .Os .Sh NAME @@ -463,8 +463,10 @@ Timeouts are specified as one or more .Dq type=interval pairs separated by whitespace, where the .Dq type -must be a channel type name (as described in the table below), optionally -containing wildcard characters. +must be the special keyword +.Dq global +or a channel type name from the list below, optionally containing +wildcard characters. .Pp The timeout value .Dq interval @@ -473,11 +475,19 @@ is specified in seconds or may use any of the units documented in the section. For example, .Dq session=5m -would cause the interactive session to terminate after five minutes of +would cause interactive sessions to terminate after five minutes of inactivity. Specifying a zero value disables the inactivity timeout. .Pp -The available channel types include: +The special timeout +.Dq global +Applies to all active channels, taken together. +Traffic on any active channel will reset the timeout, but when the timeout +expires then all open channels will be closed. +Note that this global timeout is not matched by wildcards and must be +specified explicitly. +.Pp +The available channel type names include: .Bl -tag -width Ds .It Cm agent-connection Open connections to diff --git a/sshd_config.5 b/sshd_config.5 index 7e1a56cd0..ca5eeb59d 100644 --- a/sshd_config.5 +++ b/sshd_config.5 @@ -33,8 +33,8 @@ .\" (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.350 2023/07/28 05:42:36 jmc Exp $ -.Dd $Mdocdate: July 28 2023 $ +.\" $OpenBSD: sshd_config.5,v 1.351 2024/01/09 22:19:00 djm Exp $ +.Dd $Mdocdate: January 9 2024 $ .Dt SSHD_CONFIG 5 .Os .Sh NAME @@ -409,8 +409,10 @@ Timeouts are specified as one or more .Dq type=interval pairs separated by whitespace, where the .Dq type -must be a channel type name (as described in the table below), optionally -containing wildcard characters. +must be the special keyword +.Dq global +or a channel type name from the list below, optionally containing +wildcard characters. .Pp The timeout value .Dq interval @@ -418,11 +420,20 @@ is specified in seconds or may use any of the units documented in the .Sx TIME FORMATS section. For example, -.Dq session:*=5m -would cause all sessions to terminate after five minutes of inactivity. +.Dq session=5m +would cause interactive sessions to terminate after five minutes of +inactivity. Specifying a zero value disables the inactivity timeout. .Pp -The available channel types include: +The special timeout +.Dq global +Applies to all active channels, taken together. +Traffic on any active channel will reset the timeout, but when the timeout +expires then all open channels will be closed. +Note that this global timeout is not matched by wildcards and must be +specified explicitly. +.Pp +The available channel type names include: .Bl -tag -width Ds .It Cm agent-connection Open connections to @@ -443,15 +454,15 @@ listening on behalf of a .Xr ssh 1 remote forwarding, i.e.\& .Cm RemoteForward . -.It Cm session:command -Command execution sessions. -.It Cm session:shell -Interactive shell sessions. -.It Cm session:subsystem:... -Subsystem sessions, e.g. for +.It Cm session +The interactive main session, including shell session, command execution, +.Xr scp 1 , .Xr sftp 1 , -which could be identified as -.Cm session:subsystem:sftp . +etc. +.It Cm tun-connection +Open +.Cm TunnelForward +connections. .It Cm x11-connection Open X11 forwarding sessions. .El @@ -465,9 +476,6 @@ close the SSH connection, nor does it prevent a client from requesting another channel of the same type. In particular, expiring an inactive forwarding session does not prevent another identical forwarding from being subsequently created. -See also -.Cm UnusedConnectionTimeout , -which may be used in conjunction with this option. .Pp The default is not to expire channels of any type for inactivity. .It Cm ChrootDirectory From 9707c8170c0c1baeb1e06e5a53f604498193885f Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Tue, 9 Jan 2024 22:19:36 +0000 Subject: [PATCH 3/9] upstream: extend ChannelTimeout regression test to exercise multiplexed connections and the new "global" timeout type. ok dtucker@ OpenBSD-Regress-ID: f10d19f697024e9941acad7c2057f73d6eacb8a2 --- regress/channel-timeout.sh | 70 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/regress/channel-timeout.sh b/regress/channel-timeout.sh index 1c42e832a..4293f0179 100644 --- a/regress/channel-timeout.sh +++ b/regress/channel-timeout.sh @@ -1,10 +1,33 @@ -# $OpenBSD: channel-timeout.sh,v 1.1 2023/01/06 08:07:39 djm Exp $ +# $OpenBSD: channel-timeout.sh,v 1.2 2024/01/09 22:19:36 djm Exp $ # Placed in the Public Domain. tid="channel timeout" # XXX not comprehensive. Still need -R -L agent X11 forwarding + interactive +rm -f $OBJ/finished.* $OBJ/mux.* + +MUXPATH=$OBJ/mux.$$ +open_mux() { + ${SSH} -nNfM -oControlPath=$MUXPATH -F $OBJ/ssh_proxy "$@" somehost || + fatal "open mux failed" + test -e $MUXPATH || fatal "mux socket $MUXPATH not established" +} + +close_mux() { + test -e $MUXPATH || fatal "mux socket $MUXPATH missing" + ${SSH} -qF $OBJ/ssh_proxy -oControlPath=$MUXPATH -O exit somehost || + fatal "could not terminate mux process" + for x in 1 2 3 4 5 6 7 8 9 10 ; do + test -e $OBJ/mux && break + sleep 1 + done + test -e $MUXPATH && fatal "mux did not clean up" +} +mux_client() { + ${SSH} -F $OBJ/ssh_proxy -oControlPath=$MUXPATH somehost "$@" +} + rm -f $OBJ/sshd_proxy.orig cp $OBJ/sshd_proxy $OBJ/sshd_proxy.orig @@ -24,6 +47,15 @@ if [ $r -ne 255 ]; then fail "ssh returned unexpected error code $r" fi +verbose "command long timeout" +(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=60") \ + > $OBJ/sshd_proxy +${SSH} -F $OBJ/ssh_proxy somehost "exit 23" +r=$? +if [ $r -ne 23 ]; then + fail "ssh returned unexpected error code $r" +fi + verbose "command wildcard timeout" (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:*=1") \ > $OBJ/sshd_proxy @@ -42,6 +74,41 @@ if [ $r -ne 23 ]; then fail "ssh failed" fi +verbose "multiplexed command timeout" +(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=1") \ + > $OBJ/sshd_proxy +open_mux +mux_client "sleep 5 ; exit 23" +r=$? +if [ $r -ne 255 ]; then + fail "ssh returned unexpected error code $r" +fi +close_mux + +verbose "irrelevant multiplexed command timeout" +(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:shell=1") \ + > $OBJ/sshd_proxy +open_mux +mux_client "sleep 5 ; exit 23" +r=$? +if [ $r -ne 23 ]; then + fail "ssh returned unexpected error code $r" +fi +close_mux + +verbose "global command timeout" +(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout global=10") \ + > $OBJ/sshd_proxy +open_mux +mux_client "sleep 1 ; echo ok ; sleep 1; echo ok; sleep 60; touch $OBJ/finished.1" >/dev/null & +mux_client "sleep 60 ; touch $OBJ/finished.2" >/dev/null & +mux_client "sleep 2 ; touch $OBJ/finished.3" >/dev/null & +wait +test -f $OBJ/finished.1 && fail "first mux process completed" +test -f $OBJ/finished.2 && fail "second mux process completed" +test -f $OBJ/finished.3 || fail "third mux process did not complete" +close_mux + # Set up a "slow sftp server" that sleeps before executing the real one. cat > $OBJ/slow-sftp-server.sh << _EOF #!/bin/sh @@ -88,4 +155,3 @@ if [ $r -ne 0 ]; then fail "sftp failed" fi cmp $DATA $COPY || fail "corrupted copy" - From afcc9028bfc411bc26d20bba803b83f90cb84e26 Mon Sep 17 00:00:00 2001 From: "jmc@openbsd.org" Date: Wed, 10 Jan 2024 06:33:13 +0000 Subject: [PATCH 4/9] upstream: fix incorrect capitalisation; OpenBSD-Commit-ID: cb07eb06e15fa2334660ac73e98f29b6a1931984 --- ssh_config.5 | 6 +++--- sshd_config.5 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ssh_config.5 b/ssh_config.5 index 15ad012f8..35aa2c0cc 100644 --- a/ssh_config.5 +++ b/ssh_config.5 @@ -33,8 +33,8 @@ .\" (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.392 2024/01/09 22:19:00 djm Exp $ -.Dd $Mdocdate: January 9 2024 $ +.\" $OpenBSD: ssh_config.5,v 1.393 2024/01/10 06:33:13 jmc Exp $ +.Dd $Mdocdate: January 10 2024 $ .Dt SSH_CONFIG 5 .Os .Sh NAME @@ -481,7 +481,7 @@ Specifying a zero value disables the inactivity timeout. .Pp The special timeout .Dq global -Applies to all active channels, taken together. +applies to all active channels, taken together. Traffic on any active channel will reset the timeout, but when the timeout expires then all open channels will be closed. Note that this global timeout is not matched by wildcards and must be diff --git a/sshd_config.5 b/sshd_config.5 index ca5eeb59d..3e0befab1 100644 --- a/sshd_config.5 +++ b/sshd_config.5 @@ -33,8 +33,8 @@ .\" (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.351 2024/01/09 22:19:00 djm Exp $ -.Dd $Mdocdate: January 9 2024 $ +.\" $OpenBSD: sshd_config.5,v 1.352 2024/01/10 06:33:13 jmc Exp $ +.Dd $Mdocdate: January 10 2024 $ .Dt SSHD_CONFIG 5 .Os .Sh NAME @@ -427,7 +427,7 @@ Specifying a zero value disables the inactivity timeout. .Pp The special timeout .Dq global -Applies to all active channels, taken together. +applies to all active channels, taken together. Traffic on any active channel will reset the timeout, but when the timeout expires then all open channels will be closed. Note that this global timeout is not matched by wildcards and must be From 4e838120a759d187b036036610402cbda33f3203 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Thu, 11 Jan 2024 01:45:36 +0000 Subject: [PATCH 5/9] upstream: make DSA key support compile-time optional, defaulting to on ok markus@ OpenBSD-Commit-ID: 4f8e98fc1fd6de399d0921d5b31b3127a03f581d --- configure.ac | 12 ++++++++++++ readconf.c | 4 +++- readconf.h | 4 ++-- ssh-add.c | 4 +++- ssh-dss.c | 7 ++++--- ssh-keygen.c | 26 ++++++++++++++++++++++---- ssh-keyscan.c | 4 +++- ssh-keysign.c | 4 +++- ssh.c | 6 +++++- sshconnect.c | 4 +++- sshkey.c | 10 +++++++++- 11 files changed, 69 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 379cd746b..acea84ca3 100644 --- a/configure.ac +++ b/configure.ac @@ -2067,6 +2067,18 @@ AC_ARG_WITH([security-key-builtin], [ enable_sk_internal=$withval ] ) +disable_ecdsa= +AC_ARG_ENABLE([dsa-keys], + [ --disable-dsa-keys disable DSA key support [no]], + [ + if test "x$enableval" = "xno" ; then + disable_ecdsa=1 + fi + ] +) +test -z "$disable_ecdsa" && + AC_DEFINE([WITH_DSA], [1], [Define if to enable DSA keys.]) + AC_SEARCH_LIBS([dlopen], [dl]) AC_CHECK_FUNCS([dlopen]) AC_CHECK_DECL([RTLD_NOW], [], [], [#include ]) diff --git a/readconf.c b/readconf.c index a2282b562..7b3754283 100644 --- a/readconf.c +++ b/readconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readconf.c,v 1.383 2023/10/12 02:18:18 djm Exp $ */ +/* $OpenBSD: readconf.c,v 1.384 2024/01/11 01:45:36 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -2711,7 +2711,9 @@ fill_default_options(Options * options) add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_ED25519_SK, 0); add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_XMSS, 0); +#ifdef WITH_DSA add_identity_file(options, "~/", _PATH_SSH_CLIENT_ID_DSA, 0); +#endif } if (options->escape_char == -1) options->escape_char = '~'; diff --git a/readconf.h b/readconf.h index ff7180cd0..b18536ab9 100644 --- a/readconf.h +++ b/readconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: readconf.h,v 1.154 2023/10/12 02:18:18 djm Exp $ */ +/* $OpenBSD: readconf.h,v 1.155 2024/01/11 01:45:36 djm Exp $ */ /* * Author: Tatu Ylonen @@ -87,7 +87,7 @@ typedef struct { char *sk_provider; /* Security key provider */ int verify_host_key_dns; /* Verify host key using DNS */ - int num_identity_files; /* Number of files for RSA/DSA identities. */ + int num_identity_files; /* Number of files for identities. */ char *identity_files[SSH_MAX_IDENTITY_FILES]; int identity_file_userprovided[SSH_MAX_IDENTITY_FILES]; struct sshkey *identity_keys[SSH_MAX_IDENTITY_FILES]; diff --git a/ssh-add.c b/ssh-add.c index 1ec6c89b0..e532d5ce1 100644 --- a/ssh-add.c +++ b/ssh-add.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-add.c,v 1.171 2024/01/08 00:30:39 djm Exp $ */ +/* $OpenBSD: ssh-add.c,v 1.172 2024/01/11 01:45:36 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -85,7 +85,9 @@ static char *default_files[] = { _PATH_SSH_CLIENT_ID_ED25519, _PATH_SSH_CLIENT_ID_ED25519_SK, _PATH_SSH_CLIENT_ID_XMSS, +#ifdef WITH_DSA _PATH_SSH_CLIENT_ID_DSA, +#endif NULL }; diff --git a/ssh-dss.c b/ssh-dss.c index 3174ef146..aea661377 100644 --- a/ssh-dss.c +++ b/ssh-dss.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-dss.c,v 1.49 2023/03/05 05:34:09 dtucker Exp $ */ +/* $OpenBSD: ssh-dss.c,v 1.50 2024/01/11 01:45:36 djm Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * @@ -25,7 +25,7 @@ #include "includes.h" -#ifdef WITH_OPENSSL +#if defined(WITH_OPENSSL) && defined(WITH_DSA) #include @@ -453,4 +453,5 @@ const struct sshkey_impl sshkey_dsa_cert_impl = { /* .keybits = */ 0, /* .funcs = */ &sshkey_dss_funcs, }; -#endif /* WITH_OPENSSL */ + +#endif /* WITH_OPENSSL && WITH_DSA */ diff --git a/ssh-keygen.c b/ssh-keygen.c index 5b945a849..97c6d134a 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keygen.c,v 1.471 2023/09/04 10:29:58 job Exp $ */ +/* $OpenBSD: ssh-keygen.c,v 1.472 2024/01/11 01:45:36 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1994 Tatu Ylonen , Espoo, Finland @@ -262,10 +262,12 @@ ask_filename(struct passwd *pw, const char *prompt) name = _PATH_SSH_CLIENT_ID_ED25519; else { switch (sshkey_type_from_name(key_type_name)) { +#ifdef WITH_DSA case KEY_DSA_CERT: case KEY_DSA: name = _PATH_SSH_CLIENT_ID_DSA; break; +#endif #ifdef OPENSSL_HAS_ECC case KEY_ECDSA_CERT: case KEY_ECDSA: @@ -376,10 +378,12 @@ do_convert_to_pkcs8(struct sshkey *k) if (!PEM_write_RSA_PUBKEY(stdout, k->rsa)) fatal("PEM_write_RSA_PUBKEY failed"); break; +#ifdef WITH_DSA case KEY_DSA: if (!PEM_write_DSA_PUBKEY(stdout, k->dsa)) fatal("PEM_write_DSA_PUBKEY failed"); break; +#endif #ifdef OPENSSL_HAS_ECC case KEY_ECDSA: if (!PEM_write_EC_PUBKEY(stdout, k->ecdsa)) @@ -400,10 +404,12 @@ do_convert_to_pem(struct sshkey *k) if (!PEM_write_RSAPublicKey(stdout, k->rsa)) fatal("PEM_write_RSAPublicKey failed"); break; +#ifdef WITH_DSA case KEY_DSA: if (!PEM_write_DSA_PUBKEY(stdout, k->dsa)) fatal("PEM_write_DSA_PUBKEY failed"); break; +#endif #ifdef OPENSSL_HAS_ECC case KEY_ECDSA: if (!PEM_write_EC_PUBKEY(stdout, k->ecdsa)) @@ -478,8 +484,10 @@ do_convert_private_ssh2(struct sshbuf *b) u_int magic, i1, i2, i3, i4; size_t slen; u_long e; +#ifdef WITH_DSA BIGNUM *dsa_p = NULL, *dsa_q = NULL, *dsa_g = NULL; BIGNUM *dsa_pub_key = NULL, *dsa_priv_key = NULL; +#endif BIGNUM *rsa_n = NULL, *rsa_e = NULL, *rsa_d = NULL; BIGNUM *rsa_p = NULL, *rsa_q = NULL, *rsa_iqmp = NULL; @@ -507,10 +515,12 @@ do_convert_private_ssh2(struct sshbuf *b) } free(cipher); - if (strstr(type, "dsa")) { - ktype = KEY_DSA; - } else if (strstr(type, "rsa")) { + if (strstr(type, "rsa")) { ktype = KEY_RSA; +#ifdef WITH_DSA + } else if (strstr(type, "dsa")) { + ktype = KEY_DSA; +#endif } else { free(type); return NULL; @@ -520,6 +530,7 @@ do_convert_private_ssh2(struct sshbuf *b) free(type); switch (key->type) { +#ifdef WITH_DSA case KEY_DSA: if ((dsa_p = BN_new()) == NULL || (dsa_q = BN_new()) == NULL || @@ -539,6 +550,7 @@ do_convert_private_ssh2(struct sshbuf *b) fatal_f("DSA_set0_key failed"); dsa_pub_key = dsa_priv_key = NULL; /* transferred */ break; +#endif case KEY_RSA: if ((r = sshbuf_get_u8(b, &e1)) != 0 || (e1 < 30 && (r = sshbuf_get_u8(b, &e2)) != 0) || @@ -702,12 +714,14 @@ do_convert_from_pkcs8(struct sshkey **k, int *private) (*k)->type = KEY_RSA; (*k)->rsa = EVP_PKEY_get1_RSA(pubkey); break; +#ifdef WITH_DSA case EVP_PKEY_DSA: if ((*k = sshkey_new(KEY_UNSPEC)) == NULL) fatal("sshkey_new failed"); (*k)->type = KEY_DSA; (*k)->dsa = EVP_PKEY_get1_DSA(pubkey); break; +#endif #ifdef OPENSSL_HAS_ECC case EVP_PKEY_EC: if ((*k = sshkey_new(KEY_UNSPEC)) == NULL) @@ -777,10 +791,12 @@ do_convert_from(struct passwd *pw) fprintf(stdout, "\n"); } else { switch (k->type) { +#ifdef WITH_DSA case KEY_DSA: ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, NULL, 0, NULL, NULL); break; +#endif #ifdef OPENSSL_HAS_ECC case KEY_ECDSA: ok = PEM_write_ECPrivateKey(stdout, k->ecdsa, NULL, @@ -3752,9 +3768,11 @@ main(int argc, char **argv) n += do_print_resource_record(pw, _PATH_HOST_RSA_KEY_FILE, rr_hostname, print_generic, opts, nopts); +#ifdef WITH_DSA n += do_print_resource_record(pw, _PATH_HOST_DSA_KEY_FILE, rr_hostname, print_generic, opts, nopts); +#endif n += do_print_resource_record(pw, _PATH_HOST_ECDSA_KEY_FILE, rr_hostname, print_generic, opts, nopts); diff --git a/ssh-keyscan.c b/ssh-keyscan.c index af0dc79b8..f2e6b59e3 100644 --- a/ssh-keyscan.c +++ b/ssh-keyscan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keyscan.c,v 1.154 2023/12/20 00:06:25 jsg Exp $ */ +/* $OpenBSD: ssh-keyscan.c,v 1.155 2024/01/11 01:45:36 djm Exp $ */ /* * Copyright 1995, 1996 by David Mazieres . * @@ -791,9 +791,11 @@ main(int argc, char **argv) int type = sshkey_type_from_name(tname); switch (type) { +#ifdef WITH_DSA case KEY_DSA: get_keytypes |= KT_DSA; break; +#endif case KEY_ECDSA: get_keytypes |= KT_ECDSA; break; diff --git a/ssh-keysign.c b/ssh-keysign.c index b989f5e94..29bd65351 100644 --- a/ssh-keysign.c +++ b/ssh-keysign.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keysign.c,v 1.71 2022/08/01 11:09:26 djm Exp $ */ +/* $OpenBSD: ssh-keysign.c,v 1.72 2024/01/11 01:45:36 djm Exp $ */ /* * Copyright (c) 2002 Markus Friedl. All rights reserved. * @@ -197,7 +197,9 @@ main(int argc, char **argv) i = 0; /* XXX This really needs to read sshd_config for the paths */ +#ifdef WITH_DSA key_fd[i++] = open(_PATH_HOST_DSA_KEY_FILE, O_RDONLY); +#endif key_fd[i++] = open(_PATH_HOST_ECDSA_KEY_FILE, O_RDONLY); key_fd[i++] = open(_PATH_HOST_ED25519_KEY_FILE, O_RDONLY); key_fd[i++] = open(_PATH_HOST_XMSS_KEY_FILE, O_RDONLY); diff --git a/ssh.c b/ssh.c index 48d93ddf2..0019281f4 100644 --- a/ssh.c +++ b/ssh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh.c,v 1.599 2023/12/18 14:47:44 djm Exp $ */ +/* $OpenBSD: ssh.c,v 1.600 2024/01/11 01:45:36 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1687,11 +1687,15 @@ main(int ac, char **av) L_CERT(_PATH_HOST_ECDSA_KEY_FILE, 0); L_CERT(_PATH_HOST_ED25519_KEY_FILE, 1); L_CERT(_PATH_HOST_RSA_KEY_FILE, 2); +#ifdef WITH_DSA L_CERT(_PATH_HOST_DSA_KEY_FILE, 3); +#endif L_PUBKEY(_PATH_HOST_ECDSA_KEY_FILE, 4); L_PUBKEY(_PATH_HOST_ED25519_KEY_FILE, 5); L_PUBKEY(_PATH_HOST_RSA_KEY_FILE, 6); +#ifdef WITH_DSA L_PUBKEY(_PATH_HOST_DSA_KEY_FILE, 7); +#endif L_CERT(_PATH_HOST_XMSS_KEY_FILE, 8); L_PUBKEY(_PATH_HOST_XMSS_KEY_FILE, 9); if (loaded == 0) diff --git a/sshconnect.c b/sshconnect.c index bd077c75c..d8efc50ce 100644 --- a/sshconnect.c +++ b/sshconnect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshconnect.c,v 1.365 2023/11/20 02:50:00 djm Exp $ */ +/* $OpenBSD: sshconnect.c,v 1.366 2024/01/11 01:45:36 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1595,7 +1595,9 @@ show_other_keys(struct hostkeys *hostkeys, struct sshkey *key) { int type[] = { KEY_RSA, +#ifdef WITH_DSA KEY_DSA, +#endif KEY_ECDSA, KEY_ED25519, KEY_XMSS, diff --git a/sshkey.c b/sshkey.c index 0705674b8..d4356e72c 100644 --- a/sshkey.c +++ b/sshkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshkey.c,v 1.141 2023/12/20 00:06:25 jsg Exp $ */ +/* $OpenBSD: sshkey.c,v 1.142 2024/01/11 01:45:36 djm Exp $ */ /* * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. * Copyright (c) 2008 Alexander von Gernler. All rights reserved. @@ -121,8 +121,10 @@ extern const struct sshkey_impl sshkey_rsa_sha256_impl; extern const struct sshkey_impl sshkey_rsa_sha256_cert_impl; extern const struct sshkey_impl sshkey_rsa_sha512_impl; extern const struct sshkey_impl sshkey_rsa_sha512_cert_impl; +# ifdef WITH_DSA extern const struct sshkey_impl sshkey_dss_impl; extern const struct sshkey_impl sshkey_dsa_cert_impl; +# endif #endif /* WITH_OPENSSL */ #ifdef WITH_XMSS extern const struct sshkey_impl sshkey_xmss_impl; @@ -152,8 +154,10 @@ const struct sshkey_impl * const keyimpls[] = { &sshkey_ecdsa_sk_webauthn_impl, # endif /* ENABLE_SK */ # endif /* OPENSSL_HAS_ECC */ +# ifdef WITH_DSA &sshkey_dss_impl, &sshkey_dsa_cert_impl, +# endif &sshkey_rsa_impl, &sshkey_rsa_cert_impl, &sshkey_rsa_sha256_impl, @@ -3230,6 +3234,7 @@ sshkey_private_to_blob_pem_pkcs8(struct sshkey *key, struct sshbuf *buf, goto out; switch (key->type) { +#ifdef WITH_DSA case KEY_DSA: if (format == SSHKEY_PRIVATE_PEM) { success = PEM_write_bio_DSAPrivateKey(bio, key->dsa, @@ -3238,6 +3243,7 @@ sshkey_private_to_blob_pem_pkcs8(struct sshkey *key, struct sshbuf *buf, success = EVP_PKEY_set1_DSA(pkey, key->dsa); } break; +#endif #ifdef OPENSSL_HAS_ECC case KEY_ECDSA: if (format == SSHKEY_PRIVATE_PEM) { @@ -3466,6 +3472,7 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, } if ((r = sshkey_check_rsa_length(prv, 0)) != 0) goto out; +#ifdef WITH_DSA } else if (EVP_PKEY_base_id(pk) == EVP_PKEY_DSA && (type == KEY_UNSPEC || type == KEY_DSA)) { if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) { @@ -3477,6 +3484,7 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type, #ifdef DEBUG_PK DSA_print_fp(stderr, prv->dsa, 8); #endif +#endif #ifdef OPENSSL_HAS_ECC } else if (EVP_PKEY_base_id(pk) == EVP_PKEY_EC && (type == KEY_UNSPEC || type == KEY_ECDSA)) { From f9311e8921d92c5efca767227a497ab63280ac39 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Thu, 11 Jan 2024 01:51:16 +0000 Subject: [PATCH 6/9] upstream: ensure key_fd is filled when DSA is disabled; spotted by tb@ OpenBSD-Commit-ID: 9dd417b6eec3cf67e870f147464a8d93f076dce7 --- ssh-keysign.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ssh-keysign.c b/ssh-keysign.c index 29bd65351..c54a4bbb7 100644 --- a/ssh-keysign.c +++ b/ssh-keysign.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keysign.c,v 1.72 2024/01/11 01:45:36 djm Exp $ */ +/* $OpenBSD: ssh-keysign.c,v 1.73 2024/01/11 01:51:16 djm Exp $ */ /* * Copyright (c) 2002 Markus Friedl. All rights reserved. * @@ -195,6 +195,9 @@ main(int argc, char **argv) if (fd > 2) close(fd); + for (i = 0; i < NUM_KEYTYPES; i++) + key_fd[i] = -1; + i = 0; /* XXX This really needs to read sshd_config for the paths */ #ifdef WITH_DSA From 415c94ce17288e0cdcb9e58cc91fba78d33c8457 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Thu, 11 Jan 2024 01:45:58 +0000 Subject: [PATCH 7/9] upstream: make DSA testing optional, defaulting to on ok markus OpenBSD-Regress-ID: dfc27b5574e3f19dc4043395594cea5f90b8572a --- regress/Makefile | 22 ++++++++++++++-------- regress/unittests/Makefile.inc | 7 ++++++- regress/unittests/hostkeys/test_iterate.c | 11 ++++++++++- regress/unittests/kex/test_kex.c | 4 +++- regress/unittests/sshkey/test_file.c | 4 +++- regress/unittests/sshkey/test_fuzz.c | 8 +++++++- regress/unittests/sshkey/test_sshkey.c | 23 +++++++++++++++-------- regress/unittests/sshsig/tests.c | 4 +++- 8 files changed, 61 insertions(+), 22 deletions(-) diff --git a/regress/Makefile b/regress/Makefile index f5cb9bd47..8add2f5cf 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.131 2023/12/18 14:50:08 djm Exp $ +# $OpenBSD: Makefile,v 1.132 2024/01/11 01:45:58 djm Exp $ tests: prep file-tests t-exec unit @@ -180,10 +180,12 @@ t5: awk '{print $$2}' | diff - ${.CURDIR}/t5.ok t6: - ${TEST_SSH_SSHKEYGEN} -if ${.CURDIR}/dsa_ssh2.prv > $(OBJ)/t6.out1 - ${TEST_SSH_SSHKEYGEN} -if ${.CURDIR}/dsa_ssh2.pub > $(OBJ)/t6.out2 - chmod 600 $(OBJ)/t6.out1 - ${TEST_SSH_SSHKEYGEN} -yf $(OBJ)/t6.out1 | diff - $(OBJ)/t6.out2 + set -xe ; if ${TEST_SSH_SSH} -Q key | grep -q ^ssh-dss ; then \ + ${TEST_SSH_SSHKEYGEN} -if ${.CURDIR}/dsa_ssh2.prv > $(OBJ)/t6.out1 ; \ + ${TEST_SSH_SSHKEYGEN} -if ${.CURDIR}/dsa_ssh2.pub > $(OBJ)/t6.out2 ; \ + chmod 600 $(OBJ)/t6.out1 ; \ + ${TEST_SSH_SSHKEYGEN} -yf $(OBJ)/t6.out1 | diff - $(OBJ)/t6.out2 ; \ + fi $(OBJ)/t7.out: ${TEST_SSH_SSHKEYGEN} -q -t rsa -N '' -f $@ @@ -193,11 +195,15 @@ t7: $(OBJ)/t7.out ${TEST_SSH_SSHKEYGEN} -Bf $(OBJ)/t7.out > /dev/null $(OBJ)/t8.out: - ${TEST_SSH_SSHKEYGEN} -q -t dsa -N '' -f $@ + set -xe ; if ssh -Q key | grep -q ^ssh-dss ; then \ + ${TEST_SSH_SSHKEYGEN} -q -t dsa -N '' -f $@ ; \ + fi t8: $(OBJ)/t8.out - ${TEST_SSH_SSHKEYGEN} -lf $(OBJ)/t8.out > /dev/null - ${TEST_SSH_SSHKEYGEN} -Bf $(OBJ)/t8.out > /dev/null + set -xe ; if ssh -Q key | grep -q ^ssh-dss ; then \ + ${TEST_SSH_SSHKEYGEN} -lf $(OBJ)/t8.out > /dev/null ; \ + ${TEST_SSH_SSHKEYGEN} -Bf $(OBJ)/t8.out > /dev/null ; \ + fi $(OBJ)/t9.out: ! ${TEST_SSH_SSH} -Q key-plain | grep ecdsa >/dev/null || \ diff --git a/regress/unittests/Makefile.inc b/regress/unittests/Makefile.inc index 623896ffa..98e280486 100644 --- a/regress/unittests/Makefile.inc +++ b/regress/unittests/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.15 2023/09/24 08:14:13 claudio Exp $ +# $OpenBSD: Makefile.inc,v 1.16 2024/01/11 01:45:58 djm Exp $ .include .include @@ -13,6 +13,11 @@ TEST_ENV?= MALLOC_OPTIONS=${MALLOC_OPTIONS} # XXX detect from ssh binary? OPENSSL?= yes +DSAKEY?= yes + +.if (${DSAKEY:L} == "yes") +CFLAGS+= -DWITH_DSA +.endif .if (${OPENSSL:L} == "yes") CFLAGS+= -DWITH_OPENSSL diff --git a/regress/unittests/hostkeys/test_iterate.c b/regress/unittests/hostkeys/test_iterate.c index 84f26b5c7..7efb8e1b9 100644 --- a/regress/unittests/hostkeys/test_iterate.c +++ b/regress/unittests/hostkeys/test_iterate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_iterate.c,v 1.8 2021/12/14 21:25:27 deraadt Exp $ */ +/* $OpenBSD: test_iterate.c,v 1.9 2024/01/11 01:45:58 djm Exp $ */ /* * Regress test for hostfile.h hostkeys_foreach() * @@ -94,6 +94,11 @@ check(struct hostkey_foreach_line *l, void *_ctx) expected->no_parse_keytype == KEY_ECDSA) skip = 1; #endif /* OPENSSL_HAS_ECC */ +#ifndef WITH_DSA + if (expected->l.keytype == KEY_DSA || + expected->no_parse_keytype == KEY_DSA) + skip = 1; +#endif #ifndef WITH_OPENSSL if (expected->l.keytype == KEY_DSA || expected->no_parse_keytype == KEY_DSA || @@ -155,6 +160,10 @@ prepare_expected(struct expected *expected, size_t n) if (expected[i].l.keytype == KEY_ECDSA) continue; #endif /* OPENSSL_HAS_ECC */ +#ifndef WITH_DSA + if (expected[i].l.keytype == KEY_DSA) + continue; +#endif #ifndef WITH_OPENSSL switch (expected[i].l.keytype) { case KEY_RSA: diff --git a/regress/unittests/kex/test_kex.c b/regress/unittests/kex/test_kex.c index c26761ee7..dc1014ea4 100644 --- a/regress/unittests/kex/test_kex.c +++ b/regress/unittests/kex/test_kex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_kex.c,v 1.6 2021/12/14 21:25:27 deraadt Exp $ */ +/* $OpenBSD: test_kex.c,v 1.7 2024/01/11 01:45:58 djm Exp $ */ /* * Regress test KEX * @@ -179,7 +179,9 @@ do_kex(char *kex) { #ifdef WITH_OPENSSL do_kex_with_key(kex, KEY_RSA, 2048); +#ifdef WITH_DSA do_kex_with_key(kex, KEY_DSA, 1024); +#endif #ifdef OPENSSL_HAS_ECC do_kex_with_key(kex, KEY_ECDSA, 256); #endif /* OPENSSL_HAS_ECC */ diff --git a/regress/unittests/sshkey/test_file.c b/regress/unittests/sshkey/test_file.c index 488944c3b..452840596 100644 --- a/regress/unittests/sshkey/test_file.c +++ b/regress/unittests/sshkey/test_file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_file.c,v 1.10 2021/12/14 21:25:27 deraadt Exp $ */ +/* $OpenBSD: test_file.c,v 1.11 2024/01/11 01:45:58 djm Exp $ */ /* * Regress test for sshkey.h key management API * @@ -165,6 +165,7 @@ sshkey_file_tests(void) sshkey_free(k1); +#ifdef WITH_DSA TEST_START("parse DSA from private"); buf = load_file("dsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -255,6 +256,7 @@ sshkey_file_tests(void) TEST_DONE(); sshkey_free(k1); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("parse ECDSA from private"); diff --git a/regress/unittests/sshkey/test_fuzz.c b/regress/unittests/sshkey/test_fuzz.c index 2fae19dcf..0aff7c9bf 100644 --- a/regress/unittests/sshkey/test_fuzz.c +++ b/regress/unittests/sshkey/test_fuzz.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_fuzz.c,v 1.13 2021/12/14 21:25:27 deraadt Exp $ */ +/* $OpenBSD: test_fuzz.c,v 1.14 2024/01/11 01:45:58 djm Exp $ */ /* * Fuzz tests for key parsing * @@ -160,6 +160,7 @@ sshkey_fuzz_tests(void) fuzz_cleanup(fuzz); TEST_DONE(); +#ifdef WITH_DSA TEST_START("fuzz DSA private"); buf = load_file("dsa_1"); fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), @@ -203,6 +204,7 @@ sshkey_fuzz_tests(void) sshbuf_free(fuzzed); fuzz_cleanup(fuzz); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("fuzz ECDSA private"); @@ -288,6 +290,7 @@ sshkey_fuzz_tests(void) sshkey_free(k1); TEST_DONE(); +#ifdef WITH_DSA TEST_START("fuzz DSA public"); buf = load_file("dsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -301,6 +304,7 @@ sshkey_fuzz_tests(void) public_fuzz(k1); sshkey_free(k1); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("fuzz ECDSA public"); @@ -358,6 +362,7 @@ sshkey_fuzz_tests(void) sshkey_free(k1); TEST_DONE(); +#ifdef WITH_DSA TEST_START("fuzz DSA sig"); buf = load_file("dsa_1"); ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); @@ -365,6 +370,7 @@ sshkey_fuzz_tests(void) sig_fuzz(k1, NULL); sshkey_free(k1); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("fuzz ECDSA sig"); diff --git a/regress/unittests/sshkey/test_sshkey.c b/regress/unittests/sshkey/test_sshkey.c index cc359aea5..c1cbb1128 100644 --- a/regress/unittests/sshkey/test_sshkey.c +++ b/regress/unittests/sshkey/test_sshkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_sshkey.c,v 1.23 2023/01/04 22:48:57 tb Exp $ */ +/* $OpenBSD: test_sshkey.c,v 1.24 2024/01/11 01:45:58 djm Exp $ */ /* * Regress test for sshkey.h key management API * @@ -180,14 +180,14 @@ get_private(const char *n) void sshkey_tests(void) { - struct sshkey *k1, *k2, *k3, *kf; + struct sshkey *k1 = NULL, *k2 = NULL, *k3 = NULL, *kf = NULL; #ifdef WITH_OPENSSL - struct sshkey *k4, *kr, *kd; + struct sshkey *k4 = NULL, *kr = NULL, *kd = NULL; #ifdef OPENSSL_HAS_ECC - struct sshkey *ke; + struct sshkey *ke = NULL; #endif /* OPENSSL_HAS_ECC */ #endif /* WITH_OPENSSL */ - struct sshbuf *b; + struct sshbuf *b = NULL; TEST_START("new invalid"); k1 = sshkey_new(-42); @@ -208,12 +208,14 @@ sshkey_tests(void) sshkey_free(k1); TEST_DONE(); +#ifdef WITH_DSA TEST_START("new/free KEY_DSA"); k1 = sshkey_new(KEY_DSA); ASSERT_PTR_NE(k1, NULL); ASSERT_PTR_NE(k1->dsa, NULL); sshkey_free(k1); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("new/free KEY_ECDSA"); @@ -245,12 +247,14 @@ sshkey_tests(void) ASSERT_PTR_EQ(k1, NULL); TEST_DONE(); +#ifdef WITH_DSA TEST_START("generate KEY_DSA wrong bits"); ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 2048, &k1), SSH_ERR_KEY_LENGTH); ASSERT_PTR_EQ(k1, NULL); sshkey_free(k1); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("generate KEY_ECDSA wrong bits"); @@ -273,6 +277,7 @@ sshkey_tests(void) ASSERT_INT_EQ(BN_num_bits(rsa_n(kr)), 1024); TEST_DONE(); +#ifdef WITH_DSA TEST_START("generate KEY_DSA"); ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0); ASSERT_PTR_NE(kd, NULL); @@ -280,6 +285,7 @@ sshkey_tests(void) ASSERT_PTR_NE(dsa_g(kd), NULL); ASSERT_PTR_NE(dsa_priv_key(kd), NULL); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("generate KEY_ECDSA"); @@ -317,6 +323,7 @@ sshkey_tests(void) sshkey_free(k1); TEST_DONE(); +#ifdef WITH_DSA TEST_START("demote KEY_DSA"); ASSERT_INT_EQ(sshkey_from_private(kd, &k1), 0); ASSERT_PTR_NE(k1, NULL); @@ -331,6 +338,7 @@ sshkey_tests(void) ASSERT_INT_EQ(sshkey_equal(kd, k1), 1); sshkey_free(k1); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("demote KEY_ECDSA"); @@ -382,9 +390,6 @@ sshkey_tests(void) ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0); ASSERT_INT_EQ(sshkey_equal(kr, k1), 0); sshkey_free(k1); - ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &k1), 0); - ASSERT_INT_EQ(sshkey_equal(kd, k1), 0); - sshkey_free(k1); #ifdef OPENSSL_HAS_ECC ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0); ASSERT_INT_EQ(sshkey_equal(ke, k1), 0); @@ -479,6 +484,7 @@ sshkey_tests(void) sshkey_free(k2); TEST_DONE(); +#ifdef WITH_DSA TEST_START("sign and verify DSA"); k1 = get_private("dsa_1"); ASSERT_INT_EQ(sshkey_load_public(test_data_file("dsa_2.pub"), &k2, @@ -487,6 +493,7 @@ sshkey_tests(void) sshkey_free(k1); sshkey_free(k2); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("sign and verify ECDSA"); diff --git a/regress/unittests/sshsig/tests.c b/regress/unittests/sshsig/tests.c index 13cfcfde2..80966bdd2 100644 --- a/regress/unittests/sshsig/tests.c +++ b/regress/unittests/sshsig/tests.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tests.c,v 1.3 2021/12/14 21:25:27 deraadt Exp $ */ +/* $OpenBSD: tests.c,v 1.4 2024/01/11 01:45:59 djm Exp $ */ /* * Regress test for sshbuf.h buffer API * @@ -103,9 +103,11 @@ tests(void) check_sig("rsa.pub", "rsa.sig", msg, namespace); TEST_DONE(); +#ifdef WITH_DSA TEST_START("check DSA signature"); check_sig("dsa.pub", "dsa.sig", msg, namespace); TEST_DONE(); +#endif #ifdef OPENSSL_HAS_ECC TEST_START("check ECDSA signature"); From 50080fa42f5f744b798ee29400c0710f1b59f50e Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Thu, 11 Jan 2024 04:50:28 +0000 Subject: [PATCH 8/9] upstream: don't disable RSA test when DSA is disabled; bug introduced in last commit OpenBSD-Regress-ID: 8780a7250bf742b33010e9336359a1c516f2d7b5 --- regress/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regress/Makefile b/regress/Makefile index 8add2f5cf..ca9c66e19 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.132 2024/01/11 01:45:58 djm Exp $ +# $OpenBSD: Makefile,v 1.133 2024/01/11 04:50:28 djm Exp $ tests: prep file-tests t-exec unit From 0d96b1506b2f4757fefa5d1f884d49e96a6fd4c3 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 16 Jan 2024 14:40:18 +1100 Subject: [PATCH 9/9] skip tests that use multiplexing on Windows Some tests here use multiplexing, skip these if DISABLE_FD_PASSING is set. Should unbreak tests on Windows. --- regress/channel-timeout.sh | 68 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/regress/channel-timeout.sh b/regress/channel-timeout.sh index 4293f0179..97708f2a2 100644 --- a/regress/channel-timeout.sh +++ b/regress/channel-timeout.sh @@ -74,40 +74,44 @@ if [ $r -ne 23 ]; then fail "ssh failed" fi -verbose "multiplexed command timeout" -(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=1") \ - > $OBJ/sshd_proxy -open_mux -mux_client "sleep 5 ; exit 23" -r=$? -if [ $r -ne 255 ]; then - fail "ssh returned unexpected error code $r" -fi -close_mux +if config_defined DISABLE_FD_PASSING ; then + verbose "skipping multiplexing tests" +else + verbose "multiplexed command timeout" + (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:command=1") \ + > $OBJ/sshd_proxy + open_mux + mux_client "sleep 5 ; exit 23" + r=$? + if [ $r -ne 255 ]; then + fail "ssh returned unexpected error code $r" + fi + close_mux -verbose "irrelevant multiplexed command timeout" -(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:shell=1") \ - > $OBJ/sshd_proxy -open_mux -mux_client "sleep 5 ; exit 23" -r=$? -if [ $r -ne 23 ]; then - fail "ssh returned unexpected error code $r" -fi -close_mux + verbose "irrelevant multiplexed command timeout" + (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout session:shell=1") \ + > $OBJ/sshd_proxy + open_mux + mux_client "sleep 5 ; exit 23" + r=$? + if [ $r -ne 23 ]; then + fail "ssh returned unexpected error code $r" + fi + close_mux -verbose "global command timeout" -(cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout global=10") \ - > $OBJ/sshd_proxy -open_mux -mux_client "sleep 1 ; echo ok ; sleep 1; echo ok; sleep 60; touch $OBJ/finished.1" >/dev/null & -mux_client "sleep 60 ; touch $OBJ/finished.2" >/dev/null & -mux_client "sleep 2 ; touch $OBJ/finished.3" >/dev/null & -wait -test -f $OBJ/finished.1 && fail "first mux process completed" -test -f $OBJ/finished.2 && fail "second mux process completed" -test -f $OBJ/finished.3 || fail "third mux process did not complete" -close_mux + verbose "global command timeout" + (cat $OBJ/sshd_proxy.orig ; echo "ChannelTimeout global=10") \ + > $OBJ/sshd_proxy + open_mux + mux_client "sleep 1 ; echo ok ; sleep 1; echo ok; sleep 60; touch $OBJ/finished.1" >/dev/null & + mux_client "sleep 60 ; touch $OBJ/finished.2" >/dev/null & + mux_client "sleep 2 ; touch $OBJ/finished.3" >/dev/null & + wait + test -f $OBJ/finished.1 && fail "first mux process completed" + test -f $OBJ/finished.2 && fail "second mux process completed" + test -f $OBJ/finished.3 || fail "third mux process did not complete" + close_mux +fi # Set up a "slow sftp server" that sleeps before executing the real one. cat > $OBJ/slow-sftp-server.sh << _EOF