diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2016-01-10 22:34:13 +0100 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2016-05-13 09:59:50 +0200 |
commit | dad3100b1303f2355b59d0623d89bc913d5f3230 (patch) | |
tree | 3453986b11eed5a654257dbafd2558ba0db5629d | |
parent | 030069b462c6a965f6f1b3c4a0224fe3df30e242 (diff) | |
download | libssh-dad3100b1303f2355b59d0623d89bc913d5f3230.tar.gz libssh-dad3100b1303f2355b59d0623d89bc913d5f3230.tar.xz libssh-dad3100b1303f2355b59d0623d89bc913d5f3230.zip |
libcrypto: detect non matching headers/shared lib
It took me a while to understand why some test cases were not always
working, and figure out I wasn't linked with the right libcrypto.
-rw-r--r-- | src/init.c | 33 | ||||
-rw-r--r-- | src/libcrypto.c | 11 |
2 files changed, 29 insertions, 15 deletions
@@ -48,19 +48,25 @@ * This function should only be called once, at the beginning of the program, in * the main thread. It may be omitted if your program is not multithreaded. * - * @returns 0 on success, -1 if an error occured. + * @returns SSH_OK on success, SSH_ERROR if an error occurred. */ int ssh_init(void) { - if(ssh_threads_init()) - return -1; - if(ssh_crypto_init()) - return -1; - if(ssh_dh_init() == SSH_ERROR){ - return -1; - } - if(ssh_socket_init()) - return -1; - return 0; + int rc = SSH_OK; + /* Continuing to execute through errors, because some users may + * ignore them until it's too late. + */ + if(ssh_threads_init() != SSH_OK){ + rc = SSH_ERROR; + } + if(ssh_crypto_init() != SSH_OK){ + rc = SSH_ERROR; + } + if(ssh_dh_init() != SSH_OK){ + rc = SSH_ERROR; + } + if(ssh_socket_init() != SSH_OK) + rc = SSH_ERROR; + return rc; } @@ -69,9 +75,8 @@ int ssh_init(void) { * * This function should only be called once, at the end of the program! * - * @returns 0 on succes, -1 if an error occured. - * - @returns 0 otherwise + * @returns SSH_OK on success, SSH_ERROR if an error occurred. + * @returns 0 otherwise */ int ssh_finalize(void) { ssh_crypto_finalize(); diff --git a/src/libcrypto.c b/src/libcrypto.c index dae6f035..0cfdc541 100644 --- a/src/libcrypto.c +++ b/src/libcrypto.c @@ -75,11 +75,20 @@ static int libcrypto_initialized = 0; * @brief Initialize libcrypto's subsystem */ int ssh_crypto_init(void) { + int rc = SSH_OK; if (libcrypto_initialized == 0) { + if (SSLeay() != OPENSSL_VERSION_NUMBER){ + SSH_LOG(SSH_LOG_WARNING, "libssh compiled with %s " + "headers, currently running with %s.", + OPENSSL_VERSION_TEXT, + SSLeay_version(SSLeay()) + ); + rc = SSH_ERROR;; + } OpenSSL_add_all_algorithms(); libcrypto_initialized = 1; } - return 0; + return rc; } /** |