Skip to content

Commit 5c9cd17

Browse files
committed
openssl: rework openssl-1.1 support
1 parent 3f4e66c commit 5c9cd17

File tree

7 files changed

+629
-76
lines changed

7 files changed

+629
-76
lines changed

configure.ac

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -303,48 +303,35 @@ if test "${have_openssl}" = "yes"; then
303303
old_LIBS="${LIBS}"
304304
LIBS="${LIBS} ${OPENSSL_LIBS}"
305305
AC_CHECK_FUNC(
306-
[ECDSA_METHOD_new],
306+
[EC_KEY_METHOD_new],
307307
[
308308
openssl_ec="yes"
309309
AC_DEFINE([ENABLE_PKCS11H_OPENSSL_EC], [1], [Enable openssl EC])
310310
],
311-
[
312-
openssl_ec="hack"
313-
old_CFLAGS="${CFLAGS}"
314-
old_CPPFLAGS="${CPPFLAGS}"
315-
CPPFLAGS="${CPPFLAGS} -I."
316-
CFLAGS="${CFLAGS} ${OPENSSL_CFLAGS}"
317-
AC_CHECK_HEADER(
318-
[ecs_locl.h],
319-
[
320-
AC_DEFINE([ENABLE_PKCS11H_OPENSSL_EC], [1], [Enable openssl EC])
321-
AC_DEFINE([ENABLE_PKCS11H_OPENSSL_EC_HACK], [1], [Enable openssl EC])
322-
AC_DEFINE_UNQUOTED(
323-
[ECDSA_METHOD_new(ecdsa)],
324-
[(ECDSA_METHOD *)memmove(malloc(sizeof(ECDSA_METHOD)), ecdsa, sizeof(ECDSA_METHOD))],
325-
[emulation],
326-
)
327-
AC_DEFINE_UNQUOTED(
328-
[ECDSA_METHOD_free(ecdsa)],
329-
[free(ecdsa)],
330-
[emulation],
331-
)
332-
AC_DEFINE_UNQUOTED(
333-
[ECDSA_METHOD_set_name(ecdsa, n)],
334-
[ecdsa->name = n],
335-
[emulation],
336-
)
337-
AC_DEFINE_UNQUOTED(
338-
[ECDSA_METHOD_set_sign(ecdsa, s)],
339-
[ecdsa->ecdsa_do_sign = s],
340-
[emulation],
341-
)
342-
],
343-
[openssl_ec="none"]
344-
)
345-
CPPFLAGS="${old_CPPFLAGS}"
346-
CFLAGS="${old_CFLAGS}"
347-
],
311+
[AC_CHECK_FUNC(
312+
[ECDSA_METHOD_new],
313+
[
314+
openssl_ec="yes"
315+
AC_DEFINE([ENABLE_PKCS11H_OPENSSL_EC], [1], [Enable openssl EC])
316+
],
317+
[
318+
openssl_ec="hack"
319+
old_CFLAGS="${CFLAGS}"
320+
old_CPPFLAGS="${CPPFLAGS}"
321+
CPPFLAGS="${CPPFLAGS} -I."
322+
CFLAGS="${CFLAGS} ${OPENSSL_CFLAGS}"
323+
AC_CHECK_HEADER(
324+
[ecs_locl.h],
325+
[
326+
AC_DEFINE([ENABLE_PKCS11H_OPENSSL_EC], [1], [Enable openssl EC])
327+
AC_DEFINE([ENABLE_PKCS11H_OPENSSL_EC_HACK], [1], [Enable openssl EC])
328+
],
329+
[openssl_ec="none"]
330+
)
331+
CPPFLAGS="${old_CPPFLAGS}"
332+
CFLAGS="${old_CFLAGS}"
333+
],
334+
)]
348335
)
349336
LIBS="${old_LIBS}"
350337
AC_MSG_CHECKING([for OpenSSL ec support])
@@ -611,6 +598,7 @@ AC_CONFIG_FILES([
611598
tests/Makefile
612599
tests/test-basic/Makefile
613600
tests/test-certificate/Makefile
601+
tests/test-openssl/Makefile
614602
tests/test-slotevent/Makefile
615603
])
616604
AC_OUTPUT

include/pkcs11-helper-1.0/pkcs11h-openssl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
#define __PKCS11H_HELPER_H
6868

6969
#include <openssl/x509.h>
70+
#ifndef OPENSSL_NO_RSA
71+
#include <openssl/rsa.h>
72+
#endif
7073
#include <pkcs11-helper-1.0/pkcs11h-core.h>
7174
#include <pkcs11-helper-1.0/pkcs11h-certificate.h>
7275

@@ -147,10 +150,12 @@ pkcs11h_openssl_freeSession (
147150
* @param openssl_session OpenSSL session reference.
148151
* @return RSA.
149152
*/
153+
#ifndef OPENSSL_NO_RSA
150154
RSA *
151155
pkcs11h_openssl_session_getRSA (
152156
IN const pkcs11h_openssl_session_t openssl_session
153157
);
158+
#endif
154159

155160
/**
156161
* @brief Returns an EVP_PKEY out of the openssl_session object.

lib/_pkcs11h-crypto-openssl.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
#if defined(ENABLE_PKCS11H_ENGINE_OPENSSL)
5656
#include <openssl/x509.h>
5757

58+
/*
59+
* Hack libressl incorrect interface number.
60+
*/
61+
#if defined(LIBRESSL_VERSION_NUMBER)
62+
#undef OPENSSL_VERSION_NUMBER
63+
#define OPENSSL_VERSION_NUMBER 0x1000107fL
64+
#endif
65+
5866
#if OPENSSL_VERSION_NUMBER < 0x00907000L && defined(CRYPTO_LOCK_ENGINE)
5967
# define RSA_get_default_method RSA_get_default_openssl_method
6068
#else
@@ -72,6 +80,11 @@
7280
#endif
7381
#endif
7482

83+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
84+
#define X509_get0_notAfter X509_get_notAfter
85+
#define X509_get0_notBefore X509_get_notBefore
86+
#endif
87+
7588
#if OPENSSL_VERSION_NUMBER < 0x00908000L
7689
typedef unsigned char *__pkcs11_openssl_d2i_t;
7790
#else
@@ -85,7 +98,9 @@ __pkcs11h_crypto_openssl_initialize (
8598
) {
8699
(void)global_data;
87100

101+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
88102
OpenSSL_add_all_digests ();
103+
#endif
89104

90105
return TRUE;
91106
}
@@ -110,8 +125,8 @@ __pkcs11h_crypto_openssl_certificate_get_expiration (
110125
) {
111126
X509 *x509 = NULL;
112127
__pkcs11_openssl_d2i_t d2i;
113-
ASN1_TIME *notBefore;
114-
ASN1_TIME *notAfter;
128+
const ASN1_TIME *notBefore;
129+
const ASN1_TIME *notAfter;
115130

116131
(void)global_data;
117132

@@ -131,8 +146,8 @@ __pkcs11h_crypto_openssl_certificate_get_expiration (
131146
goto cleanup;
132147
}
133148

134-
notBefore = X509_get_notBefore (x509);
135-
notAfter = X509_get_notAfter (x509);
149+
notBefore = X509_get0_notBefore (x509);
150+
notAfter = X509_get0_notAfter (x509);
136151

137152
if (
138153
notBefore != NULL &&

0 commit comments

Comments
 (0)