openssl_link.c revision d362465c77b375be2707bc83cebc731d0645d12d
/*
* Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (C) 1999-2003 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Portions Copyright (C) 1995-2000 by Network Associates, Inc.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Principal Author: Brian Wellington
* $Id: openssl_link.c,v 1.24 2009/01/17 23:47:42 tbox Exp $
*/
#ifdef OPENSSL
#include <config.h>
#include <isc/mutexblock.h>
#include "dst_internal.h"
#include "dst_openssl.h"
#define USE_ENGINE 1
#endif
#ifdef USE_ENGINE
#ifdef ENGINE_ID
#else
const char *engine_id;
#endif
#endif
static int nlocks;
#ifdef USE_ENGINE
static ENGINE *e;
#endif
#ifdef USE_PKCS11
static isc_result_t
#endif
static int
if (num < 0)
return (-1);
}
static int
entropy_status(void) {
return (dst__entropy_status() > 32);
}
static int
if (num < 0)
return (-1);
}
static void
/*
* Do nothing. The only call to this provides no useful data anyway.
*/
}
static void
if ((mode & CRYPTO_LOCK) != 0)
else
}
static unsigned long
id_callback(void) {
return ((unsigned long)isc_thread_self());
}
static void *
}
static void
}
static void *
void *p;
p = NULL;
if (size > 0U) {
}
return (p);
}
#ifdef USE_ENGINE
/* const char *name; */
#endif
#ifdef DNS_CRYPTO_LEAKS
#endif
nlocks = CRYPTO_num_locks();
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS)
goto cleanup_mutexalloc;
goto cleanup_mutexinit;
}
#ifdef USE_ENGINE
#ifdef USE_PKCS11
#ifndef PKCS11_SO_PATH
#define PKCS11_SO_PATH "/usr/local/lib/engines/engine_pkcs11.so"
#endif
#ifndef PKCS11_MODULE_PATH
#define PKCS11_MODULE_PATH "/usr/lib/libpkcs11.so"
#endif
{
/*
* to use this to config the PIN, add in openssl.cnf:
* - at the beginning: "openssl_conf = openssl_def"
* - at any place these sections:
* [ openssl_def ]
* engines = engine_section
* [ engine_section ]
* pkcs11 = pkcs11_section
* [ pkcs11_section ]
* PIN = my___pin
*/
const char *pre_cmds[] = {
"SO_PATH", PKCS11_SO_PATH,
"LOAD", NULL,
"MODULE_PATH", PKCS11_MODULE_PATH
};
const char *post_cmds[] = {
/* "PIN", "my___pin" */
};
pre_cmds, 0,
post_cmds, /*1*/ 0);
if (result != ISC_R_SUCCESS)
goto cleanup_rm;
}
#endif /* USE_PKCS11 */
e = ENGINE_by_id(engine_id);
if (e == NULL) {
goto cleanup_rm;
}
if (!ENGINE_init(e)) {
ENGINE_free(e);
goto cleanup_rm;
}
ENGINE_free(e);
} else {
/*
* Something weird here. If we call ENGINE_finish()
* ENGINE_get_default_RAND() will fail.
*/
if (ENGINE_init(e)) {
he = e;
}
}
}
re = ENGINE_new();
goto cleanup_rm;
}
} else
#else
#endif /* USE_ENGINE */
return (ISC_R_SUCCESS);
#ifdef USE_ENGINE
#endif
return (result);
}
void
/*
*/
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
#endif
EVP_cleanup();
#if defined(USE_ENGINE)
if (e != NULL) {
ENGINE_finish(e);
e = NULL;
}
#endif
#endif
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
#endif
ERR_remove_state(0);
#ifdef DNS_CRYPTO_LEAKS
#endif
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
RAND_cleanup();
#endif
}
}
}
int err = ERR_get_error();
switch (ERR_GET_REASON(err)) {
case ERR_R_MALLOC_FAILURE:
break;
default:
break;
}
return (result);
}
ENGINE *
dst__openssl_getengine(const char *name) {
#if defined(USE_ENGINE)
return (he);
#else
return (NULL);
#endif
}
dst__openssl_setdefault(const char *name) {
#if defined(USE_ENGINE)
#endif
/*
* XXXMPA If the engine does not have a default RAND method
* restore our method.
*/
return (ISC_R_SUCCESS);
}
#ifdef USE_PKCS11
/*
* 'name' is the name the engine is known by to the dst library.
* This may or may not match the name the engine is known by to
* openssl. It is the name that is stored in the private key file.
*
* 'engine_id' is the openssl engine name.
*
* pre_cmds and post_cmds a sequence if command argument pairs
* pre_num and post_num are a count of those pairs.
*
* "SO_PATH", PKCS11_SO_PATH ("/usr/local/lib/engines/engine_pkcs11.so")
* "LOAD", NULL
* "MODULE_PATH", PKCS11_MODULE_PATH ("/usr/lib/libpkcs11.so")
*/
static isc_result_t
{
ENGINE *e;
e = ENGINE_by_id(engine_id);
if (e == NULL)
return (ISC_R_NOTFOUND);
while (pre_num--) {
ENGINE_free(e);
return (ISC_R_FAILURE);
}
pre_cmds += 2;
}
if (!ENGINE_init(e)) {
ENGINE_free(e);
return (ISC_R_FAILURE);
}
/*
* ENGINE_init() returned a functional reference, so free the
* structural reference from ENGINE_by_id().
*/
ENGINE_free(e);
while (post_num--) {
ENGINE_free(e);
return (ISC_R_FAILURE);
}
post_cmds += 2;
}
he = e;
return (ISC_R_SUCCESS);
}
#endif /* USE_PKCS11 */
#else /* OPENSSL */
#endif /* OPENSSL */
/*! \file */