summaryrefslogtreecommitdiff
path: root/backport-openssh-7.7p1-fips.patch
blob: 36618184a469fe0774dc33baeace1e3cc53d03e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
diff -up openssh-8.6p1/cipher-ctr.c.fips openssh-8.6p1/cipher-ctr.c
--- openssh-8.6p1/cipher-ctr.c.fips	2021-04-19 16:53:02.994577324 +0200
+++ openssh-8.6p1/cipher-ctr.c	2021-04-19 16:53:03.064577862 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -179,7 +179,8 @@ evp_aes_128_ctr(void)
 	aes_ctr.do_cipher = ssh_aes_ctr;
 #ifndef SSH_OLD_EVP
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
+	    EVP_CIPH_FLAG_FIPS;
 #endif
 	return (&aes_ctr);
 }
diff -up openssh-8.6p1/dh.c.fips openssh-8.6p1/dh.c
--- openssh-8.6p1/dh.c.fips	2021-04-16 05:55:25.000000000 +0200
+++ openssh-8.6p1/dh.c	2021-04-19 16:58:47.750263410 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -164,6 +164,12 @@ choose_dh(int min, int wantbits, int max
 	int best, bestcount, which, linenum;
 	struct dhgroup dhg;
 
+	if (FIPS_mode()) {
+		logit("Using arbitrary primes is not allowed in FIPS mode."
+		    " Falling back to known groups.");
+		return (dh_new_group_fallback(max));
+	}
+
 	if ((f = fopen(get_moduli_filename(), "r")) == NULL) {
 		logit("WARNING: could not open %s (%s), using fixed modulus",
 		    get_moduli_filename(), strerror(errno));
@@ -502,4 +508,38 @@ dh_estimate(int bits)
 	return 8192;
 }
 
+/*
+ * Compares the received DH parameters with known-good groups,
+ * which might be either from group14, group16 or group18.
+ */
+int
+dh_is_known_group(const DH *dh)
+{
+	const BIGNUM *p, *g;
+	const BIGNUM *known_p, *known_g;
+	DH *known = NULL;
+	int bits = 0, rv = 0;
+
+	DH_get0_pqg(dh, &p, NULL, &g);
+	bits = BN_num_bits(p);
+
+	if (bits <= 3072) {
+		known = dh_new_group14();
+	} else if (bits <= 6144) {
+		known = dh_new_group16();
+	} else {
+		known = dh_new_group18();
+	}
+
+	DH_get0_pqg(known, &known_p, NULL, &known_g);
+
+	if (BN_cmp(g, known_g) == 0 &&
+	    BN_cmp(p, known_p) == 0) {
+		rv = 1;
+	}
+
+	DH_free(known);
+	return rv;
+}
+
 #endif /* WITH_OPENSSL */
diff -up openssh-8.6p1/dh.h.fips openssh-8.6p1/dh.h
--- openssh-8.6p1/dh.h.fips	2021-04-19 16:53:03.064577862 +0200
+++ openssh-8.6p1/dh.h	2021-04-19 16:59:31.951616078 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -45,6 +45,7 @@ DH	*dh_new_group_fallback(int);
 
 int	 dh_gen_key(DH *, int);
 int	 dh_pub_is_valid(const DH *, const BIGNUM *);
+int	 dh_is_known_group(const DH *);
 
 u_int	 dh_estimate(int);
 void	 dh_set_moduli_file(const char *);
diff -up openssh-8.6p1/kex.c.fips openssh-8.6p1/kex.c
--- openssh-8.6p1/kex.c.fips	2021-04-19 16:53:03.058577815 +0200
+++ openssh-8.6p1/kex.c	2021-04-19 16:53:03.065577869 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -203,7 +203,10 @@ kex_names_valid(const char *names)
 	for ((p = strsep(&cp, ",")); p && *p != '\0';
 	    (p = strsep(&cp, ","))) {
 		if (kex_alg_by_name(p) == NULL) {
-			error("Unsupported KEX algorithm \"%.100s\"", p);
+			if (FIPS_mode())
+				error("\"%.100s\" is not allowed in FIPS mode", p);
+			else
+				error("Unsupported KEX algorithm \"%.100s\"", p);
 			free(s);
 			return 0;
 		}
diff -up openssh-8.6p1/kexgexc.c.fips openssh-8.6p1/kexgexc.c
--- openssh-8.6p1/kexgexc.c.fips	2021-04-16 05:55:25.000000000 +0200
+++ openssh-8.6p1/kexgexc.c	2021-04-19 16:53:03.065577869 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -28,6 +28,7 @@
 
 #ifdef WITH_OPENSSL
 
+#include <openssl/crypto.h>
 #include <sys/types.h>
 
 #include <openssl/dh.h>
@@ -115,6 +116,10 @@ input_kex_dh_gex_group(int type, u_int32
 		r = SSH_ERR_ALLOC_FAIL;
 		goto out;
 	}
+	if (FIPS_mode() && dh_is_known_group(kex->dh) == 0) {
+		r = SSH_ERR_INVALID_ARGUMENT;
+		goto out;
+	}
 	p = g = NULL; /* belong to kex->dh now */
 
 	/* generate and send 'e', client DH public key */
diff -up openssh-8.6p1/myproposal.h.fips openssh-8.6p1/myproposal.h
--- openssh-8.6p1/myproposal.h.fips	2021-04-16 05:55:25.000000000 +0200
+++ openssh-8.6p1/myproposal.h	2021-04-19 16:53:03.065577869 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -57,6 +57,18 @@
 	"rsa-sha2-512," \
 	"rsa-sha2-256"
 
+#define	KEX_FIPS_PK_ALG	\
+	"ecdsa-sha2-nistp256-cert-v01@openssh.com," \
+	"ecdsa-sha2-nistp384-cert-v01@openssh.com," \
+	"ecdsa-sha2-nistp521-cert-v01@openssh.com," \
+	"rsa-sha2-512-cert-v01@openssh.com," \
+	"rsa-sha2-256-cert-v01@openssh.com," \
+	"ecdsa-sha2-nistp256," \
+	"ecdsa-sha2-nistp384," \
+	"ecdsa-sha2-nistp521," \
+	"rsa-sha2-512," \
+	"rsa-sha2-256," \
+
 #define	KEX_SERVER_ENCRYPT \
 	"chacha20-poly1305@openssh.com," \
 	"aes128-ctr,aes192-ctr,aes256-ctr," \
@@ -78,6 +92,27 @@
 
 #define KEX_CLIENT_MAC KEX_SERVER_MAC
 
+#define	KEX_FIPS_ENCRYPT \
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
+	"aes128-cbc,3des-cbc," \
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
+	"aes128-gcm@openssh.com,aes256-gcm@openssh.com"
+#define KEX_DEFAULT_KEX_FIPS		\
+	"ecdh-sha2-nistp256," \
+	"ecdh-sha2-nistp384," \
+	"ecdh-sha2-nistp521," \
+	"diffie-hellman-group-exchange-sha256," \
+	"diffie-hellman-group16-sha512," \
+	"diffie-hellman-group18-sha512," \
+	"diffie-hellman-group14-sha256"
+#define KEX_FIPS_MAC \
+	"hmac-sha1," \
+	"hmac-sha2-256," \
+	"hmac-sha2-512," \
+	"hmac-sha1-etm@openssh.com," \
+	"hmac-sha2-256-etm@openssh.com," \
+	"hmac-sha2-512-etm@openssh.com"
+
 /* Not a KEX value, but here so all the algorithm defaults are together */
 #define	SSH_ALLOWED_CA_SIGALGS	\
 	"ssh-ed25519," \
diff -up openssh-8.6p1/readconf.c.fips openssh-8.6p1/readconf.c
--- openssh-8.6p1/readconf.c.fips	2021-04-19 16:53:02.999577362 +0200
+++ openssh-8.6p1/readconf.c	2021-04-19 16:53:03.065577869 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -2538,11 +2538,16 @@ fill_default_options(Options * options)
 	all_key = sshkey_alg_list(0, 0, 1, ',');
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
 	/* remove unsupported algos from default lists */
-	def_cipher = match_filter_allowlist(KEX_CLIENT_ENCRYPT, all_cipher);
-	def_mac = match_filter_allowlist(KEX_CLIENT_MAC, all_mac);
-	def_kex = match_filter_allowlist(KEX_CLIENT_KEX, all_kex);
-	def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
-	def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
+	def_cipher = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_ENCRYPT : KEX_CLIENT_ENCRYPT), all_cipher);
+	def_mac = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_MAC : KEX_CLIENT_MAC), all_mac);
+	def_kex = match_filter_allowlist((FIPS_mode() ?
+	    KEX_DEFAULT_KEX_FIPS : KEX_CLIENT_KEX), all_kex);
+	def_key = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
+	def_sig = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
 #define ASSEMBLE(what, defaults, all) \
 	do { \
 		if ((r = kex_assemble_names(&options->what, \
diff -up openssh-8.6p1/sandbox-seccomp-filter.c.fips openssh-8.6p1/sandbox-seccomp-filter.c
--- openssh-8.6p1/sandbox-seccomp-filter.c.fips	2021-04-19 16:53:03.034577631 +0200
+++ openssh-8.6p1/sandbox-seccomp-filter.c	2021-04-19 16:53:03.065577869 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -160,6 +160,9 @@ static const struct sock_filter preauth_
 #ifdef __NR_open
 	SC_DENY(__NR_open, EACCES),
 #endif
+#ifdef __NR_socket
+	SC_DENY(__NR_socket, EACCES),
+#endif
 #ifdef __NR_openat
 	SC_DENY(__NR_openat, EACCES),
 #endif
diff -up openssh-8.6p1/servconf.c.fips openssh-8.6p1/servconf.c
--- openssh-8.6p1/servconf.c.fips	2021-04-19 16:53:03.027577577 +0200
+++ openssh-8.6p1/servconf.c	2021-04-19 16:53:03.066577877 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -226,11 +226,16 @@ assemble_algorithms(ServerOptions *o)
 	all_key = sshkey_alg_list(0, 0, 1, ',');
 	all_sig = sshkey_alg_list(0, 1, 1, ',');
 	/* remove unsupported algos from default lists */
-	def_cipher = match_filter_allowlist(KEX_SERVER_ENCRYPT, all_cipher);
-	def_mac = match_filter_allowlist(KEX_SERVER_MAC, all_mac);
-	def_kex = match_filter_allowlist(KEX_SERVER_KEX, all_kex);
-	def_key = match_filter_allowlist(KEX_DEFAULT_PK_ALG, all_key);
-	def_sig = match_filter_allowlist(SSH_ALLOWED_CA_SIGALGS, all_sig);
+	def_cipher = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_ENCRYPT : KEX_SERVER_ENCRYPT), all_cipher);
+	def_mac = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_MAC : KEX_SERVER_MAC), all_mac);
+	def_kex = match_filter_allowlist((FIPS_mode() ?
+	    KEX_DEFAULT_KEX_FIPS : KEX_SERVER_KEX), all_kex);
+	def_key = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_PK_ALG : KEX_DEFAULT_PK_ALG), all_key);
+	def_sig = match_filter_allowlist((FIPS_mode() ?
+	    KEX_FIPS_PK_ALG : SSH_ALLOWED_CA_SIGALGS), all_sig);
 #define ASSEMBLE(what, defaults, all) \
 	do { \
 		if ((r = kex_assemble_names(&o->what, defaults, all)) != 0) \
diff -up openssh-8.6p1/ssh.c.fips openssh-8.6p1/ssh.c
--- openssh-8.6p1/ssh.c.fips	2021-04-19 16:53:03.038577662 +0200
+++ openssh-8.6p1/ssh.c	2021-04-19 16:53:03.066577877 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -77,6 +77,7 @@
 #include <openssl/evp.h>
 #include <openssl/err.h>
 #endif
+#include <openssl/crypto.h>
 #include "openbsd-compat/openssl-compat.h"
 #include "openbsd-compat/sys-queue.h"
 
@@ -1516,6 +1517,10 @@ main(int ac, char **av)
 		exit(0);
 	}
 
