Gentoo Archives: gentoo-commits

From: Patrick McLean <chutzpah@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: net-misc/openssh/files/, net-misc/openssh/
Date: Fri, 27 Aug 2021 00:13:10
Message-Id: 1630023182.4df896235ee386a1c1830b94bc86cb7a790c0fd7.chutzpah@gentoo
1 commit: 4df896235ee386a1c1830b94bc86cb7a790c0fd7
2 Author: Patrick McLean <chutzpah <AT> gentoo <DOT> org>
3 AuthorDate: Thu Aug 26 21:28:53 2021 +0000
4 Commit: Patrick McLean <chutzpah <AT> gentoo <DOT> org>
5 CommitDate: Fri Aug 27 00:13:02 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4df89623
7
8 net-misc/openssh-8.7_p1: Version bump, no X509 yet
9
10 Package-Manager: Portage-3.0.22, Repoman-3.0.3
11 Signed-off-by: Patrick McLean <chutzpah <AT> gentoo.org>
12
13 net-misc/openssh/Manifest | 2 +
14 .../openssh/files/openssh-8.7_p1-GSSAPI-dns.patch | 357 ++++++++++++++
15 .../files/openssh-8.7_p1-hpn-15.2-glue.patch | 198 ++++++++
16 net-misc/openssh/openssh-8.7_p1.ebuild | 513 +++++++++++++++++++++
17 4 files changed, 1070 insertions(+)
18
19 diff --git a/net-misc/openssh/Manifest b/net-misc/openssh/Manifest
20 index 7e7889daada..b6ea0efce2b 100644
21 --- a/net-misc/openssh/Manifest
22 +++ b/net-misc/openssh/Manifest
23 @@ -4,6 +4,8 @@ DIST openssh-8.5p1.tar.gz 1779733 BLAKE2B f4e4bd39e2dd275d4811e06ca994f2239ad27c
24 DIST openssh-8.6p1+x509-13.1.diff.gz 1011666 BLAKE2B 0ac0cf2ff962b8ef677c49de0bb586f375f14d8964e077c10f6a88ec15734807940ab6c0277e44ebdfde0e50c2c80103cff614a6cde4d66e9986152032eeaa90 SHA512 ae4986dd079678c7b0cfd805136ff7ac940d1049fdddeb5a7c4ea2141bfcca70463b951485fb2b113bc930f519b1b41562900ced0269f5673dbdad867f464251
25 DIST openssh-8.6p1-sctp-1.2.patch.xz 7696 BLAKE2B 37f9e943a1881af05d9cf2234433711dc45ca30c60af4c0ea38a1d361df02abb491fa114f3698285f582b40b838414c1a048c4f09aa4f7ae9499adb09201d2ac SHA512 ba8c4d38a3d90854e79dc18918fffde246d7609a3f1c3a35e06c0fbe33d3688ed29b0ec33556ae37d1654e1dc2133d892613ad8d1ecbdce9aaa5b9eb10dcbb7a
26 DIST openssh-8.6p1.tar.gz 1786328 BLAKE2B 261a0f1a6235275894d487cce37537755c86835e3a34871462fe29bfe72b49cd9a6b6a547aea4bd554f0957e110c84458cc75a5f2560717fb04804d62228562a SHA512 9854eda0b773c64c9f1f74844ce466b2b42ee8845f58ad062b73141d617af944fa4ebafdf72069f400106d2c2bd0a69c92fe805ec1fc26d4f0faadf06c3fbbe6
27 +DIST openssh-8.7p1-sctp-1.2.patch.xz 6740 BLAKE2B 468a455018ffddf4fa64d63acb732ad3e1fb722ae8b24d06cf3a683167a4580626b477bbc286f296c83d39dd36c101ac58597a21daa63de83ad55af00aa3a6be SHA512 aa9067c9025b6e4edfad5e45ec92da43db14edb11aae02cbbc296e66b48377cbbf62cdafcdd5edfd1fd4bf69420ee017223ab52e50a42b1976002d767984777c
28 +DIST openssh-8.7p1.tar.gz 1814595 BLAKE2B 9fdb8898485053d08c9eca419c15d0d03b7a60152cf6a9d7f1beed3a21c9e6ac3bd9f854580e6e474fb0c871f3d4be9ef4b49bee8c355d9e5769a5505f4e6ea9 SHA512 08c81024d9e1248abfda6cc874886ff5ae916669b93cd6aff640e0614ee8cbcbc3fe87a9ce47136b6443ddbb1168b114367c74e117551905994e1a7e3fa2c0c2
29 DIST openssh-8_5_P1-hpn-AES-CTR-15.2.diff 30096 BLAKE2B f0c020dd2403806c79d4c37a019996d275655b04997301e247f5c4dd7fad35d12b3b7c25afb1b078d915ef2a4ae02f736f0aec9ba2a8c56a405d7ca303bcadf7 SHA512 4c2dbf99a9b5953fdb955f700272bbaeaa025f108a8860d2190197962b849f8385327af82c4d6a3a130a7fba35a74a8ec9437d642867601acb29817c49632a8f
30 DIST openssh-8_5_P1-hpn-DynWinNoneSwitch-15.2.diff 51428 BLAKE2B 370b88a7da7f148bf5a4d445f05cf593b486e9df53bba027e2e179726f534b68cf9d94edd6e53024e0b6ff5f20e568727bc9d26c94d0d415603602a80d3ad241 SHA512 2d8d887901164b33b2799ff3ec72e86a39ae4a1696e52bcee0872dbae7772fcc534351e6e7f87126ee71b164c74e9091350f14b782f4b242a09f09b4f50d047a
31 DIST openssh-8_5_P1-hpn-PeakTput-15.2.diff 2429 BLAKE2B 849bf3c313719ab7a25c75e82d5dc5ac98365a038b2a66fe58d01eae5b20c7777258b94b5830e799d6909e75c69753cda05a910f3bdab9606fb7d5efa68e05f1 SHA512 c4a56fab55fabd1d902d45f235b603708d43f969920e45c9a57e557dccfa9cade2ec61f26d1ace938f6f73e79f17b12f119b5aea9166cbda8e3435b910500914
32
33 diff --git a/net-misc/openssh/files/openssh-8.7_p1-GSSAPI-dns.patch b/net-misc/openssh/files/openssh-8.7_p1-GSSAPI-dns.patch
34 new file mode 100644
35 index 00000000000..ffc40b70ae3
36 --- /dev/null
37 +++ b/net-misc/openssh/files/openssh-8.7_p1-GSSAPI-dns.patch
38 @@ -0,0 +1,357 @@
39 +diff --git a/auth.c b/auth.c
40 +index 00b168b4..8ee93581 100644
41 +--- a/auth.c
42 ++++ b/auth.c
43 +@@ -729,118 +729,6 @@ fakepw(void)
44 + return (&fake);
45 + }
46 +
47 +-/*
48 +- * Returns the remote DNS hostname as a string. The returned string must not
49 +- * be freed. NB. this will usually trigger a DNS query the first time it is
50 +- * called.
51 +- * This function does additional checks on the hostname to mitigate some
52 +- * attacks on based on conflation of hostnames and IP addresses.
53 +- */
54 +-
55 +-static char *
56 +-remote_hostname(struct ssh *ssh)
57 +-{
58 +- struct sockaddr_storage from;
59 +- socklen_t fromlen;
60 +- struct addrinfo hints, *ai, *aitop;
61 +- char name[NI_MAXHOST], ntop2[NI_MAXHOST];
62 +- const char *ntop = ssh_remote_ipaddr(ssh);
63 +-
64 +- /* Get IP address of client. */
65 +- fromlen = sizeof(from);
66 +- memset(&from, 0, sizeof(from));
67 +- if (getpeername(ssh_packet_get_connection_in(ssh),
68 +- (struct sockaddr *)&from, &fromlen) == -1) {
69 +- debug("getpeername failed: %.100s", strerror(errno));
70 +- return xstrdup(ntop);
71 +- }
72 +-
73 +- ipv64_normalise_mapped(&from, &fromlen);
74 +- if (from.ss_family == AF_INET6)
75 +- fromlen = sizeof(struct sockaddr_in6);
76 +-
77 +- debug3("Trying to reverse map address %.100s.", ntop);
78 +- /* Map the IP address to a host name. */
79 +- if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
80 +- NULL, 0, NI_NAMEREQD) != 0) {
81 +- /* Host name not found. Use ip address. */
82 +- return xstrdup(ntop);
83 +- }
84 +-
85 +- /*
86 +- * if reverse lookup result looks like a numeric hostname,
87 +- * someone is trying to trick us by PTR record like following:
88 +- * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5
89 +- */
90 +- memset(&hints, 0, sizeof(hints));
91 +- hints.ai_socktype = SOCK_DGRAM; /*dummy*/
92 +- hints.ai_flags = AI_NUMERICHOST;
93 +- if (getaddrinfo(name, NULL, &hints, &ai) == 0) {
94 +- logit("Nasty PTR record \"%s\" is set up for %s, ignoring",
95 +- name, ntop);
96 +- freeaddrinfo(ai);
97 +- return xstrdup(ntop);
98 +- }
99 +-
100 +- /* Names are stored in lowercase. */
101 +- lowercase(name);
102 +-
103 +- /*
104 +- * Map it back to an IP address and check that the given
105 +- * address actually is an address of this host. This is
106 +- * necessary because anyone with access to a name server can
107 +- * define arbitrary names for an IP address. Mapping from
108 +- * name to IP address can be trusted better (but can still be
109 +- * fooled if the intruder has access to the name server of
110 +- * the domain).
111 +- */
112 +- memset(&hints, 0, sizeof(hints));
113 +- hints.ai_family = from.ss_family;
114 +- hints.ai_socktype = SOCK_STREAM;
115 +- if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {
116 +- logit("reverse mapping checking getaddrinfo for %.700s "
117 +- "[%s] failed.", name, ntop);
118 +- return xstrdup(ntop);
119 +- }
120 +- /* Look for the address from the list of addresses. */
121 +- for (ai = aitop; ai; ai = ai->ai_next) {
122 +- if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2,
123 +- sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 &&
124 +- (strcmp(ntop, ntop2) == 0))
125 +- break;
126 +- }
127 +- freeaddrinfo(aitop);
128 +- /* If we reached the end of the list, the address was not there. */
129 +- if (ai == NULL) {
130 +- /* Address not found for the host name. */
131 +- logit("Address %.100s maps to %.600s, but this does not "
132 +- "map back to the address.", ntop, name);
133 +- return xstrdup(ntop);
134 +- }
135 +- return xstrdup(name);
136 +-}
137 +-
138 +-/*
139 +- * Return the canonical name of the host in the other side of the current
140 +- * connection. The host name is cached, so it is efficient to call this
141 +- * several times.
142 +- */
143 +-
144 +-const char *
145 +-auth_get_canonical_hostname(struct ssh *ssh, int use_dns)
146 +-{
147 +- static char *dnsname;
148 +-
149 +- if (!use_dns)
150 +- return ssh_remote_ipaddr(ssh);
151 +- else if (dnsname != NULL)
152 +- return dnsname;
153 +- else {
154 +- dnsname = remote_hostname(ssh);
155 +- return dnsname;
156 +- }
157 +-}
158 +-
159 + /* These functions link key/cert options to the auth framework */
160 +
161 + /* Log sshauthopt options locally and (optionally) for remote transmission */
162 +diff --git a/canohost.c b/canohost.c
163 +index a810da0e..18e9d8d4 100644
164 +--- a/canohost.c
165 ++++ b/canohost.c
166 +@@ -202,3 +202,117 @@ get_local_port(int sock)
167 + {
168 + return get_sock_port(sock, 1);
169 + }
170 ++
171 ++/*
172 ++ * Returns the remote DNS hostname as a string. The returned string must not
173 ++ * be freed. NB. this will usually trigger a DNS query the first time it is
174 ++ * called.
175 ++ * This function does additional checks on the hostname to mitigate some
176 ++ * attacks on legacy rhosts-style authentication.
177 ++ * XXX is RhostsRSAAuthentication vulnerable to these?
178 ++ * XXX Can we remove these checks? (or if not, remove RhostsRSAAuthentication?)
179 ++ */
180 ++
181 ++static char *
182 ++remote_hostname(struct ssh *ssh)
183 ++{
184 ++ struct sockaddr_storage from;
185 ++ socklen_t fromlen;
186 ++ struct addrinfo hints, *ai, *aitop;
187 ++ char name[NI_MAXHOST], ntop2[NI_MAXHOST];
188 ++ const char *ntop = ssh_remote_ipaddr(ssh);
189 ++
190 ++ /* Get IP address of client. */
191 ++ fromlen = sizeof(from);
192 ++ memset(&from, 0, sizeof(from));
193 ++ if (getpeername(ssh_packet_get_connection_in(ssh),
194 ++ (struct sockaddr *)&from, &fromlen) == -1) {
195 ++ debug("getpeername failed: %.100s", strerror(errno));
196 ++ return xstrdup(ntop);
197 ++ }
198 ++
199 ++ ipv64_normalise_mapped(&from, &fromlen);
200 ++ if (from.ss_family == AF_INET6)
201 ++ fromlen = sizeof(struct sockaddr_in6);
202 ++
203 ++ debug3("Trying to reverse map address %.100s.", ntop);
204 ++ /* Map the IP address to a host name. */
205 ++ if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
206 ++ NULL, 0, NI_NAMEREQD) != 0) {
207 ++ /* Host name not found. Use ip address. */
208 ++ return xstrdup(ntop);
209 ++ }
210 ++
211 ++ /*
212 ++ * if reverse lookup result looks like a numeric hostname,
213 ++ * someone is trying to trick us by PTR record like following:
214 ++ * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5
215 ++ */
216 ++ memset(&hints, 0, sizeof(hints));
217 ++ hints.ai_socktype = SOCK_DGRAM; /*dummy*/
218 ++ hints.ai_flags = AI_NUMERICHOST;
219 ++ if (getaddrinfo(name, NULL, &hints, &ai) == 0) {
220 ++ logit("Nasty PTR record \"%s\" is set up for %s, ignoring",
221 ++ name, ntop);
222 ++ freeaddrinfo(ai);
223 ++ return xstrdup(ntop);
224 ++ }
225 ++
226 ++ /* Names are stored in lowercase. */
227 ++ lowercase(name);
228 ++
229 ++ /*
230 ++ * Map it back to an IP address and check that the given
231 ++ * address actually is an address of this host. This is
232 ++ * necessary because anyone with access to a name server can
233 ++ * define arbitrary names for an IP address. Mapping from
234 ++ * name to IP address can be trusted better (but can still be
235 ++ * fooled if the intruder has access to the name server of
236 ++ * the domain).
237 ++ */
238 ++ memset(&hints, 0, sizeof(hints));
239 ++ hints.ai_family = from.ss_family;
240 ++ hints.ai_socktype = SOCK_STREAM;
241 ++ if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {
242 ++ logit("reverse mapping checking getaddrinfo for %.700s "
243 ++ "[%s] failed.", name, ntop);
244 ++ return xstrdup(ntop);
245 ++ }
246 ++ /* Look for the address from the list of addresses. */
247 ++ for (ai = aitop; ai; ai = ai->ai_next) {
248 ++ if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2,
249 ++ sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 &&
250 ++ (strcmp(ntop, ntop2) == 0))
251 ++ break;
252 ++ }
253 ++ freeaddrinfo(aitop);
254 ++ /* If we reached the end of the list, the address was not there. */
255 ++ if (ai == NULL) {
256 ++ /* Address not found for the host name. */
257 ++ logit("Address %.100s maps to %.600s, but this does not "
258 ++ "map back to the address.", ntop, name);
259 ++ return xstrdup(ntop);
260 ++ }
261 ++ return xstrdup(name);
262 ++}
263 ++
264 ++/*
265 ++ * Return the canonical name of the host in the other side of the current
266 ++ * connection. The host name is cached, so it is efficient to call this
267 ++ * several times.
268 ++ */
269 ++
270 ++const char *
271 ++auth_get_canonical_hostname(struct ssh *ssh, int use_dns)
272 ++{
273 ++ static char *dnsname;
274 ++
275 ++ if (!use_dns)
276 ++ return ssh_remote_ipaddr(ssh);
277 ++ else if (dnsname != NULL)
278 ++ return dnsname;
279 ++ else {
280 ++ dnsname = remote_hostname(ssh);
281 ++ return dnsname;
282 ++ }
283 ++}
284 +diff --git a/readconf.c b/readconf.c
285 +index 03369a08..b45898ce 100644
286 +--- a/readconf.c
287 ++++ b/readconf.c
288 +@@ -161,6 +161,7 @@ typedef enum {
289 + oClearAllForwardings, oNoHostAuthenticationForLocalhost,
290 + oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
291 + oAddressFamily, oGssAuthentication, oGssDelegateCreds,
292 ++ oGssTrustDns,
293 + oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
294 + oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
295 + oHashKnownHosts,
296 +@@ -207,9 +208,11 @@ static struct {
297 + #if defined(GSSAPI)
298 + { "gssapiauthentication", oGssAuthentication },
299 + { "gssapidelegatecredentials", oGssDelegateCreds },
300 ++ { "gssapitrustdns", oGssTrustDns },
301 + # else
302 + { "gssapiauthentication", oUnsupported },
303 + { "gssapidelegatecredentials", oUnsupported },
304 ++ { "gssapitrustdns", oUnsupported },
305 + #endif
306 + #ifdef ENABLE_PKCS11
307 + { "pkcs11provider", oPKCS11Provider },
308 +@@ -1117,6 +1120,10 @@ parse_time:
309 + intptr = &options->gss_deleg_creds;
310 + goto parse_flag;
311 +
312 ++ case oGssTrustDns:
313 ++ intptr = &options->gss_trust_dns;
314 ++ goto parse_flag;
315 ++
316 + case oBatchMode:
317 + intptr = &options->batch_mode;
318 + goto parse_flag;
319 +@@ -2307,6 +2314,7 @@ initialize_options(Options * options)
320 + options->pubkey_authentication = -1;
321 + options->gss_authentication = -1;
322 + options->gss_deleg_creds = -1;
323 ++ options->gss_trust_dns = -1;
324 + options->password_authentication = -1;
325 + options->kbd_interactive_authentication = -1;
326 + options->kbd_interactive_devices = NULL;
327 +@@ -2465,6 +2473,8 @@ fill_default_options(Options * options)
328 + options->gss_authentication = 0;
329 + if (options->gss_deleg_creds == -1)
330 + options->gss_deleg_creds = 0;
331 ++ if (options->gss_trust_dns == -1)
332 ++ options->gss_trust_dns = 0;
333 + if (options->password_authentication == -1)
334 + options->password_authentication = 1;
335 + if (options->kbd_interactive_authentication == -1)
336 +diff --git a/readconf.h b/readconf.h
337 +index f7d53b06..c3a91898 100644
338 +--- a/readconf.h
339 ++++ b/readconf.h
340 +@@ -40,6 +40,7 @@ typedef struct {
341 + int hostbased_authentication; /* ssh2's rhosts_rsa */
342 + int gss_authentication; /* Try GSS authentication */
343 + int gss_deleg_creds; /* Delegate GSS credentials */
344 ++ int gss_trust_dns; /* Trust DNS for GSS canonicalization */
345 + int password_authentication; /* Try password
346 + * authentication. */
347 + int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
348 +diff --git a/ssh_config.5 b/ssh_config.5
349 +index cd0eea86..27101943 100644
350 +--- a/ssh_config.5
351 ++++ b/ssh_config.5
352 +@@ -832,6 +832,16 @@ The default is
353 + Forward (delegate) credentials to the server.
354 + The default is
355 + .Cm no .
356 ++Note that this option applies to protocol version 2 connections using GSSAPI.
357 ++.It Cm GSSAPITrustDns
358 ++Set to
359 ++.Dq yes to indicate that the DNS is trusted to securely canonicalize
360 ++the name of the host being connected to. If
361 ++.Dq no, the hostname entered on the
362 ++command line will be passed untouched to the GSSAPI library.
363 ++The default is
364 ++.Dq no .
365 ++This option only applies to protocol version 2 connections using GSSAPI.
366 + .It Cm HashKnownHosts
367 + Indicates that
368 + .Xr ssh 1
369 +diff --git a/sshconnect2.c b/sshconnect2.c
370 +index fea50fab..aeff639b 100644
371 +--- a/sshconnect2.c
372 ++++ b/sshconnect2.c
373 +@@ -776,6 +776,13 @@ userauth_gssapi(struct ssh *ssh)
374 + OM_uint32 min;
375 + int r, ok = 0;
376 + gss_OID mech = NULL;
377 ++ const char *gss_host;
378 ++
379 ++ if (options.gss_trust_dns) {
380 ++ extern const char *auth_get_canonical_hostname(struct ssh *ssh, int use_dns);
381 ++ gss_host = auth_get_canonical_hostname(ssh, 1);
382 ++ } else
383 ++ gss_host = authctxt->host;
384 +
385 + /* Try one GSSAPI method at a time, rather than sending them all at
386 + * once. */
387 +@@ -790,7 +797,7 @@ userauth_gssapi(struct ssh *ssh)
388 + elements[authctxt->mech_tried];
389 + /* My DER encoding requires length<128 */
390 + if (mech->length < 128 && ssh_gssapi_check_mechanism(&gssctxt,
391 +- mech, authctxt->host)) {
392 ++ mech, gss_host)) {
393 + ok = 1; /* Mechanism works */
394 + } else {
395 + authctxt->mech_tried++;
396
397 diff --git a/net-misc/openssh/files/openssh-8.7_p1-hpn-15.2-glue.patch b/net-misc/openssh/files/openssh-8.7_p1-hpn-15.2-glue.patch
398 new file mode 100644
399 index 00000000000..309e57e8864
400 --- /dev/null
401 +++ b/net-misc/openssh/files/openssh-8.7_p1-hpn-15.2-glue.patch
402 @@ -0,0 +1,198 @@
403 +diff -ur '--exclude=.*.un~' a/openssh-8_5_P1-hpn-AES-CTR-15.2.diff b/openssh-8_5_P1-hpn-AES-CTR-15.2.diff
404 +--- a/openssh-8_5_P1-hpn-AES-CTR-15.2.diff 2021-08-20 11:49:32.351767063 -0700
405 ++++ b/openssh-8_5_P1-hpn-AES-CTR-15.2.diff 2021-08-20 11:58:08.746214945 -0700
406 +@@ -1026,9 +1026,9 @@
407 + + }
408 + +#endif
409 + +
410 +- debug("Authentication succeeded (%s).", authctxt.method->name);
411 +- }
412 +-
413 ++ if (ssh_packet_connection_is_on_socket(ssh)) {
414 ++ verbose("Authenticated to %s ([%s]:%d) using \"%s\".", host,
415 ++ ssh_remote_ipaddr(ssh), ssh_remote_port(ssh),
416 + diff --git a/sshd.c b/sshd.c
417 + index 6277e6d6..bf3d6e4a 100644
418 + --- a/sshd.c
419 +diff -ur '--exclude=.*.un~' a/openssh-8_5_P1-hpn-DynWinNoneSwitch-15.2.diff b/openssh-8_5_P1-hpn-DynWinNoneSwitch-15.2.diff
420 +--- a/openssh-8_5_P1-hpn-DynWinNoneSwitch-15.2.diff 2021-08-20 11:49:32.351767063 -0700
421 ++++ b/openssh-8_5_P1-hpn-DynWinNoneSwitch-15.2.diff 2021-08-20 12:04:45.008038085 -0700
422 +@@ -536,18 +536,10 @@
423 + if (state->rekey_limit)
424 + *max_blocks = MINIMUM(*max_blocks,
425 + state->rekey_limit / enc->block_size);
426 +-@@ -954,6 +963,24 @@ ssh_set_newkeys(struct ssh *ssh, int mode)
427 ++@@ -954,6 +963,16 @@ ssh_set_newkeys(struct ssh *ssh, int mode)
428 + return 0;
429 + }
430 +
431 +-+/* this supports the forced rekeying required for the NONE cipher */
432 +-+int rekey_requested = 0;
433 +-+void
434 +-+packet_request_rekeying(void)
435 +-+{
436 +-+ rekey_requested = 1;
437 +-+}
438 +-+
439 + +/* used to determine if pre or post auth when rekeying for aes-ctr
440 + + * and none cipher switch */
441 + +int
442 +@@ -561,20 +553,6 @@
443 + #define MAX_PACKETS (1U<<31)
444 + static int
445 + ssh_packet_need_rekeying(struct ssh *ssh, u_int outbound_packet_len)
446 +-@@ -980,6 +1007,13 @@ ssh_packet_need_rekeying(struct ssh *ssh, u_int outbound_packet_len)
447 +- if (state->p_send.packets == 0 && state->p_read.packets == 0)
448 +- return 0;
449 +-
450 +-+ /* used to force rekeying when called for by the none
451 +-+ * cipher switch methods -cjr */
452 +-+ if (rekey_requested == 1) {
453 +-+ rekey_requested = 0;
454 +-+ return 1;
455 +-+ }
456 +-+
457 +- /* Time-based rekeying */
458 +- if (state->rekey_interval != 0 &&
459 +- (int64_t)state->rekey_time + state->rekey_interval <= monotime())
460 + @@ -1317,7 +1351,7 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
461 + struct session_state *state = ssh->state;
462 + int len, r, ms_remain;
463 +@@ -598,12 +576,11 @@
464 + };
465 +
466 + typedef int (ssh_packet_hook_fn)(struct ssh *, struct sshbuf *,
467 +-@@ -155,6 +158,10 @@ int ssh_packet_inc_alive_timeouts(struct ssh *);
468 ++@@ -155,6 +158,9 @@ int ssh_packet_inc_alive_timeouts(struct ssh *);
469 + int ssh_packet_set_maxsize(struct ssh *, u_int);
470 + u_int ssh_packet_get_maxsize(struct ssh *);
471 +
472 + +/* for forced packet rekeying post auth */
473 +-+void packet_request_rekeying(void);
474 + +int packet_authentication_state(const struct ssh *);
475 + +
476 + int ssh_packet_get_state(struct ssh *, struct sshbuf *);
477 +@@ -627,9 +604,9 @@
478 + oLocalCommand, oPermitLocalCommand, oRemoteCommand,
479 + + oTcpRcvBufPoll, oTcpRcvBuf, oHPNDisabled, oHPNBufferSize,
480 + + oNoneEnabled, oNoneMacEnabled, oNoneSwitch,
481 ++ oDisableMTAES,
482 + oVisualHostKey,
483 + oKexAlgorithms, oIPQoS, oRequestTTY, oIgnoreUnknown, oProxyUseFdpass,
484 +- oCanonicalDomains, oCanonicalizeHostname, oCanonicalizeMaxDots,
485 + @@ -297,6 +300,9 @@ static struct {
486 + { "kexalgorithms", oKexAlgorithms },
487 + { "ipqos", oIPQoS },
488 +@@ -637,9 +614,9 @@
489 + + { "noneenabled", oNoneEnabled },
490 + + { "nonemacenabled", oNoneMacEnabled },
491 + + { "noneswitch", oNoneSwitch },
492 +- { "proxyusefdpass", oProxyUseFdpass },
493 +- { "canonicaldomains", oCanonicalDomains },
494 +- { "canonicalizefallbacklocal", oCanonicalizeFallbackLocal },
495 ++ { "sessiontype", oSessionType },
496 ++ { "stdinnull", oStdinNull },
497 ++ { "forkafterauthentication", oForkAfterAuthentication },
498 + @@ -317,6 +323,11 @@ static struct {
499 + { "securitykeyprovider", oSecurityKeyProvider },
500 + { "knownhostscommand", oKnownHostsCommand },
501 +@@ -717,9 +694,9 @@
502 + + options->hpn_buffer_size = -1;
503 + + options->tcp_rcv_buf_poll = -1;
504 + + options->tcp_rcv_buf = -1;
505 +- options->proxy_use_fdpass = -1;
506 +- options->ignored_unknown = NULL;
507 +- options->num_canonical_domains = 0;
508 ++ options->session_type = -1;
509 ++ options->stdin_null = -1;
510 ++ options->fork_after_authentication = -1;
511 + @@ -2426,6 +2484,41 @@ fill_default_options(Options * options)
512 + options->server_alive_interval = 0;
513 + if (options->server_alive_count_max == -1)
514 +@@ -778,9 +755,9 @@
515 + int ip_qos_bulk; /* IP ToS/DSCP/class for bulk traffic */
516 + SyslogFacility log_facility; /* Facility for system logging. */
517 + @@ -120,7 +124,11 @@ typedef struct {
518 +-
519 + int enable_ssh_keysign;
520 + int64_t rekey_limit;
521 ++ int disable_multithreaded; /*disable multithreaded aes-ctr*/
522 + + int none_switch; /* Use none cipher */
523 + + int none_enabled; /* Allow none cipher to be used */
524 + + int nonemac_enabled; /* Allow none MAC to be used */
525 +@@ -842,9 +819,9 @@
526 + /* Portable-specific options */
527 + if (options->use_pam == -1)
528 + @@ -424,6 +434,49 @@ fill_default_server_options(ServerOptions *options)
529 +- }
530 +- if (options->permit_tun == -1)
531 + options->permit_tun = SSH_TUNMODE_NO;
532 ++ if (options->disable_multithreaded == -1)
533 ++ options->disable_multithreaded = 0;
534 + + if (options->none_enabled == -1)
535 + + options->none_enabled = 0;
536 + + if (options->nonemac_enabled == -1)
537 +@@ -1047,17 +1024,17 @@
538 + Note that
539 + diff --git a/sftp.c b/sftp.c
540 + index fb3c08d1..89bebbb2 100644
541 +---- a/sftp.c
542 +-+++ b/sftp.c
543 +-@@ -71,7 +71,7 @@ typedef void EditLine;
544 +- #include "sftp-client.h"
545 +-
546 +- #define DEFAULT_COPY_BUFLEN 32768 /* Size of buffer for up/download */
547 +--#define DEFAULT_NUM_REQUESTS 64 /* # concurrent outstanding requests */
548 +-+#define DEFAULT_NUM_REQUESTS 256 /* # concurrent outstanding requests */
549 ++--- a/sftp-client.c
550 +++++ b/sftp-client.c
551 ++@@ -65,7 +65,7 @@ typedef void EditLine;
552 ++ #define DEFAULT_COPY_BUFLEN 32768
553 ++
554 ++ /* Default number of concurrent outstanding requests */
555 ++-#define DEFAULT_NUM_REQUESTS 64
556 +++#define DEFAULT_NUM_REQUESTS 256
557 +
558 +- /* File to read commands from */
559 +- FILE* infile;
560 ++ /* Minimum amount of data to read at a time */
561 ++ #define MIN_READ_SIZE 512
562 + diff --git a/ssh-keygen.c b/ssh-keygen.c
563 + index cfb5f115..36a6e519 100644
564 + --- a/ssh-keygen.c
565 +@@ -1330,9 +1307,9 @@
566 + + }
567 + + }
568 + +
569 +- debug("Authentication succeeded (%s).", authctxt.method->name);
570 +- }
571 +
572 ++ #ifdef WITH_OPENSSL
573 ++ if (options.disable_multithreaded == 0) {
574 + diff --git a/sshd.c b/sshd.c
575 + index 6277e6d6..d66fa41a 100644
576 + --- a/sshd.c
577 +@@ -1359,8 +1336,8 @@
578 + if (bind(listen_sock, ai->ai_addr, ai->ai_addrlen) == -1) {
579 + error("Bind to port %s on %s failed: %.200s.",
580 + @@ -1727,6 +1734,19 @@ main(int ac, char **av)
581 +- /* Fill in default values for those options not explicitly set. */
582 +- fill_default_server_options(&options);
583 ++ fatal("AuthorizedPrincipalsCommand set without "
584 ++ "AuthorizedPrincipalsCommandUser");
585 +
586 + + if (options.none_enabled == 1) {
587 + + char *old_ciphers = options.ciphers;
588 +@@ -1375,9 +1352,9 @@
589 + + }
590 + + }
591 + +
592 +- /* challenge-response is implemented via keyboard interactive */
593 +- if (options.challenge_response_authentication)
594 +- options.kbd_interactive_authentication = 1;
595 ++ /*
596 ++ * Check whether there is any path through configured auth methods.
597 ++ * Unfortunately it is not possible to verify this generally before
598 + @@ -2166,6 +2186,9 @@ main(int ac, char **av)
599 + rdomain == NULL ? "" : "\"");
600 + free(laddr);
601
602 diff --git a/net-misc/openssh/openssh-8.7_p1.ebuild b/net-misc/openssh/openssh-8.7_p1.ebuild
603 new file mode 100644
604 index 00000000000..2b26a0f2548
605 --- /dev/null
606 +++ b/net-misc/openssh/openssh-8.7_p1.ebuild
607 @@ -0,0 +1,513 @@
608 +# Copyright 1999-2021 Gentoo Authors
609 +# Distributed under the terms of the GNU General Public License v2
610 +
611 +EAPI=7
612 +
613 +inherit user-info flag-o-matic autotools pam systemd toolchain-funcs
614 +
615 +# Make it more portable between straight releases
616 +# and _p? releases.
617 +PARCH=${P/_}
618 +
619 +# PV to USE for HPN patches
620 +#HPN_PV="${PV^^}"
621 +HPN_PV="8.5_P1"
622 +
623 +HPN_VER="15.2"
624 +HPN_PATCHES=(
625 + ${PN}-${HPN_PV/./_}-hpn-DynWinNoneSwitch-${HPN_VER}.diff
626 + ${PN}-${HPN_PV/./_}-hpn-AES-CTR-${HPN_VER}.diff
627 + ${PN}-${HPN_PV/./_}-hpn-PeakTput-${HPN_VER}.diff
628 +)
629 +
630 +SCTP_VER="1.2" SCTP_PATCH="${PARCH}-sctp-${SCTP_VER}.patch.xz"
631 +#X509_VER="13.1" X509_PATCH="${PARCH}+x509-${X509_VER}.diff.gz"
632 +
633 +DESCRIPTION="Port of OpenBSD's free SSH release"
634 +HOMEPAGE="https://www.openssh.com/"
635 +SRC_URI="mirror://openbsd/OpenSSH/portable/${PARCH}.tar.gz
636 + ${SCTP_PATCH:+sctp? ( https://dev.gentoo.org/~chutzpah/dist/openssh/${SCTP_PATCH} )}
637 + ${HPN_VER:+hpn? ( $(printf "mirror://sourceforge/project/hpnssh/Patches/HPN-SSH%%20${HPN_VER/./v}%%20${HPN_PV/_P/p}/%s\n" "${HPN_PATCHES[@]}") )}
638 + ${X509_PATCH:+X509? ( https://roumenpetrov.info/openssh/x509-${X509_VER}/${X509_PATCH} )}
639 +"
640 +S="${WORKDIR}/${PARCH}"
641 +
642 +LICENSE="BSD GPL-2"
643 +SLOT="0"
644 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
645 +# Probably want to drop ssl defaulting to on in a future version.
646 +IUSE="abi_mips_n32 audit bindist debug hpn kerberos kernel_linux ldns libedit livecd pam +pie +scp sctp security-key selinux +ssl static test X X509 xmss"
647 +
648 +RESTRICT="!test? ( test )"
649 +
650 +REQUIRED_USE="
651 + hpn? ( ssl )
652 + ldns? ( ssl )
653 + pie? ( !static )
654 + static? ( !kerberos !pam )
655 + X509? ( !sctp !security-key ssl !xmss )
656 + xmss? ( ssl )
657 + test? ( ssl )
658 +"
659 +
660 +# tests currently fail with XMSS
661 +REQUIRED_USE+="test? ( !xmss )"
662 +
663 +LIB_DEPEND="
664 + audit? ( sys-process/audit[static-libs(+)] )
665 + ldns? (
666 + net-libs/ldns[static-libs(+)]
667 + !bindist? ( net-libs/ldns[ecdsa,ssl(+)] )
668 + bindist? ( net-libs/ldns[-ecdsa,ssl(+)] )
669 + )
670 + libedit? ( dev-libs/libedit:=[static-libs(+)] )
671 + sctp? ( net-misc/lksctp-tools[static-libs(+)] )
672 + security-key? ( >=dev-libs/libfido2-1.5.0:=[static-libs(+)] )
673 + selinux? ( >=sys-libs/libselinux-1.28[static-libs(+)] )
674 + ssl? (
675 + || (
676 + (
677 + >=dev-libs/openssl-1.0.1:0[bindist(-)=]
678 + <dev-libs/openssl-1.1.0:0[bindist(-)=]
679 + )
680 + >=dev-libs/openssl-1.1.0g:0[bindist(-)=]
681 + )
682 + dev-libs/openssl:0=[static-libs(+)]
683 + )
684 + virtual/libcrypt:=[static-libs(+)]
685 + >=sys-libs/zlib-1.2.3:=[static-libs(+)]
686 +"
687 +RDEPEND="
688 + acct-group/sshd
689 + acct-user/sshd
690 + !static? ( ${LIB_DEPEND//\[static-libs(+)]} )
691 + pam? ( sys-libs/pam )
692 + kerberos? ( virtual/krb5 )
693 +"
694 +DEPEND="${RDEPEND}
695 + virtual/os-headers
696 + kernel_linux? ( !prefix-guest? ( >=sys-kernel/linux-headers-5.1 ) )
697 + static? ( ${LIB_DEPEND} )
698 +"
699 +RDEPEND="${RDEPEND}
700 + pam? ( >=sys-auth/pambase-20081028 )
701 + userland_GNU? ( !prefix? ( sys-apps/shadow ) )
702 + X? ( x11-apps/xauth )
703 +"
704 +BDEPEND="
705 + virtual/pkgconfig
706 + sys-devel/autoconf
707 +"
708 +
709 +pkg_pretend() {
710 + # this sucks, but i'd rather have people unable to `emerge -u openssh`
711 + # than not be able to log in to their server any more
712 + maybe_fail() { [[ -z ${!2} ]] && echo "$1" ; }
713 + local fail="
714 + $(use hpn && maybe_fail hpn HPN_VER)
715 + $(use sctp && maybe_fail sctp SCTP_PATCH)
716 + $(use X509 && maybe_fail X509 X509_PATCH)
717 + "
718 + fail=$(echo ${fail})
719 + if [[ -n ${fail} ]] ; then
720 + eerror "Sorry, but this version does not yet support features"
721 + eerror "that you requested: ${fail}"
722 + eerror "Please mask ${PF} for now and check back later:"
723 + eerror " # echo '=${CATEGORY}/${PF}' >> /etc/portage/package.mask"
724 + die "Missing requested third party patch."
725 + fi
726 +
727 + # Make sure people who are using tcp wrappers are notified of its removal. #531156
728 + if grep -qs '^ *sshd *:' "${EROOT}"/etc/hosts.{allow,deny} ; then
729 + ewarn "Sorry, but openssh no longer supports tcp-wrappers, and it seems like"
730 + ewarn "you're trying to use it. Update your ${EROOT}/etc/hosts.{allow,deny} please."
731 + fi
732 +}
733 +
734 +src_prepare() {
735 + sed -i \
736 + -e "/_PATH_XAUTH/s:/usr/X11R6/bin/xauth:${EPREFIX}/usr/bin/xauth:" \
737 + pathnames.h || die
738 +
739 + # don't break .ssh/authorized_keys2 for fun
740 + sed -i '/^AuthorizedKeysFile/s:^:#:' sshd_config || die
741 +
742 + eapply "${FILESDIR}"/${PN}-7.9_p1-include-stdlib.patch
743 + eapply "${FILESDIR}"/${PN}-8.7_p1-GSSAPI-dns.patch #165444 integrated into gsskex
744 + eapply "${FILESDIR}"/${PN}-6.7_p1-openssl-ignore-status.patch
745 + eapply "${FILESDIR}"/${PN}-7.5_p1-disable-conch-interop-tests.patch
746 + eapply "${FILESDIR}"/${PN}-8.0_p1-fix-putty-tests.patch
747 + eapply "${FILESDIR}"/${PN}-8.0_p1-deny-shmget-shmat-shmdt-in-preauth-privsep-child.patch
748 +
749 + [[ -d ${WORKDIR}/patches ]] && eapply "${WORKDIR}"/patches
750 +
751 + local PATCHSET_VERSION_MACROS=()
752 +
753 + if use X509 ; then
754 + pushd "${WORKDIR}" &>/dev/null || die
755 + eapply "${FILESDIR}/${P}-X509-glue-"${X509_VER}".patch"
756 + popd &>/dev/null || die
757 +
758 + eapply "${WORKDIR}"/${X509_PATCH%.*}
759 +
760 + # We need to patch package version or any X.509 sshd will reject our ssh client
761 + # with "userauth_pubkey: could not parse key: string is too large [preauth]"
762 + # error
763 + einfo "Patching package version for X.509 patch set ..."
764 + sed -i \
765 + -e "s/^AC_INIT(\[OpenSSH\], \[Portable\]/AC_INIT([OpenSSH], [${X509_VER}]/" \
766 + "${S}"/configure.ac || die "Failed to patch package version for X.509 patch"
767 +
768 + einfo "Patching version.h to expose X.509 patch set ..."
769 + sed -i \
770 + -e "/^#define SSH_PORTABLE.*/a #define SSH_X509 \"-PKIXSSH-${X509_VER}\"" \
771 + "${S}"/version.h || die "Failed to sed-in X.509 patch version"
772 + PATCHSET_VERSION_MACROS+=( 'SSH_X509' )
773 + fi
774 +
775 + if use sctp ; then
776 + eapply "${WORKDIR}"/${SCTP_PATCH%.*}
777 +
778 + einfo "Patching version.h to expose SCTP patch set ..."
779 + sed -i \
780 + -e "/^#define SSH_PORTABLE/a #define SSH_SCTP \"-sctp-${SCTP_VER}\"" \
781 + "${S}"/version.h || die "Failed to sed-in SCTP patch version"
782 + PATCHSET_VERSION_MACROS+=( 'SSH_SCTP' )
783 +
784 + einfo "Disabling know failing test (cfgparse) caused by SCTP patch ..."
785 + sed -i \
786 + -e "/\t\tcfgparse \\\/d" \
787 + "${S}"/regress/Makefile || die "Failed to disable known failing test (cfgparse) caused by SCTP patch"
788 + fi
789 +
790 + if use hpn ; then
791 + local hpn_patchdir="${T}/${P}-hpn${HPN_VER}"
792 + mkdir "${hpn_patchdir}" || die
793 + cp $(printf -- "${DISTDIR}/%s\n" "${HPN_PATCHES[@]}") "${hpn_patchdir}" || die
794 + pushd "${hpn_patchdir}" &>/dev/null || die
795 + eapply "${FILESDIR}"/${P}-hpn-${HPN_VER}-glue.patch
796 + use X509 && eapply "${FILESDIR}"/${PN}-8.6_p1-hpn-${HPN_VER}-X509-glue.patch
797 + use sctp && eapply "${FILESDIR}"/${PN}-8.5_p1-hpn-${HPN_VER}-sctp-glue.patch
798 + popd &>/dev/null || die
799 +
800 + eapply "${hpn_patchdir}"
801 +
802 + use X509 || eapply "${FILESDIR}/openssh-8.6_p1-hpn-version.patch"
803 +
804 + einfo "Patching Makefile.in for HPN patch set ..."
805 + sed -i \
806 + -e "/^LIBS=/ s/\$/ -lpthread/" \
807 + "${S}"/Makefile.in || die "Failed to patch Makefile.in"
808 +
809 + einfo "Patching version.h to expose HPN patch set ..."
810 + sed -i \
811 + -e "/^#define SSH_PORTABLE/a #define SSH_HPN \"-hpn${HPN_VER//./v}\"" \
812 + "${S}"/version.h || die "Failed to sed-in HPN patch version"
813 + PATCHSET_VERSION_MACROS+=( 'SSH_HPN' )
814 +
815 + if [[ -n "${HPN_DISABLE_MTAES}" ]] ; then
816 + einfo "Disabling known non-working MT AES cipher per default ..."
817 +
818 + cat > "${T}"/disable_mtaes.conf <<- EOF
819 +
820 + # HPN's Multi-Threaded AES CTR cipher is currently known to be broken
821 + # and therefore disabled per default.
822 + DisableMTAES yes
823 + EOF
824 + sed -i \
825 + -e "/^#HPNDisabled.*/r ${T}/disable_mtaes.conf" \
826 + "${S}"/sshd_config || die "Failed to disabled MT AES ciphers in sshd_config"
827 +
828 + sed -i \
829 + -e "/AcceptEnv.*_XXX_TEST$/a \\\tDisableMTAES\t\tyes" \
830 + "${S}"/regress/test-exec.sh || die "Failed to disable MT AES ciphers in test config"
831 + fi
832 + fi
833 +
834 + if use X509 || use sctp || use hpn ; then
835 + einfo "Patching sshconnect.c to use SSH_RELEASE in send_client_banner() ..."
836 + sed -i \
837 + -e "s/PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION/PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_RELEASE/" \
838 + "${S}"/sshconnect.c || die "Failed to patch send_client_banner() to use SSH_RELEASE (sshconnect.c)"
839 +
840 + einfo "Patching sshd.c to use SSH_RELEASE in sshd_exchange_identification() ..."
841 + sed -i \
842 + -e "s/PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION/PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_RELEASE/" \
843 + "${S}"/sshd.c || die "Failed to patch sshd_exchange_identification() to use SSH_RELEASE (sshd.c)"
844 +
845 + einfo "Patching version.h to add our patch sets to SSH_RELEASE ..."
846 + sed -i \
847 + -e "s/^#define SSH_RELEASE.*/#define SSH_RELEASE SSH_VERSION SSH_PORTABLE ${PATCHSET_VERSION_MACROS[*]}/" \
848 + "${S}"/version.h || die "Failed to patch SSH_RELEASE (version.h)"
849 + fi
850 +
851 + sed -i \
852 + -e "/#UseLogin no/d" \
853 + "${S}"/sshd_config || die "Failed to remove removed UseLogin option (sshd_config)"
854 +
855 + eapply_user #473004
856 +
857 + # These tests are currently incompatible with PORTAGE_TMPDIR/sandbox
858 + sed -e '/\t\tpercent \\/ d' \
859 + -i regress/Makefile || die
860 +
861 + tc-export PKG_CONFIG
862 + local sed_args=(
863 + -e "s:-lcrypto:$(${PKG_CONFIG} --libs openssl):"
864 + # Disable PATH reset, trust what portage gives us #254615
865 + -e 's:^PATH=/:#PATH=/:'
866 + # Disable fortify flags ... our gcc does this for us
867 + -e 's:-D_FORTIFY_SOURCE=2::'
868 + )
869 +
870 + # The -ftrapv flag ICEs on hppa #505182
871 + use hppa && sed_args+=(
872 + -e '/CFLAGS/s:-ftrapv:-fdisable-this-test:'
873 + -e '/OSSH_CHECK_CFLAG_LINK.*-ftrapv/d'
874 + )
875 + # _XOPEN_SOURCE causes header conflicts on Solaris
876 + [[ ${CHOST} == *-solaris* ]] && sed_args+=(
877 + -e 's/-D_XOPEN_SOURCE//'
878 + )
879 + sed -i "${sed_args[@]}" configure{.ac,} || die
880 +
881 + eautoreconf
882 +}
883 +
884 +src_configure() {
885 + addwrite /dev/ptmx
886 +
887 + use debug && append-cppflags -DSANDBOX_SECCOMP_FILTER_DEBUG
888 + use static && append-ldflags -static
889 + use xmss && append-cflags -DWITH_XMSS
890 +
891 + if [[ ${CHOST} == *-solaris* ]] ; then
892 + # Solaris' glob.h doesn't have things like GLOB_TILDE, configure
893 + # doesn't check for this, so force the replacement to be put in
894 + # place
895 + append-cppflags -DBROKEN_GLOB
896 + fi
897 +
898 + # use replacement, RPF_ECHO_ON doesn't exist here
899 + [[ ${CHOST} == *-darwin* ]] && export ac_cv_func_readpassphrase=no
900 +
901 + local myconf=(
902 + --with-ldflags="${LDFLAGS}"
903 + --disable-strip
904 + --with-pid-dir="${EPREFIX}"$(usex kernel_linux '' '/var')/run
905 + --sysconfdir="${EPREFIX}"/etc/ssh
906 + --libexecdir="${EPREFIX}"/usr/$(get_libdir)/misc
907 + --datadir="${EPREFIX}"/usr/share/openssh
908 + --with-privsep-path="${EPREFIX}"/var/empty
909 + --with-privsep-user=sshd
910 + $(use_with audit audit linux)
911 + $(use_with kerberos kerberos5 "${EPREFIX}"/usr)
912 + # We apply the sctp patch conditionally, so can't pass --without-sctp
913 + # unconditionally else we get unknown flag warnings.
914 + $(use sctp && use_with sctp)
915 + $(use_with ldns ldns "${EPREFIX}"/usr)
916 + $(use_with libedit)
917 + $(use_with pam)
918 + $(use_with pie)
919 + $(use_with selinux)
920 + $(usex X509 '' "$(use_with security-key security-key-builtin)")
921 + $(use_with ssl openssl)
922 + $(use_with ssl md5-passwords)
923 + $(use_with ssl ssl-engine)
924 + $(use_with !elibc_Cygwin hardening) #659210
925 + )
926 +
927 + if use elibc_musl; then
928 + # stackprotect is broken on musl x86 and ppc
929 + if use x86 || use ppc; then
930 + myconf+=( --without-stackprotect )
931 + fi
932 +
933 + # musl defines bogus values for UTMP_FILE and WTMP_FILE
934 + # https://bugs.gentoo.org/753230
935 + myconf+=( --disable-utmp --disable-wtmp )
936 + fi
937 +
938 + # The seccomp sandbox is broken on x32, so use the older method for now. #553748
939 + use amd64 && [[ ${ABI} == "x32" ]] && myconf+=( --with-sandbox=rlimit )
940 +
941 + econf "${myconf[@]}"
942 +}
943 +
944 +src_test() {
945 + local t skipped=() failed=() passed=()
946 + local tests=( interop-tests compat-tests )
947 +
948 + local shell=$(egetshell "${UID}")
949 + if [[ ${shell} == */nologin ]] || [[ ${shell} == */false ]] ; then
950 + elog "Running the full OpenSSH testsuite requires a usable shell for the 'portage'"
951 + elog "user, so we will run a subset only."
952 + skipped+=( tests )
953 + else
954 + tests+=( tests )
955 + fi
956 +
957 + # It will also attempt to write to the homedir .ssh.
958 + local sshhome=${T}/homedir
959 + mkdir -p "${sshhome}"/.ssh
960 + for t in "${tests[@]}" ; do
961 + # Some tests read from stdin ...
962 + HOMEDIR="${sshhome}" HOME="${sshhome}" TMPDIR="${T}" \
963 + SUDO="" SSH_SK_PROVIDER="" \
964 + TEST_SSH_UNSAFE_PERMISSIONS=1 \
965 + emake -k -j1 ${t} </dev/null \
966 + && passed+=( "${t}" ) \
967 + || failed+=( "${t}" )
968 + done
969 +
970 + einfo "Passed tests: ${passed[*]}"
971 + [[ ${#skipped[@]} -gt 0 ]] && ewarn "Skipped tests: ${skipped[*]}"
972 + [[ ${#failed[@]} -gt 0 ]] && die "Some tests failed: ${failed[*]}"
973 +}
974 +
975 +# Gentoo tweaks to default config files.
976 +tweak_ssh_configs() {
977 + local locale_vars=(
978 + # These are language variables that POSIX defines.
979 + # http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02
980 + LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME
981 +
982 + # These are the GNU extensions.
983 + # https://www.gnu.org/software/autoconf/manual/html_node/Special-Shell-Variables.html
984 + LANGUAGE LC_ADDRESS LC_IDENTIFICATION LC_MEASUREMENT LC_NAME LC_PAPER LC_TELEPHONE
985 + )
986 +
987 + # First the server config.
988 + cat <<-EOF >> "${ED}"/etc/ssh/sshd_config
989 +
990 + # Allow client to pass locale environment variables. #367017
991 + AcceptEnv ${locale_vars[*]}
992 +
993 + # Allow client to pass COLORTERM to match TERM. #658540
994 + AcceptEnv COLORTERM
995 + EOF
996 +
997 + # Then the client config.
998 + cat <<-EOF >> "${ED}"/etc/ssh/ssh_config
999 +
1000 + # Send locale environment variables. #367017
1001 + SendEnv ${locale_vars[*]}
1002 +
1003 + # Send COLORTERM to match TERM. #658540
1004 + SendEnv COLORTERM
1005 + EOF
1006 +
1007 + if use pam ; then
1008 + sed -i \
1009 + -e "/^#UsePAM /s:.*:UsePAM yes:" \
1010 + -e "/^#PasswordAuthentication /s:.*:PasswordAuthentication no:" \
1011 + -e "/^#PrintMotd /s:.*:PrintMotd no:" \
1012 + -e "/^#PrintLastLog /s:.*:PrintLastLog no:" \
1013 + "${ED}"/etc/ssh/sshd_config || die
1014 + fi
1015 +
1016 + if use livecd ; then
1017 + sed -i \
1018 + -e '/^#PermitRootLogin/c# Allow root login with password on livecds.\nPermitRootLogin Yes' \
1019 + "${ED}"/etc/ssh/sshd_config || die
1020 + fi
1021 +}
1022 +
1023 +src_install() {
1024 + emake install-nokeys DESTDIR="${D}"
1025 + fperms 600 /etc/ssh/sshd_config
1026 + dobin contrib/ssh-copy-id
1027 + newinitd "${FILESDIR}"/sshd-r1.initd sshd
1028 + newconfd "${FILESDIR}"/sshd-r1.confd sshd
1029 +
1030 + if use pam; then
1031 + newpamd "${FILESDIR}"/sshd.pam_include.2 sshd
1032 + fi
1033 +
1034 + tweak_ssh_configs
1035 +
1036 + doman contrib/ssh-copy-id.1
1037 + dodoc CREDITS OVERVIEW README* TODO sshd_config
1038 + use hpn && dodoc HPN-README
1039 + use X509 || dodoc ChangeLog
1040 +
1041 + diropts -m 0700
1042 + dodir /etc/skel/.ssh
1043 +
1044 + # https://bugs.gentoo.org/733802
1045 + if ! use scp; then
1046 + rm -f "${ED}"/usr/{bin/scp,share/man/man1/scp.1} \
1047 + || die "failed to remove scp"
1048 + fi
1049 +
1050 + rmdir "${ED}"/var/empty || die
1051 +
1052 + systemd_dounit "${FILESDIR}"/sshd.{service,socket}
1053 + systemd_newunit "${FILESDIR}"/sshd_at.service 'sshd@.service'
1054 +}
1055 +
1056 +pkg_preinst() {
1057 + if ! use ssl && has_version "${CATEGORY}/${PN}[ssl]"; then
1058 + show_ssl_warning=1
1059 + fi
1060 +}
1061 +
1062 +pkg_postinst() {
1063 + local old_ver
1064 + for old_ver in ${REPLACING_VERSIONS}; do
1065 + if ver_test "${old_ver}" -lt "5.8_p1"; then
1066 + elog "Starting with openssh-5.8p1, the server will default to a newer key"
1067 + elog "algorithm (ECDSA). You are encouraged to manually update your stored"
1068 + elog "keys list as servers update theirs. See ssh-keyscan(1) for more info."
1069 + fi
1070 + if ver_test "${old_ver}" -lt "7.0_p1"; then
1071 + elog "Starting with openssh-6.7, support for USE=tcpd has been dropped by upstream."
1072 + elog "Make sure to update any configs that you might have. Note that xinetd might"
1073 + elog "be an alternative for you as it supports USE=tcpd."
1074 + fi
1075 + if ver_test "${old_ver}" -lt "7.1_p1"; then #557388 #555518
1076 + elog "Starting with openssh-7.0, support for ssh-dss keys were disabled due to their"
1077 + elog "weak sizes. If you rely on these key types, you can re-enable the key types by"
1078 + elog "adding to your sshd_config or ~/.ssh/config files:"
1079 + elog " PubkeyAcceptedKeyTypes=+ssh-dss"
1080 + elog "You should however generate new keys using rsa or ed25519."
1081 +
1082 + elog "Starting with openssh-7.0, the default for PermitRootLogin changed from 'yes'"
1083 + elog "to 'prohibit-password'. That means password auth for root users no longer works"
1084 + elog "out of the box. If you need this, please update your sshd_config explicitly."
1085 + fi
1086 + if ver_test "${old_ver}" -lt "7.6_p1"; then
1087 + elog "Starting with openssh-7.6p1, openssh upstream has removed ssh1 support entirely."
1088 + elog "Furthermore, rsa keys with less than 1024 bits will be refused."
1089 + fi
1090 + if ver_test "${old_ver}" -lt "7.7_p1"; then
1091 + elog "Starting with openssh-7.7p1, we no longer patch openssh to provide LDAP functionality."
1092 + elog "Install sys-auth/ssh-ldap-pubkey and use OpenSSH's \"AuthorizedKeysCommand\" option"
1093 + elog "if you need to authenticate against LDAP."
1094 + elog "See https://wiki.gentoo.org/wiki/SSH/LDAP_migration for more details."
1095 + fi
1096 + if ver_test "${old_ver}" -lt "8.2_p1"; then
1097 + ewarn "After upgrading to openssh-8.2p1 please restart sshd, otherwise you"
1098 + ewarn "will not be able to establish new sessions. Restarting sshd over a ssh"
1099 + ewarn "connection is generally safe."
1100 + fi
1101 + done
1102 +
1103 + if [[ -n ${show_ssl_warning} ]]; then
1104 + elog "Be aware that by disabling openssl support in openssh, the server and clients"
1105 + elog "no longer support dss/rsa/ecdsa keys. You will need to generate ed25519 keys"
1106 + elog "and update all clients/servers that utilize them."
1107 + fi
1108 +
1109 + if use hpn && [[ -n "${HPN_DISABLE_MTAES}" ]] ; then
1110 + elog ""
1111 + elog "HPN's multi-threaded AES CTR cipher is currently known to be broken"
1112 + elog "and therefore disabled at runtime per default."
1113 + elog "Make sure your sshd_config is up to date and contains"
1114 + elog ""
1115 + elog " DisableMTAES yes"
1116 + elog ""
1117 + elog "Otherwise you maybe unable to connect to this sshd using any AES CTR cipher."
1118 + elog ""
1119 + fi
1120 +}