1 /* $KAME: dnssec.c,v 1.2 2001/08/05 18:46:07 itojun 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>
45 #include "isakmp_var.h"
47 #include "ipsec_doi.h"
49 #include "netdb_dnssec.h"
61 struct certinfo *res = NULL;
62 struct ipsecdoi_id_b *id_b;
68 id_b = (struct ipsecdoi_id_b *)id->v;
70 namelen = id->l - sizeof(*id_b);
71 name = racoon_malloc(namelen + 1);
73 plog(LLV_ERROR, LOCATION, NULL,
74 "failed to get buffer.\n");
77 memcpy(name, id_b + 1, namelen);
81 case IPSECDOI_ID_FQDN:
82 error = getcertsbyname(name, &res);
84 plog(LLV_ERROR, LOCATION, NULL,
85 "getcertsbyname(\"%s\") failed.\n", name);
89 case IPSECDOI_ID_IPV4_ADDR:
90 case IPSECDOI_ID_IPV6_ADDR:
91 /* XXX should be processed to query PTR ? */
93 plog(LLV_ERROR, LOCATION, NULL,
94 "inpropper ID type passed %s "
95 "though getcert method is dnssec.\n",
96 s_ipsecdoi_ident(id_b->type));
101 if (res->ci_next == NULL) {
102 plog(LLV_WARNING, LOCATION, NULL,
103 "not supported multiple CERT RR.\n");
105 switch (res->ci_type) {
106 case DNSSEC_TYPE_PKIX:
107 /* XXX is it enough condition to set this type ? */
108 type = ISAKMP_CERT_X509SIGN;
111 plog(LLV_ERROR, LOCATION, NULL,
112 "not supported CERT RR type %d.\n", res->ci_type);
116 /* create cert holder */
117 cert = oakley_newcert();
119 plog(LLV_ERROR, LOCATION, NULL,
120 "failed to get cert buffer.\n");
123 cert->pl = vmalloc(res->ci_certlen + 1);
124 if (cert->pl == NULL) {
125 plog(LLV_ERROR, LOCATION, NULL,
126 "failed to get cert buffer.\n");
129 memcpy(cert->pl->v + 1, res->ci_cert, res->ci_certlen);
130 cert->pl->v[0] = type;
131 cert->cert.v = cert->pl->v + 1;
132 cert->cert.l = cert->pl->l - 1;
134 plog(LLV_DEBUG, LOCATION, NULL, "created CERT payload:\n");
135 plogdump(LLV_DEBUG, cert->pl->v, cert->pl->l);
147 oakley_delcert(cert);