Fixed key pair generation with NULL return key pointers.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 10 Dec 2006 16:09:38 +0000 (16:09 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 10 Dec 2006 16:09:38 +0000 (16:09 +0000)
lib/silcapputil/silcapputil.c
lib/silcapputil/silcapputil.h

index 2e9fbe685ff6bc3e51a86005aaec33ca77f0d877..c8a9a35a1ca0b39f0d09555da630e2fc9e10f4bc 100644 (file)
@@ -71,6 +71,8 @@ SilcBool silc_create_key_pair(const char *pkcs_name,
   char *alg = pkcs_name ? strdup(pkcs_name) : NULL;
   char *identifier = pub_identifier ? strdup(pub_identifier) : NULL;
   char *pass = passphrase ? strdup(passphrase) : NULL;
+  SilcPublicKey public_key;
+  SilcPrivateKey private_key;
 
   if (interactive && (!alg || !pub_filename || !prv_filename))
     printf("\
@@ -192,18 +194,28 @@ New pair of keys will be created.  Please, answer to following questions.\n\
 
   /* Generate keys */
   if (!silc_pkcs_silc_generate_key(alg, "pkcs1-no-oid", key_len_bits,
-                                  identifier, rng, return_public_key,
-                                  return_private_key))
+                                  identifier, rng, &public_key,
+                                  &private_key))
     return FALSE;
 
   /* Save public key into file */
-  silc_pkcs_save_public_key(pkfile, *return_public_key, SILC_PKCS_FILE_BASE64);
+  silc_pkcs_save_public_key(pkfile, public_key, SILC_PKCS_FILE_BASE64);
 
   /* Save private key into file */
-  silc_pkcs_save_private_key(prvfile, *return_private_key,
+  silc_pkcs_save_private_key(prvfile, private_key,
                             (const unsigned char *)pass, strlen(pass),
                             SILC_PKCS_FILE_BIN, rng);
 
+  if (return_public_key)
+    *return_public_key = public_key;
+  else
+    silc_pkcs_public_key_free(public_key);
+
+  if (return_private_key)
+    *return_private_key = private_key;
+  else
+    silc_pkcs_private_key_free(private_key);
+
   printf("Public key has been saved into `%s'.\n", pkfile);
   printf("Private key has been saved into `%s'.\n", prvfile);
   if (interactive) {
index 4d3b8b01475da53a19ef2fe4796185838d3a2014..31964a46a0701eaddffa9073640fb08e86511336 100644 (file)
@@ -58,7 +58,8 @@
  *    and `prv_filename' is the public key and private key filenames.
  *    The `pub_identifier' is the public key identifier (for example:
  *    "UN=foobar, HN=hostname"), or if NULL the routine generates it
- *    automatically.
+ *    automatically.  The `return_public_key' and `return_private_key' may
+ *    be NULL.
  *
  *    The `passphrase' is the passphrase that is used to encrypt the
  *    private key file.  It is recommended that you would protect your