SKEYID derivation based on libstrongswan
[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
15 #include <stdlib.h>
16 #include <string.h>
17 #include <ctype.h>
18 #include <sys/queue.h>
19 #include <freeswan.h>
20
21 #include <library.h>
22 #include <crypto/hashers/hasher.h>
23
24 #include "constants.h"
25 #include "defs.h"
26 #include "log.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 chunk_t vid;
96 };
97
98 #define DEC_MD5_VID_D(id,str,descr) \
99 { VID_##id, VID_MD5HASH, str, descr, { NULL, 0 } },
100 #define DEC_MD5_VID(id,str) \
101 { VID_##id, VID_MD5HASH, str, NULL, { NULL, 0 } },
102
103 static struct vid_struct _vid_tab[] = {
104
105 /* Implementation names */
106
107 { VID_OPENPGP, VID_STRING, "OpenPGP10171", "OpenPGP", { NULL, 0 } },
108
109 DEC_MD5_VID(KAME_RACOON, "KAME/racoon")
110
111 { VID_MS_NT5, VID_MD5HASH | VID_SUBSTRING_DUMPHEXA,
112 "MS NT5 ISAKMPOAKLEY", NULL, { NULL, 0 } },
113
114 DEC_MD5_VID(SSH_SENTINEL, "SSH Sentinel")
115 DEC_MD5_VID(SSH_SENTINEL_1_1, "SSH Sentinel 1.1")
116 DEC_MD5_VID(SSH_SENTINEL_1_2, "SSH Sentinel 1.2")
117 DEC_MD5_VID(SSH_SENTINEL_1_3, "SSH Sentinel 1.3")
118 DEC_MD5_VID(SSH_SENTINEL_1_4, "SSH Sentinel 1.4")
119 DEC_MD5_VID(SSH_SENTINEL_1_4_1, "SSH Sentinel 1.4.1")
120
121 /* These ones come from SSH vendors.txt */
122 DEC_MD5_VID(SSH_IPSEC_1_1_0,
123 "Ssh Communications Security IPSEC Express version 1.1.0")
124 DEC_MD5_VID(SSH_IPSEC_1_1_1,
125 "Ssh Communications Security IPSEC Express version 1.1.1")
126 DEC_MD5_VID(SSH_IPSEC_1_1_2,
127 "Ssh Communications Security IPSEC Express version 1.1.2")
128 DEC_MD5_VID(SSH_IPSEC_1_2_1,
129 "Ssh Communications Security IPSEC Express version 1.2.1")
130 DEC_MD5_VID(SSH_IPSEC_1_2_2,
131 "Ssh Communications Security IPSEC Express version 1.2.2")
132 DEC_MD5_VID(SSH_IPSEC_2_0_0,
133 "SSH Communications Security IPSEC Express version 2.0.0")
134 DEC_MD5_VID(SSH_IPSEC_2_1_0,
135 "SSH Communications Security IPSEC Express version 2.1.0")
136 DEC_MD5_VID(SSH_IPSEC_2_1_1,
137 "SSH Communications Security IPSEC Express version 2.1.1")
138 DEC_MD5_VID(SSH_IPSEC_2_1_2,
139 "SSH Communications Security IPSEC Express version 2.1.2")
140 DEC_MD5_VID(SSH_IPSEC_3_0_0,
141 "SSH Communications Security IPSEC Express version 3.0.0")
142 DEC_MD5_VID(SSH_IPSEC_3_0_1,
143 "SSH Communications Security IPSEC Express version 3.0.1")
144 DEC_MD5_VID(SSH_IPSEC_4_0_0,
145 "SSH Communications Security IPSEC Express version 4.0.0")
146 DEC_MD5_VID(SSH_IPSEC_4_0_1,
147 "SSH Communications Security IPSEC Express version 4.0.1")
148 DEC_MD5_VID(SSH_IPSEC_4_1_0,
149 "SSH Communications Security IPSEC Express version 4.1.0")
150 DEC_MD5_VID(SSH_IPSEC_4_2_0,
151 "SSH Communications Security IPSEC Express version 4.2.0")
152
153 /* note: md5('CISCO-UNITY') = 12f5f28c457168a9702d9fe274cc02d4 */
154 { VID_CISCO_UNITY, VID_KEEP, NULL, "Cisco-Unity",
155 { "\x12\xf5\xf2\x8c\x45\x71\x68\xa9\x70\x2d\x9f\xe2\x74\xcc\x01\x00", 16 } },
156
157 { VID_CISCO3K, VID_KEEP | VID_SUBSTRING_MATCH, NULL, "Cisco VPN 3000 Series" ,
158 { "\x1f\x07\xf7\x0e\xaa\x65\x14\xd3\xb0\xfa\x96\x54\x2a\x50", 14 } },
159
160 { VID_CISCO_IOS, VID_KEEP | VID_SUBSTRING_MATCH,
161 NULL, "Cisco IOS Device", { "\x3e\x98\x40\x48", 4 } },
162
163 /*
164 * Timestep VID seen:
165 * - 54494d455354455020312053475720313532302033313520322e303145303133
166 * = 'TIMESTEP 1 SGW 1520 315 2.01E013'
167 */
168 { VID_TIMESTEP, VID_STRING | VID_SUBSTRING_DUMPASCII, "TIMESTEP",
169 NULL, { NULL, 0 } },
170
171 /*
172 * Netscreen:
173 * 4865617274426561745f4e6f74696679386b0100 (HeartBeat_Notify + 386b0100)
174 */
175 { VID_MISC_HEARTBEAT_NOTIFY, VID_STRING | VID_SUBSTRING_DUMPHEXA,
176 "HeartBeat_Notify", "HeartBeat Notify", { NULL, 0 } },
177 /*
178 * MacOS X
179 */
180 { VID_MACOSX, VID_STRING|VID_SUBSTRING_DUMPHEXA, "Mac OSX 10.x",
181 "\x4d\xf3\x79\x28\xe9\xfc\x4f\xd1\xb3\x26\x21\x70\xd5\x15\xc6\x62", { NULL, 0 } },
182
183 /* NCP */
184 { VID_NCP_SERVER, VID_KEEP | VID_SUBSTRING_MATCH, NULL, "NCP Server",
185 { "\xc6\xf5\x7a\xc3\x98\xf4\x93\x20\x81\x45\xb7\x58", 12 } },
186 { VID_NCP_CLIENT, VID_KEEP | VID_SUBSTRING_MATCH, NULL, "NCP Client",
187 { "\xeb\x4c\x1b\x78\x8a\xfd\x4a\x9c\xb7\x73\x0a\x68", 12 } },
188
189 /*
190 * Windows Vista (and Windows Server 2008?)
191 */
192 DEC_MD5_VID(VISTA_AUTHIP, "MS-Negotiation Discovery Capable")
193 DEC_MD5_VID(VISTA_AUTHIP2, "IKE CGA version 1")
194 DEC_MD5_VID(VISTA_AUTHIP3, "MS-MamieExists")
195
196 /*
197 * strongSwan
198 */
199 DEC_MD5_VID(STRONGSWAN, "strongSwan 4.3.1")
200 DEC_MD5_VID(STRONGSWAN_4_3_0, "strongSwan 4.3.0")
201 DEC_MD5_VID(STRONGSWAN_4_2_14,"strongSwan 4.2.14")
202 DEC_MD5_VID(STRONGSWAN_4_2_13,"strongSwan 4.2.13")
203 DEC_MD5_VID(STRONGSWAN_4_2_12,"strongSwan 4.2.12")
204 DEC_MD5_VID(STRONGSWAN_4_2_11,"strongSwan 4.2.11")
205 DEC_MD5_VID(STRONGSWAN_4_2_10,"strongSwan 4.2.10")
206 DEC_MD5_VID(STRONGSWAN_4_2_9, "strongSwan 4.2.9")
207 DEC_MD5_VID(STRONGSWAN_4_2_8, "strongSwan 4.2.8")
208 DEC_MD5_VID(STRONGSWAN_4_2_7, "strongSwan 4.2.7")
209 DEC_MD5_VID(STRONGSWAN_4_2_6, "strongSwan 4.2.6")
210 DEC_MD5_VID(STRONGSWAN_4_2_5, "strongSwan 4.2.5")
211 DEC_MD5_VID(STRONGSWAN_4_2_4, "strongSwan 4.2.4")
212 DEC_MD5_VID(STRONGSWAN_4_2_3, "strongSwan 4.2.3")
213 DEC_MD5_VID(STRONGSWAN_4_2_2, "strongSwan 4.2.2")
214 DEC_MD5_VID(STRONGSWAN_4_2_1, "strongSwan 4.2.1")
215 DEC_MD5_VID(STRONGSWAN_4_2_0, "strongSwan 4.2.0")
216 DEC_MD5_VID(STRONGSWAN_4_1_11,"strongSwan 4.1.11")
217 DEC_MD5_VID(STRONGSWAN_4_1_10,"strongSwan 4.1.10")
218 DEC_MD5_VID(STRONGSWAN_4_1_9, "strongSwan 4.1.9")
219 DEC_MD5_VID(STRONGSWAN_4_1_8, "strongSwan 4.1.8")
220 DEC_MD5_VID(STRONGSWAN_4_1_7, "strongSwan 4.1.7")
221 DEC_MD5_VID(STRONGSWAN_4_1_6, "strongSwan 4.1.6")
222 DEC_MD5_VID(STRONGSWAN_4_1_5, "strongSwan 4.1.5")
223 DEC_MD5_VID(STRONGSWAN_4_1_4, "strongSwan 4.1.4")
224 DEC_MD5_VID(STRONGSWAN_4_1_3, "strongSwan 4.1.3")
225 DEC_MD5_VID(STRONGSWAN_4_1_2, "strongSwan 4.1.2")
226 DEC_MD5_VID(STRONGSWAN_4_1_1, "strongSwan 4.1.1")
227 DEC_MD5_VID(STRONGSWAN_4_1_0, "strongSwan 4.1.0")
228 DEC_MD5_VID(STRONGSWAN_4_0_7, "strongSwan 4.0.7")
229 DEC_MD5_VID(STRONGSWAN_4_0_6, "strongSwan 4.0.6")
230 DEC_MD5_VID(STRONGSWAN_4_0_5, "strongSwan 4.0.5")
231 DEC_MD5_VID(STRONGSWAN_4_0_4, "strongSwan 4.0.4")
232 DEC_MD5_VID(STRONGSWAN_4_0_3, "strongSwan 4.0.3")
233 DEC_MD5_VID(STRONGSWAN_4_0_2, "strongSwan 4.0.2")
234 DEC_MD5_VID(STRONGSWAN_4_0_1, "strongSwan 4.0.1")
235 DEC_MD5_VID(STRONGSWAN_4_0_0, "strongSwan 4.0.0")
236
237 DEC_MD5_VID(STRONGSWAN_2_8_9, "strongSwan 2.8.9")
238 DEC_MD5_VID(STRONGSWAN_2_8_8, "strongSwan 2.8.8")
239 DEC_MD5_VID(STRONGSWAN_2_8_7, "strongSwan 2.8.7")
240 DEC_MD5_VID(STRONGSWAN_2_8_6, "strongSwan 2.8.6")
241 DEC_MD5_VID(STRONGSWAN_2_8_5, "strongSwan 2.8.5")
242 DEC_MD5_VID(STRONGSWAN_2_8_4, "strongSwan 2.8.4")
243 DEC_MD5_VID(STRONGSWAN_2_8_3, "strongSwan 2.8.3")
244 DEC_MD5_VID(STRONGSWAN_2_8_2, "strongSwan 2.8.2")
245 DEC_MD5_VID(STRONGSWAN_2_8_1, "strongSwan 2.8.1")
246 DEC_MD5_VID(STRONGSWAN_2_8_0, "strongSwan 2.8.0")
247 DEC_MD5_VID(STRONGSWAN_2_7_3, "strongSwan 2.7.3")
248 DEC_MD5_VID(STRONGSWAN_2_7_2, "strongSwan 2.7.2")
249 DEC_MD5_VID(STRONGSWAN_2_7_1, "strongSwan 2.7.1")
250 DEC_MD5_VID(STRONGSWAN_2_7_0, "strongSwan 2.7.0")
251 DEC_MD5_VID(STRONGSWAN_2_6_4, "strongSwan 2.6.4")
252 DEC_MD5_VID(STRONGSWAN_2_6_3, "strongSwan 2.6.3")
253 DEC_MD5_VID(STRONGSWAN_2_6_2, "strongSwan 2.6.2")
254 DEC_MD5_VID(STRONGSWAN_2_6_1, "strongSwan 2.6.1")
255 DEC_MD5_VID(STRONGSWAN_2_6_0, "strongSwan 2.6.0")
256 DEC_MD5_VID(STRONGSWAN_2_5_7, "strongSwan 2.5.7")
257 DEC_MD5_VID(STRONGSWAN_2_5_6, "strongSwan 2.5.6")
258 DEC_MD5_VID(STRONGSWAN_2_5_5, "strongSwan 2.5.5")
259 DEC_MD5_VID(STRONGSWAN_2_5_4, "strongSwan 2.5.4")
260 DEC_MD5_VID(STRONGSWAN_2_5_3, "strongSwan 2.5.3")
261 DEC_MD5_VID(STRONGSWAN_2_5_2, "strongSwan 2.5.2")
262 DEC_MD5_VID(STRONGSWAN_2_5_1, "strongSwan 2.5.1")
263 DEC_MD5_VID(STRONGSWAN_2_5_0, "strongSwan 2.5.0")
264 DEC_MD5_VID(STRONGSWAN_2_4_4, "strongSwan 2.4.4")
265 DEC_MD5_VID(STRONGSWAN_2_4_3, "strongSwan 2.4.3")
266 DEC_MD5_VID(STRONGSWAN_2_4_2, "strongSwan 2.4.2")
267 DEC_MD5_VID(STRONGSWAN_2_4_1, "strongSwan 2.4.1")
268 DEC_MD5_VID(STRONGSWAN_2_4_0, "strongSwan 2.4.0")
269 DEC_MD5_VID(STRONGSWAN_2_3_2, "strongSwan 2.3.2")
270 DEC_MD5_VID(STRONGSWAN_2_3_1, "strongSwan 2.3.1")
271 DEC_MD5_VID(STRONGSWAN_2_3_0, "strongSwan 2.3.0")
272 DEC_MD5_VID(STRONGSWAN_2_2_2, "strongSwan 2.2.2")
273 DEC_MD5_VID(STRONGSWAN_2_2_1, "strongSwan 2.2.1")
274 DEC_MD5_VID(STRONGSWAN_2_2_0, "strongSwan 2.2.0")
275
276 /* NAT-Traversal */
277
278 DEC_MD5_VID(NATT_STENBERG_01, "draft-stenberg-ipsec-nat-traversal-01")
279 DEC_MD5_VID(NATT_STENBERG_02, "draft-stenberg-ipsec-nat-traversal-02")
280 DEC_MD5_VID(NATT_HUTTUNEN, "ESPThruNAT")
281 DEC_MD5_VID(NATT_HUTTUNEN_ESPINUDP, "draft-huttunen-ipsec-esp-in-udp-00.txt")
282 DEC_MD5_VID(NATT_IETF_00, "draft-ietf-ipsec-nat-t-ike-00")
283 DEC_MD5_VID(NATT_IETF_02, "draft-ietf-ipsec-nat-t-ike-02")
284 /* hash in draft-ietf-ipsec-nat-t-ike-02 contains '\n'... Accept both */
285 DEC_MD5_VID_D(NATT_IETF_02_N, "draft-ietf-ipsec-nat-t-ike-02\n", "draft-ietf-ipsec-nat-t-ike-02_n")
286 DEC_MD5_VID(NATT_IETF_03, "draft-ietf-ipsec-nat-t-ike-03")
287 DEC_MD5_VID(NATT_RFC, "RFC 3947")
288
289 /* misc */
290
291 { VID_MISC_XAUTH, VID_KEEP, NULL, "XAUTH",
292 { "\x09\x00\x26\x89\xdf\xd6\xb7\x12", 8 } },
293
294 { VID_MISC_DPD, VID_KEEP, NULL, "Dead Peer Detection",
295 { "\xaf\xca\xd7\x13\x68\xa1\xf1\xc9\x6b\x86\x96\xfc\x77\x57\x01\x00", 16 } },
296
297 DEC_MD5_VID(MISC_FRAGMENTATION, "FRAGMENTATION")
298
299 DEC_MD5_VID(INITIAL_CONTACT, "Vid-Initial-Contact")
300
301 /**
302 * Cisco VPN 3000
303 */
304 { VID_MISC_FRAGMENTATION, VID_MD5HASH | VID_SUBSTRING_DUMPHEXA,
305 "FRAGMENTATION", NULL, { NULL, 0 } },
306
307 /* -- */
308 { 0, 0, NULL, NULL, { NULL, 0 } }
309
310 };
311
312 static const char _hexdig[] = "0123456789abcdef";
313
314 static int _vid_struct_init = 0;
315
316 void init_vendorid(void)
317 {
318 hasher_t *hasher = lib->crypto->create_hasher(lib->crypto, HASH_MD5);
319 struct vid_struct *vid;
320
321 for (vid = _vid_tab; vid->id; vid++)
322 {
323 if (vid->flags & VID_STRING)
324 {
325 /** VendorID is a string **/
326 vid->vid = chunk_create((u_char *)vid->data, strlen(vid->data));
327 vid->vid = chunk_clone(vid->vid);
328 }
329 else if (vid->flags & VID_MD5HASH)
330 {
331 chunk_t vid_data = { (u_char *)vid->data, strlen(vid->data) };
332
333 /** VendorID is a string to hash with MD5 **/
334 hasher->allocate_hash(hasher, vid_data, &vid->vid);
335 }
336
337 if (vid->descr == NULL)
338 {
339 /** Find something to display **/
340 vid->descr = vid->data;
341 }
342 }
343 hasher->destroy(hasher);
344 _vid_struct_init = 1;
345 }
346
347 void free_vendorid(void)
348 {
349 struct vid_struct *vid;
350
351 for (vid = _vid_tab; vid->id; vid++)
352 {
353 if (vid->flags & (VID_STRING | VID_MD5HASH | VID_FSWAN_HASH))
354 {
355 free(vid->vid.ptr);
356 }
357 }
358 }
359
360 static void handle_known_vendorid (struct msg_digest *md, const char *vidstr,
361 size_t len, struct vid_struct *vid)
362 {
363 char vid_dump[128];
364 bool vid_useful = FALSE;
365 size_t i, j;
366
367 switch (vid->id) {
368 /* Remote side supports OpenPGP certificates */
369 case VID_OPENPGP:
370 md->openpgp = TRUE;
371 vid_useful = TRUE;
372 break;
373
374 /*
375 * Use most recent supported NAT-Traversal method and ignore the
376 * other ones (implementations will send all supported methods but
377 * only one will be used)
378 *
379 * Note: most recent == higher id in vendor.h
380 */
381 case VID_NATT_IETF_00:
382 if (!nat_traversal_support_non_ike)
383 break;
384 if ((nat_traversal_enabled) && (!md->nat_traversal_vid))
385 {
386 md->nat_traversal_vid = vid->id;
387 vid_useful = TRUE;
388 }
389 break;
390 case VID_NATT_IETF_02:
391 case VID_NATT_IETF_02_N:
392 case VID_NATT_IETF_03:
393 case VID_NATT_RFC:
394 if (nat_traversal_support_port_floating
395 && md->nat_traversal_vid < vid->id)
396 {
397 md->nat_traversal_vid = vid->id;
398 vid_useful = TRUE;
399 }
400 break;
401
402 /* Remote side would like to do DPD with us on this connection */
403 case VID_MISC_DPD:
404 md->dpd = TRUE;
405 vid_useful = TRUE;
406 break;
407 case VID_MISC_XAUTH:
408 vid_useful = TRUE;
409 break;
410 default:
411 break;
412 }
413
414 if (vid->flags & VID_SUBSTRING_DUMPHEXA)
415 {
416 /* Dump description + Hexa */
417 memset(vid_dump, 0, sizeof(vid_dump));
418 snprintf(vid_dump, sizeof(vid_dump), "%s ",
419 vid->descr ? vid->descr : "");
420 for (i = strlen(vid_dump), j = vid->vid.len;
421 j < len && i < sizeof(vid_dump) - 2;
422 i += 2, j++)
423 {
424 vid_dump[i] = _hexdig[(vidstr[j] >> 4) & 0xF];
425 vid_dump[i+1] = _hexdig[vidstr[j] & 0xF];
426 }
427 }
428 else if (vid->flags & VID_SUBSTRING_DUMPASCII)
429 {
430 /* Dump ASCII content */
431 memset(vid_dump, 0, sizeof(vid_dump));
432 for (i = 0; i < len && i < sizeof(vid_dump) - 1; i++)
433 {
434 vid_dump[i] = (isprint(vidstr[i])) ? vidstr[i] : '.';
435 }
436 }
437 else
438 {
439 /* Dump description (descr) */
440 snprintf(vid_dump, sizeof(vid_dump), "%s",
441 vid->descr ? vid->descr : "");
442 }
443
444 loglog(RC_LOG_SERIOUS, "%s Vendor ID payload [%s]",
445 vid_useful ? "received" : "ignoring", vid_dump);
446 }
447
448 void handle_vendorid (struct msg_digest *md, const char *vid, size_t len)
449 {
450 struct vid_struct *pvid;
451
452 if (!_vid_struct_init)
453 init_vendorid();
454
455 /*
456 * Find known VendorID in _vid_tab
457 */
458 for (pvid = _vid_tab; pvid->id; pvid++)
459 {
460 if (pvid->vid.ptr && vid && pvid->vid.len && len)
461 {
462 if (pvid->vid.len == len)
463 {
464 if (memeq(pvid->vid.ptr, vid, len))
465 {
466 handle_known_vendorid(md, vid, len, pvid);
467 return;
468 }
469 }
470 else if ((pvid->vid.len < len) && (pvid->flags & VID_SUBSTRING))
471 {
472 if (memeq(pvid->vid.ptr, vid, pvid->vid.len))
473 {
474 handle_known_vendorid(md, vid, len, pvid);
475 return;
476 }
477 }
478 }
479 }
480
481 /*
482 * Unknown VendorID. Log the beginning.
483 */
484 {
485 char log_vid[2*MAX_LOG_VID_LEN+1];
486 size_t i;
487
488 memset(log_vid, 0, sizeof(log_vid));
489
490 for (i = 0; i < len && i < MAX_LOG_VID_LEN; i++)
491 {
492 log_vid[2*i] = _hexdig[(vid[i] >> 4) & 0xF];
493 log_vid[2*i+1] = _hexdig[vid[i] & 0xF];
494 }
495 loglog(RC_LOG_SERIOUS, "ignoring Vendor ID payload [%s%s]",
496 log_vid, (len>MAX_LOG_VID_LEN) ? "..." : "");
497 }
498 }
499
500 /**
501 * Add a vendor id payload to the msg
502 */
503 bool out_vendorid (u_int8_t np, pb_stream *outs, enum known_vendorid vid)
504 {
505 struct vid_struct *pvid;
506
507 if (!_vid_struct_init)
508 init_vendorid();
509
510 for (pvid = _vid_tab; pvid->id && pvid->id != vid; pvid++);
511
512 if (pvid->id != vid)
513 return STF_INTERNAL_ERROR; /* not found */
514 if (!pvid->vid.ptr)
515 return STF_INTERNAL_ERROR; /* not initialized */
516
517 DBG(DBG_EMITTING,
518 DBG_log("out_vendorid(): sending [%s]", pvid->descr)
519 )
520 return out_generic_raw(np, &isakmp_vendor_id_desc, outs,
521 pvid->vid.ptr, pvid->vid.len, "V_ID");
522 }
523