1 /* $OpenBSD: compat.c,v 1.82 2013/12/30 23:52:27 djm Exp $ */
4 * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (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.
30 #include <sys/types.h>
52 debug("Enabling compatibility mode for protocol 2.0");
58 debug("Enabling compatibility mode for protocol 1.3");
61 /* datafellows bug compatibility */
63 compat_datafellows(const char *version)
73 "OpenSSH_2.2*", SSH_OLD_SESSIONID|SSH_BUG_BANNER|
74 SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
75 SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
76 { "OpenSSH_2.3.0*", SSH_BUG_BANNER|SSH_BUG_BIGENDIANAES|
77 SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
78 SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
79 { "OpenSSH_2.3.*", SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
80 SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
81 SSH_OLD_FORWARD_ADDR},
84 SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
85 SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
86 SSH_OLD_FORWARD_ADDR},
89 "OpenSSH_2.5.2*", SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
90 SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
91 { "OpenSSH_2.5.3*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
92 SSH_OLD_FORWARD_ADDR},
95 "OpenSSH_3.1*", SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
96 { "OpenSSH_3.*", SSH_OLD_FORWARD_ADDR },
97 { "Sun_SSH_1.0*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF},
99 { "OpenSSH_5*", SSH_NEW_OPENSSH|SSH_BUG_DYNAMIC_RPORT},
100 { "OpenSSH*", SSH_NEW_OPENSSH },
102 { "2.1.0*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
103 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
104 SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
106 { "2.1 *", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
107 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
108 SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
116 "2.0.19*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
117 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
118 SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
119 SSH_BUG_PKOK|SSH_BUG_RSASIGMD5|
120 SSH_BUG_HBSERVICE|SSH_BUG_OPENFAILURE|
121 SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
123 "2.0.12*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
124 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
125 SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
126 SSH_BUG_PKAUTH|SSH_BUG_PKOK|
127 SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
128 SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
129 { "2.0.*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
130 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
131 SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
132 SSH_BUG_PKAUTH|SSH_BUG_PKOK|
133 SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
134 SSH_BUG_DERIVEKEY|SSH_BUG_DUMMYCHAN|
137 "2.3.0*", SSH_BUG_HMAC|SSH_BUG_DEBUG|
138 SSH_BUG_RSASIGMD5|SSH_BUG_FIRSTKEX },
139 { "2.3.*", SSH_BUG_DEBUG|SSH_BUG_RSASIGMD5|
141 { "2.4", SSH_OLD_SESSIONID }, /* Van Dyke */
142 { "2.*", SSH_BUG_DEBUG|SSH_BUG_FIRSTKEX|
144 { "3.0.*", SSH_BUG_DEBUG },
145 { "3.0 SecureCRT*", SSH_OLD_SESSIONID },
146 { "1.7 SecureFX*", SSH_OLD_SESSIONID },
151 "1.2.22*", SSH_BUG_IGNOREMSG },
152 { "1.3.2*", /* F-Secure */
154 { "*SSH Compatible Server*", /* Netscreen */
155 SSH_BUG_PASSWORDPAD },
164 "OSU_1.5alpha3*", SSH_BUG_PASSWORDPAD },
165 { "*SSH_Version_Mapper*",
172 /* process table, return first match */
173 for (i = 0; check[i].pat; i++) {
174 if (match_pattern_list(version, check[i].pat,
175 strlen(check[i].pat), 0) == 1) {
176 datafellows = check[i].bugs;
177 debug("match: %s pat %s compat 0x%08x",
178 version, check[i].pat, datafellows);
180 * Check to see if the remote side is OpenSSH and not
181 * HPN. It is utterly strange to check it from the
182 * version string and expose the option that way.
184 if (strstr(version,"OpenSSH") != NULL &&
185 strstr(version,"hpn") == NULL) {
186 datafellows |= SSH_BUG_LARGEWINDOW;
187 debug("Remote is not HPN-aware");
192 debug("no match: %s", version);
197 proto_spec(const char *spec)
200 int ret = SSH_PROTO_UNKNOWN;
204 q = s = xstrdup(spec);
205 for ((p = strsep(&q, SEP)); p && *p != '\0'; (p = strsep(&q, SEP))) {
208 if (ret == SSH_PROTO_UNKNOWN)
209 ret |= SSH_PROTO_1_PREFERRED;
216 logit("ignoring bad proto spec: '%s'.", p);
225 * Filters a proposal string, excluding any algorithm matching the 'filter'
229 filter_proposal(char *proposal, const char *filter)
232 char *orig_prop, *fix_prop;
236 tmp = orig_prop = xstrdup(proposal);
237 while ((cp = strsep(&tmp, ",")) != NULL) {
238 if (match_pattern_list(cp, filter, strlen(cp), 0) != 1) {
239 if (buffer_len(&b) > 0)
240 buffer_append(&b, ",", 1);
241 buffer_append(&b, cp, strlen(cp));
243 debug2("Compat: skipping algorithm \"%s\"", cp);
245 buffer_append(&b, "\0", 1);
246 fix_prop = xstrdup(buffer_ptr(&b));
254 compat_cipher_proposal(char *cipher_prop)
256 if (!(datafellows & SSH_BUG_BIGENDIANAES))
258 debug2("%s: original cipher proposal: %s", __func__, cipher_prop);
259 cipher_prop = filter_proposal(cipher_prop, "aes*");
260 debug2("%s: compat cipher proposal: %s", __func__, cipher_prop);
261 if (*cipher_prop == '\0')
262 fatal("No supported ciphers found");
268 compat_pkalg_proposal(char *pkalg_prop)
270 if (!(datafellows & SSH_BUG_RSASIGMD5))
272 debug2("%s: original public key proposal: %s", __func__, pkalg_prop);
273 pkalg_prop = filter_proposal(pkalg_prop, "ssh-rsa");
274 debug2("%s: compat public key proposal: %s", __func__, pkalg_prop);
275 if (*pkalg_prop == '\0')
276 fatal("No supported PK algorithms found");