vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F 003cb0
diff -up openssh-5.8p1/audit.c.fips openssh-5.8p1/audit.c
Jan F 9cefae
--- openssh-5.8p1/audit.c.fips	2011-02-21 17:05:13.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/audit.c	2011-02-21 17:06:18.000000000 +0100
Jan F 9cefae
@@ -121,7 +121,7 @@ audit_key(int host_user, int *rv, const 
Jan F 9cefae
 	char *fp;
Jan F 9cefae
 	const char *crypto_name;
Jan F af8738
 
Jan F af8738
-	fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
Jan F af8738
+	fp = key_fingerprint(key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Jan F 9cefae
 	if (key->type == KEY_RSA1)
Jan F 9cefae
 		crypto_name = "ssh-rsa1";
Jan F 9cefae
 	else
Jan F 003cb0
diff -up openssh-5.8p1/auth2-pubkey.c.fips openssh-5.8p1/auth2-pubkey.c
Jan F 9cefae
--- openssh-5.8p1/auth2-pubkey.c.fips	2011-02-21 17:05:14.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/auth2-pubkey.c	2011-02-21 17:05:14.000000000 +0100
Jan F. Chadima 1b8a26
@@ -36,6 +36,7 @@
Jan F. Chadima 974c89
 #include <string.h>
Jan F. Chadima 974c89
 #include <time.h>
Tomáš Mráz d93958
 #include <unistd.h>
Tomáš Mráz d93958
+#include <openssl/fips.h>
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 #include "xmalloc.h"
Tomáš Mráz d93958
 #include "ssh.h"
Jan F af8738
@@ -371,7 +372,7 @@ user_search_key_in_file(FILE *f, char *f
Tomáš Mráz d93958
 			found_key = 1;
Tomáš Mráz d93958
 			debug("matching key found: file %s, line %lu",
Tomáš Mráz d93958
 			    file, linenum);
Tomáš Mráz d93958
-			fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz d93958
+			fp = key_fingerprint(found, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz d93958
 			verbose("Found matching %s key: %s",
Tomáš Mráz d93958
 			    key_type(found), fp);
Tomáš Mráz d93958
 			xfree(fp);
Jan F 003cb0
diff -up openssh-5.8p1/authfile.c.fips openssh-5.8p1/authfile.c
Jan F 003cb0
--- openssh-5.8p1/authfile.c.fips	2010-12-01 02:03:39.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/authfile.c	2011-02-21 17:05:14.000000000 +0100
Jan F 003cb0
@@ -145,8 +145,14 @@ key_private_rsa1_to_blob(Key *key, Buffe
Tomáš Mráz 76f329
 	/* Allocate space for the private part of the key in the buffer. */
Tomáš Mráz 76f329
 	cp = buffer_append_space(&encrypted, buffer_len(&buffer));
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
-	cipher_set_key_string(&ciphercontext, cipher, passphrase,
Tomáš Mráz 76f329
-	    CIPHER_ENCRYPT);
Tomáš Mráz 76f329
+	if (cipher_set_key_string(&ciphercontext, cipher, passphrase,
Tomáš Mráz 76f329
+	    CIPHER_ENCRYPT) < 0) {
Tomáš Mráz 76f329
+	    error("cipher_set_key_string failed.");
Tomáš Mráz 76f329
+	    buffer_free(&encrypted);
Tomáš Mráz 76f329
+	    buffer_free(&buffer);
Tomáš Mráz 76f329
+	    return 0;
Tomáš Mráz 76f329
+	}
Tomáš Mráz 76f329
+
Tomáš Mráz 76f329
 	cipher_crypt(&ciphercontext, cp,
Tomáš Mráz 76f329
 	    buffer_ptr(&buffer), buffer_len(&buffer));
Tomáš Mráz 76f329
 	cipher_cleanup(&ciphercontext);
Jan F 003cb0
@@ -447,8 +453,13 @@ key_parse_private_rsa1(Buffer *blob, con
Jan F 003cb0
 	cp = buffer_append_space(&decrypted, buffer_len(blob));
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
 	/* Rest of the buffer is encrypted.  Decrypt it using the passphrase. */
Tomáš Mráz 76f329
-	cipher_set_key_string(&ciphercontext, cipher, passphrase,
Tomáš Mráz 76f329
-	    CIPHER_DECRYPT);
Tomáš Mráz 76f329
+	if (cipher_set_key_string(&ciphercontext, cipher, passphrase,
Tomáš Mráz 76f329
+	    CIPHER_DECRYPT) < 0) {
Tomáš Mráz 76f329
+	    error("cipher_set_key_string failed.");
Tomáš Mráz 76f329
+	    buffer_free(&decrypted);
Tomáš Mráz 76f329
+	    goto fail;
Tomáš Mráz 76f329
+	}
Tomáš Mráz 76f329
+
Tomáš Mráz 76f329
 	cipher_crypt(&ciphercontext, cp,
Jan F 003cb0
 	    buffer_ptr(blob), buffer_len(blob));
Tomáš Mráz 76f329
 	cipher_cleanup(&ciphercontext);
Jan F 003cb0
diff -up openssh-5.8p1/auth-rsa.c.fips openssh-5.8p1/auth-rsa.c
Jan F 9cefae
--- openssh-5.8p1/auth-rsa.c.fips	2011-02-21 17:05:13.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/auth-rsa.c	2011-02-21 17:07:33.000000000 +0100
Jan F 003cb0
@@ -119,7 +119,7 @@ auth_rsa_verify_response(Key *key, BIGNU
Jan F af8738
 	rv = timingsafe_bcmp(response, mdbuf, 16) == 0;
Jan F af8738
 
Jan F af8738
 #ifdef SSH_AUDIT_EVENTS
Jan F af8738
-	fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
Jan F af8738
+	fp = key_fingerprint(key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Jan F 9cefae
 	if (audit_keyusage(1, "ssh-rsa1", RSA_size(key->rsa) * 8, fp, rv) == 0) {
Jan F af8738
 		debug("unsuccessful audit");
Jan F af8738
 		rv = 0;
Jan F 003cb0
diff -up openssh-5.8p1/cipher.c.fips openssh-5.8p1/cipher.c
Jan F 9cefae
--- openssh-5.8p1/cipher.c.fips	2011-02-21 17:05:13.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/cipher.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz 0a4fa5
@@ -40,6 +40,7 @@
Tomáš Mráz 0a4fa5
 #include <sys/types.h>
Tomáš Mráz d93958
 
Tomáš Mráz 0a4fa5
 #include <openssl/md5.h>
Tomáš Mráz d93958
+#include <openssl/fips.h>
Jan F. Chadima adad2a
 
Tomáš Mráz 0a4fa5
 #include <string.h>
Tomáš Mráz 0a4fa5
 #include <stdarg.h>
Jan F af8738
@@ -85,6 +86,22 @@ struct Cipher ciphers[] = {
Tomáš Mráz 0a4fa5
 	{ NULL,			SSH_CIPHER_INVALID, 0, 0, 0, 0, NULL }
Tomáš Mráz 0a4fa5
 };
Jan F. Chadima adad2a
 
Tomáš Mráz 0a4fa5
+struct Cipher fips_ciphers[] = {
Tomáš Mráz 0a4fa5
+	{ "none",		SSH_CIPHER_NONE, 8, 0, 0, 0, EVP_enc_null },
Tomáš Mráz 0a4fa5
+	{ "3des",		SSH_CIPHER_3DES, 8, 16, 0, 1, evp_ssh1_3des },
Tomáš Mráz d93958
+
Tomáš Mráz 0a4fa5
+	{ "3des-cbc",		SSH_CIPHER_SSH2, 8, 24, 0, 1, EVP_des_ede3_cbc },
Tomáš Mráz 0a4fa5
+	{ "aes128-cbc",		SSH_CIPHER_SSH2, 16, 16, 0, 1, EVP_aes_128_cbc },
Tomáš Mráz 0a4fa5
+	{ "aes192-cbc",		SSH_CIPHER_SSH2, 16, 24, 0, 1, EVP_aes_192_cbc },
Tomáš Mráz 0a4fa5
+	{ "aes256-cbc",		SSH_CIPHER_SSH2, 16, 32, 0, 1, EVP_aes_256_cbc },
Tomáš Mráz 0a4fa5
+	{ "rijndael-cbc@lysator.liu.se",
Tomáš Mráz 0a4fa5
+				SSH_CIPHER_SSH2, 16, 32, 0, 1, EVP_aes_256_cbc },
Tomáš Mráz 0a4fa5
+	{ "aes128-ctr",		SSH_CIPHER_SSH2, 16, 16, 0, 0, evp_aes_128_ctr },
Tomáš Mráz 0a4fa5
+	{ "aes192-ctr",		SSH_CIPHER_SSH2, 16, 24, 0, 0, evp_aes_128_ctr },
Tomáš Mráz 0a4fa5
+	{ "aes256-ctr",		SSH_CIPHER_SSH2, 16, 32, 0, 0, evp_aes_128_ctr },
Tomáš Mráz 0a4fa5
+	{ NULL,			SSH_CIPHER_INVALID, 0, 0, 0, 0, NULL }
Tomáš Mráz 0a4fa5
+};
Jan F. Chadima adad2a
+
Tomáš Mráz 0a4fa5
 /*--*/
Jan F. Chadima adad2a
 
Tomáš Mráz 0a4fa5
 u_int
Jan F af8738
@@ -127,7 +144,7 @@ Cipher *
Tomáš Mráz 0a4fa5
 cipher_by_name(const char *name)
Tomáš Mráz 0a4fa5
 {
Tomáš Mráz 0a4fa5
 	Cipher *c;
Tomáš Mráz 0a4fa5
-	for (c = ciphers; c->name != NULL; c++)
Tomáš Mráz 0a4fa5
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
Tomáš Mráz 0a4fa5
 		if (strcmp(c->name, name) == 0)
Tomáš Mráz 0a4fa5
 			return c;
Tomáš Mráz 0a4fa5
 	return NULL;
Jan F af8738
@@ -137,7 +154,7 @@ Cipher *
Tomáš Mráz 0a4fa5
 cipher_by_number(int id)
Tomáš Mráz 0a4fa5
 {
Tomáš Mráz 0a4fa5
 	Cipher *c;
Tomáš Mráz 0a4fa5
-	for (c = ciphers; c->name != NULL; c++)
Tomáš Mráz 0a4fa5
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
Tomáš Mráz 0a4fa5
 		if (c->number == id)
Tomáš Mráz 0a4fa5
 			return c;
Tomáš Mráz 0a4fa5
 	return NULL;
Jan F af8738
@@ -181,7 +198,7 @@ cipher_number(const char *name)
Tomáš Mráz 0a4fa5
 	Cipher *c;
Tomáš Mráz 0a4fa5
 	if (name == NULL)
Tomáš Mráz 0a4fa5
 		return -1;
Tomáš Mráz 0a4fa5
-	for (c = ciphers; c->name != NULL; c++)
Tomáš Mráz 0a4fa5
+	for (c = FIPS_mode() ? fips_ciphers : ciphers; c->name != NULL; c++)
Tomáš Mráz 0a4fa5
 		if (strcasecmp(c->name, name) == 0)
Tomáš Mráz 0a4fa5
 			return c->number;
Tomáš Mráz 0a4fa5
 	return -1;
Jan F af8738
@@ -288,14 +305,15 @@ cipher_cleanup(CipherContext *cc)
Tomáš Mráz 76f329
  * passphrase and using the resulting 16 bytes as the key.
Tomáš Mráz 76f329
  */
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
-void
Tomáš Mráz 76f329
+int
Tomáš Mráz 76f329
 cipher_set_key_string(CipherContext *cc, Cipher *cipher,
Tomáš Mráz 76f329
     const char *passphrase, int do_encrypt)
Tomáš Mráz 76f329
 {
Tomáš Mráz 76f329
 	MD5_CTX md;
Tomáš Mráz 76f329
 	u_char digest[16];
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
-	MD5_Init(&md);
Tomáš Mráz 76f329
+	if (MD5_Init(&md) <= 0)
Tomáš Mráz 76f329
+		return -1;
Tomáš Mráz 76f329
 	MD5_Update(&md, (const u_char *)passphrase, strlen(passphrase));
Tomáš Mráz 76f329
 	MD5_Final(digest, &md);
Tomáš Mráz 76f329
 
Jan F af8738
@@ -303,6 +321,7 @@ cipher_set_key_string(CipherContext *cc,
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
 	memset(digest, 0, sizeof(digest));
Tomáš Mráz 76f329
 	memset(&md, 0, sizeof(md));
Tomáš Mráz 76f329
+	return 0;
Tomáš Mráz 76f329
 }
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
 /*
Jan F 003cb0
diff -up openssh-5.8p1/cipher-ctr.c.fips openssh-5.8p1/cipher-ctr.c
Jan F 003cb0
--- openssh-5.8p1/cipher-ctr.c.fips	2010-10-07 13:06:42.000000000 +0200
Jan F 9cefae
+++ openssh-5.8p1/cipher-ctr.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz 0a4fa5
@@ -140,7 +140,8 @@ evp_aes_128_ctr(void)
Tomáš Mráz 0a4fa5
 	aes_ctr.do_cipher = ssh_aes_ctr;
Tomáš Mráz 0a4fa5
 #ifndef SSH_OLD_EVP
Tomáš Mráz 0a4fa5
 	aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
Tomáš Mráz 0a4fa5
-	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV;
Tomáš Mráz 0a4fa5
+	    EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV |
Tomáš Mráz 0a4fa5
+	    EVP_CIPH_FLAG_FIPS;
Jan F. Chadima adad2a
 #endif
Tomáš Mráz 0a4fa5
 	return (&aes_ctr);
Tomáš Mráz 0a4fa5
 }
Jan F 003cb0
diff -up openssh-5.8p1/cipher.h.fips openssh-5.8p1/cipher.h
Jan F 9cefae
--- openssh-5.8p1/cipher.h.fips	2011-02-21 17:05:13.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/cipher.h	2011-02-21 17:05:14.000000000 +0100
Jan F af8738
@@ -87,7 +87,7 @@ void	 cipher_init(CipherContext *, Ciphe
Tomáš Mráz 76f329
     const u_char *, u_int, int);
Tomáš Mráz 76f329
 void	 cipher_crypt(CipherContext *, u_char *, const u_char *, u_int);
Tomáš Mráz 76f329
 void	 cipher_cleanup(CipherContext *);
Tomáš Mráz 76f329
-void	 cipher_set_key_string(CipherContext *, Cipher *, const char *, int);
Tomáš Mráz 76f329
+int	 cipher_set_key_string(CipherContext *, Cipher *, const char *, int);
Tomáš Mráz 76f329
 u_int	 cipher_blocksize(const Cipher *);
Tomáš Mráz 76f329
 u_int	 cipher_keylen(const Cipher *);
Tomáš Mráz 76f329
 u_int	 cipher_is_cbc(const Cipher *);
Jan F 003cb0
diff -up openssh-5.8p1/mac.c.fips openssh-5.8p1/mac.c
Jan F 9cefae
--- openssh-5.8p1/mac.c.fips	2011-02-21 17:05:13.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/mac.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz d93958
@@ -28,6 +28,7 @@
Tomáš Mráz d93958
 #include <sys/types.h>
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 #include <openssl/hmac.h>
Tomáš Mráz d93958
+#include <openssl/fips.h>
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 #include <stdarg.h>
Tomáš Mráz d93958
 #include <string.h>
Tomáš Mráz d93958
@@ -47,14 +48,14 @@
Tomáš Mráz d93958
 #define SSH_EVP		1	/* OpenSSL EVP-based MAC */
Tomáš Mráz d93958
 #define SSH_UMAC	2	/* UMAC (not integrated with OpenSSL) */
Tomáš Mráz d93958
 
Tomáš Mráz d93958
-struct {
Tomáš Mráz d93958
+struct Macs {
Tomáš Mráz d93958
 	char		*name;
Tomáš Mráz d93958
 	int		type;
Tomáš Mráz d93958
 	const EVP_MD *	(*mdfunc)(void);
Tomáš Mráz d93958
 	int		truncatebits;	/* truncate digest if != 0 */
Tomáš Mráz d93958
 	int		key_len;	/* just for UMAC */
Tomáš Mráz d93958
 	int		len;		/* just for UMAC */
Tomáš Mráz d93958
-} macs[] = {
Tomáš Mráz d93958
+} all_macs[] = {
Tomáš Mráz d93958
 	{ "hmac-sha1",			SSH_EVP, EVP_sha1, 0, -1, -1 },
Tomáš Mráz d93958
 	{ "hmac-sha1-96",		SSH_EVP, EVP_sha1, 96, -1, -1 },
Tomáš Mráz d93958
 	{ "hmac-md5",			SSH_EVP, EVP_md5, 0, -1, -1 },
Tomáš Mráz d93958
@@ -65,9 +66,15 @@ struct {
Tomáš Mráz d93958
 	{ NULL,				0, NULL, 0, -1, -1 }
Tomáš Mráz d93958
 };
Tomáš Mráz d93958
 
Tomáš Mráz d93958
+struct Macs fips_macs[] = {
Tomáš Mráz d93958
+	{ "hmac-sha1",			SSH_EVP, EVP_sha1, 0, -1, -1 },
Tomáš Mráz d93958
+	{ NULL,				0, NULL, 0, -1, -1 }
Tomáš Mráz d93958
+};
Tomáš Mráz d93958
+
Tomáš Mráz d93958
 static void
Tomáš Mráz d93958
 mac_setup_by_id(Mac *mac, int which)
Tomáš Mráz d93958
 {
Tomáš Mráz d93958
+	struct Macs *macs = FIPS_mode() ? fips_macs : all_macs;
Tomáš Mráz d93958
 	int evp_len;
Tomáš Mráz d93958
 	mac->type = macs[which].type;
Tomáš Mráz d93958
 	if (mac->type == SSH_EVP) {
Tomáš Mráz d93958
@@ -88,6 +95,7 @@ int
Tomáš Mráz d93958
 mac_setup(Mac *mac, char *name)
Tomáš Mráz d93958
 {
Tomáš Mráz d93958
 	int i;
Tomáš Mráz d93958
+	struct Macs *macs = FIPS_mode() ? fips_macs : all_macs;
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 	for (i = 0; macs[i].name; i++) {
Tomáš Mráz d93958
 		if (strcmp(name, macs[i].name) == 0) {
Jan F 003cb0
diff -up openssh-5.8p1/Makefile.in.fips openssh-5.8p1/Makefile.in
Jan F 9cefae
--- openssh-5.8p1/Makefile.in.fips	2011-02-21 17:05:14.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/Makefile.in	2011-02-21 17:05:14.000000000 +0100
Jan F 003cb0
@@ -145,25 +145,25 @@ libssh.a: $(LIBSSH_OBJS)
Tomáš Mráz 0a4fa5
 	$(RANLIB) $@
Tomáš Mráz d93958
 
Tomáš Mráz 0a4fa5
 ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS)
Jan F 003cb0
-	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHLIBS) $(LIBS)
Jan F 003cb0
+	$(LD) -o $@ $(SSHOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(SSHLIBS) $(LIBS)
Tomáš Mráz d93958
 
Tomáš Mráz 0a4fa5
 sshd$(EXEEXT): libssh.a	$(LIBCOMPAT) $(SSHDOBJS)
Tomáš Mráz 0a4fa5
-	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(SSHDLIBS) $(LIBS)
Jan F. Chadima c54a8b
+	$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(SSHDLIBS) $(LIBS)
Tomáš Mráz d93958
 
Tomáš Mráz 0a4fa5
 scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o
Tomáš Mráz 0a4fa5
 	$(LD) -o $@ scp.o progressmeter.o bufaux.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Tomáš Mráz d93958
 
Tomáš Mráz 0a4fa5
 ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o
Tomáš Mráz 0a4fa5
-	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Tomáš Mráz 0a4fa5
+	$(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Jan F. Chadima a3ba41
 
Jan F. Chadima 974c89
 ssh-agent$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-agent.o ssh-pkcs11-client.o
Jan F. Chadima 974c89
-	$(LD) -o $@ ssh-agent.o ssh-pkcs11-client.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Jan F. Chadima 82bc82
+	$(LD) -o $@ ssh-agent.o ssh-pkcs11-client.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Jan F. Chadima a3ba41
 
Tomáš Mráz 0a4fa5
 ssh-keygen$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keygen.o
Tomáš Mráz 0a4fa5
-	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Tomáš Mráz 0a4fa5
+	$(LD) -o $@ ssh-keygen.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Jan F. Chadima a3ba41
 
Jan F. Chadima 974c89
 ssh-keysign$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keysign.o roaming_dummy.o readconf.o
Jan F. Chadima c54a8b
-	$(LD) -o $@ ssh-keysign.o readconf.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Jan F. Chadima c54a8b
+	$(LD) -o $@ ssh-keysign.o readconf.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Tomáš Mráz 0a4fa5
 
Jan F. Chadima 974c89
 ssh-pkcs11-helper$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-pkcs11-helper.o ssh-pkcs11.o
Jan F. Chadima 1b8a26
 	$(LD) -o $@ ssh-pkcs11-helper.o ssh-pkcs11.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS)
Jan F 003cb0
@@ -172,7 +172,7 @@ ssh-ldap-helper$(EXEEXT): $(LIBCOMPAT) l
Jan F. Chadima 3fdf10
 	$(LD) -o $@ ldapconf.o ldapbody.o ldapmisc.o ldap-helper.o $(LDFLAGS) -lssh -lopenbsd-compat -lfipscheck $(LIBS)
Jan F. Chadima 974c89
 
Jan F. Chadima c54a8b
 ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o roaming_dummy.o
Jan F. Chadima c54a8b
-	$(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
Jan F. Chadima c54a8b
+	$(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o sftp-server-main.o
Tomáš Mráz 0a4fa5
 	$(LD) -o $@ sftp-server.o sftp-common.o sftp-server-main.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
Jan F 003cb0
diff -up openssh-5.8p1/myproposal.h.fips openssh-5.8p1/myproposal.h
Jan F 003cb0
--- openssh-5.8p1/myproposal.h.fips	2011-01-13 12:00:22.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/myproposal.h	2011-02-21 17:05:14.000000000 +0100
Jan F 003cb0
@@ -81,7 +81,12 @@
Tomáš Mráz 0a4fa5
 	"hmac-sha1-96,hmac-md5-96"
Tomáš Mráz 0a4fa5
 #define	KEX_DEFAULT_COMP	"none,zlib@openssh.com,zlib"
Tomáš Mráz 0a4fa5
 #define	KEX_DEFAULT_LANG	""
Tomáš Mráz 0a4fa5
-
Tomáš Mráz 0a4fa5
+#define	KEX_FIPS_ENCRYPT \
Tomáš Mráz 0a4fa5
+	"aes128-ctr,aes192-ctr,aes256-ctr," \
Tomáš Mráz 0a4fa5
+	"aes128-cbc,3des-cbc," \
Tomáš Mráz 0a4fa5
+	"aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se"
Tomáš Mráz 0a4fa5
+#define	KEX_FIPS_MAC \
Tomáš Mráz 0a4fa5
+	"hmac-sha1"
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 static char *myproposal[PROPOSAL_MAX] = {
Tomáš Mráz 0a4fa5
 	KEX_DEFAULT_KEX,
Jan F 003cb0
diff -up openssh-5.8p1/openbsd-compat/bsd-arc4random.c.fips openssh-5.8p1/openbsd-compat/bsd-arc4random.c
Jan F 003cb0
--- openssh-5.8p1/openbsd-compat/bsd-arc4random.c.fips	2010-03-25 22:52:02.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/openbsd-compat/bsd-arc4random.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz d93958
@@ -39,6 +39,7 @@
Tomáš Mráz d93958
 static int rc4_ready = 0;
Tomáš Mráz d93958
 static RC4_KEY rc4;
Tomáš Mráz d93958
 
Tomáš Mráz d93958
+#if 0
Tomáš Mráz d93958
 unsigned int
Tomáš Mráz d93958
 arc4random(void)
Tomáš Mráz d93958
 {
Tomáš Mráz d93958
@@ -82,6 +83,32 @@ arc4random_stir(void)
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 	rc4_ready = REKEY_BYTES;
Tomáš Mráz d93958
 }
Tomáš Mráz d93958
+#else
Tomáš Mráz d93958
+unsigned int
Tomáš Mráz d93958
+arc4random(void)
Tomáš Mráz d93958
+{
Tomáš Mráz d93958
+	unsigned int r = 0;
Tomáš Mráz d93958
+	void *rp = &r;
Tomáš Mráz d93958
+
Tomáš Mráz d93958
+	if (!rc4_ready) {
Tomáš Mráz d93958
+		arc4random_stir();
Tomáš Mráz d93958
+	}
Tomáš Mráz d93958
+	RAND_bytes(rp, sizeof(r));
Tomáš Mráz d93958
+
Tomáš Mráz d93958
+	return(r);
Tomáš Mráz d93958
+}
Tomáš Mráz d93958
+
Tomáš Mráz d93958
+void
Tomáš Mráz d93958
+arc4random_stir(void)
Tomáš Mráz d93958
+{
Tomáš Mráz d93958
+	unsigned char rand_buf[SEED_SIZE];
Tomáš Mráz d93958
+
Tomáš Mráz d93958
+	if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
Tomáš Mráz d93958
+		fatal("Couldn't obtain random bytes (error %ld)",
Tomáš Mráz d93958
+		    ERR_get_error());
Tomáš Mráz d93958
+	rc4_ready = 1;
Tomáš Mráz d93958
+}
Tomáš Mráz d93958
+#endif
Tomáš Mráz d93958
 #endif /* !HAVE_ARC4RANDOM */
Tomáš Mráz d93958
 
Jan F. Chadima 82bc82
 #ifndef HAVE_ARC4RANDOM_BUF
Jan F 003cb0
diff -up openssh-5.8p1/ssh-add.c.fips openssh-5.8p1/ssh-add.c
Jan F 003cb0
--- openssh-5.8p1/ssh-add.c.fips	2010-11-11 04:17:02.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/ssh-add.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz 685b62
@@ -42,6 +42,7 @@
Tomáš Mráz 0a4fa5
 #include <sys/param.h>
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 #include <openssl/evp.h>
Tomáš Mráz d93958
+#include <openssl/fips.h>
Tomáš Mráz 0a4fa5
 #include "openbsd-compat/openssl-compat.h"
Tomáš Mráz d93958
 
Jan F. Chadima 974c89
 #include <fcntl.h>
Jan F 003cb0
@@ -280,7 +281,7 @@ list_identities(AuthenticationConnection
Tomáš Mráz 0a4fa5
 		    key = ssh_get_next_identity(ac, &comment, version)) {
Tomáš Mráz 0a4fa5
 			had_identities = 1;
Tomáš Mráz 0a4fa5
 			if (do_fp) {
Tomáš Mráz 0a4fa5
-				fp = key_fingerprint(key, SSH_FP_MD5,
Tomáš Mráz 0a4fa5
+				fp = key_fingerprint(key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5,
Tomáš Mráz 0a4fa5
 				    SSH_FP_HEX);
Tomáš Mráz 0a4fa5
 				printf("%d %s %s (%s)\n",
Tomáš Mráz 0a4fa5
 				    key_size(key), fp, comment, key_type(key));
Jan F 003cb0
diff -up openssh-5.8p1/ssh-agent.c.fips openssh-5.8p1/ssh-agent.c
Jan F 003cb0
--- openssh-5.8p1/ssh-agent.c.fips	2010-12-01 01:50:35.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/ssh-agent.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz 685b62
@@ -51,6 +51,7 @@
Jan F. Chadima adad2a
 
Tomáš Mráz 0a4fa5
 #include <openssl/evp.h>
Jan F. Chadima adad2a
 #include <openssl/md5.h>
Jan F. Chadima adad2a
+#include <openssl/fips.h>
Tomáš Mráz 0a4fa5
 #include "openbsd-compat/openssl-compat.h"
Jan F. Chadima adad2a
 
Tomáš Mráz 0a4fa5
 #include <errno.h>
Jan F. Chadima 974c89
@@ -199,9 +200,9 @@ confirm_key(Identity *id)
Tomáš Mráz 0a4fa5
 	char *p;
Tomáš Mráz 0a4fa5
 	int ret = -1;
Jan F. Chadima adad2a
 
Tomáš Mráz 0a4fa5
-	p = key_fingerprint(id->key, SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz 0a4fa5
-	if (ask_permission("Allow use of key %s?\nKey fingerprint %s.",
Tomáš Mráz 0a4fa5
-	    id->comment, p))
Tomáš Mráz 0a4fa5
+	p = key_fingerprint(id->key, FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz 0a4fa5
+	if (ask_permission("Allow use of key %s?\nKey %sfingerprint %s.",
Tomáš Mráz 0a4fa5
+	    id->comment, FIPS_mode() ? "SHA1 " : "", p))
Tomáš Mráz 0a4fa5
 		ret = 0;
Tomáš Mráz 0a4fa5
 	xfree(p);
Jan F. Chadima adad2a
 
Jan F 003cb0
diff -up openssh-5.8p1/ssh.c.fips openssh-5.8p1/ssh.c
Jan F 003cb0
--- openssh-5.8p1/ssh.c.fips	2011-02-04 01:42:15.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/ssh.c	2011-02-21 17:05:14.000000000 +0100
Jan F 003cb0
@@ -73,6 +73,8 @@
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 #include <openssl/evp.h>
Tomáš Mráz 0a4fa5
 #include <openssl/err.h>
Tomáš Mráz d93958
+#include <openssl/fips.h>
Tomáš Mráz d93958
+#include <fipscheck.h>
Tomáš Mráz 0a4fa5
 #include "openbsd-compat/openssl-compat.h"
Tomáš Mráz 0a4fa5
 #include "openbsd-compat/sys-queue.h"
Tomáš Mráz d93958
 
Jan F 003cb0
@@ -234,6 +236,10 @@ main(int ac, char **av)
Tomáš Mráz 0a4fa5
 	sanitise_stdfd();
Jan F. Chadima a3ba41
 
Tomáš Mráz 0a4fa5
 	__progname = ssh_get_progname(av[0]);
Jan F. Chadima adad2a
+        SSLeay_add_all_algorithms();
Tomáš Mráz d93958
+        if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
Tomáš Mráz 0a4fa5
+                fatal("FIPS integrity verification test failed.");
Tomáš Mráz d93958
+        }
Jan F. Chadima adad2a
 	init_rng();
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 	/*
Jan F 003cb0
@@ -300,6 +306,9 @@ main(int ac, char **av)
Jan F. Chadima 974c89
 	    "ACD:F:I:KL:MNO:PR:S:TVw:W:XYy")) != -1) {
Tomáš Mráz 76f329
 		switch (opt) {
Tomáš Mráz 76f329
 		case '1':
Tomáš Mráz 76f329
+			if (FIPS_mode()) {
Tomáš Mráz 76f329
+				fatal("Protocol 1 not allowed in the FIPS mode.");
Tomáš Mráz 76f329
+			}
Tomáš Mráz 76f329
 			options.protocol = SSH_PROTO_1;
Tomáš Mráz 76f329
 			break;
Tomáš Mráz 76f329
 		case '2':
Jan F 003cb0
@@ -598,7 +607,6 @@ main(int ac, char **av)
Tomáš Mráz 0a4fa5
 	if (!host)
Tomáš Mráz 0a4fa5
 		usage();
Tomáš Mráz 0a4fa5
 
Jan F 003cb0
-	OpenSSL_add_all_algorithms();
Tomáš Mráz 0a4fa5
 	ERR_load_crypto_strings();
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 	/* Initialize the command to execute on remote host. */
Jan F 003cb0
@@ -684,6 +692,10 @@ main(int ac, char **av)
Tomáš Mráz 0a4fa5
 
Jan F. Chadima adad2a
 	seed_rng();
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
+	if (FIPS_mode()) {
Tomáš Mráz 0a4fa5
+		logit("FIPS mode initialized");
Tomáš Mráz 0a4fa5
+	}
Tomáš Mráz 0a4fa5
+
Tomáš Mráz 0a4fa5
 	if (options.user == NULL)
Tomáš Mráz 0a4fa5
 		options.user = xstrdup(pw->pw_name);
Tomáš Mráz 0a4fa5
 
Jan F 003cb0
@@ -753,6 +765,12 @@ main(int ac, char **av)
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
 	timeout_ms = options.connection_timeout * 1000;
Tomáš Mráz 76f329
 
Tomáš Mráz 76f329
+	if (FIPS_mode()) {
Tomáš Mráz 76f329
+		options.protocol &= SSH_PROTO_2;
Tomáš Mráz 76f329
+		if (options.protocol == 0)
Tomáš Mráz 76f329
+			fatal("Protocol 2 disabled by configuration but required in the FIPS mode.");
Tomáš Mráz 76f329
+	}
Tomáš Mráz 76f329
+
Tomáš Mráz 76f329
 	/* Open a connection to the remote host. */
Tomáš Mráz 76f329
 	if (ssh_connect(host, &hostaddr, options.port,
Tomáš Mráz 76f329
 	    options.address_family, options.connection_attempts, &timeout_ms,
Jan F 003cb0
diff -up openssh-5.8p1/sshconnect2.c.fips openssh-5.8p1/sshconnect2.c
Jan F 003cb0
--- openssh-5.8p1/sshconnect2.c.fips	2010-12-01 02:21:51.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/sshconnect2.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz 0a4fa5
@@ -44,6 +44,8 @@
Tomáš Mráz 0a4fa5
 #include <vis.h>
Tomáš Mráz 0a4fa5
 #endif
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
+#include <openssl/fips.h>
Tomáš Mráz 0a4fa5
+
Tomáš Mráz 0a4fa5
 #include "openbsd-compat/sys-queue.h"
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 #include "xmalloc.h"
Jan F 003cb0
@@ -169,6 +171,10 @@ ssh_kex2(char *host, struct sockaddr *ho
Tomáš Mráz 0a4fa5
 	if (options.ciphers != NULL) {
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
Tomáš Mráz 0a4fa5
+	} else if (FIPS_mode()) {
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
Tomáš Mráz 0a4fa5
+
Tomáš Mráz 0a4fa5
 	}
Tomáš Mráz 0a4fa5
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
Jan F 003cb0
@@ -184,7 +190,11 @@ ssh_kex2(char *host, struct sockaddr *ho
Tomáš Mráz 0a4fa5
 	if (options.macs != NULL) {
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
Tomáš Mráz 0a4fa5
+	} else if (FIPS_mode()) {
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
Tomáš Mráz 0a4fa5
 	}
Tomáš Mráz 0a4fa5
+
Tomáš Mráz 0a4fa5
 	if (options.hostkeyalgorithms != NULL)
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
Tomáš Mráz 0a4fa5
 		    options.hostkeyalgorithms;
Jan F 003cb0
@@ -590,8 +600,8 @@ input_userauth_pk_ok(int type, u_int32_t
Tomáš Mráz 0a4fa5
 		    key->type, pktype);
Tomáš Mráz 0a4fa5
 		goto done;
Tomáš Mráz 0a4fa5
 	}
Tomáš Mráz 0a4fa5
-	fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz 0a4fa5
-	debug2("input_userauth_pk_ok: fp %s", fp);
Tomáš Mráz 0a4fa5
+	fp = key_fingerprint(key, SSH_FP_SHA1, SSH_FP_HEX);
Tomáš Mráz 0a4fa5
+	debug2("input_userauth_pk_ok: SHA1 fp %s", fp);
Tomáš Mráz 0a4fa5
 	xfree(fp);
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 	/*
Jan F 003cb0
diff -up openssh-5.8p1/sshconnect.c.fips openssh-5.8p1/sshconnect.c
Jan F 003cb0
--- openssh-5.8p1/sshconnect.c.fips	2011-01-16 13:17:59.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/sshconnect.c	2011-02-21 17:05:14.000000000 +0100
Jan F 003cb0
@@ -41,6 +41,8 @@
Jan F. Chadima 974c89
 #include <string.h>
Tomáš Mráz d93958
 #include <unistd.h>
Tomáš Mráz d93958
 
Tomáš Mráz d93958
+#include <openssl/fips.h>
Tomáš Mráz d93958
+
Tomáš Mráz d93958
 #include "xmalloc.h"
Tomáš Mráz d93958
 #include "key.h"
Tomáš Mráz d93958
 #include "hostfile.h"
Jan F 003cb0
@@ -705,6 +707,7 @@ check_host_key(char *hostname, struct so
Jan F 003cb0
 	int len, cancelled_forwarding = 0;
Jan F 003cb0
 	struct hostkeys *host_hostkeys, *ip_hostkeys;
Jan F 003cb0
 	const struct hostkey_entry *host_found, *ip_found;
Jan F 003cb0
+	int fips_on = FIPS_mode();
Jan F 003cb0
 
Jan F 003cb0
 	/*
Jan F 003cb0
 	 * Force accepting of the host key for loopback/localhost. The
Jan F 003cb0
@@ -798,10 +801,10 @@ check_host_key(char *hostname, struct so
Jan F 003cb0
 				    "key for IP address '%.128s' to the list "
Jan F 003cb0
 				    "of known hosts.", type, ip);
Jan F 003cb0
 		} else if (options.visual_host_key) {
Jan F 003cb0
-			fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
Jan F 003cb0
-			ra = key_fingerprint(host_key, SSH_FP_MD5,
Jan F 003cb0
+			fp = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Jan F 003cb0
+			ra = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5,
Jan F 003cb0
 			    SSH_FP_RANDOMART);
Jan F 003cb0
-			logit("Host key fingerprint is %s\n%s\n", fp, ra);
Jan F 003cb0
+			logit("Host key %sfingerprint is %s\n%s\n", fips_on ? "SHA1 " : "", fp, ra);
Jan F 003cb0
 			xfree(ra);
Jan F 003cb0
 			xfree(fp);
Jan F 003cb0
 		}
Jan F 003cb0
@@ -830,6 +833,7 @@ check_host_key(char *hostname, struct so
Tomáš Mráz d93958
 			goto fail;
Tomáš Mráz d93958
 		} else if (options.strict_host_key_checking == 2) {
Tomáš Mráz d93958
 			char msg1[1024], msg2[1024];
Tomáš Mráz d93958
+			int fips_on = FIPS_mode();
Tomáš Mráz d93958
 
Jan F 003cb0
 			if (show_other_keys(host_hostkeys, host_key))
Tomáš Mráz d93958
 				snprintf(msg1, sizeof(msg1),
Jan F 003cb0
@@ -838,8 +842,8 @@ check_host_key(char *hostname, struct so
Tomáš Mráz d93958
 			else
Tomáš Mráz d93958
 				snprintf(msg1, sizeof(msg1), ".");
Tomáš Mráz d93958
 			/* The default */
Tomáš Mráz d93958
-			fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz d93958
-			ra = key_fingerprint(host_key, SSH_FP_MD5,
Tomáš Mráz d93958
+			fp = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz d93958
+			ra = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5,
Tomáš Mráz d93958
 			    SSH_FP_RANDOMART);
Tomáš Mráz d93958
 			msg2[0] = '\0';
Tomáš Mráz d93958
 			if (options.verify_host_key_dns) {
Jan F 003cb0
@@ -855,10 +859,10 @@ check_host_key(char *hostname, struct so
Tomáš Mráz d93958
 			snprintf(msg, sizeof(msg),
Tomáš Mráz d93958
 			    "The authenticity of host '%.200s (%s)' can't be "
Tomáš Mráz d93958
 			    "established%s\n"
Tomáš Mráz d93958
-			    "%s key fingerprint is %s.%s%s\n%s"
Tomáš Mráz d93958
+			    "%s key %sfingerprint is %s.%s%s\n%s"
Tomáš Mráz d93958
 			    "Are you sure you want to continue connecting "
Tomáš Mráz d93958
 			    "(yes/no)? ",
Tomáš Mráz d93958
-			    host, ip, msg1, type, fp,
Tomáš Mráz d93958
+			    host, ip, msg1, type, fips_on ? "SHA1 " : "", fp,
Tomáš Mráz d93958
 			    options.visual_host_key ? "\n" : "",
Tomáš Mráz d93958
 			    options.visual_host_key ? ra : "",
Tomáš Mráz d93958
 			    msg2);
Jan F 003cb0
@@ -1208,20 +1212,21 @@ show_other_keys(struct hostkeys *hostkey
Jan F 003cb0
 	int i, ret = 0;
Tomáš Mráz d93958
 	char *fp, *ra;
Jan F 003cb0
 	const struct hostkey_entry *found;
Tomáš Mráz d93958
+	int fips_on = FIPS_mode();
Tomáš Mráz d93958
 
Jan F 003cb0
 	for (i = 0; type[i] != -1; i++) {
Jan F 003cb0
 		if (type[i] == key->type)
Jan F 003cb0
 			continue;
Jan F 003cb0
 		if (!lookup_key_in_hostkeys_by_type(hostkeys, type[i], &found))
Jan F 003cb0
 			continue;
Jan F 003cb0
-		fp = key_fingerprint(found->key, SSH_FP_MD5, SSH_FP_HEX);
Jan F 003cb0
-		ra = key_fingerprint(found->key, SSH_FP_MD5, SSH_FP_RANDOMART);
Jan F 003cb0
+		fp = key_fingerprint(found->key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Jan F 003cb0
+		ra = key_fingerprint(found->key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_RANDOMART);
Tomáš Mráz d93958
 		logit("WARNING: %s key found for host %s\n"
Jan F 003cb0
 		    "in %s:%lu\n"
Jan F 003cb0
-		    "%s key fingerprint %s.",
Tomáš Mráz d93958
+		    "%s key %sfingerprint %s.\n%s\n",
Jan F 003cb0
 		    key_type(found->key),
Jan F 003cb0
 		    found->host, found->file, found->line,
Jan F 003cb0
-		    key_type(found->key), fp);
Tomáš Mráz d93958
+		    key_type(found), fips_on ? "SHA1 ":"", fp, ra);
Jan F 003cb0
 		if (options.visual_host_key)
Jan F 003cb0
 			logit("%s", ra);
Tomáš Mráz d93958
 		xfree(ra);
Jan F 003cb0
@@ -1235,8 +1240,9 @@ static void
Jan F 003cb0
 warn_changed_key(Key *host_key)
Tomáš Mráz d93958
 {
Tomáš Mráz d93958
 	char *fp;
Tomáš Mráz d93958
+	int fips_on = FIPS_mode();
Tomáš Mráz d93958
 
Tomáš Mráz d93958
-	fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz d93958
+	fp = key_fingerprint(host_key, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 	error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
Tomáš Mráz d93958
 	error("@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @");
Jan F 003cb0
@@ -1244,8 +1250,8 @@ warn_changed_key(Key *host_key)
Tomáš Mráz d93958
 	error("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!");
Tomáš Mráz d93958
 	error("Someone could be eavesdropping on you right now (man-in-the-middle attack)!");
Jan F 003cb0
 	error("It is also possible that a host key has just been changed.");
Tomáš Mráz d93958
-	error("The fingerprint for the %s key sent by the remote host is\n%s.",
Jan F 003cb0
-	    key_type(host_key), fp);
Tomáš Mráz d93958
+	error("The %sfingerprint for the %s key sent by the remote host is\n%s.",
Jan F 003cb0
+	    fips_on ? "SHA1 ":"", key_type(host_key), fp);
Tomáš Mráz d93958
 	error("Please contact your system administrator.");
Tomáš Mráz d93958
 
Tomáš Mráz d93958
 	xfree(fp);
Jan F 003cb0
diff -up openssh-5.8p1/sshd.c.fips openssh-5.8p1/sshd.c
Jan F 9cefae
--- openssh-5.8p1/sshd.c.fips	2011-02-21 17:05:14.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/sshd.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz 0a4fa5
@@ -76,6 +76,8 @@
Tomáš Mráz 0a4fa5
 #include <openssl/bn.h>
Tomáš Mráz 0a4fa5
 #include <openssl/md5.h>
Tomáš Mráz 0a4fa5
 #include <openssl/rand.h>
Tomáš Mráz 0a4fa5
+#include <openssl/fips.h>
Tomáš Mráz 0a4fa5
+#include <fipscheck.h>
Tomáš Mráz 0a4fa5
 #include "openbsd-compat/openssl-compat.h"
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 #ifdef HAVE_SECUREWARE
Jan F 9cefae
@@ -1327,6 +1329,12 @@ main(int ac, char **av)
Tomáš Mráz 0a4fa5
 	(void)set_auth_parameters(ac, av);
Tomáš Mráz 0a4fa5
 #endif
Tomáš Mráz 0a4fa5
 	__progname = ssh_get_progname(av[0]);
Tomáš Mráz 0a4fa5
+
Tomáš Mráz 0a4fa5
+        SSLeay_add_all_algorithms();
Tomáš Mráz 0a4fa5
+        if (FIPS_mode() && !FIPSCHECK_verify(NULL, NULL)) {
Tomáš Mráz 0a4fa5
+                fatal("FIPS integrity verification test failed.");
Tomáš Mráz 0a4fa5
+        }
Tomáš Mráz 0a4fa5
+
Tomáš Mráz 0a4fa5
 	init_rng();
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 	/* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
Jan F 9cefae
@@ -1488,8 +1496,6 @@ main(int ac, char **av)
Tomáš Mráz 0a4fa5
 	else
Tomáš Mráz 0a4fa5
 		closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
Tomáš Mráz 0a4fa5
 
Jan F 003cb0
-	OpenSSL_add_all_algorithms();
Tomáš Mráz 0a4fa5
-
Tomáš Mráz 0a4fa5
 	/*
Tomáš Mráz 0a4fa5
 	 * Force logging to stderr until we have loaded the private host
Tomáš Mráz 0a4fa5
 	 * key (unless started from inetd)
Jan F 9cefae
@@ -1608,6 +1614,10 @@ main(int ac, char **av)
Tomáš Mráz 76f329
 		debug("private host key: #%d type %d %s", i, key->type,
Tomáš Mráz 76f329
 		    key_type(key));
Tomáš Mráz 76f329
 	}
Tomáš Mráz 76f329
+	if ((options.protocol & SSH_PROTO_1) && FIPS_mode()) {
Tomáš Mráz 76f329
+		logit("Disabling protocol version 1. Not allowed in the FIPS mode.");
Tomáš Mráz 76f329
+		options.protocol &= ~SSH_PROTO_1;
Tomáš Mráz 76f329
+	}
Tomáš Mráz 76f329
 	if ((options.protocol & SSH_PROTO_1) && !sensitive_data.have_ssh1_key) {
Tomáš Mráz 76f329
 		logit("Disabling protocol version 1. Could not load host key");
Tomáš Mráz 76f329
 		options.protocol &= ~SSH_PROTO_1;
Jan F 9cefae
@@ -1772,6 +1782,10 @@ main(int ac, char **av)
Tomáš Mráz 0a4fa5
 	/* Initialize the random number generator. */
Tomáš Mráz 0a4fa5
 	arc4random_stir();
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
+	if (FIPS_mode()) {
Tomáš Mráz 0a4fa5
+		logit("FIPS mode initialized");
Tomáš Mráz 0a4fa5
+	}
Tomáš Mráz 0a4fa5
+
Tomáš Mráz 0a4fa5
 	/* Chdir to the root directory so that the current disk can be
Tomáš Mráz 0a4fa5
 	   unmounted if desired. */
Tomáš Mráz 0a4fa5
 	chdir("/");
Jan F 9cefae
@@ -2315,6 +2329,9 @@ do_ssh2_kex(void)
Tomáš Mráz 0a4fa5
 	if (options.ciphers != NULL) {
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
Tomáš Mráz 0a4fa5
+	} else if (FIPS_mode()) {
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_ENC_ALGS_STOC] = KEX_FIPS_ENCRYPT;
Tomáš Mráz 0a4fa5
 	}
Tomáš Mráz 0a4fa5
 	myproposal[PROPOSAL_ENC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
 	    compat_cipher_proposal(myproposal[PROPOSAL_ENC_ALGS_CTOS]);
Jan F 9cefae
@@ -2324,6 +2341,9 @@ do_ssh2_kex(void)
Tomáš Mráz 0a4fa5
 	if (options.macs != NULL) {
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
Tomáš Mráz 0a4fa5
+	} else if (FIPS_mode()) {
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_MAC_ALGS_CTOS] =
Tomáš Mráz 0a4fa5
+		myproposal[PROPOSAL_MAC_ALGS_STOC] = KEX_FIPS_MAC;
Tomáš Mráz 0a4fa5
 	}
Tomáš Mráz 0a4fa5
 	if (options.compression == COMP_NONE) {
Tomáš Mráz 0a4fa5
 		myproposal[PROPOSAL_COMP_ALGS_CTOS] =
Jan F 003cb0
diff -up openssh-5.8p1/ssh-keygen.c.fips openssh-5.8p1/ssh-keygen.c
Jan F 9cefae
--- openssh-5.8p1/ssh-keygen.c.fips	2011-02-21 17:05:14.000000000 +0100
Jan F 9cefae
+++ openssh-5.8p1/ssh-keygen.c	2011-02-21 17:05:14.000000000 +0100
Tomáš Mráz 685b62
@@ -21,6 +21,7 @@
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 #include <openssl/evp.h>
Tomáš Mráz 0a4fa5
 #include <openssl/pem.h>
Tomáš Mráz 0a4fa5
+#include <openssl/fips.h>
Tomáš Mráz 0a4fa5
 #include "openbsd-compat/openssl-compat.h"
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 #include <errno.h>
Jan F 003cb0
@@ -721,7 +722,7 @@ do_fingerprint(struct passwd *pw)
Tomáš Mráz 0a4fa5
 	enum fp_type fptype;
Tomáš Mráz 0a4fa5
 	struct stat st;
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
-	fptype = print_bubblebabble ? SSH_FP_SHA1 : SSH_FP_MD5;
Tomáš Mráz 0a4fa5
+	fptype = print_bubblebabble ? SSH_FP_SHA1 : FIPS_mode() ? SSH_FP_SHA1 : SSH_FP_MD5;
Tomáš Mráz 0a4fa5
 	rep =    print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_HEX;
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 	if (!have_identity)
Jan F 003cb0
@@ -2253,14 +2254,15 @@ passphrase_again:
Tomáš Mráz 0a4fa5
 	fclose(f);
Tomáš Mráz 0a4fa5
 
Tomáš Mráz 0a4fa5
 	if (!quiet) {
Tomáš Mráz 0a4fa5
-		char *fp = key_fingerprint(public, SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz 0a4fa5
-		char *ra = key_fingerprint(public, SSH_FP_MD5,
Tomáš Mráz 0a4fa5
+		int fips_on = FIPS_mode();
Tomáš Mráz 0a4fa5
+		char *fp = key_fingerprint(public, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5, SSH_FP_HEX);
Tomáš Mráz 0a4fa5
+		char *ra = key_fingerprint(public, fips_on ? SSH_FP_SHA1 : SSH_FP_MD5,
Tomáš Mráz 0a4fa5
 		    SSH_FP_RANDOMART);
Tomáš Mráz 0a4fa5
 		printf("Your public key has been saved in %s.\n",
Tomáš Mráz 0a4fa5
 		    identity_file);
Tomáš Mráz 0a4fa5
-		printf("The key fingerprint is:\n");
Tomáš Mráz 0a4fa5
+		printf("The key %sfingerprint is:\n", fips_on ? "SHA1 " : "");
Tomáš Mráz 0a4fa5
 		printf("%s %s\n", fp, comment);
Tomáš Mráz 0a4fa5
-		printf("The key's randomart image is:\n");
Tomáš Mráz 0a4fa5
+		printf("The key's %srandomart image is:\n", fips_on ? "SHA1 " :"");
Tomáš Mráz 0a4fa5
 		printf("%s\n", ra);
Tomáš Mráz 0a4fa5
 		xfree(ra);
Tomáš Mráz 0a4fa5
 		xfree(fp);