]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
keygen progress indication [RT #20284]
authorFrancis Dupont <fdupont@isc.org>
Sat, 24 Oct 2009 09:46:19 +0000 (09:46 +0000)
committerFrancis Dupont <fdupont@isc.org>
Sat, 24 Oct 2009 09:46:19 +0000 (09:46 +0000)
CHANGES
bin/dnssec/dnssec-keygen.c
lib/dns/dst_api.c
lib/dns/dst_internal.h
lib/dns/gssapi_link.c
lib/dns/hmac_link.c
lib/dns/include/dst/dst.h
lib/dns/openssldh_link.c
lib/dns/openssldsa_link.c
lib/dns/opensslrsa_link.c
lib/dns/win32/libdns.def

diff --git a/CHANGES b/CHANGES
index eb9ace7af3bba31259445de3e096753ffb29b270..159108b04d648650e707c7d80288a5c9ece7be45 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+2730.  [func]          Have dnssec-keygen display a progress indication
+                       a la 'openssl genrsa' on standard error. Note
+                       when the first '.' is followed by a long stop
+                       one has the choice between slow generation vs.
+                       poor random quality, i.e., '-r /dev/urandom'.
+                       [RT #20284]
+
 2729.  [func]          When constructing a CNAME from a DNAME use the DNAME
                        TTL. [RT #20451]
 
index 0631af15b7361d0fe3e4f71b1ec4bb7a96113b45..fb5782d110a597558c856a6a29b42551948b332a 100644 (file)
@@ -29,7 +29,7 @@
  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dnssec-keygen.c,v 1.103 2009/10/24 00:00:06 each Exp $ */
+/* $Id: dnssec-keygen.c,v 1.104 2009/10/24 09:46:18 fdupont Exp $ */
 
 /*! \file */
 
@@ -74,6 +74,8 @@ dsa_size_ok(int size) {
 ISC_PLATFORM_NORETURN_PRE static void
 usage(void) ISC_PLATFORM_NORETURN_POST;
 
+static void progress(int p);
+
 static void
 usage(void) {
        fprintf(stderr, "Usage:\n");
@@ -157,6 +159,31 @@ usage(void) {
        exit (-1);
 }
 
+static void
+progress(int p)
+{
+       char c = '*';
+
+       switch (p) {
+       case 0:
+               c = '.';
+               break;
+       case 1:
+               c = '+';
+               break;
+       case 2:
+               c = '*';
+               break;
+       case 3:
+               c = '\n';
+               break;
+       default:
+               break;
+       }
+       (void) putc(c, stderr);
+       (void) fflush(stderr);
+}
+
 int
 main(int argc, char **argv) {
        char            *algname = NULL, *nametype = NULL, *type = NULL;
@@ -687,8 +714,9 @@ main(int argc, char **argv) {
                oldkey = NULL;
 
                /* generate the key */
-               ret = dst_key_generate(name, alg, size, param, flags, protocol,
-                                      rdclass, mctx, &key);
+               ret = dst_key_generate2(name, alg, size, param, flags,
+                                       protocol, rdclass, mctx, &key,
+                                       &progress);
                isc_entropy_stopcallbacksources(ectx);
 
                if (ret != ISC_R_SUCCESS) {
index 72f4fe670d7dfc32257f69d63dd3345b699e1fdb..9a08ed5d79cf98f0bda83d9d41a0749ed42d02c5 100644 (file)
@@ -31,7 +31,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: dst_api.c,v 1.43 2009/10/22 02:21:30 each Exp $
+ * $Id: dst_api.c,v 1.44 2009/10/24 09:46:18 fdupont Exp $
  */
 
 /*! \file */
@@ -752,6 +752,18 @@ dst_key_generate(dns_name_t *name, unsigned int alg,
                 unsigned int flags, unsigned int protocol,
                 dns_rdataclass_t rdclass,
                 isc_mem_t *mctx, dst_key_t **keyp)
+{
+       return (dst_key_generate2(name, alg, bits, param, flags, protocol,
+                                 rdclass, mctx, keyp, NULL));
+}
+
+isc_result_t
+dst_key_generate2(dns_name_t *name, unsigned int alg,
+                 unsigned int bits, unsigned int param,
+                 unsigned int flags, unsigned int protocol,
+                 dns_rdataclass_t rdclass,
+                 isc_mem_t *mctx, dst_key_t **keyp,
+                 void (*callback)(int))
 {
        dst_key_t *key;
        isc_result_t ret;
@@ -778,7 +790,7 @@ dst_key_generate(dns_name_t *name, unsigned int alg,
                return (DST_R_UNSUPPORTEDALG);
        }
 
-       ret = key->func->generate(key, param);
+       ret = key->func->generate(key, param, callback);
        if (ret != ISC_R_SUCCESS) {
                dst_key_free(&key);
                return (ret);
index c0c09a8aa2d0df66c226df50b2ceecc6f16f1dfb..19b0f8bf2cda66de692578986a948f6448ae4d10 100644 (file)
@@ -29,7 +29,7 @@
  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dst_internal.h,v 1.21 2009/10/22 02:21:30 each Exp $ */
+/* $Id: dst_internal.h,v 1.22 2009/10/24 09:46:19 fdupont Exp $ */
 
 #ifndef DST_DST_INTERNAL_H
 #define DST_DST_INTERNAL_H 1
@@ -170,7 +170,8 @@ struct dst_func {
        isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
        isc_boolean_t (*paramcompare)(const dst_key_t *key1,
                                      const dst_key_t *key2);
-       isc_result_t (*generate)(dst_key_t *key, int parms);
+       isc_result_t (*generate)(dst_key_t *key, int parms,
+                                void (*callback)(int));
        isc_boolean_t (*isprivate)(const dst_key_t *key);
        void (*destroy)(dst_key_t *key);
 
index 0dd27bbea3e91a0469d2869c2a6699b6f029ed4f..edc2bf26ff6d29ee784d6a9be5668f25c0a4637a 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 /*
- * $Id: gssapi_link.c,v 1.12 2008/11/11 03:55:01 marka Exp $
+ * $Id: gssapi_link.c,v 1.13 2009/10/24 09:46:19 fdupont Exp $
  */
 
 #include <config.h>
@@ -254,9 +254,10 @@ gssapi_compare(const dst_key_t *key1, const dst_key_t *key2) {
 }
 
 static isc_result_t
-gssapi_generate(dst_key_t *key, int unused) {
+gssapi_generate(dst_key_t *key, int unused, void (*callback)(int)) {
        UNUSED(key);
        UNUSED(unused);
+       UNUSED(callback);
 
        /* No idea */
        return (ISC_R_FAILURE);
@@ -292,7 +293,7 @@ static dst_func_t gssapi_functions = {
        NULL, /*%< tofile */
        NULL, /*%< parse */
        NULL, /*%< cleanup */
-       NULL  /*%< fromlabel */
+       NULL,  /*%< fromlabel */
 };
 
 isc_result_t
index 24d836538c8d5d8cb05b8e18d33dfcbdae418c15..70eb41bef9622882a8d38439fc29fb6f796e7125 100644 (file)
@@ -31,7 +31,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: hmac_link.c,v 1.14 2009/10/09 06:09:21 each Exp $
+ * $Id: hmac_link.c,v 1.15 2009/10/24 09:46:19 fdupont Exp $
  */
 
 #include <config.h>
@@ -149,12 +149,14 @@ hmacmd5_compare(const dst_key_t *key1, const dst_key_t *key2) {
 }
 
 static isc_result_t
-hmacmd5_generate(dst_key_t *key, int pseudorandom_ok) {
+hmacmd5_generate(dst_key_t *key, int pseudorandom_ok, void (*callback)(int)) {
        isc_buffer_t b;
        isc_result_t ret;
        int bytes;
        unsigned char data[HMAC_LEN];
 
+       UNUSED(callback);
+
        bytes = (key->key_size + 7) / 8;
        if (bytes > HMAC_LEN) {
                bytes = HMAC_LEN;
@@ -420,12 +422,14 @@ hmacsha1_compare(const dst_key_t *key1, const dst_key_t *key2) {
 }
 
 static isc_result_t
-hmacsha1_generate(dst_key_t *key, int pseudorandom_ok) {
+hmacsha1_generate(dst_key_t *key, int pseudorandom_ok, void (*callback)(int)) {
        isc_buffer_t b;
        isc_result_t ret;
        int bytes;
        unsigned char data[HMAC_LEN];
 
+       UNUSED(callback);
+
        bytes = (key->key_size + 7) / 8;
        if (bytes > HMAC_LEN) {
                bytes = HMAC_LEN;
@@ -691,12 +695,16 @@ hmacsha224_compare(const dst_key_t *key1, const dst_key_t *key2) {
 }
 
 static isc_result_t
-hmacsha224_generate(dst_key_t *key, int pseudorandom_ok) {
+hmacsha224_generate(dst_key_t *key, int pseudorandom_ok,
+                   void (*callback)(int))
+{
        isc_buffer_t b;
        isc_result_t ret;
        int bytes;
        unsigned char data[HMAC_LEN];
 
+       UNUSED(callback);
+
        bytes = (key->key_size + 7) / 8;
        if (bytes > HMAC_LEN) {
                bytes = HMAC_LEN;
@@ -962,12 +970,16 @@ hmacsha256_compare(const dst_key_t *key1, const dst_key_t *key2) {
 }
 
 static isc_result_t
-hmacsha256_generate(dst_key_t *key, int pseudorandom_ok) {
+hmacsha256_generate(dst_key_t *key, int pseudorandom_ok,
+                   void (*callback)(int))
+{
        isc_buffer_t b;
        isc_result_t ret;
        int bytes;
        unsigned char data[HMAC_LEN];
 
+       UNUSED(callback);
+
        bytes = (key->key_size + 7) / 8;
        if (bytes > HMAC_LEN) {
                bytes = HMAC_LEN;
@@ -1233,12 +1245,16 @@ hmacsha384_compare(const dst_key_t *key1, const dst_key_t *key2) {
 }
 
 static isc_result_t
-hmacsha384_generate(dst_key_t *key, int pseudorandom_ok) {
+hmacsha384_generate(dst_key_t *key, int pseudorandom_ok,
+                   void (*callback)(int))
+{
        isc_buffer_t b;
        isc_result_t ret;
        int bytes;
        unsigned char data[HMAC_LEN];
 
+       UNUSED(callback);
+
        bytes = (key->key_size + 7) / 8;
        if (bytes > HMAC_LEN) {
                bytes = HMAC_LEN;
@@ -1504,12 +1520,16 @@ hmacsha512_compare(const dst_key_t *key1, const dst_key_t *key2) {
 }
 
 static isc_result_t
-hmacsha512_generate(dst_key_t *key, int pseudorandom_ok) {
+hmacsha512_generate(dst_key_t *key, int pseudorandom_ok,
+                   void (*callback)(int))
+{
        isc_buffer_t b;
        isc_result_t ret;
        int bytes;
        unsigned char data[HMAC_LEN];
 
+       UNUSED(callback);
+
        bytes = (key->key_size + 7) / 8;
        if (bytes > HMAC_LEN) {
                bytes = HMAC_LEN;
index fffd4b40d2f57cf89afb86c46499e510be1ce048..2217139e3d2b12b2ba682e2e1c82243506b9403b 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dst.h,v 1.23 2009/10/22 02:21:31 each Exp $ */
+/* $Id: dst.h,v 1.24 2009/10/24 09:46:19 fdupont Exp $ */
 
 #ifndef DST_DST_H
 #define DST_DST_H 1
@@ -479,6 +479,14 @@ dst_key_generate(dns_name_t *name, unsigned int alg,
                 unsigned int flags, unsigned int protocol,
                 dns_rdataclass_t rdclass,
                 isc_mem_t *mctx, dst_key_t **keyp);
+
+isc_result_t
+dst_key_generate2(dns_name_t *name, unsigned int alg,
+                 unsigned int bits, unsigned int param,
+                 unsigned int flags, unsigned int protocol,
+                 dns_rdataclass_t rdclass,
+                 isc_mem_t *mctx, dst_key_t **keyp,
+                 void (*callback)(int));
 /*%<
  * Generate a DST key (or keypair) with the supplied parameters.  The
  * interpretation of the "param" field depends on the algorithm:
index 43506d5555b645c9d5a42df73065310b18576674..8773cbf9c3080824ed2c95ad0f70d58aa572d53e 100644 (file)
@@ -31,7 +31,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: openssldh_link.c,v 1.16 2009/09/03 23:48:13 tbox Exp $
+ * $Id: openssldh_link.c,v 1.17 2009/10/24 09:46:19 fdupont Exp $
  */
 
 #ifdef OPENSSL
@@ -149,12 +149,28 @@ openssldh_paramcompare(const dst_key_t *key1, const dst_key_t *key2) {
        return (ISC_TRUE);
 }
 
+#if OPENSSL_VERSION_NUMBER > 0x00908000L
+static int
+progress_cb(int p, int n, BN_GENCB *cb)
+{
+       void (*callback)(int) = cb->arg;
+
+       UNUSED(n);
+       if (callback != NULL)
+               callback(p);
+       return (1);
+}
+#endif
+
 static isc_result_t
-openssldh_generate(dst_key_t *key, int generator) {
+openssldh_generate(dst_key_t *key, int generator, void (*callback)(int)) {
+       DH *dh = NULL;
 #if OPENSSL_VERSION_NUMBER > 0x00908000L
        BN_GENCB cb;
+#else
+
+       UNUSED(callback);
 #endif
-       DH *dh = NULL;
 
        if (generator == 0) {
                if (key->key_size == 768 ||
@@ -181,7 +197,11 @@ openssldh_generate(dst_key_t *key, int generator) {
                if (dh == NULL)
                        return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
 
-               BN_GENCB_set_old(&cb, NULL, NULL);
+               if (callback == NULL) {
+                       BN_GENCB_set_old(&cb, NULL, NULL);
+               } else {
+                       BN_GENCB_set(&cb, &progress_cb, callback);
+               }
 
                if (!DH_generate_parameters_ex(dh, key->key_size, generator,
                                               &cb)) {
index 3cad0f907a79f5904b83f37dfeeda4f0f71cb382..e25b27e6bae070e61c44d212b27bba481bc2c1bc 100644 (file)
@@ -29,7 +29,7 @@
  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: openssldsa_link.c,v 1.16 2009/09/03 04:09:58 marka Exp $ */
+/* $Id: openssldsa_link.c,v 1.17 2009/10/24 09:46:19 fdupont Exp $ */
 
 #ifdef OPENSSL
 #ifndef USE_EVP
@@ -313,15 +313,30 @@ openssldsa_compare(const dst_key_t *key1, const dst_key_t *key2) {
        return (ISC_TRUE);
 }
 
-static isc_result_t
-openssldsa_generate(dst_key_t *key, int unused) {
 #if OPENSSL_VERSION_NUMBER > 0x00908000L
-       BN_GENCB cb;
+static int
+progress_cb(int p, int n, BN_GENCB *cb)
+{
+       void (*callback)(int) = cb->arg;
+
+       UNUSED(n);
+       if (callback != NULL)
+               callback(p);
+       return (1);
+}
 #endif
+
+static isc_result_t
+openssldsa_generate(dst_key_t *key, int unused, void (*callback)(int)) {
        DSA *dsa;
        unsigned char rand_array[ISC_SHA1_DIGESTLENGTH];
        isc_result_t result;
+#if OPENSSL_VERSION_NUMBER > 0x00908000L
+       BN_GENCB cb;
 
+#else
+       UNUSED(callback);
+#endif
        UNUSED(unused);
 
        result = dst__entropy_getdata(rand_array, sizeof(rand_array),
@@ -334,7 +349,11 @@ openssldsa_generate(dst_key_t *key, int unused) {
        if (dsa == NULL)
                return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
 
-       BN_GENCB_set_old(&cb, NULL, NULL);
+       if (callback == NULL) {
+               BN_GENCB_set_old(&cb, NULL, NULL);
+       } else {
+               BN_GENCB_set(&cb, &progress_cb, callback);
+       }
 
        if (!DSA_generate_parameters_ex(dsa, key->key_size, rand_array,
                                        ISC_SHA1_DIGESTLENGTH,  NULL, NULL,
index 71c3fa90a5be1efd14696af0c817ee5290b0e4fb..68b0a84d8c43aba2b20c8a3a194468525e93a5be 100644 (file)
@@ -17,7 +17,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: opensslrsa_link.c,v 1.32 2009/10/22 23:48:07 tbox Exp $
+ * $Id: opensslrsa_link.c,v 1.33 2009/10/24 09:46:19 fdupont Exp $
  */
 #ifdef OPENSSL
 #ifndef USE_EVP
@@ -653,8 +653,21 @@ opensslrsa_compare(const dst_key_t *key1, const dst_key_t *key2) {
        return (ISC_TRUE);
 }
 
+#if OPENSSL_VERSION_NUMBER > 0x00908000L
+static int
+progress_cb(int p, int n, BN_GENCB *cb)
+{
+       void (*callback)(int) = cb->arg;
+
+       UNUSED(n);
+       if (callback != NULL)
+               callback(p);
+       return (1);
+}
+#endif
+
 static isc_result_t
-opensslrsa_generate(dst_key_t *key, int exp) {
+opensslrsa_generate(dst_key_t *key, int exp, void (*callback)(int)) {
 #if OPENSSL_VERSION_NUMBER > 0x00908000L
        BN_GENCB cb;
        RSA *rsa = RSA_new();
@@ -682,7 +695,11 @@ opensslrsa_generate(dst_key_t *key, int exp) {
                BN_set_bit(e, 32);
        }
 
-       BN_GENCB_set_old(&cb, NULL, NULL);
+       if (callback == NULL) {
+               BN_GENCB_set_old(&cb, NULL, NULL);
+       } else {
+               BN_GENCB_set(&cb, &progress_cb, callback);
+       }
 
        if (RSA_generate_key_ex(rsa, key->key_size, e, &cb)) {
                BN_free(e);
@@ -713,8 +730,12 @@ err:
 #if USE_EVP
        EVP_PKEY *pkey = EVP_PKEY_new();
 
+       UNUSED(callback);
+
        if (pkey == NULL)
                return (ISC_R_NOMEMORY);
+#else
+       UNUSED(callback);
 #endif
 
        if (exp == 0)
index 657c72c662504be9c20884d5263ca627f22d5372..f0c8522e01e9a67913da4eb6d48674f33074816e 100644 (file)
@@ -881,6 +881,7 @@ dst_key_fromgssapi
 dst_key_fromlabel
 dst_key_fromnamedfile
 dst_key_generate
+dst_key_generate2
 dst_key_getprivateformat
 dst_key_gettime
 dst_key_id