1999-07-12 20:08:42 +00:00
|
|
|
/*
|
2018-03-15 18:32:45 -07:00
|
|
|
* Portions Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2007-06-18 23:47:57 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10: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 http://mozilla.org/MPL/2.0/.
|
2007-06-18 23:47:57 +00:00
|
|
|
*
|
2018-02-23 09:53:12 +01:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*
|
|
|
|
* Portions Copyright (C) Network Associates, Inc.
|
2000-08-01 01:33:37 +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-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +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
|
|
|
*/
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include "dst_parse.h"
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <isc/base64.h>
|
1999-10-08 22:25:14 +00:00
|
|
|
#include <isc/dir.h>
|
2015-05-23 14:21:51 +02:00
|
|
|
#include <isc/file.h>
|
2000-06-20 04:13:40 +00:00
|
|
|
#include <isc/fsaccess.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <isc/lex.h>
|
|
|
|
#include <isc/mem.h>
|
2015-05-23 14:21:51 +02:00
|
|
|
#include <isc/print.h>
|
2009-07-19 04:18:05 +00:00
|
|
|
#include <isc/stdtime.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
2012-07-05 16:07:31 -05:00
|
|
|
#include <dns/log.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <dns/time.h>
|
2009-07-19 04:18:05 +00:00
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
#include "dst/result.h"
|
2020-02-12 13:59:18 +01:00
|
|
|
#include "dst_internal.h"
|
|
|
|
|
|
|
|
#include <pk11/site.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2002-01-21 01:07:32 +00:00
|
|
|
#define DST_AS_STR(t) ((t).value.as_textregion.base)
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
#define PRIVATE_KEY_STR "Private-key-format:"
|
|
|
|
#define ALGORITHM_STR "Algorithm:"
|
|
|
|
|
2009-10-09 06:09:21 +00:00
|
|
|
#define TIMING_NTAGS (DST_MAX_TIMES + 1)
|
|
|
|
static const char *timetags[TIMING_NTAGS] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
"Created:", "Publish:", "Activate:", "Revoke:",
|
|
|
|
"Inactive:", "Delete:", "DSPublish:", "SyncPublish:",
|
|
|
|
"SyncDelete:", NULL, NULL, NULL,
|
2019-09-12 11:57:55 +02:00
|
|
|
NULL
|
2009-10-09 06:09:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NUMERIC_NTAGS (DST_MAX_NUMERIC + 1)
|
|
|
|
static const char *numerictags[NUMERIC_NTAGS] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
"Predecessor:", "Successor:", "MaxTTL:", "RollPeriod:", NULL
|
2009-07-19 04:18:05 +00:00
|
|
|
};
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
struct parse_map {
|
2020-02-12 13:59:18 +01:00
|
|
|
const int value;
|
2000-06-01 18:26:56 +00:00
|
|
|
const char *tag;
|
1999-07-12 20:08:42 +00:00
|
|
|
};
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static struct parse_map map[] = { { TAG_RSA_MODULUS, "Modulus:" },
|
|
|
|
{ TAG_RSA_PUBLICEXPONENT, "PublicExponent:" },
|
|
|
|
{ TAG_RSA_PRIVATEEXPONENT, "PrivateExponent"
|
|
|
|
":" },
|
|
|
|
{ TAG_RSA_PRIME1, "Prime1:" },
|
|
|
|
{ TAG_RSA_PRIME2, "Prime2:" },
|
|
|
|
{ TAG_RSA_EXPONENT1, "Exponent1:" },
|
|
|
|
{ TAG_RSA_EXPONENT2, "Exponent2:" },
|
|
|
|
{ TAG_RSA_COEFFICIENT, "Coefficient:" },
|
|
|
|
{ TAG_RSA_ENGINE, "Engine:" },
|
|
|
|
{ TAG_RSA_LABEL, "Label:" },
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_DH_PRIME, "Prime(p):" },
|
|
|
|
{ TAG_DH_GENERATOR, "Generator(g):" },
|
|
|
|
{ TAG_DH_PRIVATE, "Private_value(x):" },
|
|
|
|
{ TAG_DH_PUBLIC, "Public_value(y):" },
|
1999-09-27 16:55:45 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_ECDSA_PRIVATEKEY, "PrivateKey:" },
|
|
|
|
{ TAG_ECDSA_ENGINE, "Engine:" },
|
|
|
|
{ TAG_ECDSA_LABEL, "Label:" },
|
2012-05-02 23:20:17 +10:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_EDDSA_PRIVATEKEY, "PrivateKey:" },
|
|
|
|
{ TAG_EDDSA_ENGINE, "Engine:" },
|
|
|
|
{ TAG_EDDSA_LABEL, "Label:" },
|
2017-07-31 15:26:00 +02:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_HMACMD5_KEY, "Key:" },
|
|
|
|
{ TAG_HMACMD5_BITS, "Bits:" },
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_HMACSHA1_KEY, "Key:" },
|
|
|
|
{ TAG_HMACSHA1_BITS, "Bits:" },
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_HMACSHA224_KEY, "Key:" },
|
|
|
|
{ TAG_HMACSHA224_BITS, "Bits:" },
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_HMACSHA256_KEY, "Key:" },
|
|
|
|
{ TAG_HMACSHA256_BITS, "Bits:" },
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_HMACSHA384_KEY, "Key:" },
|
|
|
|
{ TAG_HMACSHA384_BITS, "Bits:" },
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ TAG_HMACSHA512_KEY, "Key:" },
|
|
|
|
{ TAG_HMACSHA512_BITS, "Bits:" },
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
{ 0, NULL } };
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
find_value(const char *s, const unsigned int alg)
|
|
|
|
{
|
1999-07-12 20:08:42 +00:00
|
|
|
int i;
|
|
|
|
|
2009-07-19 04:18:05 +00:00
|
|
|
for (i = 0; map[i].tag != NULL; i++) {
|
|
|
|
if (strcasecmp(s, map[i].tag) == 0 &&
|
|
|
|
(TAG_ALG(map[i].value) == alg))
|
1999-07-12 20:08:42 +00:00
|
|
|
return (map[i].value);
|
|
|
|
}
|
2009-07-19 04:18:05 +00:00
|
|
|
return (-1);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-06-01 18:26:56 +00:00
|
|
|
static const char *
|
2020-02-12 13:59:18 +01:00
|
|
|
find_tag(const int value)
|
|
|
|
{
|
1999-07-12 20:08:42 +00:00
|
|
|
int i;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
for (i = 0;; i++) {
|
1999-07-12 20:08:42 +00:00
|
|
|
if (map[i].tag == NULL)
|
|
|
|
return (NULL);
|
|
|
|
else if (value == map[i].value)
|
|
|
|
return (map[i].tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-09 06:09:21 +00:00
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
find_metadata(const char *s, const char *tags[], int ntags)
|
|
|
|
{
|
2009-10-09 06:09:21 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ntags; i++) {
|
2015-11-05 12:09:48 +11:00
|
|
|
if (tags[i] != NULL && strcasecmp(s, tags[i]) == 0)
|
2009-10-09 06:09:21 +00:00
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
find_timedata(const char *s)
|
|
|
|
{
|
2009-10-09 06:09:21 +00:00
|
|
|
return (find_metadata(s, timetags, TIMING_NTAGS));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
find_numericdata(const char *s)
|
|
|
|
{
|
2009-10-09 06:09:21 +00:00
|
|
|
return (find_metadata(s, numerictags, NUMERIC_NTAGS));
|
|
|
|
}
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
check_rsa(const dst_private_t *priv, bool external)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
bool have[RSA_NTAGS];
|
|
|
|
bool ok;
|
2008-03-31 14:42:51 +00:00
|
|
|
unsigned int mask;
|
|
|
|
|
2013-09-04 13:53:02 +10:00
|
|
|
if (external)
|
|
|
|
return ((priv->nelements == 0) ? 0 : -1);
|
|
|
|
|
2008-03-31 14:42:51 +00:00
|
|
|
for (i = 0; i < RSA_NTAGS; i++)
|
2018-04-17 08:29:14 -07:00
|
|
|
have[i] = false;
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2008-03-31 14:42:51 +00:00
|
|
|
for (j = 0; j < priv->nelements; j++) {
|
|
|
|
for (i = 0; i < RSA_NTAGS; i++)
|
2018-10-25 10:27:49 +02:00
|
|
|
if (priv->elements[j].tag == TAG(DST_ALG_RSA, i))
|
1999-07-12 20:08:42 +00:00
|
|
|
break;
|
2008-03-31 14:42:51 +00:00
|
|
|
if (i == RSA_NTAGS)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (-1);
|
2018-04-17 08:29:14 -07:00
|
|
|
have[i] = true;
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
2008-03-31 14:42:51 +00:00
|
|
|
|
2018-05-01 10:08:23 +10:00
|
|
|
mask = (1ULL << TAG_SHIFT) - 1;
|
2008-03-31 23:47:11 +00:00
|
|
|
|
2008-03-31 14:42:51 +00:00
|
|
|
if (have[TAG_RSA_ENGINE & mask])
|
|
|
|
ok = have[TAG_RSA_MODULUS & mask] &&
|
|
|
|
have[TAG_RSA_PUBLICEXPONENT & mask] &&
|
|
|
|
have[TAG_RSA_LABEL & mask];
|
2008-03-31 23:47:11 +00:00
|
|
|
else
|
2008-03-31 14:42:51 +00:00
|
|
|
ok = have[TAG_RSA_MODULUS & mask] &&
|
|
|
|
have[TAG_RSA_PUBLICEXPONENT & mask] &&
|
|
|
|
have[TAG_RSA_PRIVATEEXPONENT & mask] &&
|
|
|
|
have[TAG_RSA_PRIME1 & mask] &&
|
|
|
|
have[TAG_RSA_PRIME2 & mask] &&
|
|
|
|
have[TAG_RSA_EXPONENT1 & mask] &&
|
|
|
|
have[TAG_RSA_EXPONENT2 & mask] &&
|
|
|
|
have[TAG_RSA_COEFFICIENT & mask];
|
2020-02-12 13:59:18 +01:00
|
|
|
return (ok ? 0 : -1);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 16:55:45 +00:00
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
check_dh(const dst_private_t *priv)
|
|
|
|
{
|
1999-09-27 16:55:45 +00:00
|
|
|
int i, j;
|
|
|
|
if (priv->nelements != DH_NTAGS)
|
|
|
|
return (-1);
|
|
|
|
for (i = 0; i < DH_NTAGS; i++) {
|
|
|
|
for (j = 0; j < priv->nelements; j++)
|
|
|
|
if (priv->elements[j].tag == TAG(DST_ALG_DH, i))
|
|
|
|
break;
|
|
|
|
if (j == priv->nelements)
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-05-02 23:20:17 +10:00
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
check_ecdsa(const dst_private_t *priv, bool external)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
bool have[ECDSA_NTAGS];
|
|
|
|
bool ok;
|
2014-01-14 15:40:56 -08:00
|
|
|
unsigned int mask;
|
2013-09-04 13:53:02 +10:00
|
|
|
|
|
|
|
if (external)
|
|
|
|
return ((priv->nelements == 0) ? 0 : -1);
|
|
|
|
|
2014-01-14 15:40:56 -08:00
|
|
|
for (i = 0; i < ECDSA_NTAGS; i++)
|
2018-04-17 08:29:14 -07:00
|
|
|
have[i] = false;
|
2014-01-14 15:40:56 -08:00
|
|
|
for (j = 0; j < priv->nelements; j++) {
|
|
|
|
for (i = 0; i < ECDSA_NTAGS; i++)
|
|
|
|
if (priv->elements[j].tag == TAG(DST_ALG_ECDSA256, i))
|
|
|
|
break;
|
|
|
|
if (i == ECDSA_NTAGS)
|
|
|
|
return (-1);
|
2018-04-17 08:29:14 -07:00
|
|
|
have[i] = true;
|
2014-01-14 15:40:56 -08:00
|
|
|
}
|
|
|
|
|
2018-05-01 10:08:23 +10:00
|
|
|
mask = (1ULL << TAG_SHIFT) - 1;
|
2014-01-14 15:40:56 -08:00
|
|
|
|
|
|
|
if (have[TAG_ECDSA_ENGINE & mask])
|
|
|
|
ok = have[TAG_ECDSA_LABEL & mask];
|
|
|
|
else
|
|
|
|
ok = have[TAG_ECDSA_PRIVATEKEY & mask];
|
2020-02-12 13:59:18 +01:00
|
|
|
return (ok ? 0 : -1);
|
2012-05-02 23:20:17 +10:00
|
|
|
}
|
|
|
|
|
2017-07-31 15:26:00 +02:00
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
check_eddsa(const dst_private_t *priv, bool external)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
bool have[EDDSA_NTAGS];
|
|
|
|
bool ok;
|
2017-07-31 15:26:00 +02:00
|
|
|
unsigned int mask;
|
|
|
|
|
|
|
|
if (external)
|
|
|
|
return ((priv->nelements == 0) ? 0 : -1);
|
|
|
|
|
|
|
|
for (i = 0; i < EDDSA_NTAGS; i++)
|
2018-04-17 08:29:14 -07:00
|
|
|
have[i] = false;
|
2017-07-31 15:26:00 +02:00
|
|
|
for (j = 0; j < priv->nelements; j++) {
|
|
|
|
for (i = 0; i < EDDSA_NTAGS; i++)
|
|
|
|
if (priv->elements[j].tag == TAG(DST_ALG_ED25519, i))
|
|
|
|
break;
|
|
|
|
if (i == EDDSA_NTAGS)
|
|
|
|
return (-1);
|
2018-04-17 08:29:14 -07:00
|
|
|
have[i] = true;
|
2017-07-31 15:26:00 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 10:08:23 +10:00
|
|
|
mask = (1ULL << TAG_SHIFT) - 1;
|
2017-07-31 15:26:00 +02:00
|
|
|
|
|
|
|
if (have[TAG_EDDSA_ENGINE & mask])
|
|
|
|
ok = have[TAG_EDDSA_LABEL & mask];
|
|
|
|
else
|
|
|
|
ok = have[TAG_EDDSA_PRIVATEKEY & mask];
|
2020-02-12 13:59:18 +01:00
|
|
|
return (ok ? 0 : -1);
|
2017-07-31 15:26:00 +02:00
|
|
|
}
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
check_hmac_md5(const dst_private_t *priv, bool old)
|
|
|
|
{
|
2006-01-27 02:35:15 +00:00
|
|
|
int i, j;
|
|
|
|
|
2006-05-16 03:44:54 +00:00
|
|
|
if (priv->nelements != HMACMD5_NTAGS) {
|
|
|
|
/*
|
2006-05-16 04:00:01 +00:00
|
|
|
* If this is a good old format and we are accepting
|
2006-05-16 03:44:54 +00:00
|
|
|
* the old format return success.
|
|
|
|
*/
|
|
|
|
if (old && priv->nelements == OLD_HMACMD5_NTAGS &&
|
|
|
|
priv->elements[0].tag == TAG_HMACMD5_KEY)
|
|
|
|
return (0);
|
1999-07-12 20:08:42 +00:00
|
|
|
return (-1);
|
2006-05-16 03:44:54 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We must be new format at this point.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < HMACMD5_NTAGS; i++) {
|
2006-01-27 02:35:15 +00:00
|
|
|
for (j = 0; j < priv->nelements; j++)
|
2006-05-16 03:44:54 +00:00
|
|
|
if (priv->elements[j].tag == TAG(DST_ALG_HMACMD5, i))
|
2006-01-27 02:35:15 +00:00
|
|
|
break;
|
|
|
|
if (j == priv->nelements)
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
check_hmac_sha(const dst_private_t *priv, unsigned int ntags, unsigned int alg)
|
2006-01-27 02:35:15 +00:00
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
if (priv->nelements != ntags)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (-1);
|
2006-01-27 02:35:15 +00:00
|
|
|
for (i = 0; i < ntags; i++) {
|
|
|
|
for (j = 0; j < priv->nelements; j++)
|
|
|
|
if (priv->elements[j].tag == TAG(alg, i))
|
|
|
|
break;
|
|
|
|
if (j == priv->nelements)
|
|
|
|
return (-1);
|
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-12 13:59:18 +01:00
|
|
|
check_data(const dst_private_t *priv, const unsigned int alg, bool old,
|
|
|
|
bool external)
|
2006-01-27 02:35:15 +00:00
|
|
|
{
|
2004-02-01 23:56:19 +00:00
|
|
|
/* XXXVIX this switch statement is too sparse to gen a jump table. */
|
1999-07-12 20:08:42 +00:00
|
|
|
switch (alg) {
|
2018-10-25 10:27:49 +02:00
|
|
|
case DST_ALG_RSA:
|
2004-02-01 23:56:19 +00:00
|
|
|
case DST_ALG_RSASHA1:
|
2012-05-16 23:12:57 -07:00
|
|
|
case DST_ALG_NSEC3RSASHA1:
|
|
|
|
case DST_ALG_RSASHA256:
|
|
|
|
case DST_ALG_RSASHA512:
|
2013-09-04 13:53:02 +10:00
|
|
|
return (check_rsa(priv, external));
|
2004-02-01 23:56:19 +00:00
|
|
|
case DST_ALG_DH:
|
|
|
|
return (check_dh(priv));
|
2012-05-02 23:20:17 +10:00
|
|
|
case DST_ALG_ECDSA256:
|
2012-05-16 23:12:57 -07:00
|
|
|
case DST_ALG_ECDSA384:
|
2013-09-04 13:53:02 +10:00
|
|
|
return (check_ecdsa(priv, external));
|
2017-07-31 15:26:00 +02:00
|
|
|
case DST_ALG_ED25519:
|
|
|
|
case DST_ALG_ED448:
|
|
|
|
return (check_eddsa(priv, external));
|
2004-02-01 23:56:19 +00:00
|
|
|
case DST_ALG_HMACMD5:
|
2006-01-27 02:35:15 +00:00
|
|
|
return (check_hmac_md5(priv, old));
|
|
|
|
case DST_ALG_HMACSHA1:
|
|
|
|
return (check_hmac_sha(priv, HMACSHA1_NTAGS, alg));
|
|
|
|
case DST_ALG_HMACSHA224:
|
|
|
|
return (check_hmac_sha(priv, HMACSHA224_NTAGS, alg));
|
|
|
|
case DST_ALG_HMACSHA256:
|
|
|
|
return (check_hmac_sha(priv, HMACSHA256_NTAGS, alg));
|
|
|
|
case DST_ALG_HMACSHA384:
|
|
|
|
return (check_hmac_sha(priv, HMACSHA384_NTAGS, alg));
|
|
|
|
case DST_ALG_HMACSHA512:
|
|
|
|
return (check_hmac_sha(priv, HMACSHA512_NTAGS, alg));
|
2004-02-01 23:56:19 +00:00
|
|
|
default:
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dst__privstruct_free(dst_private_t *priv, isc_mem_t *mctx)
|
|
|
|
{
|
1999-07-12 20:08:42 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (priv == NULL)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < priv->nelements; i++) {
|
|
|
|
if (priv->elements[i].data == NULL)
|
|
|
|
continue;
|
|
|
|
memset(priv->elements[i].data, 0, MAXFIELDSIZE);
|
|
|
|
isc_mem_put(mctx, priv->elements[i].data, MAXFIELDSIZE);
|
|
|
|
}
|
|
|
|
priv->nelements = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
isc_result_t
|
2002-02-27 22:12:06 +00:00
|
|
|
dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex,
|
|
|
|
isc_mem_t *mctx, dst_private_t *priv)
|
1999-07-12 20:08:42 +00:00
|
|
|
{
|
2020-02-12 13:59:18 +01:00
|
|
|
int n = 0, major, minor, check;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_token_t token;
|
2002-02-27 22:12:06 +00:00
|
|
|
unsigned char *data = NULL;
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned int opt = ISC_LEXOPT_EOL;
|
|
|
|
isc_stdtime_t when;
|
|
|
|
isc_result_t ret;
|
|
|
|
bool external = false;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
REQUIRE(priv != NULL);
|
|
|
|
|
|
|
|
priv->nelements = 0;
|
2008-01-22 01:34:15 +00:00
|
|
|
memset(priv->elements, 0, sizeof(priv->elements));
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define NEXTTOKEN(lex, opt, token) \
|
|
|
|
do { \
|
|
|
|
ret = isc_lex_gettoken(lex, opt, token); \
|
|
|
|
if (ret != ISC_R_SUCCESS) \
|
|
|
|
goto fail; \
|
2002-02-27 22:12:06 +00:00
|
|
|
} while (0)
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define READLINE(lex, opt, token) \
|
|
|
|
do { \
|
|
|
|
ret = isc_lex_gettoken(lex, opt, token); \
|
|
|
|
if (ret == ISC_R_EOF) \
|
|
|
|
break; \
|
|
|
|
else if (ret != ISC_R_SUCCESS) \
|
|
|
|
goto fail; \
|
2002-02-27 22:12:06 +00:00
|
|
|
} while ((*token).type != isc_tokentype_eol)
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-13 19:30:19 +00:00
|
|
|
/*
|
|
|
|
* Read the description line.
|
|
|
|
*/
|
1999-07-12 20:08:42 +00:00
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
if (token.type != isc_tokentype_string ||
|
2020-02-12 13:59:18 +01:00
|
|
|
strcmp(DST_AS_STR(token), PRIVATE_KEY_STR) != 0) {
|
2000-09-08 14:25:40 +00:00
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2000-09-08 14:25:40 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
if (token.type != isc_tokentype_string ||
|
2020-02-12 13:59:18 +01:00
|
|
|
(DST_AS_STR(token))[0] != 'v') {
|
2000-09-08 14:25:40 +00:00
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2000-09-08 14:25:40 +00:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
if (sscanf(DST_AS_STR(token), "v%d.%d", &major, &minor) != 2) {
|
2000-09-08 14:25:40 +00:00
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2000-09-08 14:25:40 +00:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2009-10-26 21:18:24 +00:00
|
|
|
if (major > DST_MAJOR_VERSION) {
|
2000-09-08 14:25:40 +00:00
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2000-09-08 14:25:40 +00:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
/*
|
|
|
|
* Store the private key format version number
|
|
|
|
*/
|
|
|
|
dst_key_setprivateformat(key, major, minor);
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
READLINE(lex, opt, &token);
|
|
|
|
|
2000-05-13 19:30:19 +00:00
|
|
|
/*
|
|
|
|
* Read the algorithm line.
|
|
|
|
*/
|
1999-07-12 20:08:42 +00:00
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
if (token.type != isc_tokentype_string ||
|
2020-02-12 13:59:18 +01:00
|
|
|
strcmp(DST_AS_STR(token), ALGORITHM_STR) != 0) {
|
2000-09-08 14:25:40 +00:00
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2000-09-08 14:25:40 +00:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
NEXTTOKEN(lex, opt | ISC_LEXOPT_NUMBER, &token);
|
|
|
|
if (token.type != isc_tokentype_number ||
|
2020-02-12 13:59:18 +01:00
|
|
|
token.value.as_ulong != (unsigned long)dst_key_alg(key)) {
|
2000-09-08 14:25:40 +00:00
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2000-09-08 14:25:40 +00:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
READLINE(lex, opt, &token);
|
|
|
|
|
2000-05-13 19:30:19 +00:00
|
|
|
/*
|
|
|
|
* Read the key data.
|
|
|
|
*/
|
1999-07-12 20:08:42 +00:00
|
|
|
for (n = 0; n < MAXFIELDS; n++) {
|
2020-02-12 13:59:18 +01:00
|
|
|
int tag;
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_region_t r;
|
2001-05-31 00:38:07 +00:00
|
|
|
do {
|
|
|
|
ret = isc_lex_gettoken(lex, opt, &token);
|
|
|
|
if (ret == ISC_R_EOF)
|
|
|
|
goto done;
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto fail;
|
|
|
|
} while (token.type == isc_tokentype_eol);
|
|
|
|
|
2000-09-08 14:25:40 +00:00
|
|
|
if (token.type != isc_tokentype_string) {
|
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2000-09-08 14:25:40 +00:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2013-09-04 13:53:02 +10:00
|
|
|
if (strcmp(DST_AS_STR(token), "External:") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
external = true;
|
2013-09-04 13:53:02 +10:00
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2009-10-09 06:09:21 +00:00
|
|
|
/* Numeric metadata */
|
|
|
|
tag = find_numericdata(DST_AS_STR(token));
|
2009-07-19 04:18:05 +00:00
|
|
|
if (tag >= 0) {
|
2009-10-09 06:09:21 +00:00
|
|
|
INSIST(tag < NUMERIC_NTAGS);
|
|
|
|
|
|
|
|
NEXTTOKEN(lex, opt | ISC_LEXOPT_NUMBER, &token);
|
|
|
|
if (token.type != isc_tokentype_number) {
|
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_key_setnum(key, tag, token.value.as_ulong);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Timing metadata */
|
|
|
|
tag = find_timedata(DST_AS_STR(token));
|
|
|
|
if (tag >= 0) {
|
|
|
|
INSIST(tag < TIMING_NTAGS);
|
2009-07-19 23:47:55 +00:00
|
|
|
|
2009-07-19 04:18:05 +00:00
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
if (token.type != isc_tokentype_string) {
|
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = dns_time32_fromtext(DST_AS_STR(token), &when);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
dst_key_settime(key, tag, when);
|
|
|
|
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Key data */
|
2002-01-21 01:07:32 +00:00
|
|
|
tag = find_value(DST_AS_STR(token), alg);
|
2009-10-26 21:18:24 +00:00
|
|
|
if (tag < 0 && minor > DST_MINOR_VERSION)
|
|
|
|
goto next;
|
|
|
|
else if (tag < 0) {
|
2001-09-15 00:01:58 +00:00
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2001-09-15 00:01:58 +00:00
|
|
|
}
|
2009-10-26 21:18:24 +00:00
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
priv->elements[n].tag = tag;
|
|
|
|
|
2019-07-16 15:52:14 +02:00
|
|
|
data = isc_mem_get(mctx, MAXFIELDSIZE);
|
2000-05-13 19:30:19 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&b, data, MAXFIELDSIZE);
|
1999-07-12 20:08:42 +00:00
|
|
|
ret = isc_base64_tobuffer(lex, &b, -1);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto fail;
|
2009-10-26 21:18:24 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&b, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
priv->elements[n].length = r.length;
|
|
|
|
priv->elements[n].data = r.base;
|
2009-07-19 04:18:05 +00:00
|
|
|
priv->nelements++;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
next:
|
1999-07-12 20:08:42 +00:00
|
|
|
READLINE(lex, opt, &token);
|
2002-02-27 22:12:06 +00:00
|
|
|
data = NULL;
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
done:
|
2013-09-04 13:53:02 +10:00
|
|
|
if (external && priv->nelements != 0) {
|
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
check = check_data(priv, alg, true, external);
|
2012-05-16 23:12:57 -07:00
|
|
|
if (check < 0) {
|
|
|
|
ret = DST_R_INVALIDPRIVATEKEY;
|
|
|
|
goto fail;
|
|
|
|
} else if (check != ISC_R_SUCCESS) {
|
|
|
|
ret = check;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto fail;
|
2012-05-16 23:12:57 -07:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2013-09-04 13:53:02 +10:00
|
|
|
key->external = external;
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
fail:
|
2000-06-02 23:36:14 +00:00
|
|
|
dst__privstruct_free(priv, mctx);
|
2002-02-27 22:12:06 +00:00
|
|
|
if (data != NULL)
|
|
|
|
isc_mem_put(mctx, data, MAXFIELDSIZE);
|
|
|
|
|
2000-09-08 14:25:40 +00:00
|
|
|
return (ret);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
isc_result_t
|
2000-06-06 21:58:16 +00:00
|
|
|
dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv,
|
|
|
|
const char *directory)
|
|
|
|
{
|
2020-02-12 13:59:18 +01:00
|
|
|
FILE * fp;
|
|
|
|
isc_result_t result;
|
|
|
|
char filename[NAME_MAX];
|
|
|
|
char buffer[MAXFIELDSIZE * 2];
|
2000-06-20 04:13:40 +00:00
|
|
|
isc_fsaccess_t access;
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_stdtime_t when;
|
|
|
|
uint32_t value;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_region_t r;
|
|
|
|
int major, minor;
|
|
|
|
mode_t mode;
|
|
|
|
int i, ret;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
REQUIRE(priv != NULL);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
ret = check_data(priv, dst_key_alg(key), false, key->external);
|
2012-05-16 23:12:57 -07:00
|
|
|
if (ret < 0)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_INVALIDPRIVATEKEY);
|
2012-05-16 23:12:57 -07:00
|
|
|
else if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-15 21:02:39 +00:00
|
|
|
isc_buffer_init(&b, filename, sizeof(filename));
|
2012-05-16 23:12:57 -07:00
|
|
|
result = dst_key_buildfilename(key, DST_TYPE_PRIVATE, directory, &b);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2012-07-05 16:07:31 -05:00
|
|
|
result = isc_file_mode(filename, &mode);
|
|
|
|
if (result == ISC_R_SUCCESS && mode != 0600) {
|
|
|
|
/* File exists; warn that we are changing its permissions */
|
2016-10-19 17:18:42 +02:00
|
|
|
int level;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* Windows security model is pretty different,
|
|
|
|
* e.g., there is no umask... */
|
|
|
|
level = ISC_LOG_NOTICE;
|
|
|
|
#else
|
|
|
|
level = ISC_LOG_WARNING;
|
|
|
|
#endif
|
2012-07-05 16:07:31 -05:00
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
|
2016-10-19 17:18:42 +02:00
|
|
|
DNS_LOGMODULE_DNSSEC, level,
|
2012-07-05 16:07:31 -05:00
|
|
|
"Permissions on the file %s "
|
|
|
|
"have changed from 0%o to 0600 as "
|
|
|
|
"a result of this operation.",
|
2012-07-24 12:58:04 +10:00
|
|
|
filename, (unsigned int)mode);
|
2012-07-05 16:07:31 -05:00
|
|
|
}
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
if ((fp = fopen(filename, "w")) == NULL)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_WRITEERROR);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-20 04:13:40 +00:00
|
|
|
access = 0;
|
|
|
|
isc_fsaccess_add(ISC_FSACCESS_OWNER,
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_FSACCESS_READ | ISC_FSACCESS_WRITE, &access);
|
2000-06-20 04:13:40 +00:00
|
|
|
(void)isc_fsaccess_set(filename, access);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
dst_key_getprivateformat(key, &major, &minor);
|
|
|
|
if (major == 0 && minor == 0) {
|
2009-10-26 21:18:24 +00:00
|
|
|
major = DST_MAJOR_VERSION;
|
|
|
|
minor = DST_MINOR_VERSION;
|
2009-09-02 06:29:01 +00:00
|
|
|
}
|
|
|
|
|
2000-06-20 04:13:40 +00:00
|
|
|
/* XXXDCL return value should be checked for full filesystem */
|
2009-09-02 06:29:01 +00:00
|
|
|
fprintf(fp, "%s v%d.%d\n", PRIVATE_KEY_STR, major, minor);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2018-02-14 19:28:13 +11:00
|
|
|
fprintf(fp, "%s %u ", ALGORITHM_STR, dst_key_alg(key));
|
2009-09-02 06:29:01 +00:00
|
|
|
|
2004-02-01 23:56:19 +00:00
|
|
|
/* XXXVIX this switch statement is too sparse to gen a jump table. */
|
2000-05-15 21:02:39 +00:00
|
|
|
switch (dst_key_alg(key)) {
|
2004-02-01 23:56:19 +00:00
|
|
|
case DST_ALG_DH:
|
|
|
|
fprintf(fp, "(DH)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_RSASHA1:
|
|
|
|
fprintf(fp, "(RSASHA1)\n");
|
|
|
|
break;
|
2009-07-19 04:18:05 +00:00
|
|
|
case DST_ALG_NSEC3RSASHA1:
|
|
|
|
fprintf(fp, "(NSEC3RSASHA1)\n");
|
|
|
|
break;
|
2009-10-22 02:21:31 +00:00
|
|
|
case DST_ALG_RSASHA256:
|
|
|
|
fprintf(fp, "(RSASHA256)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_RSASHA512:
|
|
|
|
fprintf(fp, "(RSASHA512)\n");
|
|
|
|
break;
|
2012-05-02 23:20:17 +10:00
|
|
|
case DST_ALG_ECDSA256:
|
|
|
|
fprintf(fp, "(ECDSAP256SHA256)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_ECDSA384:
|
|
|
|
fprintf(fp, "(ECDSAP384SHA384)\n");
|
|
|
|
break;
|
2017-07-31 15:26:00 +02:00
|
|
|
case DST_ALG_ED25519:
|
|
|
|
fprintf(fp, "(ED25519)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_ED448:
|
|
|
|
fprintf(fp, "(ED448)\n");
|
|
|
|
break;
|
2004-02-01 23:56:19 +00:00
|
|
|
case DST_ALG_HMACMD5:
|
|
|
|
fprintf(fp, "(HMAC_MD5)\n");
|
|
|
|
break;
|
2006-01-27 02:35:15 +00:00
|
|
|
case DST_ALG_HMACSHA1:
|
|
|
|
fprintf(fp, "(HMAC_SHA1)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA224:
|
|
|
|
fprintf(fp, "(HMAC_SHA224)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA256:
|
|
|
|
fprintf(fp, "(HMAC_SHA256)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA384:
|
|
|
|
fprintf(fp, "(HMAC_SHA384)\n");
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA512:
|
|
|
|
fprintf(fp, "(HMAC_SHA512)\n");
|
|
|
|
break;
|
2004-02-01 23:56:19 +00:00
|
|
|
default:
|
2004-03-18 02:58:08 +00:00
|
|
|
fprintf(fp, "(?)\n");
|
2004-02-01 23:56:19 +00:00
|
|
|
break;
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < priv->nelements; i++) {
|
2000-06-01 18:26:56 +00:00
|
|
|
const char *s;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
s = find_tag(priv->elements[i].tag);
|
|
|
|
|
|
|
|
r.base = priv->elements[i].data;
|
|
|
|
r.length = priv->elements[i].length;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&b, buffer, sizeof(buffer));
|
2009-07-19 04:18:05 +00:00
|
|
|
result = isc_base64_totext(&r, sizeof(buffer), "", &b);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-07-12 20:08:42 +00:00
|
|
|
fclose(fp);
|
1999-10-20 22:14:15 +00:00
|
|
|
return (DST_R_INVALIDPRIVATEKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&b, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(fp, "%s %.*s\n", s, (int)r.length, r.base);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2013-09-04 13:53:02 +10:00
|
|
|
if (key->external)
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(fp, "External:\n");
|
2013-09-04 13:53:02 +10:00
|
|
|
|
2009-10-09 06:09:21 +00:00
|
|
|
/* Add the metadata tags */
|
2009-09-02 06:29:01 +00:00
|
|
|
if (major > 1 || (major == 1 && minor >= 3)) {
|
2009-10-09 06:09:21 +00:00
|
|
|
for (i = 0; i < NUMERIC_NTAGS; i++) {
|
|
|
|
result = dst_key_getnum(key, i, &value);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
continue;
|
2019-09-11 16:29:33 +02:00
|
|
|
if (numerictags[i] != NULL) {
|
|
|
|
fprintf(fp, "%s %u\n", numerictags[i], value);
|
|
|
|
}
|
2009-10-09 06:09:21 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < TIMING_NTAGS; i++) {
|
2009-09-02 06:29:01 +00:00
|
|
|
result = dst_key_gettime(key, i, &when);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
isc_buffer_init(&b, buffer, sizeof(buffer));
|
|
|
|
result = dns_time32_totext(when, &b);
|
2013-09-04 13:53:02 +10:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fclose(fp);
|
|
|
|
return (DST_R_INVALIDPRIVATEKEY);
|
2013-09-04 13:53:02 +10:00
|
|
|
}
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
isc_buffer_usedregion(&b, &r);
|
|
|
|
|
2019-09-11 16:29:33 +02:00
|
|
|
if (timetags[i] != NULL) {
|
|
|
|
fprintf(fp, "%s %.*s\n", timetags[i],
|
2019-09-12 11:57:55 +02:00
|
|
|
(int)r.length, r.base);
|
2019-09-11 16:29:33 +02:00
|
|
|
}
|
2009-09-02 06:29:01 +00:00
|
|
|
}
|
2009-07-19 04:18:05 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 03:01:04 +00:00
|
|
|
fflush(fp);
|
2009-07-19 04:18:05 +00:00
|
|
|
result = ferror(fp) ? DST_R_WRITEERROR : ISC_R_SUCCESS;
|
1999-07-12 20:08:42 +00:00
|
|
|
fclose(fp);
|
2009-07-19 04:18:05 +00:00
|
|
|
return (result);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
2005-04-27 04:57:32 +00:00
|
|
|
|
|
|
|
/*! \file */
|