37 gnutls_x509_privkey_t key;
38 char buffer[16 * 2048];
40 size_t size =
sizeof (buffer);
42 if (pkcs8_key == NULL)
45 rc = gnutls_x509_privkey_init (&key);
48 data.size = strlen (pkcs8_key);
49 data.data = (
void *) g_strdup (pkcs8_key);
50 rc = gnutls_x509_privkey_import_pkcs8 (key, &data, GNUTLS_X509_FMT_PEM,
51 passphrase ? passphrase :
"", 0);
55 gnutls_x509_privkey_deinit (key);
58 rc = gnutls_x509_privkey_export (key, GNUTLS_X509_FMT_PEM, buffer, &size);
59 gnutls_x509_privkey_deinit (key);
62 return g_strdup (buffer);
78 char *pub_key, *decrypted_priv, *pub_str = NULL;
82 if (private_key == NULL)
85 ret = ssh_pki_import_privkey_base64 (decrypted_priv ? decrypted_priv
87 passphrase, NULL, NULL, &priv);
88 g_free (decrypted_priv);
91 ret = ssh_pki_export_pubkey_base64 (priv, &pub_key);
92 type = ssh_key_type_to_char (ssh_key_type (priv));
93#if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 4)
94 if (!strcmp (type,
"ssh-ecdsa"))
95 type = ssh_pki_key_ecdsa_name (priv);
100 pub_str = g_strdup_printf (
"%s %s", type, pub_key);
117 const char **type,
char **sha256_hash)
120 char *decrypted_priv;
128 if (private_key == NULL)
131 ret = ssh_pki_import_privkey_base64 (decrypted_priv ? decrypted_priv
133 passphrase, NULL, NULL, &priv);
134 free (decrypted_priv);
140 *type = ssh_key_type_to_char (ssh_key_type (priv));
145 unsigned char *hash = NULL;
146 size_t hash_size = 0;
147 ret = ssh_get_publickey_hash (priv, SSH_PUBLICKEY_HASH_SHA256, &hash,
151 gchar *hex = g_malloc0 (hash_size * 2 + 1);
152 for (
unsigned int i = 0; i < hash_size; i++)
154 g_snprintf (hex + i * 2, 3,
"%02x", hash[i]);
156 ssh_clean_pubkey_hash (&hash);
int gvm_ssh_private_key_info(const char *private_key, const char *passphrase, const char **type, char **sha256_hash)
Gets information from a SSH private key.
Definition sshutils.c:116
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.
Definition sshutils.c:75