version bump to 4.0.6
[strongswan.git] / src / pluto / vendor.c
1 /* ISAKMP VendorID
2 * Copyright (C) 2002-2005 Mathieu Lafon - Arkoon Network Security
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * RCSID $Id: vendor.c,v 1.35 2006/04/12 16:44:28 as Exp $
15 */
16
17 #include <stdlib.h>
18 #include <string.h>
19 #include <ctype.h>
20 #include <sys/queue.h>
21 #include <freeswan.h>
22
23 #include "constants.h"
24 #include "defs.h"
25 #include "log.h"
26 #include "md5.h"
27 #include "connections.h"
28 #include "packet.h"
29 #include "demux.h"
30 #include "whack.h"
31 #include "vendor.h"
32 #include "kernel.h"
33 #include "nat_traversal.h"
34
35 /**
36 * Unknown/Special VID:
37 *
38 * SafeNet SoftRemote 8.0.0:
39 * 47bbe7c993f1fc13b4e6d0db565c68e5010201010201010310382e302e3020284275696c6420313029000000
40 * >> 382e302e3020284275696c6420313029 = '8.0.0 (Build 10)'
41 * da8e937880010000
42 *
43 * SafeNet SoftRemote 9.0.1
44 * 47bbe7c993f1fc13b4e6d0db565c68e5010201010201010310392e302e3120284275696c6420313229000000
45 * >> 392e302e3120284275696c6420313229 = '9.0.1 (Build 12)'
46 * da8e937880010000
47 *
48 * Netscreen:
49 * d6b45f82f24bacb288af59a978830ab7
50 * cf49908791073fb46439790fdeb6aeed981101ab0000000500000300
51 *
52 * Cisco:
53 * 1f07f70eaa6514d3b0fa96542a500300 (VPN 3000 version 3.0.0)
54 * 1f07f70eaa6514d3b0fa96542a500301 (VPN 3000 version 3.0.1)
55 * 1f07f70eaa6514d3b0fa96542a500305 (VPN 3000 version 3.0.5)
56 * 1f07f70eaa6514d3b0fa96542a500407 (VPN 3000 version 4.0.7)
57 * (Can you see the pattern?)
58 * afcad71368a1f1c96b8696fc77570100 (Non-RFC Dead Peer Detection ?)
59 * c32364b3b4f447eb17c488ab2a480a57
60 * 6d761ddc26aceca1b0ed11fabbb860c4
61 * 5946c258f99a1a57b03eb9d1759e0f24 (From a Cisco VPN 3k)
62 * ebbc5b00141d0c895e11bd395902d690 (From a Cisco VPN 3k)
63 *
64 * Microsoft L2TP (???):
65 * 47bbe7c993f1fc13b4e6d0db565c68e5010201010201010310382e312e3020284275696c6420313029000000
66 * >> 382e312e3020284275696c6420313029 = '8.1.0 (Build 10)'
67 * 3025dbd21062b9e53dc441c6aab5293600000000
68 * da8e937880010000
69 *
70 * 3COM-superstack
71 * da8e937880010000
72 * 404bf439522ca3f6
73 *
74
75 * If someone know what they mean, mail me.
76 */
77
78 #define MAX_LOG_VID_LEN 32
79
80 #define VID_KEEP 0x0000
81 #define VID_MD5HASH 0x0001
82 #define VID_STRING 0x0002
83 #define VID_FSWAN_HASH 0x0004
84
85 #define VID_SUBSTRING_DUMPHEXA 0x0100
86 #define VID_SUBSTRING_DUMPASCII 0x0200
87 #define VID_SUBSTRING_MATCH 0x0400
88 #define VID_SUBSTRING (VID_SUBSTRING_DUMPHEXA | VID_SUBSTRING_DUMPASCII | VID_SUBSTRING_MATCH)
89
90 struct vid_struct {
91 enum known_vendorid id;
92 unsigned short flags;
93 const char *data;
94 const char *descr;
95 const char *vid;
96 u_int vid_len;
97 };
98
99 #define DEC_MD5_VID_D(id,str,descr) \
100 { VID_##id, VID_MD5HASH, str, descr, NULL, 0 },
101 #define DEC_MD5_VID(id,str) \
102 { VID_##id, VID_MD5HASH, str, NULL, NULL, 0 },
103 #define DEC_FSWAN_VID(id,str,descr) \
104 { VID_##id, VID_FSWAN_HASH, str, descr, NULL, 0 },
105
106 static struct vid_struct _vid_tab[] = {
107
108 /* Implementation names */
109
110 { VID_OPENPGP, VID_STRING, "OpenPGP10171", "OpenPGP", NULL, 0 },
111
112 DEC_MD5_VID(KAME_RACOON, "KAME/racoon")
113
114 { VID_MS_NT5, VID_MD5HASH | VID_SUBSTRING_DUMPHEXA,
115 "MS NT5 ISAKMPOAKLEY", NULL, NULL, 0 },
116
117 DEC_MD5_VID(SSH_SENTINEL, "SSH Sentinel")
118 DEC_MD5_VID(SSH_SENTINEL_1_1, "SSH Sentinel 1.1")
119 DEC_MD5_VID(SSH_SENTINEL_1_2, "SSH Sentinel 1.2")
120 DEC_MD5_VID(SSH_SENTINEL_1_3, "SSH Sentinel 1.3")
121 DEC_MD5_VID(SSH_SENTINEL_1_4, "SSH Sentinel 1.4")
122 DEC_MD5_VID(SSH_SENTINEL_1_4_1, "SSH Sentinel 1.4.1")
123
124 /* These ones come from SSH vendors.txt */
125 DEC_MD5_VID(SSH_IPSEC_1_1_0,
126 "Ssh Communications Security IPSEC Express version 1.1.0")
127 DEC_MD5_VID(SSH_IPSEC_1_1_1,
128 "Ssh Communications Security IPSEC Express version 1.1.1")
129 DEC_MD5_VID(SSH_IPSEC_1_1_2,
130 "Ssh Communications Security IPSEC Express version 1.1.2")
131 DEC_MD5_VID(SSH_IPSEC_1_2_1,
132 "Ssh Communications Security IPSEC Express version 1.2.1")
133 DEC_MD5_VID(SSH_IPSEC_1_2_2,
134 "Ssh Communications Security IPSEC Express version 1.2.2")
135 DEC_MD5_VID(SSH_IPSEC_2_0_0,
136 "SSH Communications Security IPSEC Express version 2.0.0")
137 DEC_MD5_VID(SSH_IPSEC_2_1_0,
138 "SSH Communications Security IPSEC Express version 2.1.0")
139 DEC_MD5_VID(SSH_IPSEC_2_1_1,
140 "SSH Communications Security IPSEC Express version 2.1.1")
141 DEC_MD5_VID(SSH_IPSEC_2_1_2,
142 "SSH Communications Security IPSEC Express version 2.1.2")
143 DEC_MD5_VID(SSH_IPSEC_3_0_0,
144 "SSH Communications Security IPSEC Express version 3.0.0")
145 DEC_MD5_VID(SSH_IPSEC_3_0_1,
146 "SSH Communications Security IPSEC Express version 3.0.1")
147 DEC_MD5_VID(SSH_IPSEC_4_0_0,
148 "SSH Communications Security IPSEC Express version 4.0.0")
149 DEC_MD5_VID(SSH_IPSEC_4_0_1,
150 "SSH Communications Security IPSEC Express version 4.0.1")
151 DEC_MD5_VID(SSH_IPSEC_4_1_0,
152 "SSH Communications Security IPSEC Express version 4.1.0")
153 DEC_MD5_VID(SSH_IPSEC_4_2_0,
154 "SSH Communications Security IPSEC Express version 4.2.0")
155
156 /* note: md5('CISCO-UNITY') = 12f5f28c457168a9702d9fe274cc02d4 */
157 { VID_CISCO_UNITY, VID_KEEP, NULL, "Cisco-Unity",
158 "\x12\xf5\xf2\x8c\x45\x71\x68\xa9\x70\x2d\x9f\xe2\x74\xcc\x01\x00",
159 16 },
160
161 { VID_CISCO3K, VID_KEEP | VID_SUBSTRING_MATCH,
162 NULL, "Cisco VPN 3000 Series" , "\x1f\x07\xf7\x0e\xaa\x65\x14\xd3\xb0\xfa\x96\x54\x2a\x50", 14},
163
164 { VID_CISCO_IOS, VID_KEEP | VID_SUBSTRING_MATCH,
165 NULL, "Cisco IOS Device", "\x3e\x98\x40\x48", 4},
166
167 /*
168 * Timestep VID seen:
169 * - 54494d455354455020312053475720313532302033313520322e303145303133
170 * = 'TIMESTEP 1 SGW 1520 315 2.01E013'
171 */
172 { VID_TIMESTEP, VID_STRING | VID_SUBSTRING_DUMPASCII, "TIMESTEP",
173 NULL, NULL, 0 },
174
175 /*
176 * Netscreen:
177 * 4865617274426561745f4e6f74696679386b0100 (HeartBeat_Notify + 386b0100)
178 */
179 { VID_MISC_HEARTBEAT_NOTIFY, VID_STRING | VID_SUBSTRING_DUMPHEXA,
180 "HeartBeat_Notify", "HeartBeat Notify", NULL, 0 },
181
182 /*
183 * MacOS X
184 */
185 { VID_MACOSX, VID_STRING|VID_SUBSTRING_DUMPHEXA, "Mac OSX 10.x",
186 "\x4d\xf3\x79\x28\xe9\xfc\x4f\xd1\xb3\x26\x21\x70\xd5\x15\xc6\x62", NULL, 0},
187
188 /*
189 * Openswan
190 */
191 DEC_FSWAN_VID(OPENSWAN2, "Openswan 2.2.0", "Openswan 2.2.0")
192
193 /* NCP */
194 { VID_NCP_SERVER, VID_KEEP | VID_SUBSTRING_MATCH, NULL, "NCP Server",
195 "\xc6\xf5\x7a\xc3\x98\xf4\x93\x20\x81\x45\xb7\x58", 12},
196 { VID_NCP_CLIENT, VID_KEEP | VID_SUBSTRING_MATCH, NULL, "NCP Client",
197 "\xeb\x4c\x1b\x78\x8a\xfd\x4a\x9c\xb7\x73\x0a\x68", 12},
198 /*
199 * strongSwan
200 */
201 DEC_MD5_VID(STRONGSWAN, "strongSwan 4.0.6")
202 DEC_MD5_VID(STRONGSWAN_4_0_5, "strongSwan 4.0.5")
203 DEC_MD5_VID(STRONGSWAN_4_0_4, "strongSwan 4.0.4")
204 DEC_MD5_VID(STRONGSWAN_4_0_3, "strongSwan 4.0.3")
205 DEC_MD5_VID(STRONGSWAN_4_0_2, "strongSwan 4.0.2")
206 DEC_MD5_VID(STRONGSWAN_4_0_1, "strongSwan 4.0.1")
207 DEC_MD5_VID(STRONGSWAN_4_0_0, "strongSwan 4.0.0")
208
209 DEC_MD5_VID(STRONGSWAN_2_8_1, "strongSwan 2.8.1")
210 DEC_MD5_VID(STRONGSWAN_2_8_0, "strongSwan 2.8.0")
211 DEC_MD5_VID(STRONGSWAN_2_7_3, "strongSwan 2.7.3")
212 DEC_MD5_VID(STRONGSWAN_2_7_2, "strongSwan 2.7.2")
213 DEC_MD5_VID(STRONGSWAN_2_7_1, "strongSwan 2.7.1")
214 DEC_MD5_VID(STRONGSWAN_2_7_0, "strongSwan 2.7.0")
215 DEC_MD5_VID(STRONGSWAN_2_6_4, "strongSwan 2.6.4")
216 DEC_MD5_VID(STRONGSWAN_2_6_3, "strongSwan 2.6.3")
217 DEC_MD5_VID(STRONGSWAN_2_6_2, "strongSwan 2.6.2")
218 DEC_MD5_VID(STRONGSWAN_2_6_1, "strongSwan 2.6.1")
219 DEC_MD5_VID(STRONGSWAN_2_6_0, "strongSwan 2.6.0")
220 DEC_MD5_VID(STRONGSWAN_2_5_7, "strongSwan 2.5.7")
221 DEC_MD5_VID(STRONGSWAN_2_5_6, "strongSwan 2.5.6")
222 DEC_MD5_VID(STRONGSWAN_2_5_5, "strongSwan 2.5.5")
223 DEC_MD5_VID(STRONGSWAN_2_5_4, "strongSwan 2.5.4")
224 DEC_MD5_VID(STRONGSWAN_2_5_3, "strongSwan 2.5.3")
225 DEC_MD5_VID(STRONGSWAN_2_5_2, "strongSwan 2.5.2")
226 DEC_MD5_VID(STRONGSWAN_2_5_1, "strongSwan 2.5.1")
227 DEC_MD5_VID(STRONGSWAN_2_5_0, "strongSwan 2.5.0")
228 DEC_MD5_VID(STRONGSWAN_2_4_4, "strongSwan 2.4.4")
229 DEC_MD5_VID(STRONGSWAN_2_4_3, "strongSwan 2.4.3")
230 DEC_MD5_VID(STRONGSWAN_2_4_2, "strongSwan 2.4.2")
231 DEC_MD5_VID(STRONGSWAN_2_4_1, "strongSwan 2.4.1")
232 DEC_MD5_VID(STRONGSWAN_2_4_0, "strongSwan 2.4.0")
233 DEC_MD5_VID(STRONGSWAN_2_3_2, "strongSwan 2.3.2")
234 DEC_MD5_VID(STRONGSWAN_2_3_1, "strongSwan 2.3.1")
235 DEC_MD5_VID(STRONGSWAN_2_3_0, "strongSwan 2.3.0")
236 DEC_MD5_VID(STRONGSWAN_2_2_2, "strongSwan 2.2.2")
237 DEC_MD5_VID(STRONGSWAN_2_2_1, "strongSwan 2.2.1")
238 DEC_MD5_VID(STRONGSWAN_2_2_0, "strongSwan 2.2.0")
239
240 /* NAT-Traversal */
241
242 DEC_MD5_VID(NATT_STENBERG_01, "draft-stenberg-ipsec-nat-traversal-01")
243 DEC_MD5_VID(NATT_STENBERG_02, "draft-stenberg-ipsec-nat-traversal-02")
244 DEC_MD5_VID(NATT_HUTTUNEN, "ESPThruNAT")
245 DEC_MD5_VID(NATT_HUTTUNEN_ESPINUDP, "draft-huttunen-ipsec-esp-in-udp-00.txt")
246 DEC_MD5_VID(NATT_IETF_00, "draft-ietf-ipsec-nat-t-ike-00")
247 DEC_MD5_VID(NATT_IETF_02, "draft-ietf-ipsec-nat-t-ike-02")
248 /* hash in draft-ietf-ipsec-nat-t-ike-02 contains '\n'... Accept both */
249 DEC_MD5_VID_D(NATT_IETF_02_N, "draft-ietf-ipsec-nat-t-ike-02\n", "draft-ietf-ipsec-nat-t-ike-02_n")
250 DEC_MD5_VID(NATT_IETF_03, "draft-ietf-ipsec-nat-t-ike-03")
251 DEC_MD5_VID(NATT_RFC, "RFC 3947")
252
253 /* misc */
254
255 { VID_MISC_XAUTH, VID_KEEP, NULL, "XAUTH",
256 "\x09\x00\x26\x89\xdf\xd6\xb7\x12", 8 },
257
258 { VID_MISC_DPD, VID_KEEP, NULL, "Dead Peer Detection",
259 "\xaf\xca\xd7\x13\x68\xa1\xf1\xc9\x6b\x86\x96\xfc\x77\x57\x01\x00", 16 },
260
261 DEC_MD5_VID(MISC_FRAGMENTATION, "FRAGMENTATION")
262
263 DEC_MD5_VID(INITIAL_CONTACT, "Vid-Initial-Contact")
264
265 /**
266 * Cisco VPN 3000
267 */
268 { VID_MISC_FRAGMENTATION, VID_MD5HASH | VID_SUBSTRING_DUMPHEXA,
269 "FRAGMENTATION", NULL, NULL, 0 },
270
271 /* -- */
272 { 0, 0, NULL, NULL, NULL, 0 }
273
274 };
275
276 static const char _hexdig[] = "0123456789abcdef";
277
278 static int _vid_struct_init = 0;
279
280 void
281 init_vendorid(void)
282 {
283 struct vid_struct *vid;
284 MD5_CTX ctx;
285 int i;
286
287 for (vid = _vid_tab; vid->id; vid++)
288 {
289 if (vid->flags & VID_STRING)
290 {
291 /** VendorID is a string **/
292 vid->vid = strdup(vid->data);
293 vid->vid_len = strlen(vid->data);
294 }
295 else if (vid->flags & VID_MD5HASH)
296 {
297 /** VendorID is a string to hash with MD5 **/
298 char *vidm = malloc(MD5_DIGEST_SIZE);
299
300 vid->vid = vidm;
301 if (vidm)
302 {
303 MD5Init(&ctx);
304 MD5Update(&ctx, (const u_char *)vid->data, strlen(vid->data));
305 MD5Final(vidm, &ctx);
306 vid->vid_len = MD5_DIGEST_SIZE;
307 }
308 }
309 else if (vid->flags & VID_FSWAN_HASH)
310 {
311 /** FreeS/WAN 2.00+ specific hash **/
312 #define FSWAN_VID_SIZE 12
313 unsigned char hash[MD5_DIGEST_SIZE];
314 char *vidm = malloc(FSWAN_VID_SIZE);
315
316 vid->vid = vidm;
317 if (vidm)
318 {
319 MD5Init(&ctx);
320 MD5Update(&ctx, (const u_char *)vid->data, strlen(vid->data));
321 MD5Final(hash, &ctx);
322 vidm[0] = 'O';
323 vidm[1] = 'E';
324 #if FSWAN_VID_SIZE - 2 <= MD5_DIGEST_SIZE
325 memcpy(vidm + 2, hash, FSWAN_VID_SIZE - 2);
326 #else
327 memcpy(vidm + 2, hash, MD5_DIGEST_SIZE);
328 memset(vidm + 2 + MD5_DIGEST_SIZE, '\0',
329 FSWAN_VID_SIZE - 2 - MD5_DIGEST_SIZE);
330 #endif
331 for (i = 2; i < FSWAN_VID_SIZE; i++)
332 {
333 vidm[i] &= 0x7f;
334 vidm[i] |= 0x40;
335 }
336 vid->vid_len = FSWAN_VID_SIZE;
337 }
338 }
339
340 if (vid->descr == NULL)
341 {
342 /** Find something to display **/
343 vid->descr = vid->data;
344 }
345 }
346 _vid_struct_init = 1;
347 }
348
349 static void
350 handle_known_vendorid (struct msg_digest *md
351 , const char *vidstr, size_t len, struct vid_struct *vid)
352 {
353 char vid_dump[128];
354 bool vid_useful = FALSE;
355 size_t i, j;
356
357 switch (vid->id) {
358 /* Remote side supports OpenPGP certificates */
359 case VID_OPENPGP:
360 md->openpgp = TRUE;
361 vid_useful = TRUE;
362 break;
363
364 /*
365 * Use most recent supported NAT-Traversal method and ignore the
366 * other ones (implementations will send all supported methods but
367 * only one will be used)
368 *
369 * Note: most recent == higher id in vendor.h
370 */
371 case VID_NATT_IETF_00:
372 if (!nat_traversal_support_non_ike)
373 break;
374 if ((nat_traversal_enabled) && (!md->nat_traversal_vid))
375 {
376 md->nat_traversal_vid = vid->id;
377 vid_useful = TRUE;
378 }
379 break;
380 case VID_NATT_IETF_02:
381 case VID_NATT_IETF_02_N:
382 case VID_NATT_IETF_03:
383 case VID_NATT_RFC:
384 if (nat_traversal_support_port_floating
385 && md->nat_traversal_vid < vid->id)
386 {
387 md->nat_traversal_vid = vid->id;
388 vid_useful = TRUE;
389 }
390 break;
391
392 /* Remote side would like to do DPD with us on this connection */
393 case VID_MISC_DPD:
394 md->dpd = TRUE;
395 vid_useful = TRUE;
396 break;
397 default:
398 break;
399 }
400
401 if (vid->flags & VID_SUBSTRING_DUMPHEXA)
402 {
403 /* Dump description + Hexa */
404 memset(vid_dump, 0, sizeof(vid_dump));
405 snprintf(vid_dump, sizeof(vid_dump), "%s ",
406 vid->descr ? vid->descr : "");
407 for (i = strlen(vid_dump), j = vid->vid_len;
408 j < len && i < sizeof(vid_dump) - 2;
409 i += 2, j++)
410 {
411 vid_dump[i] = _hexdig[(vidstr[j] >> 4) & 0xF];
412 vid_dump[i+1] = _hexdig[vidstr[j] & 0xF];
413 }
414 }
415 else if (vid->flags & VID_SUBSTRING_DUMPASCII)
416 {
417 /* Dump ASCII content */
418 memset(vid_dump, 0, sizeof(vid_dump));
419 for (i = 0; i < len && i < sizeof(vid_dump) - 1; i++)
420 {
421 vid_dump[i] = (isprint(vidstr[i])) ? vidstr[i] : '.';
422 }
423 }
424 else
425 {
426 /* Dump description (descr) */
427 snprintf(vid_dump, sizeof(vid_dump), "%s",
428 vid->descr ? vid->descr : "");
429 }
430
431 loglog(RC_LOG_SERIOUS, "%s Vendor ID payload [%s]",
432 vid_useful ? "received" : "ignoring", vid_dump);
433 }
434
435 void
436 handle_vendorid (struct msg_digest *md, const char *vid, size_t len)
437 {
438 struct vid_struct *pvid;
439
440 if (!_vid_struct_init)
441 init_vendorid();
442
443 /*
444 * Find known VendorID in _vid_tab
445 */
446 for (pvid = _vid_tab; pvid->id; pvid++)
447 {
448 if (pvid->vid && vid && pvid->vid_len && len)
449 {
450 if (pvid->vid_len == len)
451 {
452 if (memcmp(pvid->vid, vid, len) == 0)
453 {
454 handle_known_vendorid(md, vid, len, pvid);
455 return;
456 }
457 }
458 else if ((pvid->vid_len < len) && (pvid->flags & VID_SUBSTRING))
459 {
460 if (memcmp(pvid->vid, vid, pvid->vid_len) == 0)
461 {
462 handle_known_vendorid(md, vid, len, pvid);
463 return;
464 }
465 }
466 }
467 }
468
469 /*
470 * Unknown VendorID. Log the beginning.
471 */
472 {
473 char log_vid[2*MAX_LOG_VID_LEN+1];
474 size_t i;
475
476 memset(log_vid, 0, sizeof(log_vid));
477
478 for (i = 0; i < len && i < MAX_LOG_VID_LEN; i++)
479 {
480 log_vid[2*i] = _hexdig[(vid[i] >> 4) & 0xF];
481 log_vid[2*i+1] = _hexdig[vid[i] & 0xF];
482 }
483 loglog(RC_LOG_SERIOUS, "ignoring Vendor ID payload [%s%s]",
484 log_vid, (len>MAX_LOG_VID_LEN) ? "..." : "");
485 }
486 }
487
488 /**
489 * Add a vendor id payload to the msg
490 */
491 bool
492 out_vendorid (u_int8_t np, pb_stream *outs, enum known_vendorid vid)
493 {
494 struct vid_struct *pvid;
495
496 if (!_vid_struct_init)
497 init_vendorid();
498
499 for (pvid = _vid_tab; pvid->id && pvid->id != vid; pvid++);
500
501 if (pvid->id != vid)
502 return STF_INTERNAL_ERROR; /* not found */
503 if (!pvid->vid)
504 return STF_INTERNAL_ERROR; /* not initialized */
505
506 DBG(DBG_EMITTING,
507 DBG_log("out_vendorid(): sending [%s]", pvid->descr)
508 )
509 return out_generic_raw(np, &isakmp_vendor_id_desc, outs,
510 pvid->vid, pvid->vid_len, "V_ID");
511 }
512