mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
keyfiles: Use BIO* in _privatekey_from_file().
(cherry picked from commit 82df5dc2083a6f7234d1545bd671ee1b5b4680b6)
This commit is contained in:
committed by
Andreas Schneider
parent
da8356b477
commit
a6dda5fefd
@@ -872,6 +872,15 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBCRYPTO
|
||||||
|
bio = BIO_new_file(filename,"r");
|
||||||
|
if (bio == NULL) {
|
||||||
|
fclose(file);
|
||||||
|
ssh_set_error(session, SSH_FATAL, "Could not create BIO.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SSH_KEYTYPE_DSS:
|
case SSH_KEYTYPE_DSS:
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
@@ -884,7 +893,7 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename,
|
|||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL);
|
dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL);
|
||||||
|
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
|
|
||||||
if (dsa == NULL) {
|
if (dsa == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
@@ -905,7 +914,7 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename,
|
|||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL);
|
rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL);
|
||||||
|
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
|
|
||||||
if (rsa == NULL) {
|
if (rsa == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
@@ -917,9 +926,9 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
fclose(file);
|
fclose(file);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
#endif
|
#endif
|
||||||
ssh_set_error(session, SSH_FATAL, "Invalid private key type %d", type);
|
ssh_set_error(session, SSH_FATAL, "Invalid private key type %d", type);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user