+	if (FIPS_mode()) {
+		debug("FIPS mode initialized");
+	}
+
 	/* Expand SecurityKeyProvider if it refers to an environment variable */
 	if (options.sk_provider != NULL && *options.sk_provider == '$' &&
 	    strlen(options.sk_provider) > 1) {
diff -up openssh-8.6p1/sshconnect2.c.fips openssh-8.6p1/sshconnect2.c
--- openssh-8.6p1/sshconnect2.c.fips	2021-04-19 16:53:03.055577792 +0200
+++ openssh-8.6p1/sshconnect2.c	2021-04-19 16:53:03.066577877 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -45,6 +45,8 @@
 #include <vis.h>
 #endif
 
+#include <openssl/crypto.h>
+
 #include "openbsd-compat/sys-queue.h"
 
 #include "xmalloc.h"
@@ -269,36 +271,41 @@ ssh_kex2(struct ssh *ssh, char *host, st
 
 #if defined(GSSAPI) && defined(WITH_OPENSSL)
 	if (options.gss_keyex) {
-		/* Add the GSSAPI mechanisms currently supported on this
-		 * client to the key exchange algorithm proposal */
-		orig = myproposal[PROPOSAL_KEX_ALGS];
-
-		if (options.gss_server_identity) {
-			gss_host = xstrdup(options.gss_server_identity);
-		} else if (options.gss_trust_dns) {
-			gss_host = remote_hostname(ssh);
-			/* Fall back to specified host if we are using proxy command
-			 * and can not use DNS on that socket */
-			if (strcmp(gss_host, "UNKNOWN") == 0) {
-				free(gss_host);
+		if (FIPS_mode()) {
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
+			options.gss_keyex = 0;
+		} else {
+			/* Add the GSSAPI mechanisms currently supported on this
+			 * client to the key exchange algorithm proposal */
+			orig = myproposal[PROPOSAL_KEX_ALGS];
+
+			if (options.gss_server_identity) {
+				gss_host = xstrdup(options.gss_server_identity);
+			} else if (options.gss_trust_dns) {
+				gss_host = remote_hostname(ssh);
+				/* Fall back to specified host if we are using proxy command
+				 * and can not use DNS on that socket */
+				if (strcmp(gss_host, "UNKNOWN") == 0) {
+					free(gss_host);
+					gss_host = xstrdup(host);
+				}
+			} else {
 				gss_host = xstrdup(host);
 			}
-		} else {
-			gss_host = xstrdup(host);
-		}
 
-		gss = ssh_gssapi_client_mechanisms(gss_host,
-		    options.gss_client_identity, options.gss_kex_algorithms);
-		if (gss) {
-			debug("Offering GSSAPI proposal: %s", gss);
-			xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
-			    "%s,%s", gss, orig);
-
-			/* If we've got GSSAPI algorithms, then we also support the
-			 * 'null' hostkey, as a last resort */
-			orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
-			xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
-			    "%s,null", orig);
+			gss = ssh_gssapi_client_mechanisms(gss_host,
+			    options.gss_client_identity, options.gss_kex_algorithms);
+			if (gss) {
+				debug("Offering GSSAPI proposal: %s", gss);
+				xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
+				    "%s,%s", gss, orig);
+
+				/* If we've got GSSAPI algorithms, then we also support the
+				 * 'null' hostkey, as a last resort */
+				orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
+				xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
+				    "%s,null", orig);
+			}
 		}
 	}
 #endif
