diff options
author | Axel Eppe <aeppe@google.com> | 2015-08-23 17:38:21 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-09-07 13:29:52 +0200 |
commit | 9775f78ab2cf6cc348bad8728caf76709729a42a (patch) | |
tree | 7da0626db1dd30c634bb982de3fd1d67c14a3eb7 /src | |
parent | 6da4e21065c30eee630cf448b4f45d29815c6f14 (diff) | |
download | libssh-9775f78ab2cf6cc348bad8728caf76709729a42a.tar.gz libssh-9775f78ab2cf6cc348bad8728caf76709729a42a.tar.xz libssh-9775f78ab2cf6cc348bad8728caf76709729a42a.zip |
pki: Add Add new pki_import_cert_buffer function
Signed-off-by: Axel Eppe <aeppe@google.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pki.c | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -827,6 +827,57 @@ fail: return SSH_ERROR; } +static int pki_import_cert_buffer(ssh_buffer buffer, + enum ssh_keytypes_e type, + ssh_key *pkey) { + ssh_buffer cert; + ssh_string type_s; + ssh_key key; + int rc; + + key = ssh_key_new(); + if (key == NULL) { + return SSH_ERROR; + } + cert = ssh_buffer_new(); + if (cert == NULL) { + ssh_key_free(key); + return SSH_ERROR; + } + + key->type = type; + key->type_c = ssh_key_type_to_char(type); + key->flags = SSH_KEY_FLAG_PUBLIC; + + /* + * The cert blob starts with the key type as an ssh_string, but this + * string has been read out of the buffer to identify the key type. + * Simply add it again as first element before copying the rest. + */ + type_s = ssh_string_from_char(key->type_c); + if (type_s == NULL) { + goto fail; + } + rc = buffer_add_ssh_string(cert, type_s); + if (rc != 0) { + goto fail; + } + + rc = buffer_add_buffer(cert, buffer); + if (rc != 0) { + goto fail; + } + key->cert = (void*) cert; + + *pkey = key; + return SSH_OK; + +fail: + ssh_key_free(key); + ssh_buffer_free(cert); + return SSH_ERROR; +} + /** * @brief Import a base64 formated public key from a memory c-string. * |