1 /* $OpenBSD: compat.c,v 1.97 2015/08/19 23:21:42 djm Exp $ */
3 * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 #include <sys/types.h>
50 debug("Enabling compatibility mode for protocol 2.0");
56 debug("Enabling compatibility mode for protocol 1.3");
59 /* datafellows bug compatibility */
61 compat_datafellows(const char *version)
71 "OpenSSH_2.2*", SSH_OLD_SESSIONID|SSH_BUG_BANNER|
72 SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
73 SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
74 { "OpenSSH_2.3.0*", SSH_BUG_BANNER|SSH_BUG_BIGENDIANAES|
75 SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
76 SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
77 { "OpenSSH_2.3.*", SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
78 SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
79 SSH_OLD_FORWARD_ADDR},
82 SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
83 SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
84 SSH_OLD_FORWARD_ADDR},
87 "OpenSSH_2.5.2*", SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
88 SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
89 { "OpenSSH_2.5.3*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
90 SSH_OLD_FORWARD_ADDR},
93 "OpenSSH_3.1*", SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
94 { "OpenSSH_3.*", SSH_OLD_FORWARD_ADDR },
95 { "Sun_SSH_1.0*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF},
97 { "OpenSSH_5*", SSH_NEW_OPENSSH|SSH_BUG_DYNAMIC_RPORT},
98 { "OpenSSH_6.6.1*", SSH_NEW_OPENSSH},
100 "OpenSSH_6.6*", SSH_NEW_OPENSSH|SSH_BUG_CURVE25519PAD},
101 { "OpenSSH*", SSH_NEW_OPENSSH },
103 { "2.1.0*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
104 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
105 SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
107 { "2.1 *", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
108 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
109 SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
117 "2.0.19*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
118 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
119 SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
120 SSH_BUG_PKOK|SSH_BUG_RSASIGMD5|
121 SSH_BUG_HBSERVICE|SSH_BUG_OPENFAILURE|
122 SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
124 "2.0.12*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
125 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
126 SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
127 SSH_BUG_PKAUTH|SSH_BUG_PKOK|
128 SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
129 SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
130 { "2.0.*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
131 SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
132 SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
133 SSH_BUG_PKAUTH|SSH_BUG_PKOK|
134 SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
135 SSH_BUG_DERIVEKEY|SSH_BUG_DUMMYCHAN|
138 "2.3.0*", SSH_BUG_HMAC|SSH_BUG_DEBUG|
139 SSH_BUG_RSASIGMD5|SSH_BUG_FIRSTKEX },
140 { "2.3.*", SSH_BUG_DEBUG|SSH_BUG_RSASIGMD5|
142 { "2.4", SSH_OLD_SESSIONID }, /* Van Dyke */
143 { "2.*", SSH_BUG_DEBUG|SSH_BUG_FIRSTKEX|
145 { "3.0.*", SSH_BUG_DEBUG },
146 { "3.0 SecureCRT*", SSH_OLD_SESSIONID },
147 { "1.7 SecureFX*", SSH_OLD_SESSIONID },
152 "1.2.22*", SSH_BUG_IGNOREMSG },
153 { "1.3.2*", /* F-Secure */
155 { "Cisco-1.*", SSH_BUG_DHGEX_LARGE|
157 { "*SSH Compatible Server*", /* Netscreen */
158 SSH_BUG_PASSWORDPAD },
167 "OSU_1.5alpha3*", SSH_BUG_PASSWORDPAD },
168 { "*SSH_Version_Mapper*",
170 { "PuTTY_Local:*," /* dev versions < Sep 2014 */
171 "PuTTY-Release-0.5*," /* 0.50-0.57, DH-GEX in >=0.52 */
172 "PuTTY_Release_0.5*," /* 0.58-0.59 */
173 "PuTTY_Release_0.60*,"
174 "PuTTY_Release_0.61*,"
175 "PuTTY_Release_0.62*,"
176 "PuTTY_Release_0.63*,"
177 "PuTTY_Release_0.64*",
179 { "FuTTY*", SSH_OLD_DHGEX }, /* Putty Fork */
192 "TTSSH/2.72*", SSH_BUG_HOSTKEYS },
193 { "WinSCP_release_4*,"
194 "WinSCP_release_5.0*,"
195 "WinSCP_release_5.1*,"
196 "WinSCP_release_5.5*,"
197 "WinSCP_release_5.6*,"
198 "WinSCP_release_5.7,"
199 "WinSCP_release_5.7.1,"
200 "WinSCP_release_5.7.2,"
201 "WinSCP_release_5.7.3,"
202 "WinSCP_release_5.7.4",
207 /* process table, return first match */
208 for (i = 0; check[i].pat; i++) {
209 if (match_pattern_list(version, check[i].pat, 0) == 1) {
210 debug("match: %s pat %s compat 0x%08x",
211 version, check[i].pat, check[i].bugs);
212 datafellows = check[i].bugs; /* XXX for now */
213 return check[i].bugs;
216 debug("no match: %s", version);
222 proto_spec(const char *spec)
225 int ret = SSH_PROTO_UNKNOWN;
229 q = s = strdup(spec);
232 for ((p = strsep(&q, SEP)); p && *p != '\0'; (p = strsep(&q, SEP))) {
236 if (ret == SSH_PROTO_UNKNOWN)
237 ret |= SSH_PROTO_1_PREFERRED;
245 logit("ignoring bad proto spec: '%s'.", p);
254 * Filters a proposal string, excluding any algorithm matching the 'filter'
258 filter_proposal(char *proposal, const char *filter)
261 char *orig_prop, *fix_prop;
265 tmp = orig_prop = xstrdup(proposal);
266 while ((cp = strsep(&tmp, ",")) != NULL) {
267 if (match_pattern_list(cp, filter, 0) != 1) {
268 if (buffer_len(&b) > 0)
269 buffer_append(&b, ",", 1);
270 buffer_append(&b, cp, strlen(cp));
272 debug2("Compat: skipping algorithm \"%s\"", cp);
274 buffer_append(&b, "\0", 1);
275 fix_prop = xstrdup((char *)buffer_ptr(&b));
283 compat_cipher_proposal(char *cipher_prop)
285 if (!(datafellows & SSH_BUG_BIGENDIANAES))
287 debug2("%s: original cipher proposal: %s", __func__, cipher_prop);
288 cipher_prop = filter_proposal(cipher_prop, "aes*");
289 debug2("%s: compat cipher proposal: %s", __func__, cipher_prop);
290 if (*cipher_prop == '\0')
291 fatal("No supported ciphers found");
296 compat_pkalg_proposal(char *pkalg_prop)
298 if (!(datafellows & SSH_BUG_RSASIGMD5))
300 debug2("%s: original public key proposal: %s", __func__, pkalg_prop);
301 pkalg_prop = filter_proposal(pkalg_prop, "ssh-rsa");
302 debug2("%s: compat public key proposal: %s", __func__, pkalg_prop);
303 if (*pkalg_prop == '\0')
304 fatal("No supported PK algorithms found");
309 compat_kex_proposal(char *p)
311 if ((datafellows & (SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX)) == 0)
313 debug2("%s: original KEX proposal: %s", __func__, p);
314 if ((datafellows & SSH_BUG_CURVE25519PAD) != 0)
315 p = filter_proposal(p, "curve25519-sha256@libssh.org");
316 if ((datafellows & SSH_OLD_DHGEX) != 0) {
317 p = filter_proposal(p, "diffie-hellman-group-exchange-sha256");
318 p = filter_proposal(p, "diffie-hellman-group-exchange-sha1");
320 debug2("%s: compat KEX proposal: %s", __func__, p);
322 fatal("No supported key exchange algorithms found");