From: Pekka Riikonen Date: Sun, 10 Dec 2006 16:09:38 +0000 (+0000) Subject: Fixed key pair generation with NULL return key pointers. X-Git-Tag: silc.client.1.1.beta1~122 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=640b1216155805dee8c654632bca5a2e1daa2c2a Fixed key pair generation with NULL return key pointers. --- diff --git a/lib/silcapputil/silcapputil.c b/lib/silcapputil/silcapputil.c index 2e9fbe68..c8a9a35a 100644 --- a/lib/silcapputil/silcapputil.c +++ b/lib/silcapputil/silcapputil.c @@ -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) { diff --git a/lib/silcapputil/silcapputil.h b/lib/silcapputil/silcapputil.h index 4d3b8b01..31964a46 100644 --- a/lib/silcapputil/silcapputil.h +++ b/lib/silcapputil/silcapputil.h @@ -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