dst_api.c revision 5c40acf2156bbc258fc290f38cf8d5e12d085bed
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff * Portions Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Portions Copyright (C) 1999-2003 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and/or distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Portions Copyright (C) 1995-2000 by Network Associates, Inc.
3761c433912beabe43abeed2c3513b6201c59f64Mark Andrews * Permission to use, copy, modify, and/or distribute this software for any
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews * purpose with or without fee is hereby granted, provided that the above
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews * copyright notice and this permission notice appear in all copies.
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Principal Author: Brian Wellington
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews * $Id: dst_api.c,v 1.50 2010/05/12 23:49:40 marka Exp $
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define DST_AS_STR(t) ((t).value.as_textregion.base)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic unsigned int dst_entropy_flags = 0;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrewsstatic isc_boolean_t dst_initialized = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsvoid gss_log(int level, const char *fmt, ...) ISC_FORMAT_PRINTF(2, 3);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Static functions.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic dst_key_t * get_key_struct(dns_name_t *name,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int alg,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int flags,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int protocol,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int bits,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t write_public_key(const dst_key_t *key, int type,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t buildfilename(dns_name_t *name,
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews unsigned int alg,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int type,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonstatic isc_result_t computeid(dst_key_t *key);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t frombuffer(dns_name_t *name,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int alg,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int flags,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonstatic isc_result_t algorithm_status(unsigned int alg);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonstatic isc_result_t addsuffix(char *filename, int len,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson const char *dirname, const char *ofilename,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson } while (0); \
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void *
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrewsdst_lib_init(isc_mem_t *mctx, isc_entropy_t *ectx, unsigned int eflags) {
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews return (dst_lib_init2(mctx, ectx, NULL, eflags));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdst_lib_init2(isc_mem_t *mctx, isc_entropy_t *ectx,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * When using --with-openssl, there seems to be no good way of not
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * leaking memory due to the openssl error handling mechanism.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Avoid assertions by using a local memory context and not checking
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * for leaks on exit. Note: as there are leaks we cannot use
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ISC_MEMFLAG_INTERNAL as it will free up memory still being used
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * by libcrypto.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews isc_mem_setname(dst__memory_pool, "dst", NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_mem_setdestroycheck(dst__memory_pool, ISC_FALSE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__hmacmd5_init(&dst_t_func[DST_ALG_HMACMD5]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__hmacsha1_init(&dst_t_func[DST_ALG_HMACSHA1]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__hmacsha224_init(&dst_t_func[DST_ALG_HMACSHA224]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__hmacsha256_init(&dst_t_func[DST_ALG_HMACSHA256]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__hmacsha384_init(&dst_t_func[DST_ALG_HMACSHA384]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__hmacsha512_init(&dst_t_func[DST_ALG_HMACSHA512]));
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSAMD5],
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA1],
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_NSEC3RSASHA1],
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA256],
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA512],
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__openssldsa_init(&dst_t_func[DST_ALG_DSA]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__openssldsa_init(&dst_t_func[DST_ALG_NSEC3DSA]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__openssldh_init(&dst_t_func[DST_ALG_DH]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#endif /* OPENSSL */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dst__gssapi_init(&dst_t_func[DST_ALG_GSSAPI]));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /* avoid immediate crash! */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (i = 0; i < DST_MAX_ALGS; i++)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (dst_t_func[i] != NULL && dst_t_func[i]->cleanup != NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (alg >= DST_MAX_ALGS || dst_t_func[alg] == NULL)
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewsdst_context_create(dst_key_t *key, isc_mem_t *mctx, dst_context_t **dctxp) {
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dctx = isc_mem_get(mctx, sizeof(dst_context_t));
05f90cac85760b4edef2962209df49ea019c180fMark Andrews isc_mem_put(mctx, dctx, sizeof(dst_context_t));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews isc_mem_put(dctx->mctx, dctx, sizeof(dst_context_t));
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleydst_context_adddata(dst_context_t *dctx, const isc_region_t *data) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewsdst_context_sign(dst_context_t *dctx, isc_buffer_t *sig) {
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halleydst_context_verify(dst_context_t *dctx, isc_region_t *sig) {
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halleydst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv,
return (DST_R_NULLKEY);
return (DST_R_KEYCANNOTCOMPUTESECRET);
return (DST_R_NOTPRIVATEKEY);
return (DST_R_UNSUPPORTEDALG);
return (ret);
return (ISC_R_SUCCESS);
isc_buffer_t b;
return (result);
return (result);
return (result);
return (DST_R_INVALIDPRIVATEKEY);
return (ISC_R_SUCCESS);
int newfilenamelen = 0;
#ifndef WIN32
return (ISC_R_NOMEMORY);
return (result);
return (result);
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
out:
return (result);
return (DST_R_UNSUPPORTEDALG);
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
isc_region_t r;
return (DST_R_INVALIDPUBLICKEY);
return (DST_R_INVALIDPUBLICKEY);
return (result);
return (ISC_R_SUCCESS);
return (result);
return (result);
return (ISC_R_SUCCESS);
return (DST_R_UNSUPPORTEDALG);
out:
return (result);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (DST_R_UNSUPPORTEDALG);
return (result);
return (result);
return (ISC_R_SUCCESS);
void (*callback)(int))
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (DST_R_UNSUPPORTEDALG);
return (ret);
return (ret);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_FALSE);
if (!match_revoked_key)
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
static isc_boolean_t
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_FALSE);
type == 0);
case DST_ALG_RSAMD5:
case DST_ALG_RSASHA1:
case DST_ALG_NSEC3RSASHA1:
case DST_ALG_RSASHA256:
case DST_ALG_RSASHA512:
case DST_ALG_DSA:
case DST_ALG_NSEC3DSA:
*n = DNS_SIG_DSASIGSIZE;
case DST_ALG_HMACMD5:
case DST_ALG_HMACSHA1:
*n = ISC_SHA1_DIGESTLENGTH;
case DST_ALG_HMACSHA224:
*n = ISC_SHA224_DIGESTLENGTH;
case DST_ALG_HMACSHA256:
*n = ISC_SHA256_DIGESTLENGTH;
case DST_ALG_HMACSHA384:
*n = ISC_SHA384_DIGESTLENGTH;
case DST_ALG_HMACSHA512:
*n = ISC_SHA512_DIGESTLENGTH;
case DST_ALG_GSSAPI:
case DST_ALG_DH:
return (DST_R_UNSUPPORTEDALG);
return (ISC_R_SUCCESS);
return (DST_R_UNSUPPORTEDALG);
return (ISC_R_SUCCESS);
sizeof(algstr));
static dst_key_t *
return (NULL);
return (NULL);
return (NULL);
return (key);
isc_buffer_t b;
goto cleanup;
goto cleanup;
goto cleanup; \
#define BADTOKEN() { \
goto cleanup; \
BADTOKEN();
BADTOKEN();
0, NULL);
goto cleanup;
BADTOKEN();
BADTOKEN();
BADTOKEN();
BADTOKEN();
goto cleanup;
goto cleanup;
keyp);
goto cleanup;
return (ret);
static isc_boolean_t
case DST_ALG_RSAMD5:
case DST_ALG_RSASHA1:
case DST_ALG_NSEC3RSASHA1:
case DST_ALG_RSASHA256:
case DST_ALG_RSASHA512:
case DST_ALG_DSA:
case DST_ALG_NSEC3DSA:
case DST_ALG_DH:
return (ISC_FALSE);
case DST_ALG_HMACMD5:
case DST_ALG_GSSAPI:
return (ISC_TRUE);
return (ISC_FALSE);
#ifdef ISC_PLATFORM_USETHREADS
const char *output;
time_t t;
isc_buffer_t b;
isc_region_t r;
t = when;
#ifdef ISC_PLATFORM_USETHREADS
#ifdef WIN32
goto error;
goto error;
goto error;
isc_buffer_usedregion(&b, &r);
static isc_result_t
isc_region_t r;
return (ret);
return (DST_R_INVALIDPUBLICKEY);
return (DST_R_INVALIDPUBLICKEY);
return (ret);
return (DST_R_WRITEERROR);
access = 0;
&access);
return (ret);
return (ret);
static isc_result_t
unsigned int len;
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (result);
return (ISC_R_NOSPACE);
suffix);
return (ISC_R_SUCCESS);
static isc_result_t
isc_region_t r;
return (ret);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_NOMEMORY);
return (ret);
return (DST_R_UNSUPPORTEDALG);
return (ret);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_SUCCESS);
#ifndef OPENSSL
return (DST_R_NOCRYPTO);
return (DST_R_UNSUPPORTEDALG);
static isc_result_t
return (ISC_R_FAILURE);
if (n >= len)
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
#ifdef BIND9
if (len == 0)
return (ISC_R_SUCCESS);
if (pseudo)
return (ISC_R_NOTIMPLEMENTED);
dst__entropy_status(void) {
#ifdef BIND9
#ifdef GSSAPI
if (first) {