]> git.saurik.com Git - apple/network_cmds.git/blob - racoon.tproj/vendorid.c
7c57233342c2599dc9f2265ad46da43dd896e0b7
[apple/network_cmds.git] / racoon.tproj / vendorid.c
1 /* $KAME: vendorid.c,v 1.8 2001/03/27 02:39:57 thorpej Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
18 *
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
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <ctype.h>
40
41 #include "var.h"
42 #include "misc.h"
43 #include "vmbuf.h"
44 #include "plog.h"
45 #include "debug.h"
46
47 #include "localconf.h"
48 #include "isakmp_var.h"
49 #include "isakmp.h"
50 #include "vendorid.h"
51 #include "crypto_openssl.h"
52
53 const char *vendorid_strings[] = VENDORID_STRINGS;
54
55 /*
56 * set hashed vendor id.
57 * hash function is always MD5.
58 */
59 vchar_t *
60 set_vendorid(int vendorid)
61 {
62 vchar_t vid, *vidhash;
63
64 if (vendorid == VENDORID_UNKNOWN) {
65 /*
66 * The default unknown ID gets translated to
67 * KAME/racoon.
68 */
69 vendorid = VENDORID_KAME;
70 }
71
72 if (vendorid < 0 || vendorid >= NUMVENDORIDS) {
73 plog(LLV_ERROR, LOCATION, NULL,
74 "invalid vendor ID index: %d\n", vendorid);
75 return (NULL);
76 }
77
78 /* XXX Cast away const. */
79 vid.v = (char *) vendorid_strings[vendorid];
80 vid.l = strlen(vendorid_strings[vendorid]);
81
82 vidhash = eay_md5_one(&vid);
83 if (vidhash == NULL)
84 plog(LLV_ERROR, LOCATION, NULL,
85 "unable to hash vendor ID string\n");
86
87 return vidhash;
88 }
89
90 /*
91 * Check the vendor ID payload -- return the vendor ID index
92 * if we find a recognized one, or UNKNOWN if we don't.
93 */
94 int
95 check_vendorid(gen)
96 struct isakmp_gen *gen; /* points to Vendor ID payload */
97 {
98 vchar_t vid, *vidhash;
99 int i, vidlen;
100
101 if (gen == NULL)
102 return (VENDORID_UNKNOWN);
103
104 vidlen = ntohs(gen->len) - sizeof(*gen);
105
106 for (i = 0; i < NUMVENDORIDS; i++) {
107 /* XXX Cast away const. */
108 vid.v = (char *) vendorid_strings[i];
109 vid.l = strlen(vendorid_strings[i]);
110
111 vidhash = eay_md5_one(&vid);
112 if (vidhash == NULL) {
113 plog(LLV_ERROR, LOCATION, NULL,
114 "unable to hash vendor ID string\n");
115 return (VENDORID_UNKNOWN);
116 }
117
118 /*
119 * XXX THIS IS NOT QUITE RIGHT!
120 *
121 * But we need to be able to recognize
122 * Windows 2000's ID, which is the MD5
123 * has of a known string + 4 bytes of
124 * what appears to be version info.
125 */
126 if (vidhash->l <= vidlen &&
127 memcmp(vidhash->v, gen + 1, vidhash->l) == 0) {
128 plog(LLV_INFO, LOCATION, NULL,
129 "received Vendor ID: %s\n",
130 vendorid_strings[i]);
131 vfree(vidhash);
132 return (i);
133 }
134 vfree(vidhash);
135 }
136
137 plog(LLV_DEBUG, LOCATION, NULL, "received unknown Vendor ID\n");
138 return (VENDORID_UNKNOWN);
139 }