summaryrefslogtreecommitdiffstats
path: root/lib/dns/dst_parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dns/dst_parse.c')
-rw-r--r--lib/dns/dst_parse.c61
1 files changed, 54 insertions, 7 deletions
diff --git a/lib/dns/dst_parse.c b/lib/dns/dst_parse.c
index 8e9efbd..95896c4 100644
--- a/lib/dns/dst_parse.c
+++ b/lib/dns/dst_parse.c
@@ -44,8 +44,10 @@
#include <isc/stdtime.h>
#include <isc/string.h>
#include <isc/util.h>
+#include <isc/file.h>
#include <dns/time.h>
+#include <dns/log.h>
#include "dst_internal.h"
#include "dst_parse.h"
@@ -106,6 +108,8 @@ static struct parse_map map[] = {
{TAG_GOST_PRIVASN1, "GostAsn1:"},
+ {TAG_ECDSA_PRIVATEKEY, "PrivateKey:"},
+
{TAG_HMACMD5_KEY, "Key:"},
{TAG_HMACMD5_BITS, "Bits:"},
@@ -251,6 +255,15 @@ check_gost(const dst_private_t *priv) {
}
static int
+check_ecdsa(const dst_private_t *priv) {
+ if (priv->nelements != ECDSA_NTAGS)
+ return (-1);
+ if (priv->elements[0].tag != TAG(DST_ALG_ECDSA256, 0))
+ return (-1);
+ return (0);
+}
+
+static int
check_hmac_md5(const dst_private_t *priv, isc_boolean_t old) {
int i, j;
@@ -302,13 +315,20 @@ check_data(const dst_private_t *priv, const unsigned int alg,
switch (alg) {
case DST_ALG_RSAMD5:
case DST_ALG_RSASHA1:
+ case DST_ALG_NSEC3RSASHA1:
+ case DST_ALG_RSASHA256:
+ case DST_ALG_RSASHA512:
return (check_rsa(priv));
case DST_ALG_DH:
return (check_dh(priv));
case DST_ALG_DSA:
+ case DST_ALG_NSEC3DSA:
return (check_dsa(priv));
case DST_ALG_ECCGOST:
return (check_gost(priv));
+ case DST_ALG_ECDSA256:
+ case DST_ALG_ECDSA384:
+ return (check_ecdsa(priv));
case DST_ALG_HMACMD5:
return (check_hmac_md5(priv, old));
case DST_ALG_HMACSHA1:
@@ -345,7 +365,7 @@ isc_result_t
dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex,
isc_mem_t *mctx, dst_private_t *priv)
{
- int n = 0, major, minor;
+ int n = 0, major, minor, check;
isc_buffer_t b;
isc_token_t token;
unsigned char *data = NULL;
@@ -515,8 +535,14 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex,
data = NULL;
}
done:
- if (check_data(priv, alg, ISC_TRUE) < 0)
+ check = check_data(priv, alg, ISC_TRUE);
+ if (check < 0) {
+ ret = DST_R_INVALIDPRIVATEKEY;
+ goto fail;
+ } else if (check != ISC_R_SUCCESS) {
+ ret = check;
goto fail;
+ }
return (ISC_R_SUCCESS);
@@ -533,7 +559,6 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv,
const char *directory)
{
FILE *fp;
- int ret, i;
isc_result_t result;
char filename[ISC_DIR_NAMEMAX];
char buffer[MAXFIELDSIZE * 2];
@@ -543,16 +568,32 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv,
isc_buffer_t b;
isc_region_t r;
int major, minor;
+ mode_t mode;
+ int i, ret;
REQUIRE(priv != NULL);
- if (check_data(priv, dst_key_alg(key), ISC_FALSE) < 0)
+ ret = check_data(priv, dst_key_alg(key), ISC_FALSE);
+ if (ret < 0)
return (DST_R_INVALIDPRIVATEKEY);
+ else if (ret != ISC_R_SUCCESS)
+ return (ret);
isc_buffer_init(&b, filename, sizeof(filename));
- ret = dst_key_buildfilename(key, DST_TYPE_PRIVATE, directory, &b);
- if (ret != ISC_R_SUCCESS)
- return (ret);
+ result = dst_key_buildfilename(key, DST_TYPE_PRIVATE, directory, &b);
+ if (result != ISC_R_SUCCESS)
+ return (result);
+
+ result = isc_file_mode(filename, &mode);
+ if (result == ISC_R_SUCCESS && mode != 0600) {
+ /* File exists; warn that we are changing its permissions */
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
+ DNS_LOGMODULE_DNSSEC, ISC_LOG_WARNING,
+ "Permissions on the file %s "
+ "have changed from 0%o to 0600 as "
+ "a result of this operation.",
+ filename, (unsigned int)mode);
+ }
if ((fp = fopen(filename, "w")) == NULL)
return (DST_R_WRITEERROR);
@@ -603,6 +644,12 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv,
case DST_ALG_ECCGOST:
fprintf(fp, "(ECC-GOST)\n");
break;
+ case DST_ALG_ECDSA256:
+ fprintf(fp, "(ECDSAP256SHA256)\n");
+ break;
+ case DST_ALG_ECDSA384:
+ fprintf(fp, "(ECDSAP384SHA384)\n");
+ break;
case DST_ALG_HMACMD5:
fprintf(fp, "(HMAC_MD5)\n");
break;
OpenPOWER on IntegriCloud