1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

pki: Search for the PEM headers not only on the start of the key file

Fixes: T76 for gcrypt and mbedtls backends

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
This commit is contained in:
Jakub Jelen
2019-06-19 16:26:24 +02:00
parent 23c837f4d0
commit d627cba476

View File

@@ -66,20 +66,20 @@
enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey) enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey)
{ {
int cmp; char *start = NULL;
cmp = strncmp(privkey, DSA_HEADER_BEGIN, strlen(DSA_HEADER_BEGIN)); start = strstr(privkey, DSA_HEADER_BEGIN);
if (cmp == 0) { if (start != NULL) {
return SSH_KEYTYPE_DSS; return SSH_KEYTYPE_DSS;
} }
cmp = strncmp(privkey, RSA_HEADER_BEGIN, strlen(RSA_HEADER_BEGIN)); start = strstr(privkey, RSA_HEADER_BEGIN);
if (cmp == 0) { if (start != NULL) {
return SSH_KEYTYPE_RSA; return SSH_KEYTYPE_RSA;
} }
cmp = strncmp(privkey, ECDSA_HEADER_BEGIN, strlen(ECDSA_HEADER_BEGIN)); start = strstr(privkey, ECDSA_HEADER_BEGIN);
if (cmp == 0) { if (start != 0) {
/* We don't know what the curve is at this point, so we don't actually /* We don't know what the curve is at this point, so we don't actually
* know the type. We figure out the actual curve and fix things up in * know the type. We figure out the actual curve and fix things up in
* pki_private_key_from_base64 */ * pki_private_key_from_base64 */