]> andersk Git - openssh.git/blob - compat.c
- stevesk@cvs.openbsd.org 2006/07/26 02:35:17
[openssh.git] / compat.c
1 /* $OpenBSD: compat.c,v 1.74 2006/07/22 20:48:23 stevesk Exp $ */
2 /*
3  * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl.  All rights reserved.
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
26 #include "includes.h"
27
28 #include <string.h>
29
30 #include "buffer.h"
31 #include "packet.h"
32 #include "xmalloc.h"
33 #include "compat.h"
34 #include "log.h"
35 #include "match.h"
36
37 int compat13 = 0;
38 int compat20 = 0;
39 int datafellows = 0;
40
41 void
42 enable_compat20(void)
43 {
44         debug("Enabling compatibility mode for protocol 2.0");
45         compat20 = 1;
46 }
47 void
48 enable_compat13(void)
49 {
50         debug("Enabling compatibility mode for protocol 1.3");
51         compat13 = 1;
52 }
53 /* datafellows bug compatibility */
54 void
55 compat_datafellows(const char *version)
56 {
57         int i;
58         static struct {
59                 char    *pat;
60                 int     bugs;
61         } check[] = {
62                 { "OpenSSH-2.0*,"
63                   "OpenSSH-2.1*,"
64                   "OpenSSH_2.1*,"
65                   "OpenSSH_2.2*",       SSH_OLD_SESSIONID|SSH_BUG_BANNER|
66                                         SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
67                                         SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
68                 { "OpenSSH_2.3.0*",     SSH_BUG_BANNER|SSH_BUG_BIGENDIANAES|
69                                         SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
70                                         SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
71                 { "OpenSSH_2.3.*",      SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
72                                         SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
73                                         SSH_OLD_FORWARD_ADDR},
74                 { "OpenSSH_2.5.0p1*,"
75                   "OpenSSH_2.5.1p1*",
76                                         SSH_BUG_BIGENDIANAES|SSH_OLD_DHGEX|
77                                         SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
78                                         SSH_OLD_FORWARD_ADDR},
79                 { "OpenSSH_2.5.0*,"
80                   "OpenSSH_2.5.1*,"
81                   "OpenSSH_2.5.2*",     SSH_OLD_DHGEX|SSH_BUG_NOREKEY|
82                                         SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
83                 { "OpenSSH_2.5.3*",     SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
84                                         SSH_OLD_FORWARD_ADDR},
85                 { "OpenSSH_2.*,"
86                   "OpenSSH_3.0*,"
87                   "OpenSSH_3.1*",       SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR},
88                 { "OpenSSH_3.*",        SSH_OLD_FORWARD_ADDR },
89                 { "Sun_SSH_1.0*",       SSH_BUG_NOREKEY|SSH_BUG_EXTEOF},
90                 { "OpenSSH*",           0 },
91                 { "*MindTerm*",         0 },
92                 { "2.1.0*",             SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
93                                         SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
94                                         SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
95                                         SSH_BUG_FIRSTKEX },
96                 { "2.1 *",              SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
97                                         SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
98                                         SSH_BUG_RSASIGMD5|SSH_BUG_HBSERVICE|
99                                         SSH_BUG_FIRSTKEX },
100                 { "2.0.13*,"
101                   "2.0.14*,"
102                   "2.0.15*,"
103                   "2.0.16*,"
104                   "2.0.17*,"
105                   "2.0.18*,"
106                   "2.0.19*",            SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
107                                         SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
108                                         SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
109                                         SSH_BUG_PKOK|SSH_BUG_RSASIGMD5|
110                                         SSH_BUG_HBSERVICE|SSH_BUG_OPENFAILURE|
111                                         SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
112                 { "2.0.11*,"
113                   "2.0.12*",            SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
114                                         SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
115                                         SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
116                                         SSH_BUG_PKAUTH|SSH_BUG_PKOK|
117                                         SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
118                                         SSH_BUG_DUMMYCHAN|SSH_BUG_FIRSTKEX },
119                 { "2.0.*",              SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
120                                         SSH_OLD_SESSIONID|SSH_BUG_DEBUG|
121                                         SSH_BUG_PKSERVICE|SSH_BUG_X11FWD|
122                                         SSH_BUG_PKAUTH|SSH_BUG_PKOK|
123                                         SSH_BUG_RSASIGMD5|SSH_BUG_OPENFAILURE|
124                                         SSH_BUG_DERIVEKEY|SSH_BUG_DUMMYCHAN|
125                                         SSH_BUG_FIRSTKEX },
126                 { "2.2.0*,"
127                   "2.3.0*",             SSH_BUG_HMAC|SSH_BUG_DEBUG|
128                                         SSH_BUG_RSASIGMD5|SSH_BUG_FIRSTKEX },
129                 { "2.3.*",              SSH_BUG_DEBUG|SSH_BUG_RSASIGMD5|
130                                         SSH_BUG_FIRSTKEX },
131                 { "2.4",                SSH_OLD_SESSIONID },    /* Van Dyke */
132                 { "2.*",                SSH_BUG_DEBUG|SSH_BUG_FIRSTKEX },
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*,"
140                   "1.2.22*",            SSH_BUG_IGNOREMSG },
141                 { "1.3.2*",             /* F-Secure */
142                                         SSH_BUG_IGNOREMSG },
143                 { "*SSH Compatible Server*",                    /* Netscreen */
144                                         SSH_BUG_PASSWORDPAD },
145                 { "*OSU_0*,"
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*",
155                                         SSH_BUG_SCANNER },
156                 { "Probe-*",
157                                         SSH_BUG_PROBE },
158                 { NULL,                 0 }
159         };
160
161         /* process table, return first match */
162         for (i = 0; check[i].pat; i++) {
163                 if (match_pattern_list(version, check[i].pat,
164                     strlen(check[i].pat), 0) == 1) {
165                         debug("match: %s pat %s", version, check[i].pat);
166                         datafellows = check[i].bugs;
167                         return;
168                 }
169         }
170         debug("no match: %s", version);
171 }
172
173 #define SEP     ","
174 int
175 proto_spec(const char *spec)
176 {
177         char *s, *p, *q;
178         int ret = SSH_PROTO_UNKNOWN;
179
180         if (spec == NULL)
181                 return ret;
182         q = s = xstrdup(spec);
183         for ((p = strsep(&q, SEP)); p && *p != '\0'; (p = strsep(&q, SEP))) {
184                 switch (atoi(p)) {
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:
194                         logit("ignoring bad proto spec: '%s'.", p);
195                         break;
196                 }
197         }
198         xfree(s);
199         return ret;
200 }
201
202 char *
203 compat_cipher_proposal(char *cipher_prop)
204 {
205         Buffer b;
206         char *orig_prop, *fix_ciphers;
207         char *cp, *tmp;
208
209         if (!(datafellows & SSH_BUG_BIGENDIANAES))
210                 return(cipher_prop);
211
212         buffer_init(&b);
213         tmp = orig_prop = xstrdup(cipher_prop);
214         while ((cp = strsep(&tmp, ",")) != NULL) {
215                 if (strncmp(cp, "aes", 3) != 0) {
216                         if (buffer_len(&b) > 0)
217                                 buffer_append(&b, ",", 1);
218                         buffer_append(&b, cp, strlen(cp));
219                 }
220         }
221         buffer_append(&b, "\0", 1);
222         fix_ciphers = xstrdup(buffer_ptr(&b));
223         buffer_free(&b);
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);
231 }
This page took 1.045251 seconds and 5 git commands to generate.