Annotation of src/usr.bin/ssh/compat.c, Revision 1.74
1.74 ! stevesk 1: /* $OpenBSD: compat.c,v 1.73 2006/03/25 13:17:01 djm Exp $ */
1.5 markus 2: /*
1.61 markus 3: * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved.
1.5 markus 4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: *
14: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24: */
25:
1.1 markus 26: #include "includes.h"
1.74 ! stevesk 27:
! 28: #include <string.h>
1.2 markus 29:
1.57 markus 30: #include "buffer.h"
1.6 markus 31: #include "packet.h"
1.10 markus 32: #include "xmalloc.h"
33: #include "compat.h"
1.34 markus 34: #include "log.h"
1.55 markus 35: #include "match.h"
1.1 markus 36:
1.4 markus 37: int compat13 = 0;
1.6 markus 38: int compat20 = 0;
39: int datafellows = 0;
1.4 markus 40:
1.11 markus 41: void
1.6 markus 42: enable_compat20(void)
43: {
1.64 stevesk 44: debug("Enabling compatibility mode for protocol 2.0");
1.7 markus 45: compat20 = 1;
1.6 markus 46: }
1.11 markus 47: void
1.4 markus 48: enable_compat13(void)
49: {
1.64 stevesk 50: debug("Enabling compatibility mode for protocol 1.3");
1.4 markus 51: compat13 = 1;
1.6 markus 52: }
53: /* datafellows bug compatibility */
54: void
55: compat_datafellows(const char *version)
56: {
1.55 markus 57: int i;
1.24 markus 58: static struct {
59: char *pat;
1.13 markus 60: int bugs;
61: } check[] = {
1.55 markus 62: { "OpenSSH-2.0*,"
63: "OpenSSH-2.1*,"
64: "OpenSSH_2.1*,"
65: "OpenSSH_2.2*", SSH_OLD_SESSIONID|SSH_BUG_BANNER|
1.62 markus 66: SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
1.71 djm 67: SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
1.55 markus 68: { "OpenSSH_2.3.0*", SSH_BUG_BANNER|SSH_BUG_BIGENDIANAES|
1.62 markus 69: SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
1.71 djm 70: SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
1.55 markus 71: { "OpenSSH_2.3.*", SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
1.71 djm 72: SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
73: SSH_OLD_FORWARD_ADDR},
1.55 markus 74: { "OpenSSH_2.5.0p1*,"
75: "OpenSSH_2.5.1p1*",
1.45 markus 76: SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
1.71 djm 77: SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
78: SSH_OLD_FORWARD_ADDR},
1.55 markus 79: { "OpenSSH_2.5.0*,"
80: "OpenSSH_2.5.1*,"
1.62 markus 81: "OpenSSH_2.5.2*", SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
1.71 djm 82: SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
83: { "OpenSSH_2.5.3*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
84: SSH_OLD_FORWARD_ADDR},
1.62 markus 85: { "OpenSSH_2.*,"
86: "OpenSSH_3.0*,"
1.71 djm 87: "OpenSSH_3.1*", SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
88: { "OpenSSH_3.*", SSH_OLD_FORWARD_ADDR },
1.62 markus 89: { "Sun_SSH_1.0*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF},
1.55 markus 90: { "OpenSSH*", 0 },
91: { "*MindTerm*", 0 },
92: { "2.1.0*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
1.41 markus 93: SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
1.66 markus 94: SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
95: SSH_BUG_FIRSTKEX },
1.55 markus 96: { "2.1 *", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
1.41 markus 97: SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
1.66 markus 98: SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
99: SSH_BUG_FIRSTKEX },
1.56 deraadt 100: { "2.0.13*,"
101: "2.0.14*,"
102: "2.0.15*,"
103: "2.0.16*,"
104: "2.0.17*,"
105: "2.0.18*,"
1.55 markus 106: "2.0.19*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
1.31 markus 107: SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
1.37 markus 108: SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
1.47 markus 109: SSH_BUG_PKOK|SSH_BUG_RSASIGMD5|
1.53 markus 110: SSH_BUG_HBSERVICE|SSH_BUG_OPENFAILURE|
1.66 markus 111: SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
1.56 deraadt 112: { "2.0.11*,"
1.55 markus 113: "2.0.12*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
1.49 markus 114: SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
115: SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
116: SSH_BUG_PKAUTH|SSH_BUG_PKOK|
1.53 markus 117: SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
1.66 markus 118: SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
1.55 markus 119: { "2.0.*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
1.31 markus 120: SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
121: SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
1.41 markus 122: SSH_BUG_PKAUTH|SSH_BUG_PKOK|
1.49 markus 123: SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
1.66 markus 124: SSH_BUG_DERIVEKEY|SSH_BUG_DUMMYCHAN|
125: SSH_BUG_FIRSTKEX },
1.55 markus 126: { "2.2.0*,"
127: "2.3.0*", SSH_BUG_HMAC|SSH_BUG_DEBUG|
1.66 markus 128: SSH_BUG_RSASIGMD5|SSH_BUG_FIRSTKEX },
129: { "2.3.*", SSH_BUG_DEBUG|SSH_BUG_RSASIGMD5|
130: SSH_BUG_FIRSTKEX },
1.55 markus 131: { "2.4", SSH_OLD_SESSIONID }, /* Van Dyke */
1.66 markus 132: { "2.*", SSH_BUG_DEBUG|SSH_BUG_FIRSTKEX },
1.55 markus 133: { "3.0.*", SSH_BUG_DEBUG },
134: { "3.0 SecureCRT*", SSH_OLD_SESSIONID },
135: { "1.7 SecureFX*", SSH_OLD_SESSIONID },
136: { "1.2.18*,"
137: "1.2.19*,"
138: "1.2.20*,"
139: "1.2.21*,"
1.69 markus 140: "1.2.22*", SSH_BUG_IGNOREMSG },
1.63 markus 141: { "1.3.2*", /* F-Secure */
1.69 markus 142: SSH_BUG_IGNOREMSG },
1.55 markus 143: { "*SSH Compatible Server*", /* Netscreen */
1.38 deraadt 144: SSH_BUG_PASSWORDPAD },
1.56 deraadt 145: { "*OSU_0*,"
1.55 markus 146: "OSU_1.0*,"
147: "OSU_1.1*,"
148: "OSU_1.2*,"
149: "OSU_1.3*,"
150: "OSU_1.4*,"
151: "OSU_1.5alpha1*,"
152: "OSU_1.5alpha2*,"
153: "OSU_1.5alpha3*", SSH_BUG_PASSWORDPAD },
154: { "*SSH_Version_Mapper*",
1.39 deraadt 155: SSH_BUG_SCANNER },
1.65 mickey 156: { "Probe-*",
157: SSH_BUG_PROBE },
1.25 markus 158: { NULL, 0 }
1.6 markus 159: };
1.55 markus 160:
1.21 markus 161: /* process table, return first match */
1.24 markus 162: for (i = 0; check[i].pat; i++) {
1.55 markus 163: if (match_pattern_list(version, check[i].pat,
164: strlen(check[i].pat), 0) == 1) {
1.32 provos 165: debug("match: %s pat %s", version, check[i].pat);
1.13 markus 166: datafellows = check[i].bugs;
1.6 markus 167: return;
168: }
169: }
1.24 markus 170: debug("no match: %s", version);
1.10 markus 171: }
172:
173: #define SEP ","
174: int
175: proto_spec(const char *spec)
176: {
1.18 provos 177: char *s, *p, *q;
1.10 markus 178: int ret = SSH_PROTO_UNKNOWN;
179:
1.14 markus 180: if (spec == NULL)
181: return ret;
1.18 provos 182: q = s = xstrdup(spec);
1.19 ho 183: for ((p = strsep(&q, SEP)); p && *p != '\0'; (p = strsep(&q, SEP))) {
1.54 deraadt 184: switch (atoi(p)) {
1.10 markus 185: case 1:
186: if (ret == SSH_PROTO_UNKNOWN)
187: ret |= SSH_PROTO_1_PREFERRED;
188: ret |= SSH_PROTO_1;
189: break;
190: case 2:
191: ret |= SSH_PROTO_2;
192: break;
193: default:
1.67 itojun 194: logit("ignoring bad proto spec: '%s'.", p);
1.10 markus 195: break;
196: }
197: }
198: xfree(s);
199: return ret;
1.40 djm 200: }
201:
202: char *
203: compat_cipher_proposal(char *cipher_prop)
204: {
1.57 markus 205: Buffer b;
1.40 djm 206: char *orig_prop, *fix_ciphers;
207: char *cp, *tmp;
208:
209: if (!(datafellows & SSH_BUG_BIGENDIANAES))
210: return(cipher_prop);
211:
1.57 markus 212: buffer_init(&b);
1.40 djm 213: tmp = orig_prop = xstrdup(cipher_prop);
1.54 deraadt 214: while ((cp = strsep(&tmp, ",")) != NULL) {
1.58 markus 215: if (strncmp(cp, "aes", 3) != 0) {
1.57 markus 216: if (buffer_len(&b) > 0)
217: buffer_append(&b, ",", 1);
218: buffer_append(&b, cp, strlen(cp));
1.40 djm 219: }
220: }
1.57 markus 221: buffer_append(&b, "\0", 1);
222: fix_ciphers = xstrdup(buffer_ptr(&b));
223: buffer_free(&b);
1.40 djm 224: xfree(orig_prop);
225: debug2("Original cipher proposal: %s", cipher_prop);
226: debug2("Compat cipher proposal: %s", fix_ciphers);
227: if (!*fix_ciphers)
228: fatal("No available ciphers found.");
229:
230: return(fix_ciphers);
1.1 markus 231: }