diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2011-08-30 10:28:57 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-08-30 10:28:57 +0200 |
commit | 822c68eb8e06204170a2b0f9641f5886a45d397f (patch) | |
tree | 92b0872cc10f949108848309dc6aeb3ab0307ee9 /src | |
parent | 60b92e458e1cf16f0029d9251e0f117ff27a02d0 (diff) | |
download | libssh-822c68eb8e06204170a2b0f9641f5886a45d397f.tar.gz libssh-822c68eb8e06204170a2b0f9641f5886a45d397f.tar.xz libssh-822c68eb8e06204170a2b0f9641f5886a45d397f.zip |
pki: Use consistent API for ssh_pki_export_privkey_to_pubkey().
Diffstat (limited to 'src')
-rw-r--r-- | src/auth.c | 4 | ||||
-rw-r--r-- | src/pki.c | 24 | ||||
-rw-r--r-- | src/server.c | 4 |
3 files changed, 23 insertions, 9 deletions
@@ -1118,8 +1118,8 @@ int ssh_userauth_publickey_auto(ssh_session session, continue; } - pubkey = ssh_pki_publickey_from_privatekey(privkey); - if (pubkey == NULL) { + rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey); + if (rc == SSH_ERROR) { ssh_key_free(privkey); return SSH_AUTH_ERROR; } @@ -784,19 +784,33 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey) } /** - * @brief Generate and duplicate a public key from a private key. + * @brief Create a public key from a private key. * - * @param[in] privkey The private key to get the public key from. + * @param[in] privkey The private key to get the public key from. + * + * @param[out] pkey A pointer to store the newly allocated public key. You + * NEED to free the key. * * @return A public key, NULL on error. + * + * @see ssh_key_free() */ -ssh_key ssh_pki_publickey_from_privatekey(const ssh_key privkey) { +int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey, + ssh_key *pkey) +{ + ssh_key pubkey; if (privkey == NULL || !ssh_key_is_private(privkey)) { - return NULL; + return SSH_ERROR; } - return pki_key_dup(privkey, 1); + pubkey = pki_key_dup(privkey, 1); + if (pubkey == NULL) { + return SSH_ERROR; + } + + *pkey = pubkey; + return SSH_OK; } /** diff --git a/src/server.c b/src/server.c index 7f3618a..5b2ccee 100644 --- a/src/server.c +++ b/src/server.c @@ -189,8 +189,8 @@ static int dh_handshake_server(ssh_session session) { privkey = NULL; } - pubkey = ssh_pki_publickey_from_privatekey(privkey); - if (pubkey == NULL) { + rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey); + if (rc < 0) { ssh_set_error(session, SSH_FATAL, "Could not get the public key from the private key"); ssh_string_free(f); |