aboutsummaryrefslogtreecommitdiff
path: root/src/pki.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2015-01-20 17:25:20 +0100
committerAndreas Schneider <asn@cryptomilk.org>2015-02-02 14:45:52 +0100
commit3ec3a926e5da5131917c7f4e66a1a865c2b524f1 (patch)
treea4190e494d9079439e0dfc9c6f5c057104cc9e60 /src/pki.c
parent2f7886837f44351fc00e1a251c464bf6de2da2d1 (diff)
downloadlibssh-3ec3a926e5da5131917c7f4e66a1a865c2b524f1.tar.gz
libssh-3ec3a926e5da5131917c7f4e66a1a865c2b524f1.tar.xz
libssh-3ec3a926e5da5131917c7f4e66a1a865c2b524f1.zip
ed25519: Add support o import OpenSSH container keys
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/pki.c')
-rw-r--r--src/pki.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/pki.c b/src/pki.c
index 3b859bb2..b35fedd8 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -1,5 +1,5 @@
/*
- * known_hosts.c
+ * pki.c
* This file is part of the SSH Library
*
* Copyright (c) 2010 by Aris Adamantiadis
@@ -402,6 +402,7 @@ int ssh_pki_import_privkey_base64(const char *b64_key,
ssh_key *pkey)
{
ssh_key key;
+ int cmp;
if (b64_key == NULL || pkey == NULL) {
return SSH_ERROR;
@@ -414,7 +415,20 @@ int ssh_pki_import_privkey_base64(const char *b64_key,
ssh_pki_log("Trying to decode privkey passphrase=%s",
passphrase ? "true" : "false");
- key = pki_private_key_from_base64(b64_key, passphrase, auth_fn, auth_data);
+ /* Test for OpenSSH key format first */
+ cmp = strncmp(b64_key, OPENSSH_HEADER_BEGIN, strlen(OPENSSH_HEADER_BEGIN));
+ if (cmp == 0) {
+ key = ssh_pki_openssh_privkey_import(b64_key,
+ passphrase,
+ auth_fn,
+ auth_data);
+ } else {
+ /* fallback on PEM decoder */
+ key = pki_private_key_from_base64(b64_key,
+ passphrase,
+ auth_fn,
+ auth_data);
+ }
if (key == NULL) {
return SSH_ERROR;
}
@@ -451,7 +465,6 @@ int ssh_pki_import_privkey_file(const char *filename,
ssh_key *pkey) {
struct stat sb;
char *key_buf;
- ssh_key key;
FILE *file;
off_t size;
int rc;
@@ -505,14 +518,14 @@ int ssh_pki_import_privkey_file(const char *filename,
}
key_buf[size] = 0;
- key = pki_private_key_from_base64(key_buf, passphrase, auth_fn, auth_data);
- SAFE_FREE(key_buf);
- if (key == NULL) {
- return SSH_ERROR;
- }
+ rc = ssh_pki_import_privkey_base64(key_buf,
+ passphrase,
+ auth_fn,
+ auth_data,
+ pkey);
- *pkey = key;
- return SSH_OK;
+ SAFE_FREE(key_buf);
+ return rc;
}
/**