1999-07-12 16:08:42 -04:00
|
|
|
/*
|
2014-01-15 23:19:24 -05:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2021-06-03 02:37:05 -04:00
|
|
|
*
|
2014-01-15 23:19:24 -05:00
|
|
|
* SPDX-License-Identifier: MPL-2.0 AND ISC
|
2007-06-18 19:47:57 -04:00
|
|
|
*
|
1999-07-12 16:08:42 -04: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 19:47:57 -04:00
|
|
|
*
|
1999-07-12 16:08:42 -04:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
|
* information regarding copyright ownership.
|
2018-02-23 03:53:12 -05:00
|
|
|
*/
|
2021-06-03 02:37:05 -04:00
|
|
|
|
2018-02-23 03:53:12 -05:00
|
|
|
/*
|
1999-07-12 16:08:42 -04:00
|
|
|
* Portions Copyright (C) Network Associates, Inc.
|
|
|
|
|
*
|
2007-08-28 03:20:43 -04:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
1999-07-12 16:08:42 -04:00
|
|
|
* 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.
|
|
|
|
|
*/
|
2000-04-28 22:02:38 -04:00
|
|
|
|
2018-06-12 05:26:04 -04:00
|
|
|
#pragma once
|
2000-06-22 18:00:42 -04:00
|
|
|
|
2018-03-28 08:19:37 -04:00
|
|
|
#include <inttypes.h>
|
2018-04-17 11:29:14 -04:00
|
|
|
#include <stdbool.h>
|
2018-03-28 08:19:37 -04:00
|
|
|
|
2021-05-20 10:26:53 -04:00
|
|
|
#include <openssl/err.h>
|
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
|
#include <openssl/objects.h>
|
|
|
|
|
#include <openssl/rsa.h>
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
#include <isc/buffer.h>
|
2018-03-20 13:20:50 -04:00
|
|
|
#include <isc/hmac.h>
|
1999-07-12 16:08:42 -04:00
|
|
|
#include <isc/lang.h>
|
2001-08-27 23:58:29 -04:00
|
|
|
#include <isc/magic.h>
|
2018-06-01 03:31:59 -04:00
|
|
|
#include <isc/md.h>
|
2010-12-08 19:54:34 -05:00
|
|
|
#include <isc/refcount.h>
|
1999-07-12 16:08:42 -04:00
|
|
|
#include <isc/region.h>
|
2009-07-19 00:18:05 -04:00
|
|
|
#include <isc/stdtime.h>
|
2018-03-20 13:20:50 -04:00
|
|
|
#include <isc/types.h>
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2020-03-09 11:17:26 -04:00
|
|
|
#include <dns/time.h>
|
|
|
|
|
|
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
ISC_LANG_BEGINDECLS
|
|
|
|
|
|
2009-06-09 20:27:22 -04:00
|
|
|
#define KEY_MAGIC ISC_MAGIC('D', 'S', 'T', 'K')
|
|
|
|
|
#define CTX_MAGIC ISC_MAGIC('D', 'S', 'T', 'C')
|
2001-01-16 20:08:08 -05:00
|
|
|
|
|
|
|
|
#define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
|
|
|
|
|
#define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
/***
|
|
|
|
|
*** Types
|
|
|
|
|
***/
|
|
|
|
|
|
2000-06-02 19:36:14 -04:00
|
|
|
typedef struct dst_func dst_func_t;
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2018-03-20 13:20:50 -04:00
|
|
|
typedef struct dst_hmac_key dst_hmac_key_t;
|
2006-12-03 20:54:53 -05:00
|
|
|
|
2014-01-14 18:40:56 -05:00
|
|
|
/*%
|
|
|
|
|
* Indicate whether a DST context will be used for signing
|
|
|
|
|
* or for verification
|
|
|
|
|
*/
|
|
|
|
|
typedef enum { DO_SIGN, DO_VERIFY } dst_use_t;
|
|
|
|
|
|
2005-04-27 00:57:32 -04:00
|
|
|
/*% DST Key Structure */
|
1999-07-12 16:08:42 -04:00
|
|
|
struct dst_key {
|
|
|
|
|
unsigned int magic;
|
2010-12-08 19:54:34 -05:00
|
|
|
isc_refcount_t refs;
|
2021-06-25 04:51:21 -04:00
|
|
|
isc_mutex_t mdlock; /*%< lock for read/write metadata */
|
2005-04-27 00:57:32 -04:00
|
|
|
dns_name_t *key_name; /*%< name of the key */
|
|
|
|
|
unsigned int key_size; /*%< size of the key in bits */
|
|
|
|
|
unsigned int key_proto; /*%< protocols this key is used for
|
|
|
|
|
* */
|
|
|
|
|
unsigned int key_alg; /*%< algorithm of the key */
|
2018-03-28 08:19:37 -04:00
|
|
|
uint32_t key_flags; /*%< flags of the public key */
|
|
|
|
|
uint16_t key_id; /*%< identifier of the key */
|
|
|
|
|
uint16_t key_rid; /*%< identifier of the key when
|
2011-10-20 17:20:02 -04:00
|
|
|
* revoked */
|
2018-03-28 08:19:37 -04:00
|
|
|
uint16_t key_bits; /*%< hmac digest bits */
|
2005-04-27 00:57:32 -04:00
|
|
|
dns_rdataclass_t key_class; /*%< class of the key record */
|
2011-03-16 21:40:40 -04:00
|
|
|
dns_ttl_t key_ttl; /*%< default/initial dnskey ttl */
|
2005-04-27 00:57:32 -04:00
|
|
|
isc_mem_t *mctx; /*%< memory context */
|
2022-03-09 05:27:03 -05:00
|
|
|
char *directory; /*%< key directory */
|
2024-08-05 05:40:42 -04:00
|
|
|
char *label; /*%< HSM label */
|
2006-12-03 20:54:53 -05:00
|
|
|
union {
|
|
|
|
|
void *generic;
|
2021-02-11 08:40:59 -05:00
|
|
|
dns_gss_ctx_id_t gssctx;
|
2018-03-20 13:20:50 -04:00
|
|
|
dst_hmac_key_t *hmac_key;
|
2022-12-26 09:29:56 -05:00
|
|
|
struct {
|
|
|
|
|
EVP_PKEY *pub;
|
|
|
|
|
EVP_PKEY *priv;
|
|
|
|
|
} pkeypair;
|
2006-12-03 20:54:53 -05:00
|
|
|
} keydata; /*%< pointer to key in crypto pkg fmt */
|
2009-07-19 00:18:05 -04:00
|
|
|
|
2009-10-09 02:09:21 -04:00
|
|
|
isc_stdtime_t times[DST_MAX_TIMES + 1]; /*%< timing metadata */
|
2019-09-11 10:29:33 -04:00
|
|
|
bool timeset[DST_MAX_TIMES + 1]; /*%< data set? */
|
2019-09-12 05:57:55 -04:00
|
|
|
|
2019-09-11 07:46:02 -04:00
|
|
|
uint32_t nums[DST_MAX_NUMERIC + 1]; /*%< numeric metadata
|
|
|
|
|
* */
|
2019-09-11 10:29:33 -04:00
|
|
|
bool numset[DST_MAX_NUMERIC + 1]; /*%< data set? */
|
2019-09-12 05:57:55 -04:00
|
|
|
|
2019-09-11 10:29:33 -04:00
|
|
|
bool bools[DST_MAX_BOOLEAN + 1]; /*%< boolean metadata
|
|
|
|
|
* */
|
|
|
|
|
bool boolset[DST_MAX_BOOLEAN + 1]; /*%< data set? */
|
|
|
|
|
|
2019-09-12 05:57:55 -04:00
|
|
|
dst_key_state_t keystates[DST_MAX_KEYSTATES + 1]; /*%< key states
|
|
|
|
|
* */
|
|
|
|
|
bool keystateset[DST_MAX_KEYSTATES + 1]; /*%< data
|
|
|
|
|
* set? */
|
|
|
|
|
|
2020-12-03 04:19:38 -05:00
|
|
|
bool kasp; /*%< key has kasp state */
|
2019-09-11 10:29:33 -04:00
|
|
|
bool inactive; /*%< private key not present as it is
|
|
|
|
|
* inactive */
|
2018-04-17 11:29:14 -04:00
|
|
|
bool external; /*%< external key */
|
2022-05-03 06:28:31 -04:00
|
|
|
bool modified; /*%< set to true if key file metadata has changed */
|
2009-09-02 02:29:01 -04:00
|
|
|
|
|
|
|
|
int fmt_major; /*%< private key format, major version
|
|
|
|
|
* */
|
|
|
|
|
int fmt_minor; /*%< private key format, minor version
|
|
|
|
|
* */
|
|
|
|
|
|
2009-07-19 00:18:05 -04:00
|
|
|
dst_func_t *func; /*%< crypto package specific functions */
|
2010-12-17 20:56:23 -05:00
|
|
|
isc_buffer_t *key_tkeytoken; /*%< TKEY token data */
|
1999-07-12 16:08:42 -04:00
|
|
|
};
|
|
|
|
|
|
2000-06-02 14:57:51 -04:00
|
|
|
struct dst_context {
|
|
|
|
|
unsigned int magic;
|
2014-01-14 18:40:56 -05:00
|
|
|
dst_use_t use;
|
2000-06-02 14:57:51 -04:00
|
|
|
dst_key_t *key;
|
|
|
|
|
isc_mem_t *mctx;
|
2024-08-14 07:25:50 -04:00
|
|
|
isc_logcategory_t category;
|
2006-12-03 20:54:53 -05:00
|
|
|
union {
|
|
|
|
|
void *generic;
|
|
|
|
|
dst_gssapi_signverifyctx_t *gssctx;
|
2018-03-20 13:20:50 -04:00
|
|
|
isc_hmac_t *hmac_ctx;
|
2008-03-31 10:42:51 -04:00
|
|
|
EVP_MD_CTX *evp_md_ctx;
|
2006-12-03 20:54:53 -05:00
|
|
|
} ctxdata;
|
2000-06-02 14:57:51 -04:00
|
|
|
};
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
struct dst_func {
|
2000-06-02 14:57:51 -04:00
|
|
|
/*
|
|
|
|
|
* Context functions
|
|
|
|
|
*/
|
|
|
|
|
isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
|
2014-01-14 18:40:56 -05:00
|
|
|
isc_result_t (*createctx2)(dst_key_t *key, int maxbits,
|
|
|
|
|
dst_context_t *dctx);
|
2000-06-02 14:57:51 -04:00
|
|
|
void (*destroyctx)(dst_context_t *dctx);
|
|
|
|
|
isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Key operations
|
|
|
|
|
*/
|
|
|
|
|
isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
|
|
|
|
|
isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
|
2012-06-14 21:54:58 -04:00
|
|
|
isc_result_t (*verify2)(dst_context_t *dctx, int maxbits,
|
2012-06-14 01:44:20 -04:00
|
|
|
const isc_region_t *sig);
|
2000-03-06 15:06:01 -05:00
|
|
|
isc_result_t (*computesecret)(const dst_key_t *pub,
|
1999-09-27 12:55:45 -04:00
|
|
|
const dst_key_t *priv,
|
|
|
|
|
isc_buffer_t *secret);
|
2018-04-17 11:29:14 -04:00
|
|
|
bool (*compare)(const dst_key_t *key1, const dst_key_t *key2);
|
|
|
|
|
bool (*paramcompare)(const dst_key_t *key1, const dst_key_t *key2);
|
2009-10-24 05:46:19 -04:00
|
|
|
isc_result_t (*generate)(dst_key_t *key, int parms,
|
|
|
|
|
void (*callback)(int));
|
2018-04-17 11:29:14 -04:00
|
|
|
bool (*isprivate)(const dst_key_t *key);
|
2000-06-02 14:57:51 -04:00
|
|
|
void (*destroy)(dst_key_t *key);
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
/* conversion functions */
|
2000-06-02 14:57:51 -04:00
|
|
|
isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
|
|
|
|
|
isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
|
2000-06-06 17:58:16 -04:00
|
|
|
isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
|
2009-09-03 00:09:58 -04:00
|
|
|
isc_result_t (*parse)(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub);
|
2001-11-06 15:47:59 -05:00
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
|
void (*cleanup)(void);
|
2008-03-31 10:42:51 -04:00
|
|
|
|
2024-08-05 05:40:42 -04:00
|
|
|
isc_result_t (*fromlabel)(dst_key_t *key, const char *label,
|
|
|
|
|
const char *pin);
|
2011-01-10 00:32:04 -05:00
|
|
|
isc_result_t (*dump)(dst_key_t *key, isc_mem_t *mctx, char **buffer,
|
|
|
|
|
int *length);
|
|
|
|
|
isc_result_t (*restore)(dst_key_t *key, const char *keystr);
|
1999-07-12 16:08:42 -04:00
|
|
|
};
|
|
|
|
|
|
2005-04-27 00:57:32 -04:00
|
|
|
/*%
|
2000-06-02 19:36:14 -04:00
|
|
|
* Initializers
|
|
|
|
|
*/
|
2024-08-05 05:40:42 -04:00
|
|
|
void
|
2000-06-06 17:58:16 -04:00
|
|
|
dst__hmacmd5_init(struct dst_func **funcp);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2006-01-26 21:35:15 -05:00
|
|
|
dst__hmacsha1_init(struct dst_func **funcp);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2006-01-26 21:35:15 -05:00
|
|
|
dst__hmacsha224_init(struct dst_func **funcp);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2006-01-26 21:35:15 -05:00
|
|
|
dst__hmacsha256_init(struct dst_func **funcp);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2006-01-26 21:35:15 -05:00
|
|
|
dst__hmacsha384_init(struct dst_func **funcp);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2006-01-26 21:35:15 -05:00
|
|
|
dst__hmacsha512_init(struct dst_func **funcp);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2009-10-27 18:25:37 -04:00
|
|
|
dst__opensslrsa_init(struct dst_func **funcp, unsigned char algorithm);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2014-01-14 18:40:56 -05:00
|
|
|
dst__opensslecdsa_init(struct dst_func **funcp);
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2022-08-15 01:36:03 -04:00
|
|
|
dst__openssleddsa_init(struct dst_func **funcp, unsigned char algorithm);
|
2018-08-07 10:46:53 -04:00
|
|
|
#if HAVE_GSSAPI
|
2024-08-05 06:14:26 -04:00
|
|
|
void
|
2018-06-12 05:26:04 -04:00
|
|
|
dst__gssapi_init(struct dst_func **funcp);
|
2018-08-07 10:46:53 -04:00
|
|
|
#endif /* HAVE_GSSAPI*/
|
2000-06-06 17:58:16 -04:00
|
|
|
|
2023-03-30 12:00:17 -04:00
|
|
|
/*%
|
|
|
|
|
* Secure private file handling
|
|
|
|
|
*/
|
|
|
|
|
FILE *
|
|
|
|
|
dst_key_open(char *tmpname, mode_t mode);
|
|
|
|
|
isc_result_t
|
|
|
|
|
dst_key_close(char *tmpname, FILE *fp, char *filename);
|
|
|
|
|
isc_result_t
|
|
|
|
|
dst_key_cleanup(char *tmpname, FILE *fp);
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
ISC_LANG_ENDDECLS
|
|
|
|
|
|
2005-04-27 00:57:32 -04:00
|
|
|
/*! \file */
|