14#include <gnutls/gnutls.h>
15#include <gnutls/x509.h>
16#include <libssh/libssh.h>
23#define G_LOG_DOMAIN "libgvm util"
37 gnutls_x509_privkey_t key;
38 char buffer[16 * 2048];
40 size_t size =
sizeof (buffer);
42 rc = gnutls_x509_privkey_init (&key);
45 data.size = strlen (pkcs8_key);
46 data.data = (
void *) g_strdup (pkcs8_key);
47 rc = gnutls_x509_privkey_import_pkcs8 (key, &data, GNUTLS_X509_FMT_PEM,
48 passphrase ? passphrase :
"", 0);
51 gnutls_x509_privkey_deinit (key);
55 rc = gnutls_x509_privkey_export (key, GNUTLS_X509_FMT_PEM, buffer, &size);
56 gnutls_x509_privkey_deinit (key);
59 return g_strdup (buffer);
75 char *pub_key, *decrypted_priv, *pub_str = NULL;
80 ret = ssh_pki_import_privkey_base64 (decrypted_priv ? decrypted_priv
82 passphrase, NULL, NULL, &priv);
83 g_free (decrypted_priv);
86 ret = ssh_pki_export_pubkey_base64 (priv, &pub_key);
87 type = ssh_key_type_to_char (ssh_key_type (priv));
88#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 4)
89 if (!strcmp (type,
"ssh-ecdsa"))
90 type = ssh_pki_key_ecdsa_name (priv);
95 pub_str = g_strdup_printf (
"%s %s", type, pub_key);
char * gvm_ssh_pkcs8_decrypt(const char *pkcs8_key, const char *passphrase)
Decrypts a base64 encrypted ssh private key.
char * gvm_ssh_public_from_private(const char *private_key, const char *passphrase)
Exports a base64 encoded public key from a private key and its passphrase.