/** * @brief Get the server public key from a session. * * @param[in] session The session to get the key from. * * @param[out] key A pointer to store the allocated key. You need to free * the key. * * @return SSH_OK on success, SSH_ERROR on errror. * * @see ssh_key_free() */ int ssh_get_publickey(ssh_session session, ssh_key *key) { if (session==NULL || session->current_crypto ==NULL || session->current_crypto->server_pubkey == NULL) { return SSH_ERROR; } return ssh_pki_import_pubkey_blob(session->current_crypto->server_pubkey, key); }
/* caller has to free commment */ ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session, char **comment) { struct ssh_key_struct *key; struct ssh_string_struct *blob = NULL; struct ssh_string_struct *tmp = NULL; int rc; if (session->agent->count == 0) { return NULL; } switch(session->version) { case 1: return NULL; case 2: /* get the blob */ blob = buffer_get_ssh_string(session->agent->ident); if (blob == NULL) { return NULL; } /* get the comment */ tmp = buffer_get_ssh_string(session->agent->ident); if (tmp == NULL) { ssh_string_free(blob); return NULL; } if (comment) { *comment = ssh_string_to_char(tmp); } else { ssh_string_free(blob); ssh_string_free(tmp); return NULL; } ssh_string_free(tmp); /* get key from blob */ rc = ssh_pki_import_pubkey_blob(blob, &key); ssh_string_free(blob); if (rc == SSH_ERROR) { return NULL; } break; default: return NULL; } return key; }
/** * @internal * * @brief Import a certificate from a ssh string. * * @param[in] cert_blob The cert blob to import as specified in RFC 4253 section * 6.6 "Public Key Algorithms". * * @param[out] pkey A pointer where the allocated key can be stored. You * need to free the memory. * * @return SSH_OK on success, SSH_ERROR on error. * * @see ssh_key_free() */ int ssh_pki_import_cert_blob(const ssh_string cert_blob, ssh_key *pkey) { return ssh_pki_import_pubkey_blob(cert_blob, pkey); }