1 /* $Id: vendorid.c,v 1.6.2.1 2005/01/23 17:16:51 vanhu Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/types.h>
35 #include <sys/param.h>
49 #include "localconf.h"
50 #include "isakmp_var.h"
53 #include "crypto_openssl.h"
55 static struct vendor_id all_vendor_ids[] = {
56 { VENDORID_KAME , "KAME/racoon" },
57 { VENDORID_GSSAPI_LONG, "A GSS-API Authentication Method for IKE" },
58 { VENDORID_GSSAPI , "GSSAPI" },
59 { VENDORID_MS_NT5 , "MS NT5 ISAKMPOAKLEY" },
60 { VENDORID_NATT_00 , "draft-ietf-ipsec-nat-t-ike-00" },
61 { VENDORID_NATT_01 , "draft-ietf-ipsec-nat-t-ike-01" },
62 { VENDORID_NATT_02 , "draft-ietf-ipsec-nat-t-ike-02" },
63 { VENDORID_NATT_02_N , "draft-ietf-ipsec-nat-t-ike-02\n" },
64 { VENDORID_NATT_03 , "draft-ietf-ipsec-nat-t-ike-03" },
65 { VENDORID_NATT_04 , "draft-ietf-ipsec-nat-t-ike-04" },
66 { VENDORID_NATT_05 , "draft-ietf-ipsec-nat-t-ike-05" },
67 { VENDORID_NATT_06 , "draft-ietf-ipsec-nat-t-ike-06" },
68 { VENDORID_NATT_07 , "draft-ietf-ipsec-nat-t-ike-07" },
69 { VENDORID_NATT_08 , "draft-ietf-ipsec-nat-t-ike-08" },
70 { VENDORID_NATT_RFC , "RFC 3947" },
71 { VENDORID_XAUTH , "draft-ietf-ipsra-isakmp-xauth-06.txt" },
72 { VENDORID_UNITY , "CISCO-UNITY" },
73 { VENDORID_FRAG , "FRAGMENTATION" },
74 /* Just a readable string for DPD ... */
75 { VENDORID_DPD , "DPD" },
78 #define NUMVENDORIDS (sizeof(all_vendor_ids)/sizeof(all_vendor_ids[0]))
80 #define DPD_MAJOR_VERSION 0x01
81 #define DPD_MINOR_VERSION 0x00
83 const char vendorid_dpd_hash[] = {
84 0xAF, 0xCA, 0xD7, 0x13,
85 0x68, 0xA1, 0xF1, 0xC9,
86 0x6B, 0x86, 0x96, 0xFC,
87 0x77, 0x57, DPD_MAJOR_VERSION, DPD_MINOR_VERSION
91 static vchar_t *vendorid_fixup(int, vchar_t *t);
93 static struct vendor_id *
94 lookup_vendor_id_by_id (int id)
98 for (i = 0; i < NUMVENDORIDS; i++)
99 if (all_vendor_ids[i].id == id)
100 return &all_vendor_ids[i];
106 vid_string_by_id (int id)
108 struct vendor_id *current;
110 if (id == VENDORID_DPD)
111 return vendorid_dpd_hash;
113 current = lookup_vendor_id_by_id(id);
115 return current ? current->string : NULL;
118 static struct vendor_id *
119 lookup_vendor_id_by_hash (const char *hash)
122 unsigned char *h = (unsigned char *)hash;
124 for (i = 0; i < NUMVENDORIDS; i++)
125 if (strncmp(all_vendor_ids[i].hash->v, hash,
126 all_vendor_ids[i].hash->l) == 0)
127 return &all_vendor_ids[i];
133 compute_vendorids (void)
138 for (i = 0; i < NUMVENDORIDS; i++) {
139 /* VENDORID_DPD is not a MD5 sum... */
140 if(i == VENDORID_DPD){
141 all_vendor_ids[i].hash = vmalloc(sizeof(vendorid_dpd_hash));
142 if (all_vendor_ids[i].hash == NULL) {
143 plog(LLV_ERROR, LOCATION, NULL,
144 "unable to get memory for VID hash\n");
145 exit(1); /* this really shouldn't happen */
147 memcpy(all_vendor_ids[i].hash->v, vendorid_dpd_hash,
148 sizeof(vendorid_dpd_hash));
152 vid.v = (char *) all_vendor_ids[i].string;
153 vid.l = strlen(vid.v);
155 all_vendor_ids[i].hash = eay_md5_one(&vid);
156 if (all_vendor_ids[i].hash == NULL)
157 plog(LLV_ERROR, LOCATION, NULL,
158 "unable to hash vendor ID string\n");
161 all_vendor_ids[i].hash =
162 vendorid_fixup(all_vendor_ids[i].id,
163 all_vendor_ids[i].hash);
168 * set hashed vendor id.
169 * hash function is always MD5.
172 set_vendorid(int vendorid)
174 struct vendor_id *current;
177 if (vendorid == VENDORID_UNKNOWN) {
179 * The default unknown ID gets translated to
182 vendorid = VENDORID_KAME;
185 current = lookup_vendor_id_by_id(vendorid);
186 if (current == NULL) {
187 plog(LLV_ERROR, LOCATION, NULL,
188 "invalid vendor ID index: %d\n", vendorid);
192 /* The rest of racoon expects a private copy
193 * of the VID that could be free'd after use.
194 * That's why we don't return the original pointer. */
195 return vdup(current->hash);
199 * Check the vendor ID payload -- return the vendor ID index
200 * if we find a recognized one, or UNKNOWN if we don't.
202 * gen ... points to Vendor ID payload.
205 check_vendorid(struct isakmp_gen *gen)
207 vchar_t vid, *vidhash;
209 struct vendor_id *current;
212 return (VENDORID_UNKNOWN);
214 vidlen = ntohs(gen->len) - sizeof(*gen);
216 current = lookup_vendor_id_by_hash((char *)(gen + 1));
220 if (current->hash->l < vidlen)
221 plog(LLV_INFO, LOCATION, NULL,
222 "received broken Microsoft ID: %s\n",
225 plog(LLV_INFO, LOCATION, NULL,
226 "received Vendor ID: %s\n",
232 plog(LLV_DEBUG, LOCATION, NULL, "received unknown Vendor ID\n");
233 return (VENDORID_UNKNOWN);
237 vendorid_fixup(vendorid, vidhash)
242 case VENDORID_XAUTH: { /* The vendor Id is truncated */
245 if ((tmp = vmalloc(8)) == NULL) {
246 plog(LLV_ERROR, LOCATION, NULL,
247 "unable to hash vendor ID string\n");
251 memcpy(tmp->v, vidhash->v, 8);
257 case VENDORID_UNITY: /* Two bytes tweak */
258 vidhash->v[14] = 0x01;
259 vidhash->v[15] = 0x00;