1999-07-12 20:08:42 +00:00
|
|
|
/*
|
2011-03-12 04:59:49 +00:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
2011-03-12 04:59:49 +00:00
|
|
|
* SPDX-License-Identifier: MPL-2.0 AND ISC
|
2007-06-18 23:47:57 +00:00
|
|
|
*
|
2000-05-08 14:38:29 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2007-06-18 23:47:57 +00:00
|
|
|
*
|
2000-05-08 14:38:29 +00:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
1999-07-12 20:08:42 +00:00
|
|
|
* information regarding copyright ownership.
|
2018-02-23 09:53:12 +01:00
|
|
|
*/
|
2021-06-03 08:37:05 +02:00
|
|
|
|
2018-02-23 09:53:12 +01:00
|
|
|
/*
|
1999-07-12 20:08:42 +00:00
|
|
|
* Copyright (C) Network Associates, Inc.
|
2000-06-09 20:58:39 +00:00
|
|
|
*
|
2007-08-28 07:20:43 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
1999-07-12 20:08:42 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2000-05-08 14:38:29 +00:00
|
|
|
* 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.
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/mem.h>
|
2000-12-04 23:06:37 +00:00
|
|
|
#include <isc/mutex.h>
|
|
|
|
#include <isc/mutexblock.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
2000-12-04 23:06:37 +00:00
|
|
|
#include <isc/thread.h>
|
2020-12-17 11:40:29 +01:00
|
|
|
#include <isc/tls.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2012-07-23 15:08:21 +10:00
|
|
|
#include <dns/log.h>
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
#include "dst_internal.h"
|
2002-03-19 04:30:57 +00:00
|
|
|
#include "dst_openssl.h"
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2021-10-08 12:10:56 +11:00
|
|
|
#if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000
|
2001-02-14 20:57:15 +00:00
|
|
|
#include <openssl/engine.h>
|
2021-10-08 12:10:56 +11:00
|
|
|
#endif /* if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 */
|
2022-12-26 19:42:32 +02:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
|
|
|
#include <openssl/core_names.h>
|
|
|
|
#include <openssl/store.h>
|
|
|
|
#endif
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2021-09-05 09:41:00 +00:00
|
|
|
#include "openssl_shim.h"
|
|
|
|
|
2022-12-26 19:31:26 +02:00
|
|
|
#define DST_RET(a) \
|
|
|
|
{ \
|
|
|
|
ret = a; \
|
|
|
|
goto err; \
|
|
|
|
}
|
|
|
|
|
2021-10-08 12:10:56 +11:00
|
|
|
#if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000
|
2022-12-26 19:17:19 +02:00
|
|
|
static ENGINE *global_engine = NULL;
|
2021-10-08 12:10:56 +11:00
|
|
|
#endif /* if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 */
|
2001-02-14 20:57:15 +00:00
|
|
|
|
2018-10-14 14:32:02 +02:00
|
|
|
static void
|
|
|
|
enable_fips_mode(void) {
|
|
|
|
#ifdef HAVE_FIPS_MODE
|
|
|
|
if (FIPS_mode() != 0) {
|
|
|
|
/*
|
|
|
|
* FIPS mode is already enabled.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FIPS_mode_set(1) == 0) {
|
|
|
|
dst__openssl_toresult2("FIPS_mode_set", DST_R_OPENSSLFAILURE);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_FIPS_MODE */
|
|
|
|
}
|
|
|
|
|
2000-06-09 22:32:20 +00:00
|
|
|
isc_result_t
|
2021-02-09 13:25:46 +01:00
|
|
|
dst__openssl_init(const char *engine) {
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
2018-10-11 15:13:27 +00:00
|
|
|
|
2018-10-14 14:32:02 +02:00
|
|
|
enable_fips_mode();
|
|
|
|
|
2021-10-08 12:10:56 +11:00
|
|
|
#if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000
|
2009-10-05 17:30:49 +00:00
|
|
|
if (engine != NULL && *engine == '\0') {
|
|
|
|
engine = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-10-05 17:30:49 +00:00
|
|
|
|
|
|
|
if (engine != NULL) {
|
2022-12-26 19:17:19 +02:00
|
|
|
global_engine = ENGINE_by_id(engine);
|
|
|
|
if (global_engine == NULL) {
|
2009-10-05 17:30:49 +00:00
|
|
|
result = DST_R_NOENGINE;
|
2008-03-31 14:42:51 +00:00
|
|
|
goto cleanup_rm;
|
|
|
|
}
|
2022-12-26 19:17:19 +02:00
|
|
|
if (!ENGINE_init(global_engine)) {
|
2022-09-07 13:46:31 +02:00
|
|
|
result = DST_R_NOENGINE;
|
|
|
|
goto cleanup_rm;
|
|
|
|
}
|
2009-10-05 17:30:49 +00:00
|
|
|
/* This will init the engine. */
|
2022-12-26 19:17:19 +02:00
|
|
|
if (!ENGINE_set_default(global_engine, ENGINE_METHOD_ALL)) {
|
2009-10-05 17:30:49 +00:00
|
|
|
result = DST_R_NOENGINE;
|
2022-09-07 13:46:31 +02:00
|
|
|
goto cleanup_init;
|
2008-03-31 14:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-05 17:30:49 +00:00
|
|
|
|
2000-06-09 22:32:20 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2022-09-07 13:46:31 +02:00
|
|
|
cleanup_init:
|
2022-12-26 19:17:19 +02:00
|
|
|
ENGINE_finish(global_engine);
|
2001-02-14 20:57:15 +00:00
|
|
|
cleanup_rm:
|
2022-12-26 19:17:19 +02:00
|
|
|
if (global_engine != NULL) {
|
|
|
|
ENGINE_free(global_engine);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2022-12-26 19:17:19 +02:00
|
|
|
global_engine = NULL;
|
2021-02-09 13:25:46 +01:00
|
|
|
#else
|
|
|
|
UNUSED(engine);
|
2021-10-08 12:10:56 +11:00
|
|
|
#endif /* if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 */
|
2001-02-14 20:57:15 +00:00
|
|
|
return (result);
|
2000-06-09 22:32:20 +00:00
|
|
|
}
|
|
|
|
|
2000-06-09 23:31:55 +00:00
|
|
|
void
|
2014-03-04 10:42:25 -08:00
|
|
|
dst__openssl_destroy(void) {
|
2021-10-08 12:10:56 +11:00
|
|
|
#if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000
|
2022-12-26 19:17:19 +02:00
|
|
|
if (global_engine != NULL) {
|
|
|
|
ENGINE_finish(global_engine);
|
|
|
|
ENGINE_free(global_engine);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2022-12-26 19:17:19 +02:00
|
|
|
global_engine = NULL;
|
2021-10-08 12:10:56 +11:00
|
|
|
#endif /* if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 */
|
2000-06-09 23:31:55 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 13:46:47 -07:00
|
|
|
static isc_result_t
|
|
|
|
toresult(isc_result_t fallback) {
|
2002-03-19 04:30:57 +00:00
|
|
|
isc_result_t result = fallback;
|
2018-08-14 12:49:19 +02:00
|
|
|
unsigned long err = ERR_peek_error();
|
2018-06-12 11:26:04 +02:00
|
|
|
#if defined(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED)
|
2012-09-28 13:46:47 -07:00
|
|
|
int lib = ERR_GET_LIB(err);
|
2012-09-28 18:47:05 -07:00
|
|
|
#endif /* if defined(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED) */
|
2012-09-28 13:46:47 -07:00
|
|
|
int reason = ERR_GET_REASON(err);
|
2002-03-19 04:30:57 +00:00
|
|
|
|
2012-09-28 13:46:47 -07:00
|
|
|
switch (reason) {
|
|
|
|
/*
|
|
|
|
* ERR_* errors are globally unique; others
|
|
|
|
* are unique per sublibrary
|
|
|
|
*/
|
2002-03-19 04:30:57 +00:00
|
|
|
case ERR_R_MALLOC_FAILURE:
|
|
|
|
result = ISC_R_NOMEMORY;
|
|
|
|
break;
|
|
|
|
default:
|
2018-06-12 11:26:04 +02:00
|
|
|
#if defined(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED)
|
2012-09-28 13:46:47 -07:00
|
|
|
if (lib == ERR_R_ECDSA_LIB &&
|
2022-11-02 19:33:14 +01:00
|
|
|
reason == ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED)
|
|
|
|
{
|
2012-09-28 13:46:47 -07:00
|
|
|
result = ISC_R_NOENTROPY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* if defined(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED) */
|
2002-03-19 04:30:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-09-28 13:46:47 -07:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dst__openssl_toresult(isc_result_t fallback) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = toresult(fallback);
|
|
|
|
|
2002-03-19 04:30:57 +00:00
|
|
|
ERR_clear_error();
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2012-07-23 15:08:21 +10:00
|
|
|
isc_result_t
|
|
|
|
dst__openssl_toresult2(const char *funcname, isc_result_t fallback) {
|
2012-10-24 12:58:16 -07:00
|
|
|
return (dst__openssl_toresult3(DNS_LOGCATEGORY_GENERAL, funcname,
|
|
|
|
fallback));
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dst__openssl_toresult3(isc_logcategory_t *category, const char *funcname,
|
|
|
|
isc_result_t fallback) {
|
2012-09-28 13:46:47 -07:00
|
|
|
isc_result_t result;
|
2012-10-12 21:57:22 +11:00
|
|
|
unsigned long err;
|
2021-09-05 09:41:00 +00:00
|
|
|
const char *file, *func, *data;
|
2012-07-23 15:08:21 +10:00
|
|
|
int line, flags;
|
|
|
|
char buf[256];
|
|
|
|
|
2012-09-28 13:46:47 -07:00
|
|
|
result = toresult(fallback);
|
|
|
|
|
2012-07-23 15:08:21 +10:00
|
|
|
isc_log_write(dns_lctx, category, DNS_LOGMODULE_CRYPTO, ISC_LOG_WARNING,
|
2012-09-28 13:46:47 -07:00
|
|
|
"%s failed (%s)", funcname, isc_result_totext(result));
|
|
|
|
|
|
|
|
if (result == ISC_R_NOMEMORY) {
|
|
|
|
goto done;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-09-28 13:46:47 -07:00
|
|
|
|
2012-07-23 15:08:21 +10:00
|
|
|
for (;;) {
|
2021-09-05 09:41:00 +00:00
|
|
|
err = ERR_get_error_all(&file, &line, &func, &data, &flags);
|
2012-08-14 14:29:47 +10:00
|
|
|
if (err == 0U) {
|
2012-07-23 15:08:21 +10:00
|
|
|
goto done;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-07-23 15:08:21 +10:00
|
|
|
ERR_error_string_n(err, buf, sizeof(buf));
|
2012-10-24 12:58:16 -07:00
|
|
|
isc_log_write(dns_lctx, category, DNS_LOGMODULE_CRYPTO,
|
2012-07-23 15:08:21 +10:00
|
|
|
ISC_LOG_INFO, "%s:%s:%d:%s", buf, file, line,
|
2018-10-11 11:57:57 +02:00
|
|
|
((flags & ERR_TXT_STRING) != 0) ? data : "");
|
2012-07-23 15:08:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
ERR_clear_error();
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2021-10-08 12:10:56 +11:00
|
|
|
#if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000
|
2008-03-31 14:42:51 +00:00
|
|
|
ENGINE *
|
2009-10-05 17:30:49 +00:00
|
|
|
dst__openssl_getengine(const char *engine) {
|
|
|
|
if (engine == NULL) {
|
|
|
|
return (NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2022-12-26 19:17:19 +02:00
|
|
|
if (global_engine == NULL) {
|
2009-10-05 17:30:49 +00:00
|
|
|
return (NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2022-12-26 19:17:19 +02:00
|
|
|
if (strcmp(engine, ENGINE_get_id(global_engine)) == 0) {
|
|
|
|
return (global_engine);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-10-05 17:30:49 +00:00
|
|
|
return (NULL);
|
2008-03-31 14:42:51 +00:00
|
|
|
}
|
2021-10-08 12:10:56 +11:00
|
|
|
#endif /* if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 */
|
2008-03-31 14:42:51 +00:00
|
|
|
|
2022-12-26 19:42:32 +02:00
|
|
|
static isc_result_t
|
|
|
|
dst__openssl_fromlabel_engine(int key_base_id, const char *engine,
|
|
|
|
const char *label, const char *pin,
|
|
|
|
EVP_PKEY **ppub, EVP_PKEY **ppriv) {
|
2022-12-26 19:31:26 +02:00
|
|
|
#if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000
|
|
|
|
isc_result_t ret = ISC_R_SUCCESS;
|
|
|
|
ENGINE *e = NULL;
|
|
|
|
|
|
|
|
UNUSED(pin);
|
|
|
|
|
|
|
|
if (engine == NULL) {
|
|
|
|
DST_RET(DST_R_NOENGINE);
|
|
|
|
}
|
|
|
|
e = dst__openssl_getengine(engine);
|
|
|
|
if (e == NULL) {
|
|
|
|
DST_RET(dst__openssl_toresult(DST_R_NOENGINE));
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppub = ENGINE_load_public_key(e, label, NULL, NULL);
|
|
|
|
if (*ppub == NULL) {
|
|
|
|
DST_RET(dst__openssl_toresult2("ENGINE_load_public_key",
|
|
|
|
DST_R_OPENSSLFAILURE));
|
|
|
|
}
|
2022-12-26 19:42:32 +02:00
|
|
|
if (EVP_PKEY_base_id(*ppub) != key_base_id) {
|
|
|
|
DST_RET(DST_R_BADKEYTYPE);
|
|
|
|
}
|
2022-12-26 19:31:26 +02:00
|
|
|
|
|
|
|
*ppriv = ENGINE_load_private_key(e, label, NULL, NULL);
|
|
|
|
if (*ppriv == NULL) {
|
|
|
|
DST_RET(dst__openssl_toresult2("ENGINE_load_private_key",
|
|
|
|
DST_R_OPENSSLFAILURE));
|
|
|
|
}
|
2022-12-26 19:42:32 +02:00
|
|
|
if (EVP_PKEY_base_id(*ppriv) != key_base_id) {
|
|
|
|
DST_RET(DST_R_BADKEYTYPE);
|
|
|
|
}
|
2022-12-26 19:31:26 +02:00
|
|
|
err:
|
|
|
|
return (ret);
|
|
|
|
#else /* if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 */
|
2022-12-26 19:42:32 +02:00
|
|
|
UNUSED(key_base_id);
|
2022-12-26 19:31:26 +02:00
|
|
|
UNUSED(engine);
|
|
|
|
UNUSED(label);
|
|
|
|
UNUSED(pin);
|
|
|
|
UNUSED(ppub);
|
|
|
|
UNUSED(ppriv);
|
|
|
|
return (DST_R_NOENGINE);
|
|
|
|
#endif /* if !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 */
|
|
|
|
}
|
|
|
|
|
2022-12-26 19:42:32 +02:00
|
|
|
static isc_result_t
|
|
|
|
dst__openssl_fromlabel_provider(int key_base_id, const char *engine,
|
|
|
|
const char *label, const char *pin,
|
|
|
|
EVP_PKEY **ppub, EVP_PKEY **ppriv) {
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
|
|
|
isc_result_t ret = DST_R_OPENSSLFAILURE;
|
|
|
|
OSSL_STORE_CTX *ctx = NULL;
|
|
|
|
|
|
|
|
UNUSED(pin);
|
|
|
|
UNUSED(engine);
|
|
|
|
|
|
|
|
ctx = OSSL_STORE_open(label, NULL, NULL, NULL, NULL);
|
|
|
|
if (!ctx) {
|
2023-01-09 21:50:01 +01:00
|
|
|
DST_RET(dst__openssl_toresult(DST_R_OPENSSLFAILURE));
|
2022-12-26 19:42:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!OSSL_STORE_eof(ctx)) {
|
|
|
|
OSSL_STORE_INFO *info = OSSL_STORE_load(ctx);
|
|
|
|
if (info == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (OSSL_STORE_INFO_get_type(info)) {
|
|
|
|
case OSSL_STORE_INFO_PKEY:
|
|
|
|
if (*ppriv != NULL) {
|
|
|
|
DST_RET(DST_R_INVALIDPRIVATEKEY);
|
|
|
|
}
|
|
|
|
*ppriv = OSSL_STORE_INFO_get1_PKEY(info);
|
|
|
|
if (EVP_PKEY_get_base_id(*ppriv) != key_base_id) {
|
|
|
|
DST_RET(DST_R_BADKEYTYPE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSSL_STORE_INFO_PUBKEY:
|
|
|
|
if (*ppub != NULL) {
|
|
|
|
DST_RET(DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
*ppub = OSSL_STORE_INFO_get1_PUBKEY(info);
|
|
|
|
if (EVP_PKEY_get_base_id(*ppub) != key_base_id) {
|
|
|
|
DST_RET(DST_R_BADKEYTYPE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
OSSL_STORE_INFO_free(info);
|
|
|
|
}
|
|
|
|
if (*ppriv != NULL && *ppub != NULL) {
|
|
|
|
ret = ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
err:
|
|
|
|
OSSL_STORE_close(ctx);
|
|
|
|
return (ret);
|
|
|
|
#else
|
|
|
|
UNUSED(key_base_id);
|
|
|
|
UNUSED(engine);
|
|
|
|
UNUSED(label);
|
|
|
|
UNUSED(pin);
|
|
|
|
UNUSED(ppub);
|
|
|
|
UNUSED(ppriv);
|
|
|
|
return (DST_R_OPENSSLFAILURE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dst__openssl_fromlabel(int key_base_id, const char *engine, const char *label,
|
|
|
|
const char *pin, EVP_PKEY **ppub, EVP_PKEY **ppriv) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = dst__openssl_fromlabel_provider(key_base_id, engine, label,
|
|
|
|
pin, ppub, ppriv);
|
|
|
|
if (result != DST_R_OPENSSLFAILURE) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (dst__openssl_fromlabel_engine(key_base_id, engine, label, pin,
|
|
|
|
ppub, ppriv));
|
|
|
|
}
|
|
|
|
|
2022-12-28 17:11:21 +02:00
|
|
|
bool
|
|
|
|
dst__openssl_compare_keypair(const dst_key_t *key1, const dst_key_t *key2) {
|
|
|
|
EVP_PKEY *pkey1 = key1->keydata.pkeypair.pub;
|
|
|
|
EVP_PKEY *pkey2 = key2->keydata.pkeypair.pub;
|
|
|
|
|
|
|
|
if (pkey1 == NULL && pkey2 == NULL) {
|
|
|
|
return (true);
|
|
|
|
} else if (pkey1 == NULL || pkey2 == NULL) {
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* `EVP_PKEY_eq` checks only the public components and parameters. */
|
|
|
|
if (EVP_PKEY_eq(pkey1, pkey2) != 1) {
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
/* The private key presence must be same for keys to match. */
|
|
|
|
if ((key1->keydata.pkeypair.priv != NULL) !=
|
|
|
|
(key2->keydata.pkeypair.priv != NULL))
|
|
|
|
{
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|