From eb7320592ee00436b07eb53584e3aa56fcf99383 Mon Sep 17 00:00:00 2001
From: Kees Cook <kees@debian.org>
Date: Sun, 9 Feb 2014 16:10:06 +0000
Subject: Add DebianBanner server configuration option

Setting this to "no" causes sshd to omit the Debian revision from its
initial protocol handshake, for those scared by package-versioning.patch.

Bug-Debian: http://bugs.debian.org/562048
Forwarded: not-needed
Last-Update: 2021-11-05

Patch-Name: debian-banner.patch
---
 kex.c         | 5 +++--
 kex.h         | 2 +-
 servconf.c    | 9 +++++++++
 servconf.h    | 2 ++
 sshconnect.c  | 2 +-
 sshd.c        | 2 +-
 sshd_config.5 | 5 +++++
 7 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/kex.c b/kex.c
index d9a97b253..3f4fe6de7 100644
--- a/kex.c
+++ b/kex.c
@@ -1272,7 +1272,7 @@ send_error(struct ssh *ssh, char *msg)
  */
 int
 kex_exchange_identification(struct ssh *ssh, int timeout_ms,
-    const char *version_addendum)
+    int debian_banner, const char *version_addendum)
 {
 	int remote_major, remote_minor, mismatch, oerrno = 0;
 	size_t len, i, n;
@@ -1290,7 +1290,8 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
 	if (version_addendum != NULL && *version_addendum == '\0')
 		version_addendum = NULL;
 	if ((r = sshbuf_putf(our_version, "SSH-%d.%d-%.100s%s%s\r\n",
-	    PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_RELEASE,
+	    PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2,
+	    debian_banner ? SSH_RELEASE : SSH_RELEASE_MINIMUM,
 	    version_addendum == NULL ? "" : " ",
 	    version_addendum == NULL ? "" : version_addendum)) != 0) {
 		oerrno = errno;
diff --git a/kex.h b/kex.h
index 240dca89d..e356f5ed0 100644
--- a/kex.h
+++ b/kex.h
@@ -200,7 +200,7 @@ char	*kex_names_cat(const char *, const char *);
 int	 kex_assemble_names(char **, const char *, const char *);
 int	 kex_gss_names_valid(const char *);
 
-int	 kex_exchange_identification(struct ssh *, int, const char *);
+int	 kex_exchange_identification(struct ssh *, int, int, const char *);
 
 struct kex *kex_new(void);
 int	 kex_ready(struct ssh *, char *[PROPOSAL_MAX]);
diff --git a/servconf.c b/servconf.c
index 27c648b02..823155248 100644
--- a/servconf.c
+++ b/servconf.c
@@ -199,6 +199,7 @@ initialize_server_options(ServerOptions *options)
 	options->fingerprint_hash = -1;
 	options->disable_forwarding = -1;
 	options->expose_userauth_info = -1;
+	options->debian_banner = -1;
 }
 
 /* Returns 1 if a string option is unset or set to "none" or 0 otherwise. */
@@ -453,6 +454,8 @@ fill_default_server_options(ServerOptions *options)
 		options->expose_userauth_info = 0;
 	if (options->sk_provider == NULL)
 		options->sk_provider = xstrdup("internal");
+	if (options->debian_banner == -1)
+		options->debian_banner = 1;
 
 	assemble_algorithms(options);
 
@@ -530,6 +533,7 @@ typedef enum {
 	sStreamLocalBindMask, sStreamLocalBindUnlink,
 	sAllowStreamLocalForwarding, sFingerprintHash, sDisableForwarding,
 	sExposeAuthInfo, sRDomain, sPubkeyAuthOptions, sSecurityKeyProvider,
+	sDebianBanner,
 	sDeprecated, sIgnore, sUnsupported
 } ServerOpCodes;
 
@@ -700,6 +704,7 @@ static struct {
 	{ "rdomain", sRDomain, SSHCFG_ALL },
 	{ "casignaturealgorithms", sCASignatureAlgorithms, SSHCFG_ALL },
 	{ "securitykeyprovider", sSecurityKeyProvider, SSHCFG_GLOBAL },
+	{ "debianbanner", sDebianBanner, SSHCFG_GLOBAL },
 	{ NULL, sBadOption, 0 }
 };
 
@@ -2476,6 +2481,10 @@ process_server_config_line_depth(ServerOptions *options, char *line,
 			*charptr = xstrdup(arg);
 		break;
 
+	case sDebianBanner:
+		intptr = &options->debian_banner;
+		goto parse_flag;
+
 	case sDeprecated:
 	case sIgnore:
 	case sUnsupported:
diff --git a/servconf.h b/servconf.h
index 413413e94..f2d9b46fc 100644
--- a/servconf.h
+++ b/servconf.h
@@ -232,6 +232,8 @@ typedef struct {
 	int	expose_userauth_info;
 	u_int64_t timing_secret;
 	char   *sk_provider;
+
+	int	debian_banner;
 }       ServerOptions;
 
 /* Information about the incoming connection as used by Match */
diff --git a/sshconnect.c b/sshconnect.c
index 60cff2d87..6d5cea60b 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1560,7 +1560,7 @@ ssh_login(struct ssh *ssh, Sensitive *sensitive, const char *orighost,
 	lowercase(host);
 
 	/* Exchange protocol version identification strings with the server. */
-	if ((r = kex_exchange_identification(ssh, timeout_ms, NULL)) != 0)
+	if ((r = kex_exchange_identification(ssh, timeout_ms, 1, NULL)) != 0)
 		sshpkt_fatal(ssh, r, "banner exchange");
 
 	/* Put the connection into non-blocking mode. */
diff --git a/sshd.c b/sshd.c
index d920c16c2..f7f9e27dd 100644
--- a/sshd.c
+++ b/sshd.c
@@ -2218,7 +2218,7 @@ main(int ac, char **av)
 	if (!debug_flag)
 		alarm(options.login_grace_time);
 
-	if ((r = kex_exchange_identification(ssh, -1,
+	if ((r = kex_exchange_identification(ssh, -1, options.debian_banner,
 	    options.version_addendum)) != 0)
 		sshpkt_fatal(ssh, r, "banner exchange");
 
diff --git a/sshd_config.5 b/sshd_config.5
index 8f262365d..513468369 100644
--- a/sshd_config.5
+++ b/sshd_config.5
@@ -546,6 +546,11 @@ or
 .Cm no .
 The default is
 .Cm yes .
+.It Cm DebianBanner
+Specifies whether the distribution-specified extra version suffix is
+included during initial protocol handshake.
+The default is
+.Cm yes .
 .It Cm DenyGroups
 This keyword can be followed by a list of group name patterns, separated
 by spaces.
