aboutsummaryrefslogtreecommitdiff
path: root/src/pki.c
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2018-09-13 13:45:46 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-09-18 09:53:49 +0200
commit1226de875b3bb419f8d0ad949156d6e1a2a153fa (patch)
tree27637d09503bcbf33227b15358f4f9523ceee7cd /src/pki.c
parent2307be32cf7d235076a201cf666b844ac206166a (diff)
downloadlibssh-1226de875b3bb419f8d0ad949156d6e1a2a153fa.tar.gz
libssh-1226de875b3bb419f8d0ad949156d6e1a2a153fa.tar.xz
libssh-1226de875b3bb419f8d0ad949156d6e1a2a153fa.zip
pki: Implement reading public key from OpenSSH private key container
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/pki.c')
-rw-r--r--src/pki.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/pki.c b/src/pki.c
index f819b94d..22ff3cd5 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -1320,7 +1320,7 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
const char *q;
FILE *file;
off_t size;
- int rc;
+ int rc, cmp;
if (pkey == NULL || filename == NULL || *filename == '\0') {
return SSH_ERROR;
@@ -1370,6 +1370,20 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
key_buf[size] = '\0';
buflen = strlen(key_buf);
+ /* Test for new OpenSSH key format first */
+ cmp = strncmp(key_buf, OPENSSH_HEADER_BEGIN, strlen(OPENSSH_HEADER_BEGIN));
+ if (cmp == 0) {
+ *pkey = ssh_pki_openssh_pubkey_import(key_buf);
+ SAFE_FREE(key_buf);
+ if (*pkey == NULL) {
+ SSH_LOG(SSH_LOG_WARN, "Failed to import public key from OpenSSH"
+ " private key file");
+ return SSH_ERROR;
+ }
+ return SSH_OK;
+ }
+
+ /* This the old one-line public key format */
q = p = key_buf;
for (i = 0; i < buflen; i++) {
if (isspace((int)p[i])) {