diff -up openssh-8.6p1/sshd.c.fips openssh-8.6p1/sshd.c
--- openssh-8.6p1/sshd.c.fips	2021-04-19 16:53:03.060577831 +0200
+++ openssh-8.6p1/sshd.c	2021-04-19 16:57:45.827769340 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -66,6 +66,7 @@
 #include <grp.h>
 #include <pwd.h>
 #include <signal.h>
+#include <syslog.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -77,6 +78,7 @@
 #include <openssl/dh.h>
 #include <openssl/bn.h>
 #include <openssl/rand.h>
+#include <openssl/crypto.h>
 #include "openbsd-compat/openssl-compat.h"
 #endif
 
@@ -1619,6 +1621,7 @@ main(int ac, char **av)
 #endif
 	__progname = ssh_get_progname(av[0]);
 
+	OpenSSL_add_all_algorithms();
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
 	saved_argc = ac;
 	rexec_argc = ac;
@@ -2110,6 +2113,10 @@ main(int ac, char **av)
 	/* Reinitialize the log (because of the fork above). */
 	log_init(__progname, options.log_level, options.log_facility, log_stderr);
 
+	if (FIPS_mode()) {
+		debug("FIPS mode initialized");
+	}
+
 	/*
 	 * Chdir to the root directory so that the current disk can be
 	 * unmounted if desired.
@@ -2494,10 +2501,14 @@ do_ssh2_kex(struct ssh *ssh)
 	if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
 		orig = NULL;
 
-	if (options.gss_keyex)
-		gss = ssh_gssapi_server_mechanisms();
-	else
-		gss = NULL;
+	if (options.gss_keyex) {
+		if (FIPS_mode()) {
+			logit("Disabling GSSAPIKeyExchange. Not usable in FIPS mode");
+			options.gss_keyex = 0;
+		} else {
+			gss = ssh_gssapi_server_mechanisms();
+		}
+	}
 
 	if (gss && orig)
 		xasprintf(&newstr, "%s,%s", gss, orig);
diff -up openssh-8.6p1/sshkey.c.fips openssh-8.6p1/sshkey.c
--- openssh-8.6p1/sshkey.c.fips	2021-04-19 16:53:03.061577838 +0200
+++ openssh-8.6p1/sshkey.c	2021-04-19 16:53:03.067577885 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -34,6 +34,7 @@
 #include <openssl/evp.h>
 #include <openssl/err.h>
 #include <openssl/pem.h>
+#include <openssl/crypto.h>
 #endif
 
 #include "crypto_api.h"
@@ -57,6 +58,7 @@
 #define SSHKEY_INTERNAL
 #include "sshkey.h"
 #include "match.h"
+#include "log.h"
 #include "ssh-sk.h"
 
 #ifdef WITH_XMSS
@@ -1705,6 +1707,8 @@ rsa_generate_private_key(u_int bits, RSA
 	}
 	if (!BN_set_word(f4, RSA_F4) ||
 	    !RSA_generate_key_ex(private, bits, f4, NULL)) {
+			if (FIPS_mode())
+				logit_f("the key length might be unsupported by FIPS mode approved key generation method");
 		ret = SSH_ERR_LIBCRYPTO_ERROR;
 		goto out;
 	}
diff -up openssh-8.6p1/ssh-keygen.c.fips openssh-8.6p1/ssh-keygen.c
--- openssh-8.6p1/ssh-keygen.c.fips	2021-04-19 16:53:03.038577662 +0200
+++ openssh-8.6p1/ssh-keygen.c	2021-04-19 16:53:03.068577892 +0200
Reference:https://src.fedoraproject.org/rpms/openssh/blob/rawhide/f/backport-openssh-7.7p1-fips.patch
@@ -205,6 +205,12 @@ type_bits_valid(int type, const char *na
 #endif
 	}
 #ifdef WITH_OPENSSL
+	if (FIPS_mode()) {
+		if (type == KEY_DSA)
+			fatal("DSA keys are not allowed in FIPS mode");
+		if (type == KEY_ED25519)
+			fatal("ED25519 keys are not allowed in FIPS mode");
+	}
 	switch (type) {
 	case KEY_DSA:
 		if (*bitsp != 1024)
@@ -1098,9 +1104,17 @@ do_gen_all_hostkeys(struct passwd *pw)
 			first = 1;
 			printf("%s: generating new host keys: ", __progname);
 		}
+		type = sshkey_type_from_name(key_types[i].key_type);
+
+		/* Skip the keys that are not supported in FIPS mode */
+		if (FIPS_mode() && (type == KEY_DSA || type == KEY_ED25519)) {
+			logit("Skipping %s key in FIPS mode",
+			    key_types[i].key_type_display);
+			goto next;
+		}
+
 		printf("%s ", key_types[i].key_type_display);
 		fflush(stdout);
-		type = sshkey_type_from_name(key_types[i].key_type);
 		if ((fd = mkstemp(prv_tmp)) == -1) {
 			error("Could not save your private key in %s: %s",
 			    prv_tmp, strerror(errno));