1
1

pki: Use consistent API for ssh_pki_export_pubkey_blob().

Этот коммит содержится в:
Andreas Schneider 2011-08-30 10:16:53 +02:00
родитель e236577503
Коммит 60b92e458e
7 изменённых файлов: 45 добавлений и 23 удалений

Просмотреть файл

@ -75,7 +75,8 @@ int ssh_pki_signature_verify_blob(ssh_session session,
size_t dlen);
/* SSH Public Key Functions */
ssh_string ssh_pki_export_pubkey_blob(const ssh_key key);
int ssh_pki_export_pubkey_blob(const ssh_key key,
ssh_string *pblob);
int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
ssh_key *pkey);

Просмотреть файл

@ -441,8 +441,8 @@ ssh_string ssh_agent_sign_data(ssh_session session,
return NULL;
}
key_blob = ssh_pki_export_pubkey_blob(pubkey);
if (key_blob == NULL) {
rc = ssh_pki_export_pubkey_blob(pubkey, &key_blob);
if (rc < 0) {
ssh_buffer_free(request);
return NULL;
}

Просмотреть файл

@ -601,8 +601,8 @@ int ssh_userauth_try_publickey(ssh_session session,
}
/* public key */
str = ssh_pki_export_pubkey_blob(pubkey);
if (str == NULL) {
rc = ssh_pki_export_pubkey_blob(pubkey, &str);
if (rc < 0) {
goto fail;
}
@ -763,8 +763,8 @@ int ssh_userauth_publickey(ssh_session session,
}
/* public key */
str = ssh_pki_export_pubkey_blob(privkey);
if (str == NULL) {
rc = ssh_pki_export_pubkey_blob(privkey, &str);
if (rc < 0) {
goto fail;
}
@ -899,8 +899,8 @@ static int ssh_userauth_agent_publickey(ssh_session session,
}
/* public key */
str = ssh_pki_export_pubkey_blob(pubkey);
if (str == NULL) {
rc = ssh_pki_export_pubkey_blob(pubkey, &str);
if (rc < 0) {
goto fail;
}

Просмотреть файл

@ -424,8 +424,8 @@ ssh_string publickey_from_file(ssh_session session, const char *filename,
return NULL;
}
key_str = ssh_pki_export_pubkey_blob(key);
if (key_str == NULL) {
rc = ssh_pki_export_pubkey_blob(key, &key_str);
if (rc < 0) {
return NULL;
}
@ -477,6 +477,7 @@ ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s) {
ssh_string publickey_to_string(ssh_public_key pubkey) {
ssh_key key;
ssh_string key_blob;
int rc;
key = ssh_key_new();
if (key == NULL) {
@ -489,7 +490,10 @@ ssh_string publickey_to_string(ssh_public_key pubkey) {
key->dsa = pubkey->dsa_pub;
key->rsa = pubkey->rsa_pub;
key_blob = ssh_pki_export_pubkey_blob(key);
rc = ssh_pki_export_pubkey_blob(key, &key_blob);
if (rc < 0) {
key_blob = NULL;
}
key->dsa = NULL;
key->rsa = NULL;

Просмотреть файл

@ -415,8 +415,8 @@ static ssh_buffer ssh_msg_userauth_build_digest(ssh_session session,
}
/* Add the publickey as blob */
str = ssh_pki_export_pubkey_blob(msg->auth_request.pubkey);
if (str == NULL) {
rc = ssh_pki_export_pubkey_blob(msg->auth_request.pubkey, &str);
if (rc < 0) {
ssh_buffer_free(buffer);
return NULL;
}

Просмотреть файл

@ -800,23 +800,39 @@ ssh_key ssh_pki_publickey_from_privatekey(const ssh_key privkey) {
}
/**
* @internal
*
* @brief Create a key_blob from a public key.
*
* The "key_blob" is encoded as per RFC 4253 section 6.6 "Public Key
* Algorithms" for any of the supported protocol 2 key types.
*
* @param[in] key A public or private key to create the public ssh_string
* @param[in] key A public or private key to create the public ssh_string
* from.
*
* @return The key_blob or NULL on error.
* @param[out] pblob A pointer to store the newly allocated key blob. You
* NEED to free it.
*
* @return SSH_OK on success, SSH_ERROR otherwise.
*
* @see ssh_string_free()
*/
ssh_string ssh_pki_export_pubkey_blob(const ssh_key key)
int ssh_pki_export_pubkey_blob(const ssh_key key,
ssh_string *pblob)
{
ssh_string blob;
if (key == NULL) {
return NULL;
return SSH_OK;
}
return pki_publickey_to_blob(key);
blob = pki_publickey_to_blob(key);
if (blob == NULL) {
return SSH_ERROR;
}
*pblob = blob;
return SSH_OK;
}
/**

Просмотреть файл

@ -159,6 +159,7 @@ static int dh_handshake_server(ssh_session session) {
ssh_string pubkey_blob;
ssh_string sig_blob;
ssh_string f;
int rc;
if (dh_generate_y(session) < 0) {
ssh_set_error(session, SSH_FATAL, "Could not create y number");
@ -196,9 +197,9 @@ static int dh_handshake_server(ssh_session session) {
return -1;
}
pubkey_blob = ssh_pki_export_pubkey_blob(pubkey);
rc = ssh_pki_export_pubkey_blob(pubkey, &pubkey_blob);
ssh_key_free(pubkey);
if (pubkey_blob == NULL) {
if (rc < 0) {
ssh_set_error_oom(session);
ssh_string_free(f);
return -1;
@ -960,8 +961,8 @@ int ssh_message_auth_reply_pk_ok_simple(ssh_message msg) {
return SSH_ERROR;
}
pubkey_blob = ssh_pki_export_pubkey_blob(msg->auth_request.pubkey);
if (pubkey_blob == NULL) {
ret = ssh_pki_export_pubkey_blob(msg->auth_request.pubkey, &pubkey_blob);
if (ret < 0) {
ssh_string_free(algo);
return SSH_ERROR;
}