Pass private-key to OpenSSL as a filename with BIO_new_file().
This keeps all FILE* handling on the OpenSSL side of the DLL boundary avoiding crashes on Windows while removing the need for libssh2 to read the private key file into memory. This is now done by OpenSSL which is likely to do a better job of it.
This commit is contained in:
		| @@ -149,8 +149,9 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, | ||||
| int | ||||
| _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, | ||||
|                          LIBSSH2_SESSION * session, | ||||
|                          FILE * fp, unsigned const char *passphrase) | ||||
|                          const char *filename, unsigned const char *passphrase) | ||||
| { | ||||
|     FILE *fp; | ||||
|     unsigned char *data, *save_data; | ||||
|     unsigned int datalen; | ||||
|     int ret; | ||||
| @@ -159,10 +160,16 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, | ||||
|  | ||||
|     (void) passphrase; | ||||
|  | ||||
|     fp = fopen(filename, "r"); | ||||
|     if (!fp) { | ||||
|         return -1; | ||||
|     } | ||||
|  | ||||
|     ret = _libssh2_pem_parse(session, | ||||
|                              "-----BEGIN RSA PRIVATE KEY-----", | ||||
|                              "-----END RSA PRIVATE KEY-----", | ||||
|                              fp, &data, &datalen); | ||||
|     fclose(fp) | ||||
|     if (ret) { | ||||
|         return -1; | ||||
|     } | ||||
| @@ -244,8 +251,9 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, | ||||
| int | ||||
| _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, | ||||
|                          LIBSSH2_SESSION * session, | ||||
|                          FILE * fp, unsigned const char *passphrase) | ||||
|                          const char *filename, unsigned const char *passphrase) | ||||
| { | ||||
|     FILE *fp; | ||||
|     unsigned char *data, *save_data; | ||||
|     unsigned int datalen; | ||||
|     int ret; | ||||
| @@ -254,10 +262,16 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, | ||||
|  | ||||
|     (void) passphrase; | ||||
|  | ||||
|     fp = fopen(filename); | ||||
|     if (!fp) { | ||||
|         return -1; | ||||
|     } | ||||
|  | ||||
|     ret = _libssh2_pem_parse(session, | ||||
|                              "-----BEGIN DSA PRIVATE KEY-----", | ||||
|                              "-----END DSA PRIVATE KEY-----", | ||||
|                              fp, &data, &datalen); | ||||
|     fclose(fp); | ||||
|     if (ret) { | ||||
|         return -1; | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Alexander Lamaison
					Alexander Lamaison