Greenbone Vulnerability Management Libraries  11.0.0
sshutils.h File Reference

SSH related API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * gvm_ssh_pkcs8_decrypt (const char *, const char *)
 Decrypts a base64 encrypted ssh private key. More...
 
char * gvm_ssh_public_from_private (const char *, const char *)
 Exports a base64 encoded public key from a private key and its passphrase. More...
 

Detailed Description

SSH related API.

Definition in file sshutils.h.

Function Documentation

◆ gvm_ssh_pkcs8_decrypt()

char* gvm_ssh_pkcs8_decrypt ( const char *  pkcs8_key,
const char *  passphrase 
)

Decrypts a base64 encrypted ssh private key.

Parameters
[in]pkcs8_keyPKCS#8 encrypted private key.
[in]passphrasePassphrase for the private key.
Returns
Decrypted private key if success, NULL otherwise.

Definition at line 42 of file sshutils.c.

43 {
44  gnutls_datum_t data;
45  gnutls_x509_privkey_t key;
46  char buffer[16 * 2048];
47  int rc;
48  size_t size = sizeof (buffer);
49 
50  rc = gnutls_x509_privkey_init (&key);
51  if (rc)
52  return NULL;
53  data.size = strlen (pkcs8_key);
54  data.data = (void *) g_strdup (pkcs8_key);
55  rc = gnutls_x509_privkey_import_pkcs8 (key, &data, GNUTLS_X509_FMT_PEM,
56  passphrase ? passphrase : "", 0);
57  if (rc)
58  {
59  gnutls_x509_privkey_deinit (key);
60  return NULL;
61  }
62  g_free (data.data);
63  rc = gnutls_x509_privkey_export (key, GNUTLS_X509_FMT_PEM, buffer, &size);
64  gnutls_x509_privkey_deinit (key);
65  if (rc)
66  return NULL;
67  return g_strdup (buffer);
68 }

Referenced by gvm_ssh_public_from_private().

Here is the caller graph for this function:

◆ gvm_ssh_public_from_private()

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.

Parameters
[in]private_keyPrivate key to export.
[in]passphrasePassphrase for the private key.
Returns
Allocated base64 encoded public key if success, NULL otherwise.

Definition at line 80 of file sshutils.c.

81 {
82  ssh_key priv;
83  char *pub_key, *decrypted_priv, *pub_str = NULL;
84  const char *type;
85  int ret;
86 
87  decrypted_priv = gvm_ssh_pkcs8_decrypt (private_key, passphrase);
88  ret = ssh_pki_import_privkey_base64 (decrypted_priv ? decrypted_priv
89  : private_key,
90  passphrase, NULL, NULL, &priv);
91  g_free (decrypted_priv);
92  if (ret)
93  return NULL;
94  ret = ssh_pki_export_pubkey_base64 (priv, &pub_key);
95  type = ssh_key_type_to_char (ssh_key_type (priv));
96 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT(0, 6, 4)
97  if (!strcmp (type, "ssh-ecdsa"))
98  type = ssh_pki_key_ecdsa_name (priv);
99 #endif
100  ssh_key_free (priv);
101  if (ret)
102  return NULL;
103  pub_str = g_strdup_printf ("%s %s", type, pub_key);
104  g_free (pub_key);
105  return pub_str;
106 }

References gvm_ssh_pkcs8_decrypt().

Here is the call graph for this function:
gvm_ssh_pkcs8_decrypt
char * gvm_ssh_pkcs8_decrypt(const char *pkcs8_key, const char *passphrase)
Decrypts a base64 encrypted ssh private key.
Definition: sshutils.c:42