2005-06-09 13:45:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-07-02 07:28:02 +02:00
|
|
|
#define SSH_DONT_OVERLOAD_OPENSSL_FUNCS
|
2005-06-09 13:45:10 +02:00
|
|
|
#include "includes.h"
|
|
|
|
|
2015-01-14 16:21:31 +01:00
|
|
|
#ifdef WITH_OPENSSL
|
|
|
|
|
2010-12-04 13:20:50 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-02-20 10:17:35 +01:00
|
|
|
#ifdef USE_OPENSSL_ENGINE
|
|
|
|
# include <openssl/engine.h>
|
2010-11-22 07:59:00 +01:00
|
|
|
# include <openssl/conf.h>
|
2006-02-20 10:17:35 +01:00
|
|
|
#endif
|
|
|
|
|
2010-12-04 13:20:50 +01:00
|
|
|
#include "log.h"
|
|
|
|
|
2008-02-28 09:13:52 +01:00
|
|
|
#include "openssl-compat.h"
|
|
|
|
|
2014-06-17 15:06:07 +02:00
|
|
|
/*
|
|
|
|
* OpenSSL version numbers: MNNFFPPS: major minor fix patch status
|
2023-05-08 12:12:59 +02:00
|
|
|
* Versions >=3 require only major versions to match.
|
|
|
|
* For versions <3, we accept compatible fix versions (so we allow 1.0.1
|
|
|
|
* to work with 1.0.0). Going backwards is only allowed within a patch series.
|
|
|
|
* See https://www.openssl.org/policies/releasestrat.html
|
2014-06-17 15:06:07 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
ssh_compatible_openssl(long headerver, long libver)
|
|
|
|
{
|
|
|
|
long mask, hfix, lfix;
|
|
|
|
|
|
|
|
/* exact match is always OK */
|
|
|
|
if (headerver == libver)
|
|
|
|
return 1;
|
|
|
|
|
2023-05-08 12:12:59 +02:00
|
|
|
/*
|
|
|
|
* For versions >= 3.0, only the major and status must match.
|
|
|
|
*/
|
|
|
|
if (headerver >= 0x3000000f) {
|
|
|
|
mask = 0xf000000fL; /* major,status */
|
2014-06-17 15:06:07 +02:00
|
|
|
return (headerver & mask) == (libver & mask);
|
|
|
|
}
|
2016-08-02 01:44:25 +02:00
|
|
|
|
2014-06-17 15:06:07 +02:00
|
|
|
/*
|
2023-05-08 12:12:59 +02:00
|
|
|
* For versions >= 1.0.0, but <3, major,minor,status must match and
|
|
|
|
* library fix version must be equal to or newer than the header.
|
2014-06-17 15:06:07 +02:00
|
|
|
*/
|
|
|
|
mask = 0xfff0000fL; /* major,minor,status */
|
|
|
|
hfix = (headerver & 0x000ff000) >> 12;
|
|
|
|
lfix = (libver & 0x000ff000) >> 12;
|
|
|
|
if ( (headerver & mask) == (libver & mask) && lfix >= hfix)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-20 10:17:35 +01:00
|
|
|
void
|
2018-11-23 00:40:06 +01:00
|
|
|
ssh_libcrypto_init(void)
|
2006-02-20 10:17:35 +01:00
|
|
|
{
|
2018-11-25 04:05:57 +01:00
|
|
|
#if defined(HAVE_OPENSSL_INIT_CRYPTO) && \
|
2018-11-23 00:40:06 +01:00
|
|
|
defined(OPENSSL_INIT_ADD_ALL_CIPHERS) && \
|
|
|
|
defined(OPENSSL_INIT_ADD_ALL_DIGESTS)
|
|
|
|
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
|
|
|
|
OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
|
2018-11-25 04:05:57 +01:00
|
|
|
#elif defined(HAVE_OPENSSL_ADD_ALL_ALGORITHMS)
|
|
|
|
OpenSSL_add_all_algorithms();
|
2018-11-23 00:40:06 +01:00
|
|
|
#endif
|
2006-02-20 10:17:35 +01:00
|
|
|
|
2018-11-23 00:40:06 +01:00
|
|
|
#ifdef USE_OPENSSL_ENGINE
|
2006-02-20 10:17:35 +01:00
|
|
|
/* Enable use of crypto hardware */
|
|
|
|
ENGINE_load_builtin_engines();
|
|
|
|
ENGINE_register_all_complete();
|
2018-10-16 01:51:52 +02:00
|
|
|
|
2018-11-23 00:40:06 +01:00
|
|
|
/* Load the libcrypto config file to pick up engines defined there */
|
|
|
|
# if defined(HAVE_OPENSSL_INIT_CRYPTO) && defined(OPENSSL_INIT_LOAD_CONFIG)
|
2018-10-16 01:51:52 +02:00
|
|
|
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
|
2018-10-16 23:12:02 +02:00
|
|
|
OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL);
|
2018-11-23 00:40:06 +01:00
|
|
|
# else
|
2018-11-16 04:11:44 +01:00
|
|
|
OPENSSL_config(NULL);
|
2018-11-23 00:40:06 +01:00
|
|
|
# endif
|
|
|
|
#endif /* USE_OPENSSL_ENGINE */
|
2006-02-20 10:17:35 +01:00
|
|
|
}
|
2015-01-14 16:21:31 +01:00
|
|
|
|
|
|
|
#endif /* WITH_OPENSSL */
|