/** @brief import a base64 formated key from a memory c-string * * @param key The key to fill, created with ssh_key_new() * @param session The ssh session * @param b64_key The c-string holding the base64 encoded key * @param passphrase The passphrase to decrypt the key, or NULL * * @return SSH_ERROR in case of error, SSH_OK otherwise */ int ssh_pki_import_privkey_base64(ssh_key key, ssh_session session, const char *b64_key, const char *passphrase) { ssh_private_key priv; if(key == NULL || session == NULL) { return SSH_ERROR; } if(b64_key == NULL || !*b64_key) { return SSH_ERROR; } priv = privatekey_from_base64(session, b64_key, 0, passphrase); if(priv == NULL) { return SSH_ERROR; } ssh_key_clean(key); key->dsa = priv->dsa_priv; key->rsa = priv->rsa_priv; key->type = priv->type; key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC; key->type_c = ssh_type_to_char(key->type); SAFE_FREE(priv); return SSH_OK; }
/** * @brief import a key from a file * @param[out] key the ssh_key to update * @param[in] session The SSH Session to use. If a key decryption callback is set, it will * be used to ask for the passphrase. * @param[in] filename The filename of the the private key. * @param[in] passphrase The passphrase to decrypt the private key. Set to null * if none is needed or it is unknown. * @returns SSH_OK on success, SSH_ERROR otherwise. **/ int ssh_key_import_private(ssh_key key, ssh_session session, const char *filename, const char *passphrase){ ssh_private_key priv=privatekey_from_file(session,filename,0,passphrase); if(priv==NULL) return SSH_ERROR; ssh_key_clean(key); key->dsa=priv->dsa_priv; key->rsa=priv->rsa_priv; key->type=priv->type; key->flags=SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC; key->type_c=ssh_type_to_char(key->type); SAFE_FREE(priv); return SSH_OK; }
/** * @brief deallocate a SSH key * @param[in] key ssh_key handle to free */ void ssh_key_free (ssh_key key){ if(key){ ssh_key_clean(key); SAFE_FREE(key); } }