]>
Commit | Line | Data |
---|---|---|
ac2f15b3 | 1 | /* $KAME: dnssec.c,v 1.2 2001/08/05 18:46:07 itojun Exp $ */ |
7ba0088d A |
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 | #include <stdlib.h> | |
35 | #include <string.h> | |
36 | ||
37 | #include "var.h" | |
38 | #include "vmbuf.h" | |
39 | #include "misc.h" | |
40 | #include "plog.h" | |
41 | #include "debug.h" | |
42 | ||
43 | #include "isakmp_var.h" | |
44 | #include "isakmp.h" | |
45 | #include "ipsec_doi.h" | |
46 | #include "oakley.h" | |
47 | #include "netdb_dnssec.h" | |
48 | #include "strnames.h" | |
49 | #include "dnssec.h" | |
50 | #include "gcmalloc.h" | |
51 | ||
52 | extern int h_errno; | |
53 | ||
54 | cert_t * | |
55 | dnssec_getcert(id) | |
56 | vchar_t *id; | |
57 | { | |
58 | cert_t *cert = NULL; | |
59 | struct certinfo *res = NULL; | |
60 | struct ipsecdoi_id_b *id_b; | |
61 | int type; | |
62 | char *name = NULL; | |
63 | int namelen; | |
64 | int error; | |
65 | ||
66 | id_b = (struct ipsecdoi_id_b *)id->v; | |
67 | ||
68 | namelen = id->l - sizeof(*id_b); | |
69 | name = racoon_malloc(namelen + 1); | |
70 | if (!name) { | |
71 | plog(LLV_ERROR, LOCATION, NULL, | |
72 | "failed to get buffer.\n"); | |
73 | return NULL; | |
74 | } | |
75 | memcpy(name, id_b + 1, namelen); | |
76 | name[namelen] = '\0'; | |
77 | ||
78 | switch (id_b->type) { | |
79 | case IPSECDOI_ID_FQDN: | |
80 | error = getcertsbyname(name, &res); | |
81 | if (error != 0) { | |
82 | plog(LLV_ERROR, LOCATION, NULL, | |
83 | "getcertsbyname(\"%s\") failed.\n", name); | |
84 | goto err; | |
85 | } | |
86 | break; | |
87 | case IPSECDOI_ID_IPV4_ADDR: | |
88 | case IPSECDOI_ID_IPV6_ADDR: | |
89 | /* XXX should be processed to query PTR ? */ | |
90 | default: | |
91 | plog(LLV_ERROR, LOCATION, NULL, | |
92 | "inpropper ID type passed %s " | |
93 | "though getcert method is dnssec.\n", | |
94 | s_ipsecdoi_ident(id_b->type)); | |
95 | return NULL; | |
96 | } | |
97 | ||
98 | /* check response */ | |
99 | if (res->ci_next == NULL) { | |
100 | plog(LLV_WARNING, LOCATION, NULL, | |
101 | "not supported multiple CERT RR.\n"); | |
102 | } | |
103 | switch (res->ci_type) { | |
104 | case DNSSEC_TYPE_PKIX: | |
105 | /* XXX is it enough condition to set this type ? */ | |
106 | type = ISAKMP_CERT_X509SIGN; | |
107 | break; | |
108 | default: | |
109 | plog(LLV_ERROR, LOCATION, NULL, | |
110 | "not supported CERT RR type %d.\n", res->ci_type); | |
111 | goto err; | |
112 | } | |
113 | ||
114 | /* create cert holder */ | |
115 | cert = oakley_newcert(); | |
116 | if (cert == NULL) { | |
117 | plog(LLV_ERROR, LOCATION, NULL, | |
118 | "failed to get cert buffer.\n"); | |
119 | goto err; | |
120 | } | |
121 | cert->pl = vmalloc(res->ci_certlen + 1); | |
122 | if (cert->pl == NULL) { | |
123 | plog(LLV_ERROR, LOCATION, NULL, | |
124 | "failed to get cert buffer.\n"); | |
125 | goto err; | |
126 | } | |
127 | memcpy(cert->pl->v + 1, res->ci_cert, res->ci_certlen); | |
128 | cert->pl->v[0] = type; | |
129 | cert->cert.v = cert->pl->v + 1; | |
130 | cert->cert.l = cert->pl->l - 1; | |
131 | ||
132 | plog(LLV_DEBUG, LOCATION, NULL, "created CERT payload:\n"); | |
133 | plogdump(LLV_DEBUG, cert->pl->v, cert->pl->l); | |
134 | ||
135 | end: | |
136 | if (res) | |
137 | freecertinfo(res); | |
138 | ||
139 | return cert; | |
140 | ||
141 | err: | |
142 | if (name) | |
143 | racoon_free(name); | |
144 | if (cert) | |
145 | oakley_delcert(cert); | |
146 | goto end; | |
147 | } |