Add support for LibreSSL compatability as well as OpenSSL-1.1.0

This commit is based on input from https://github.com/lbschenkel
LibreSSL is based on OpenSSL 1.0.1. API.

 Changes to be committed:
	modified:   libopensc/sc-ossl-compat.h
	modified:   tools/pkcs11-tool.c
	modified:   tools/pkcs15-init.c
	modified:   tools/sc-hsm-tool.c
This commit is contained in:
Doug Engert 2016-10-03 20:10:21 -05:00
parent 5fb4db6373
commit c6dba96f55
4 changed files with 16 additions and 9 deletions

View File

@ -32,6 +32,13 @@ extern "C" {
/*
* Provide backward compatability to older versions of OpenSSL
* while using most of OpenSSL 1.1 API
*
* LibreSSL is a fork of OpenSSL from 2014
* In its version of openssl/opensslv.h it defines:
* OPENSSL_VERSION_NUMBER 0x20000000L (Will not change)
* LIBRESSL_VERSION_NUMBER 0x2050000fL (changes with its versions.
* The LibreSSL appears to follow the OpenSSL-1.0.1 API
*
*/
/*
@ -81,7 +88,7 @@ extern "C" {
#define EVP_PKEY_base_id(x) (x->type)
#endif
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
#define RSA_PKCS1_OpenSSL RSA_PKCS1_SSLeay
#define OPENSSL_malloc_init CRYPTO_malloc_init
@ -101,7 +108,7 @@ extern "C" {
* If that is not good enough, versions could be added to libopensc
*/
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
/* based on OpenSSL-1.1.0 e_os2.h */
/* sc_ossl_inline: portable inline definition usable in public headers */
# if !defined(inline) && !defined(__cplusplus)
@ -120,7 +127,7 @@ extern "C" {
# endif
#endif
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
#define RSA_bits(R) (BN_num_bits(R->n))

View File

@ -35,6 +35,7 @@
#ifdef ENABLE_OPENSSL
#include <openssl/opensslv.h>
#include "libopensc/sc-ossl-compat.h"
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
#include <openssl/opensslconf.h>
#include <openssl/crypto.h>
@ -56,7 +57,6 @@
#include <openssl/err.h>
#endif
#include "libopensc/sc-ossl-compat.h"
#include "pkcs11/pkcs11.h"
#include "pkcs11/pkcs11-opensc.h"
#include "libopensc/asn1.h"
@ -460,10 +460,10 @@ int main(int argc, char * argv[])
#endif
#ifdef ENABLE_OPENSSL
#if OPENSSL_VERSION_NUMBER >= 0x00907000L && OPENSSL_VERSION_NUMBER < 0x10100000L
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L && OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
OPENSSL_config(NULL);
#endif
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS
| OPENSSL_INIT_ADD_ALL_CIPHERS
| OPENSSL_INIT_ADD_ALL_DIGESTS

View File

@ -39,6 +39,7 @@
#include <string.h>
#endif
#include <openssl/opensslv.h>
#include "libopensc/sc-ossl-compat.h"
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
#include <openssl/conf.h>
#endif
@ -60,7 +61,6 @@
#endif /* OPENSSL_VERSION_NUMBER >= 0x10000000L */
#include "common/compat_strlcpy.h"
#include "libopensc/sc-ossl-compat.h"
#include "libopensc/cardctl.h"
#include "libopensc/pkcs15.h"
#include "libopensc/log.h"
@ -439,7 +439,7 @@ main(int argc, char **argv)
#if OPENSSL_VERSION_NUMBER >= 0x00907000L && OPENSSL_VERSION_NUMBER < 0x10100000L
OPENSSL_config(NULL);
#endif
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !(defined LIBRESSL_VERSION_NUMBER)
/* Openssl 1.1.0 magic */
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS
| OPENSSL_INIT_ADD_ALL_CIPHERS

View File

@ -1745,7 +1745,7 @@ int main(int argc, char * const argv[])
}
}
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !(defined LIBRESSL_VERSION_NUMBER)
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS
| OPENSSL_INIT_ADD_ALL_CIPHERS
| OPENSSL_INIT_ADD_ALL_DIGESTS,