summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-02-15 03:01:59 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-02-15 03:01:59 +0000
commit06b33aa0e83163f3dcd679317afec1ee95910512 (patch)
treeeae5cbd1cd71619bdd1e5d4a28e6bb96057f4479
parent4272ed803ff309f1fdb9c149b9cf083769f53744 (diff)
- markus@cvs.openbsd.org 2001/02/11 12:59:25
[Makefile.in sshd.8 sshconnect2.c readconf.h readconf.c packet.c sshd.c ssh.c ssh.1 servconf.h servconf.c myproposal.h kex.h kex.c] 1) clean up the MAC support for SSH-2 2) allow you to specify the MAC with 'ssh -m' 3) or the 'MACs' keyword in ssh(d)_config 4) add hmac-{md5,sha1}-96 ok stevesk@, provos@
-rw-r--r--ChangeLog10
-rw-r--r--Makefile.in4
-rw-r--r--hmac.c56
-rw-r--r--kex.c17
-rw-r--r--kex.h6
-rw-r--r--mac.c114
-rw-r--r--mac.h (renamed from hmac.h)18
-rw-r--r--myproposal.h7
-rw-r--r--packet.c25
-rw-r--r--readconf.c20
-rw-r--r--readconf.h3
-rw-r--r--servconf.c19
-rw-r--r--servconf.h7
-rw-r--r--ssh.122
-rw-r--r--ssh.c14
-rw-r--r--sshconnect2.c10
-rw-r--r--sshd.813
-rw-r--r--sshd.c6
18 files changed, 252 insertions, 119 deletions
diff --git a/ChangeLog b/ChangeLog
index e6bc60239..ec9e00be8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,14 @@
7 - markus@cvs.openbsd.org 2001/02/12 12:45:06 7 - markus@cvs.openbsd.org 2001/02/12 12:45:06
8 [sshconnect1.c] 8 [sshconnect1.c]
9 fix xmalloc(0), ok dugsong@ 9 fix xmalloc(0), ok dugsong@
10 - markus@cvs.openbsd.org 2001/02/11 12:59:25
11 [Makefile.in sshd.8 sshconnect2.c readconf.h readconf.c packet.c
12 sshd.c ssh.c ssh.1 servconf.h servconf.c myproposal.h kex.h kex.c]
13 1) clean up the MAC support for SSH-2
14 2) allow you to specify the MAC with 'ssh -m'
15 3) or the 'MACs' keyword in ssh(d)_config
16 4) add hmac-{md5,sha1}-96
17 ok stevesk@, provos@
10 18
1120010214 1920010214
12 - (djm) Don't try to close PAM session or delete credentials if the 20 - (djm) Don't try to close PAM session or delete credentials if the
@@ -3935,4 +3943,4 @@
3935 - Wrote replacements for strlcpy and mkdtemp 3943 - Wrote replacements for strlcpy and mkdtemp
3936 - Released 1.0pre1 3944 - Released 1.0pre1
3937 3945
3938$Id: ChangeLog,v 1.762 2001/02/15 02:36:46 mouring Exp $ 3946$Id: ChangeLog,v 1.763 2001/02/15 03:01:59 mouring Exp $
diff --git a/Makefile.in b/Makefile.in
index f9c48d29a..1f8696a9c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.151 2001/02/13 14:25:23 djm Exp $ 1# $Id: Makefile.in,v 1.152 2001/02/15 03:01:59 mouring Exp $
2 2
3prefix=@prefix@ 3prefix=@prefix@
4exec_prefix=@exec_prefix@ 4exec_prefix=@exec_prefix@
@@ -44,7 +44,7 @@ INSTALL_SSH_PRNG_CMDS=@INSTALL_SSH_PRNG_CMDS@
44 44
45TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) $(SFTP_PROGS) 45TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-agent$(EXEEXT) scp$(EXEEXT) $(SFTP_PROGS)
46 46
47LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o deattack.o dispatch.o hmac.o hostfile.o key.o kex.o log.o match.o misc.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o uuencode.o xmalloc.o 47LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o deattack.o dispatch.o mac.o hostfile.o key.o kex.o log.o match.o misc.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o uuencode.o xmalloc.o
48 48
49SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o clientloop.o 49SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o clientloop.o
50 50
diff --git a/hmac.c b/hmac.c
deleted file mode 100644
index 831dd243a..000000000
--- a/hmac.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 * Copyright (c) 2000 Markus Friedl. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26RCSID("$OpenBSD: hmac.c,v 1.7 2001/02/08 19:30:51 itojun Exp $");
27
28#include "xmalloc.h"
29#include "getput.h"
30#include "log.h"
31
32#include <openssl/hmac.h>
33
34#include "hmac.h"
35
36u_char *
37hmac(
38 EVP_MD *evp_md,
39 u_int seqno,
40 u_char *data, int datalen,
41 u_char *key, int keylen)
42{
43 HMAC_CTX c;
44 static u_char m[EVP_MAX_MD_SIZE];
45 u_char b[4];
46
47 if (key == NULL)
48 fatal("hmac: no key");
49 HMAC_Init(&c, key, keylen, evp_md);
50 PUT_32BIT(b, seqno);
51 HMAC_Update(&c, b, sizeof b);
52 HMAC_Update(&c, data, datalen);
53 HMAC_Final(&c, m, NULL);
54 HMAC_cleanup(&c);
55 return(m);
56}
diff --git a/kex.c b/kex.c
index 7c1326ed0..1038546ca 100644
--- a/kex.c
+++ b/kex.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: kex.c,v 1.20 2001/02/08 19:30:51 itojun Exp $"); 26RCSID("$OpenBSD: kex.c,v 1.21 2001/02/11 12:59:24 markus Exp $");
27 27
28#include <openssl/crypto.h> 28#include <openssl/crypto.h>
29#include <openssl/bio.h> 29#include <openssl/bio.h>
@@ -41,6 +41,7 @@ RCSID("$OpenBSD: kex.c,v 1.20 2001/02/08 19:30:51 itojun Exp $");
41#include "kex.h" 41#include "kex.h"
42#include "key.h" 42#include "key.h"
43#include "log.h" 43#include "log.h"
44#include "mac.h"
44 45
45#define KEX_COOKIE_LEN 16 46#define KEX_COOKIE_LEN 16
46 47
@@ -412,18 +413,12 @@ choose_mac(Mac *mac, char *client, char *server)
412 char *name = get_match(client, server); 413 char *name = get_match(client, server);
413 if (name == NULL) 414 if (name == NULL)
414 fatal("no matching mac found: client %s server %s", client, server); 415 fatal("no matching mac found: client %s server %s", client, server);
415 if (strcmp(name, "hmac-md5") == 0) { 416 if (mac_init(mac, name) < 0)
416 mac->md = EVP_md5();
417 } else if (strcmp(name, "hmac-sha1") == 0) {
418 mac->md = EVP_sha1();
419 } else if (strcmp(name, "hmac-ripemd160@openssh.com") == 0) {
420 mac->md = EVP_ripemd160();
421 } else {
422 fatal("unsupported mac %s", name); 417 fatal("unsupported mac %s", name);
423 } 418 /* truncate the key */
419 if (datafellows & SSH_BUG_HMAC)
420 mac->key_len = 16;
424 mac->name = name; 421 mac->name = name;
425 mac->mac_len = mac->md->md_size;
426 mac->key_len = (datafellows & SSH_BUG_HMAC) ? 16 : mac->mac_len;
427 mac->key = NULL; 422 mac->key = NULL;
428 mac->enabled = 0; 423 mac->enabled = 0;
429} 424}
diff --git a/kex.h b/kex.h
index d8f37c1a6..90496fbdf 100644
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.h,v 1.13 2001/02/04 15:32:24 stevesk Exp $ */ 1/* $OpenBSD: kex.h,v 1.14 2001/02/11 12:59:24 markus Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -26,9 +26,11 @@
26#ifndef KEX_H 26#ifndef KEX_H
27#define KEX_H 27#define KEX_H
28 28
29#include <openssl/evp.h>
30#include "buffer.h"
31
29#define KEX_DH1 "diffie-hellman-group1-sha1" 32#define KEX_DH1 "diffie-hellman-group1-sha1"
30#define KEX_DHGEX "diffie-hellman-group-exchange-sha1" 33#define KEX_DHGEX "diffie-hellman-group-exchange-sha1"
31#define KEX_DSS "ssh-dss"
32 34
33enum kex_init_proposals { 35enum kex_init_proposals {
34 PROPOSAL_KEX_ALGS, 36 PROPOSAL_KEX_ALGS,
diff --git a/mac.c b/mac.c
new file mode 100644
index 000000000..3ff107c8a
--- /dev/null
+++ b/mac.c
@@ -0,0 +1,114 @@
1/*
2 * Copyright (c) 2001 Markus Friedl. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26RCSID("$OpenBSD: mac.c,v 1.1 2001/02/11 12:59:24 markus Exp $");
27
28#include <openssl/hmac.h>
29
30#include "xmalloc.h"
31#include "getput.h"
32#include "log.h"
33#include "cipher.h"
34#include "kex.h"
35#include "mac.h"
36
37struct {
38 char *name;
39 EVP_MD * (*mdfunc)(void);
40 int truncatebits; /* truncate digest if != 0 */
41} macs[] = {
42 { "hmac-sha1", EVP_sha1, 0, },
43 { "hmac-sha1-96", EVP_sha1, 96 },
44 { "hmac-md5", EVP_md5, 0 },
45 { "hmac-md5-96", EVP_md5, 96 },
46 { "hmac-ripemd160", EVP_ripemd160, 0 },
47 { "hmac-ripemd160@openssh.com", EVP_ripemd160, 0 },
48 { NULL, NULL, 0 }
49};
50
51int
52mac_init(Mac *mac, char *name)
53{
54 int i;
55 for (i = 0; macs[i].name; i++) {
56 if (strcmp(name, macs[i].name) == 0) {
57 if (mac != NULL) {
58 mac->md = (*macs[i].mdfunc)();
59 mac->key_len = mac->mac_len = mac->md->md_size;
60 if (macs[i].truncatebits != 0)
61 mac->mac_len = macs[i].truncatebits/8;
62 }
63 debug2("mac_init: found %s", name);
64 return (0);
65 }
66 }
67 debug2("mac_init: unknown %s", name);
68 return (-1);
69}
70
71u_char *
72mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen)
73{
74 HMAC_CTX c;
75 static u_char m[EVP_MAX_MD_SIZE];
76 u_char b[4];
77
78 if (mac->key == NULL)
79 fatal("mac_compute: no key");
80 if (mac->mac_len > sizeof(m))
81 fatal("mac_compute: mac too long");
82 HMAC_Init(&c, mac->key, mac->key_len, mac->md);
83 PUT_32BIT(b, seqno);
84 HMAC_Update(&c, b, sizeof(b));
85 HMAC_Update(&c, data, datalen);
86 HMAC_Final(&c, m, NULL);
87 HMAC_cleanup(&c);
88 return (m);
89}
90
91/* XXX copied from ciphers_valid */
92#define MAC_SEP ","
93int
94mac_valid(const char *names)
95{
96 char *maclist, *cp, *p;
97
98 if (names == NULL || strcmp(names, "") == 0)
99 return (0);
100 maclist = cp = xstrdup(names);
101 for ((p = strsep(&cp, MAC_SEP)); p && *p != '\0';
102 (p = strsep(&cp, MAC_SEP))) {
103 if (mac_init(NULL, p) < 0) {
104 debug("bad mac %s [%s]", p, names);
105 xfree(maclist);
106 return (0);
107 } else {
108 debug3("mac ok: %s [%s]", p, names);
109 }
110 }
111 debug3("macs ok: [%s]", names);
112 xfree(maclist);
113 return (1);
114}
diff --git a/hmac.h b/mac.h
index d9dc048a7..6173eaa66 100644
--- a/hmac.h
+++ b/mac.h
@@ -1,7 +1,6 @@
1/* $OpenBSD: hmac.h,v 1.4 2001/01/29 01:58:15 niklas Exp $ */ 1/* $OpenBSD: mac.h,v 1.1 2001/02/11 12:59:24 markus Exp $ */
2
3/* 2/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
5 * 4 *
6 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -23,14 +22,7 @@
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 24 */
26#ifndef HMAC_H
27#define HMAC_H
28
29u_char *
30hmac(
31 EVP_MD *evp_md,
32 u_int seqno,
33 u_char *data, int datalen,
34 u_char *key, int len);
35 25
36#endif 26int mac_valid(const char *names);
27int mac_init(Mac *mac, char *name);
28u_char *mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen);
diff --git a/myproposal.h b/myproposal.h
index 9dfecdafc..03f76839b 100644
--- a/myproposal.h
+++ b/myproposal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: myproposal.h,v 1.10 2001/01/29 01:58:17 niklas Exp $ */ 1/* $OpenBSD: myproposal.h,v 1.11 2001/02/11 12:59:24 markus Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -30,7 +30,10 @@
30 "aes128-cbc,aes192-cbc,aes256-cbc," \ 30 "aes128-cbc,aes192-cbc,aes256-cbc," \
31 "rijndael128-cbc,rijndael192-cbc,rijndael256-cbc," \ 31 "rijndael128-cbc,rijndael192-cbc,rijndael256-cbc," \
32 "rijndael-cbc@lysator.liu.se" 32 "rijndael-cbc@lysator.liu.se"
33#define KEX_DEFAULT_MAC "hmac-sha1,hmac-md5,hmac-ripemd160@openssh.com" 33#define KEX_DEFAULT_MAC \
34 "hmac-sha1,hmac-md5,hmac-ripemd160," \
35 "hmac-ripemd160@openssh.com," \
36 "hmac-sha1-96,hmac-md5-96"
34#define KEX_DEFAULT_COMP "none,zlib" 37#define KEX_DEFAULT_COMP "none,zlib"
35#define KEX_DEFAULT_LANG "" 38#define KEX_DEFAULT_LANG ""
36 39
diff --git a/packet.c b/packet.c
index 956e711ec..46e89bc0c 100644
--- a/packet.c
+++ b/packet.c
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#include "includes.h" 39#include "includes.h"
40RCSID("$OpenBSD: packet.c,v 1.49 2001/02/08 19:30:52 itojun Exp $"); 40RCSID("$OpenBSD: packet.c,v 1.50 2001/02/11 12:59:25 markus Exp $");
41 41
42#include "xmalloc.h" 42#include "xmalloc.h"
43#include "buffer.h" 43#include "buffer.h"
@@ -54,12 +54,9 @@ RCSID("$OpenBSD: packet.c,v 1.49 2001/02/08 19:30:52 itojun Exp $");
54#include "ssh1.h" 54#include "ssh1.h"
55#include "ssh2.h" 55#include "ssh2.h"
56 56
57#include <openssl/bn.h>
58#include <openssl/dh.h>
59#include <openssl/hmac.h>
60#include "cipher.h" 57#include "cipher.h"
61#include "kex.h" 58#include "kex.h"
62#include "hmac.h" 59#include "mac.h"
63#include "log.h" 60#include "log.h"
64#include "canohost.h" 61#include "canohost.h"
65 62
@@ -531,12 +528,12 @@ packet_send1(void)
531void 528void
532packet_send2(void) 529packet_send2(void)
533{ 530{
531 static u_int32_t seqnr = 0;
534 u_char *macbuf = NULL; 532 u_char *macbuf = NULL;
535 char *cp; 533 char *cp;
536 u_int packet_length = 0; 534 u_int packet_length = 0;
537 u_int i, padlen, len; 535 u_int i, padlen, len;
538 u_int32_t rand = 0; 536 u_int32_t rand = 0;
539 static u_int seqnr = 0;
540 int type; 537 int type;
541 Enc *enc = NULL; 538 Enc *enc = NULL;
542 Mac *mac = NULL; 539 Mac *mac = NULL;
@@ -604,11 +601,9 @@ packet_send2(void)
604 601
605 /* compute MAC over seqnr and packet(length fields, payload, padding) */ 602 /* compute MAC over seqnr and packet(length fields, payload, padding) */
606 if (mac && mac->enabled) { 603 if (mac && mac->enabled) {
607 macbuf = hmac( mac->md, seqnr, 604 macbuf = mac_compute(mac, seqnr,
608 (u_char *) buffer_ptr(&outgoing_packet), 605 (u_char *) buffer_ptr(&outgoing_packet),
609 buffer_len(&outgoing_packet), 606 buffer_len(&outgoing_packet));
610 mac->key, mac->key_len
611 );
612 DBG(debug("done calc MAC out #%d", seqnr)); 607 DBG(debug("done calc MAC out #%d", seqnr));
613 } 608 }
614 /* encrypt packet and append to output buffer. */ 609 /* encrypt packet and append to output buffer. */
@@ -818,12 +813,12 @@ packet_read_poll1(int *payload_len_ptr)
818int 813int
819packet_read_poll2(int *payload_len_ptr) 814packet_read_poll2(int *payload_len_ptr)
820{ 815{
816 static u_int32_t seqnr = 0;
817 static u_int packet_length = 0;
821 u_int padlen, need; 818 u_int padlen, need;
822 u_char buf[8], *macbuf; 819 u_char buf[8], *macbuf;
823 u_char *ucp; 820 u_char *ucp;
824 char *cp; 821 char *cp;
825 static u_int packet_length = 0;
826 static u_int seqnr = 0;
827 int type; 822 int type;
828 int maclen, block_size; 823 int maclen, block_size;
829 Enc *enc = NULL; 824 Enc *enc = NULL;
@@ -883,11 +878,9 @@ packet_read_poll2(int *payload_len_ptr)
883 * increment sequence number for incoming packet 878 * increment sequence number for incoming packet
884 */ 879 */
885 if (mac && mac->enabled) { 880 if (mac && mac->enabled) {
886 macbuf = hmac( mac->md, seqnr, 881 macbuf = mac_compute(mac, seqnr,
887 (u_char *) buffer_ptr(&incoming_packet), 882 (u_char *) buffer_ptr(&incoming_packet),
888 buffer_len(&incoming_packet), 883 buffer_len(&incoming_packet));
889 mac->key, mac->key_len
890 );
891 if (memcmp(macbuf, buffer_ptr(&input), mac->mac_len) != 0) 884 if (memcmp(macbuf, buffer_ptr(&input), mac->mac_len) != 0)
892 packet_disconnect("Corrupted MAC on input."); 885 packet_disconnect("Corrupted MAC on input.");
893 DBG(debug("MAC #%d ok", seqnr)); 886 DBG(debug("MAC #%d ok", seqnr));
diff --git a/readconf.c b/readconf.c
index f62905c29..3ac86ea06 100644
--- a/readconf.c
+++ b/readconf.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: readconf.c,v 1.61 2001/02/08 14:39:36 deraadt Exp $"); 15RCSID("$OpenBSD: readconf.c,v 1.62 2001/02/11 12:59:25 markus Exp $");
16 16
17#include "ssh.h" 17#include "ssh.h"
18#include "xmalloc.h" 18#include "xmalloc.h"
@@ -23,6 +23,8 @@ RCSID("$OpenBSD: readconf.c,v 1.61 2001/02/08 14:39:36 deraadt Exp $");
23#include "readconf.h" 23#include "readconf.h"
24#include "match.h" 24#include "match.h"
25#include "misc.h" 25#include "misc.h"
26#include "kex.h"
27#include "mac.h"
26 28
27/* Format of the configuration file: 29/* Format of the configuration file:
28 30
@@ -105,7 +107,7 @@ typedef enum {
105 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts, 107 oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
106 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression, 108 oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
107 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts, 109 oCompressionLevel, oKeepAlives, oNumberOfPasswordPrompts,
108 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, 110 oUsePrivilegedPort, oLogLevel, oCiphers, oProtocol, oMacs,
109 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication, 111 oGlobalKnownHostsFile2, oUserKnownHostsFile2, oPubkeyAuthentication,
110 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias 112 oKbdInteractiveAuthentication, oKbdInteractiveDevices, oHostKeyAlias
111} OpCodes; 113} OpCodes;
@@ -148,6 +150,7 @@ static struct {
148 { "port", oPort }, 150 { "port", oPort },
149 { "cipher", oCipher }, 151 { "cipher", oCipher },
150 { "ciphers", oCiphers }, 152 { "ciphers", oCiphers },
153 { "macs", oMacs },
151 { "protocol", oProtocol }, 154 { "protocol", oProtocol },
152 { "remoteforward", oRemoteForward }, 155 { "remoteforward", oRemoteForward },
153 { "localforward", oLocalForward }, 156 { "localforward", oLocalForward },
@@ -502,6 +505,17 @@ parse_int:
502 options->ciphers = xstrdup(arg); 505 options->ciphers = xstrdup(arg);
503 break; 506 break;
504 507
508 case oMacs:
509 arg = strdelim(&s);
510 if (!arg || *arg == '\0')
511 fatal("%.200s line %d: Missing argument.", filename, linenum);
512 if (!mac_valid(arg))
513 fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",
514 filename, linenum, arg ? arg : "<NONE>");
515 if (*activep && options->macs == NULL)
516 options->macs = xstrdup(arg);
517 break;
518
505 case oProtocol: 519 case oProtocol:
506 intptr = &options->protocol; 520 intptr = &options->protocol;
507 arg = strdelim(&s); 521 arg = strdelim(&s);
@@ -693,6 +707,7 @@ initialize_options(Options * options)
693 options->number_of_password_prompts = -1; 707 options->number_of_password_prompts = -1;
694 options->cipher = -1; 708 options->cipher = -1;
695 options->ciphers = NULL; 709 options->ciphers = NULL;
710 options->macs = NULL;
696 options->protocol = SSH_PROTO_UNKNOWN; 711 options->protocol = SSH_PROTO_UNKNOWN;
697 options->num_identity_files = 0; 712 options->num_identity_files = 0;
698 options->hostname = NULL; 713 options->hostname = NULL;
@@ -781,6 +796,7 @@ fill_default_options(Options * options)
781 if (options->cipher == -1) 796 if (options->cipher == -1)
782 options->cipher = SSH_CIPHER_NOT_SET; 797 options->cipher = SSH_CIPHER_NOT_SET;
783 /* options->ciphers, default set in myproposals.h */ 798 /* options->ciphers, default set in myproposals.h */
799 /* options->macs, default set in myproposals.h */
784 if (options->protocol == SSH_PROTO_UNKNOWN) 800 if (options->protocol == SSH_PROTO_UNKNOWN)
785 options->protocol = SSH_PROTO_1|SSH_PROTO_2|SSH_PROTO_1_PREFERRED; 801 options->protocol = SSH_PROTO_1|SSH_PROTO_2|SSH_PROTO_1_PREFERRED;
786 if (options->num_identity_files == 0) { 802 if (options->num_identity_files == 0) {
diff --git a/readconf.h b/readconf.h
index 241b7165c..575b2646d 100644
--- a/readconf.h
+++ b/readconf.h
@@ -11,7 +11,7 @@
11 * called by a name other than "ssh" or "Secure Shell". 11 * called by a name other than "ssh" or "Secure Shell".
12 */ 12 */
13 13
14/* RCSID("$OpenBSD: readconf.h,v 1.25 2001/01/22 23:06:39 markus Exp $"); */ 14/* RCSID("$OpenBSD: readconf.h,v 1.26 2001/02/11 12:59:25 markus Exp $"); */
15 15
16#ifndef READCONF_H 16#ifndef READCONF_H
17#define READCONF_H 17#define READCONF_H
@@ -68,6 +68,7 @@ typedef struct {
68 * prompts. */ 68 * prompts. */
69 int cipher; /* Cipher to use. */ 69 int cipher; /* Cipher to use. */
70 char *ciphers; /* SSH2 ciphers in order of preference. */ 70 char *ciphers; /* SSH2 ciphers in order of preference. */
71 char *macs; /* SSH2 macs in order of preference. */
71 int protocol; /* Protocol in order of preference. */ 72 int protocol; /* Protocol in order of preference. */
72 char *hostname; /* Real host to connect. */ 73 char *hostname; /* Real host to connect. */
73 char *host_key_alias; /* hostname alias for .ssh/known_hosts */ 74 char *host_key_alias; /* hostname alias for .ssh/known_hosts */
diff --git a/servconf.c b/servconf.c
index 59687e16d..43a2c111e 100644
--- a/servconf.c
+++ b/servconf.c
@@ -10,7 +10,7 @@
10 */ 10 */
11 11
12#include "includes.h" 12#include "includes.h"
13RCSID("$OpenBSD: servconf.c,v 1.65 2001/02/04 15:32:24 stevesk Exp $"); 13RCSID("$OpenBSD: servconf.c,v 1.66 2001/02/11 12:59:25 markus Exp $");
14 14
15#ifdef KRB4 15#ifdef KRB4
16#include <krb.h> 16#include <krb.h>
@@ -28,6 +28,8 @@ RCSID("$OpenBSD: servconf.c,v 1.65 2001/02/04 15:32:24 stevesk Exp $");
28#include "tildexpand.h" 28#include "tildexpand.h"
29#include "misc.h" 29#include "misc.h"
30#include "cipher.h" 30#include "cipher.h"
31#include "kex.h"
32#include "mac.h"
31 33
32/* add listen address */ 34/* add listen address */
33void add_listen_addr(ServerOptions *options, char *addr); 35void add_listen_addr(ServerOptions *options, char *addr);
@@ -85,6 +87,7 @@ initialize_server_options(ServerOptions *options)
85 options->num_allow_groups = 0; 87 options->num_allow_groups = 0;
86 options->num_deny_groups = 0; 88 options->num_deny_groups = 0;
87 options->ciphers = NULL; 89 options->ciphers = NULL;
90 options->macs = NULL;
88 options->protocol = SSH_PROTO_UNKNOWN; 91 options->protocol = SSH_PROTO_UNKNOWN;
89 options->gateway_ports = -1; 92 options->gateway_ports = -1;
90 options->num_subsystems = 0; 93 options->num_subsystems = 0;
@@ -209,7 +212,7 @@ typedef enum {
209 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail, 212 sStrictModes, sEmptyPasswd, sRandomSeedFile, sKeepAlives, sCheckMail,
210 sUseLogin, sAllowTcpForwarding, 213 sUseLogin, sAllowTcpForwarding,
211 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups, 214 sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
212 sIgnoreUserKnownHosts, sCiphers, sProtocol, sPidFile, 215 sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
213 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups, 216 sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
214 sBanner, sReverseMappingCheck 217 sBanner, sReverseMappingCheck
215} ServerOpCodes; 218} ServerOpCodes;
@@ -266,6 +269,7 @@ static struct {
266 { "allowgroups", sAllowGroups }, 269 { "allowgroups", sAllowGroups },
267 { "denygroups", sDenyGroups }, 270 { "denygroups", sDenyGroups },
268 { "ciphers", sCiphers }, 271 { "ciphers", sCiphers },
272 { "macs", sMacs },
269 { "protocol", sProtocol }, 273 { "protocol", sProtocol },
270 { "gatewayports", sGatewayPorts }, 274 { "gatewayports", sGatewayPorts },
271 { "subsystem", sSubsystem }, 275 { "subsystem", sSubsystem },
@@ -658,6 +662,17 @@ parse_flag:
658 options->ciphers = xstrdup(arg); 662 options->ciphers = xstrdup(arg);
659 break; 663 break;
660 664
665 case sMacs:
666 arg = strdelim(&cp);
667 if (!arg || *arg == '\0')
668 fatal("%s line %d: Missing argument.", filename, linenum);
669 if (!mac_valid(arg))
670 fatal("%s line %d: Bad SSH2 mac spec '%s'.",
671 filename, linenum, arg ? arg : "<NONE>");
672 if (options->macs == NULL)
673 options->macs = xstrdup(arg);
674 break;
675
661 case sProtocol: 676 case sProtocol:
662 intptr = &options->protocol; 677 intptr = &options->protocol;
663 arg = strdelim(&cp); 678 arg = strdelim(&cp);
diff --git a/servconf.h b/servconf.h
index e7abb94d8..8236a6391 100644
--- a/servconf.h
+++ b/servconf.h
@@ -11,7 +11,7 @@
11 * called by a name other than "ssh" or "Secure Shell". 11 * called by a name other than "ssh" or "Secure Shell".
12 */ 12 */
13 13
14/* RCSID("$OpenBSD: servconf.h,v 1.36 2001/02/03 10:08:37 markus Exp $"); */ 14/* RCSID("$OpenBSD: servconf.h,v 1.37 2001/02/11 12:59:25 markus Exp $"); */
15 15
16#ifndef SERVCONF_H 16#ifndef SERVCONF_H
17#define SERVCONF_H 17#define SERVCONF_H
@@ -50,8 +50,9 @@ typedef struct {
50 char *xauth_location; /* Location of xauth program */ 50 char *xauth_location; /* Location of xauth program */
51 int strict_modes; /* If true, require string home dir modes. */ 51 int strict_modes; /* If true, require string home dir modes. */
52 int keepalives; /* If true, set SO_KEEPALIVE. */ 52 int keepalives; /* If true, set SO_KEEPALIVE. */
53 char *ciphers; /* Ciphers in order of preference. */ 53 char *ciphers; /* Supported SSH2 ciphers. */
54 int protocol; /* Protocol in order of preference. */ 54 char *macs; /* Supported SSH2 macs. */
55 int protocol; /* Supported protocol versions. */
55 int gateway_ports; /* If true, allow remote connects to forwarded ports. */ 56 int gateway_ports; /* If true, allow remote connects to forwarded ports. */
56 SyslogFacility log_facility; /* Facility for system logging. */ 57 SyslogFacility log_facility; /* Facility for system logging. */
57 LogLevel log_level; /* Level for system logging. */ 58 LogLevel log_level; /* Level for system logging. */
diff --git a/ssh.1 b/ssh.1
index dc177c8ba..eeeab9bd1 100644
--- a/ssh.1
+++ b/ssh.1
@@ -34,7 +34,7 @@
34.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36.\" 36.\"
37.\" $OpenBSD: ssh.1,v 1.90 2001/02/10 16:03:29 markus Exp $ 37.\" $OpenBSD: ssh.1,v 1.91 2001/02/11 12:59:25 markus Exp $
38.Dd September 25, 1999 38.Dd September 25, 1999
39.Dt SSH 1 39.Dt SSH 1
40.Os 40.Os
@@ -53,6 +53,7 @@
53.Op Fl e Ar escape_char 53.Op Fl e Ar escape_char
54.Op Fl i Ar identity_file 54.Op Fl i Ar identity_file
55.Op Fl l Ar login_name 55.Op Fl l Ar login_name
56.Op Fl m Ar mac_spec
56.Op Fl o Ar option 57.Op Fl o Ar option
57.Op Fl p Ar port 58.Op Fl p Ar port
58.Oo Fl L Xo 59.Oo Fl L Xo
@@ -425,6 +426,13 @@ This may also be specified on a per-host basis in the configuration file.
425.It Fl l Ar login_name 426.It Fl l Ar login_name
426Specifies the user to log in as on the remote machine. 427Specifies the user to log in as on the remote machine.
427This also may be specified on a per-host basis in the configuration file. 428This also may be specified on a per-host basis in the configuration file.
429.It Fl m Ar mac_spec
430Additionally, for protocol version 2 a comma-separated list of MAC
431(message authentication code) algorithms can
432be specified in order of preference.
433See the
434.Cm MACs
435keyword for more information.
428.It Fl n 436.It Fl n
429Redirects stdin from 437Redirects stdin from
430.Pa /dev/null 438.Pa /dev/null
@@ -814,6 +822,18 @@ Gives the verbosity level that is used when logging messages from
814The possible values are: 822The possible values are:
815QUIET, FATAL, ERROR, INFO, VERBOSE and DEBUG. 823QUIET, FATAL, ERROR, INFO, VERBOSE and DEBUG.
816The default is INFO. 824The default is INFO.
825.It Cm MACs
826Specifies the MAC (message authentication code) algorithms
827in order of preference.
828The MAC algorithm is used in protocol version 2
829for data integrity protection.
830Multiple algorithms must be comma-separated.
831The default is
832.Pp
833.Bd -literal
834 ``hmac-sha1,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,
835 hmac-sha1-96,hmac-md5-96''
836.Ed
817.It Cm NumberOfPasswordPrompts 837.It Cm NumberOfPasswordPrompts
818Specifies the number of password prompts before giving up. 838Specifies the number of password prompts before giving up.
819The argument to this keyword must be an integer. 839The argument to this keyword must be an integer.
diff --git a/ssh.c b/ssh.c
index 4ca1e7bf8..1b022402d 100644
--- a/ssh.c
+++ b/ssh.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: ssh.c,v 1.94 2001/02/10 01:46:28 markus Exp $"); 42RCSID("$OpenBSD: ssh.c,v 1.95 2001/02/11 12:59:25 markus Exp $");
43 43
44#include <openssl/evp.h> 44#include <openssl/evp.h>
45#include <openssl/err.h> 45#include <openssl/err.h>
@@ -65,6 +65,8 @@ RCSID("$OpenBSD: ssh.c,v 1.94 2001/02/10 01:46:28 markus Exp $");
65#include "tildexpand.h" 65#include "tildexpand.h"
66#include "dispatch.h" 66#include "dispatch.h"
67#include "misc.h" 67#include "misc.h"
68#include "kex.h"
69#include "mac.h"
68 70
69#ifdef HAVE___PROGNAME 71#ifdef HAVE___PROGNAME
70extern char *__progname; 72extern char *__progname;
@@ -305,7 +307,7 @@ main(int ac, char **av)
305 opt = av[optind][1]; 307 opt = av[optind][1];
306 if (!opt) 308 if (!opt)
307 usage(); 309 usage();
308 if (strchr("eilcpLRo", opt)) { /* options with arguments */ 310 if (strchr("eilcmpLRo", opt)) { /* options with arguments */
309 optarg = av[optind] + 2; 311 optarg = av[optind] + 2;
310 if (strcmp(optarg, "") == 0) { 312 if (strcmp(optarg, "") == 0) {
311 if (optind >= ac - 1) 313 if (optind >= ac - 1)
@@ -434,6 +436,14 @@ main(int ac, char **av)
434 } 436 }
435 } 437 }
436 break; 438 break;
439 case 'm':
440 if (mac_valid(optarg))
441 options.macs = xstrdup(optarg);
442 else {
443 fprintf(stderr, "Unknown mac type '%s'\n", optarg);
444 exit(1);
445 }
446 break;
437 case 'p': 447 case 'p':
438 options.port = atoi(optarg); 448 options.port = atoi(optarg);
439 break; 449 break;
diff --git a/sshconnect2.c b/sshconnect2.c
index 031f719ba..9681ca2d4 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: sshconnect2.c,v 1.46 2001/02/10 12:09:21 markus Exp $"); 26RCSID("$OpenBSD: sshconnect2.c,v 1.47 2001/02/11 12:59:25 markus Exp $");
27 27
28#include <openssl/bn.h> 28#include <openssl/bn.h>
29#include <openssl/md5.h> 29#include <openssl/md5.h>
@@ -84,12 +84,16 @@ ssh_kex2(char *host, struct sockaddr *hostaddr)
84 myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers; 84 myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
85 } 85 }
86 if (options.compression) { 86 if (options.compression) {
87 myproposal[PROPOSAL_COMP_ALGS_CTOS] = "zlib"; 87 myproposal[PROPOSAL_COMP_ALGS_CTOS] =
88 myproposal[PROPOSAL_COMP_ALGS_STOC] = "zlib"; 88 myproposal[PROPOSAL_COMP_ALGS_STOC] = "zlib";
89 } else { 89 } else {
90 myproposal[PROPOSAL_COMP_ALGS_CTOS] = "none"; 90 myproposal[PROPOSAL_COMP_ALGS_CTOS] =
91 myproposal[PROPOSAL_COMP_ALGS_STOC] = "none"; 91 myproposal[PROPOSAL_COMP_ALGS_STOC] = "none";
92 } 92 }
93 if (options.macs != NULL) {
94 myproposal[PROPOSAL_MAC_ALGS_CTOS] =
95 myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
96 }
93 97
94 /* buffers with raw kexinit messages */ 98 /* buffers with raw kexinit messages */
95 server_kexinit = xmalloc(sizeof(*server_kexinit)); 99 server_kexinit = xmalloc(sizeof(*server_kexinit));
diff --git a/sshd.8 b/sshd.8
index 5bf0b3a6e..1b1e9645c 100644
--- a/sshd.8
+++ b/sshd.8
@@ -34,7 +34,7 @@
34.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36.\" 36.\"
37.\" $OpenBSD: sshd.8,v 1.92 2001/02/09 23:38:11 deraadt Exp $ 37.\" $OpenBSD: sshd.8,v 1.93 2001/02/11 12:59:25 markus Exp $
38.Dd September 25, 1999 38.Dd September 25, 1999
39.Dt SSHD 8 39.Dt SSHD 8
40.Os 40.Os
@@ -501,6 +501,17 @@ QUIET, FATAL, ERROR, INFO, VERBOSE and DEBUG.
501The default is INFO. 501The default is INFO.
502Logging with level DEBUG violates the privacy of users 502Logging with level DEBUG violates the privacy of users
503and is not recommended. 503and is not recommended.
504.It Cm MACs
505Specifies the available MAC (message authentication code) algorithms.
506The MAC algorithm is used in protocol version 2
507for data integrity protection.
508Multiple algorithms must be comma-separated.
509The default is
510.Pp
511.Bd -literal
512 ``hmac-sha1,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,
513 hmac-sha1-96,hmac-md5-96''
514.Ed
504.It Cm MaxStartups 515.It Cm MaxStartups
505Specifies the maximum number of concurrent unauthenticated connections to the 516Specifies the maximum number of concurrent unauthenticated connections to the
506.Nm 517.Nm
diff --git a/sshd.c b/sshd.c
index 88ce79028..dd8f6d83d 100644
--- a/sshd.c
+++ b/sshd.c
@@ -40,7 +40,7 @@
40 */ 40 */
41 41
42#include "includes.h" 42#include "includes.h"
43RCSID("$OpenBSD: sshd.c,v 1.165 2001/02/08 19:30:53 itojun Exp $"); 43RCSID("$OpenBSD: sshd.c,v 1.166 2001/02/11 12:59:25 markus Exp $");
44 44
45#include <openssl/dh.h> 45#include <openssl/dh.h>
46#include <openssl/bn.h> 46#include <openssl/bn.h>
@@ -1412,6 +1412,10 @@ do_ssh2_kex(void)
1412 myproposal[PROPOSAL_ENC_ALGS_CTOS] = 1412 myproposal[PROPOSAL_ENC_ALGS_CTOS] =
1413 myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers; 1413 myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers;
1414 } 1414 }
1415 if (options.macs != NULL) {
1416 myproposal[PROPOSAL_MAC_ALGS_CTOS] =
1417 myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
1418 }
1415 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types(); 1419 myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types();
1416 1420
1417 server_kexinit = kex_init(myproposal); 1421 server_kexinit = kex_init(myproposal);