]>
git.saurik.com Git - apple/network_cmds.git/blob - racoon.tproj/vendorid.c
1 /* $KAME: vendorid.c,v 1.7 2000/12/15 13:43:57 sakane 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
32 #include <sys/types.h>
33 #include <sys/param.h>
47 #include "localconf.h"
48 #include "isakmp_var.h"
51 #include "crypto_openssl.h"
53 const char *vendorid_strings
[] = VENDORID_STRINGS
;
56 * set hashed vendor id.
57 * hash function is always MD5.
60 set_vendorid(int vendorid
)
62 vchar_t vid
, *vidhash
;
64 if (vendorid
== VENDORID_UNKNOWN
) {
66 * The default unknown ID gets translated to
69 vendorid
= VENDORID_KAME
;
72 if (vendorid
< 0 || vendorid
>= NUMVENDORIDS
) {
73 plog(LLV_ERROR
, LOCATION
, NULL
,
74 "invalid vendor ID index: %d\n", vendorid
);
78 /* XXX Cast away const. */
79 vid
.v
= (char *) vendorid_strings
[vendorid
];
80 vid
.l
= strlen(vendorid_strings
[vendorid
]);
82 vidhash
= eay_md5_one(&vid
);
84 plog(LLV_ERROR
, LOCATION
, NULL
,
85 "unable to hash vendor ID string\n");
91 * Check the vendor ID payload -- return the vendor ID index
92 * if we find a recognized one, or UNKNOWN if we don't.
96 struct isakmp_gen
*gen
; /* points to Vendor ID payload */
98 vchar_t vid
, *vidhash
;
102 return (VENDORID_UNKNOWN
);
104 vidlen
= ntohs(gen
->len
) - sizeof(*gen
);
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
]);
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
);
119 * XXX THIS IS NOT QUITE RIGHT!
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.
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
]);
137 plog(LLV_DEBUG
, LOCATION
, NULL
, "received unknown Vendor ID\n");
138 return (VENDORID_UNKNOWN
);