X-RT-Original-Encoding: utf-8 MIME-Version: 1.0 X-Cam-Scannerinfo: http://help.uis.cam.ac.uk/email-scanner-virus To: "Tony Finch via RT" Received: from mx.pao1.isc.org (mx.pao1.isc.org [149.20.64.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx.pao1.isc.org", Issuer "COMODO RSA Organization Validation Secure Server CA" (not verified)) by bugs.isc.org (Postfix) with ESMTPS id F3C73D78B08 for ; Mon, 25 Sep 2017 11:18:08 +0000 (UTC) Received: from ppsw-32.csi.cam.ac.uk (ppsw-32.csi.cam.ac.uk [131.111.8.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx.pao1.isc.org (Postfix) with ESMTPS id D75203494F1 for ; Mon, 25 Sep 2017 11:17:12 +0000 (UTC) Received: from grey.csi.cam.ac.uk ([131.111.57.57]:45824) by ppsw-32.csi.cam.ac.uk (ppsw.cam.ac.uk [131.111.8.136]:25) with esmtps (TLSv1:ECDHE-RSA-AES256-SHA:256) id 1dwRNv-000PTk-0l (Exim 4.89) for bind9-confidential@isc.org (return-path ); Mon, 25 Sep 2017 12:17:11 +0100 From dot@dotat.at Mon Sep 25 11:18:09 2017 User-Agent: Alpine 2.11 (DEB 23 2013-08-11) Subject: [ISC-Bugs #46090] [PATCH] dnssec-dsfromkey: make better use of shared dnssectool code Return-Path: Delivered-To: bind9-confidential@bugs.isc.org content-type: TEXT/PLAIN; charset="utf-8" X-Cam-Antivirus: no malware found From: "Tony Finch" X-RT-Incoming-Encryption: Not encrypted X-RT-Interface: Email X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mx.pao1.isc.org In-Reply-To: X-Original-To: bind9-confidential@bugs.isc.org Message-ID: References: Date: Mon, 25 Sep 2017 12:17:11 +0100 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=3.4.0 RT-Message-ID: Content-Length: 3272 Use strtottl() for the -T option, and make a new strtodigest() function for parsing DS digest type names. --- bin/dnssec/dnssec-dsfromkey.c | 24 +++--------------------- bin/dnssec/dnssectool.c | 19 +++++++++++++++++++ bin/dnssec/dnssectool.h | 3 +++ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/bin/dnssec/dnssec-dsfromkey.c b/bin/dnssec/dnssec-dsfromkey.c index ad44c3c..8597d05 100644 --- a/bin/dnssec/dnssec-dsfromkey.c +++ b/bin/dnssec/dnssec-dsfromkey.c @@ -346,7 +346,7 @@ usage(void) { int main(int argc, char **argv) { - char *algname = NULL, *classname = NULL; + char *classname = NULL; char *filename = NULL, *dir = NULL, *namestr; char *lookaside = NULL; char *endp; @@ -393,7 +393,7 @@ main(int argc, char **argv) { showall = ISC_TRUE; break; case 'a': - algname = isc_commandline_argument; + dtype = strtodsdigest(isc_commandline_argument); both = ISC_FALSE; break; case 'C': @@ -430,7 +430,7 @@ main(int argc, char **argv) { break; case 'T': emitttl = ISC_TRUE; - ttl = atol(isc_commandline_argument); + ttl = strtottl(isc_commandline_argument); break; case 'v': verbose = strtol(isc_commandline_argument, &endp, 0); @@ -460,24 +460,6 @@ main(int argc, char **argv) { } } - if (algname != NULL) { - if (strcasecmp(algname, "SHA1") == 0 || - strcasecmp(algname, "SHA-1") == 0) - dtype = DNS_DSDIGEST_SHA1; - else if (strcasecmp(algname, "SHA256") == 0 || - strcasecmp(algname, "SHA-256") == 0) - dtype = DNS_DSDIGEST_SHA256; -#if defined(HAVE_OPENSSL_GOST) || defined(HAVE_PKCS11_GOST) - else if (strcasecmp(algname, "GOST") == 0) - dtype = DNS_DSDIGEST_GOST; -#endif - else if (strcasecmp(algname, "SHA384") == 0 || - strcasecmp(algname, "SHA-384") == 0) - dtype = DNS_DSDIGEST_SHA384; - else - fatal("unknown algorithm %s", algname); - } - rdclass = strtoclass(classname); if (usekeyset && filename != NULL) diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index 908a2bc..6e67391 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -414,6 +414,25 @@ strtoclass(const char *str) { return (rdclass); } +unsigned int +strtodsdigest(const char *algname) { + if (strcasecmp(algname, "SHA1") == 0 || + strcasecmp(algname, "SHA-1") == 0) + return (DNS_DSDIGEST_SHA1); + else if (strcasecmp(algname, "SHA256") == 0 || + strcasecmp(algname, "SHA-256") == 0) + return (DNS_DSDIGEST_SHA256); +#if defined(HAVE_OPENSSL_GOST) || defined(HAVE_PKCS11_GOST) + else if (strcasecmp(algname, "GOST") == 0) + return (DNS_DSDIGEST_GOST); +#endif + else if (strcasecmp(algname, "SHA384") == 0 || + strcasecmp(algname, "SHA-384") == 0) + return (DNS_DSDIGEST_SHA384); + else + fatal("unknown algorithm %s", algname); +} + isc_result_t try_dir(const char *dirname) { isc_result_t result; diff --git a/bin/dnssec/dnssectool.h b/bin/dnssec/dnssectool.h index 13cbf33..8de518b 100644 --- a/bin/dnssec/dnssectool.h +++ b/bin/dnssec/dnssectool.h @@ -65,6 +65,9 @@ isc_stdtime_t strtotime(const char *str, isc_int64_t now, isc_int64_t base, isc_boolean_t *setp); +unsigned int +strtodsdigest(const char *str); + dns_rdataclass_t strtoclass(const char *str); -- 2.10.1.445.g3cdd5d1