[glib-networking: 116/129] tls: Fix the build with openssl 1.0 on Windows



commit 9cfe149f76c4fac8d00d76eeaba8f786d3d71879
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Mon May 21 21:13:44 2018 +0200

    tls: Fix the build with openssl 1.0 on Windows
    
    Due to name clashes between the Windows headers and openssl headers the include
    order matters. In addition the 1.0 headers include the Windows headers themselves
    which makes things more complicated.
    
    According to
    https://github.com/openssl/openssl/issues/1157#issuecomment-231330913
    this is fixed in 1.1 by not including the Windows headers in the openssl headers
    and requiring the user to include the Windows headers first (but I haven't tested this)
    
    To avoid future breakage gather all openssl includes in one file, include the
    Windows headers first and undef all the clashing macros.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795782

 tls/openssl/Makefile.am                    |  1 +
 tls/openssl/gtlsbackend-openssl.c          |  3 +-
 tls/openssl/gtlsbio.h                      |  2 +-
 tls/openssl/gtlscertificate-openssl.c      |  4 +--
 tls/openssl/gtlscertificate-openssl.h      |  2 +-
 tls/openssl/gtlsclientconnection-openssl.c |  8 +----
 tls/openssl/gtlsconnection-openssl.c       |  7 +---
 tls/openssl/gtlsconnection-openssl.h       |  2 +-
 tls/openssl/gtlsfiledatabase-openssl.c     |  5 +--
 tls/openssl/gtlsfiledatabase-openssl.h     |  4 ---
 tls/openssl/gtlsserverconnection-openssl.c |  3 +-
 tls/openssl/openssl-include.h              | 58 ++++++++++++++++++++++++++++++
 tls/openssl/openssl-util.c                 |  2 +-
 tls/openssl/openssl-util.h                 |  2 +-
 14 files changed, 70 insertions(+), 33 deletions(-)
---
diff --git a/tls/openssl/Makefile.am b/tls/openssl/Makefile.am
index fc0cde3..05a1875 100644
--- a/tls/openssl/Makefile.am
+++ b/tls/openssl/Makefile.am
@@ -22,6 +22,7 @@ libgioopenssl_la_SOURCES =            \
        gtlsbio.c                       \
        openssl-util.h                  \
        openssl-util.c                  \
+       openssl-include.h                       \
        $(NULL)
 
 AM_CPPFLAGS +=                         \
diff --git a/tls/openssl/gtlsbackend-openssl.c b/tls/openssl/gtlsbackend-openssl.c
index 10c8ed2..287404b 100644
--- a/tls/openssl/gtlsbackend-openssl.c
+++ b/tls/openssl/gtlsbackend-openssl.c
@@ -28,8 +28,7 @@
 #include <errno.h>
 #include <string.h>
 
-#include <openssl/ssl.h>
-#include <openssl/crypto.h>
+#include "openssl-include.h"
 
 #include "gtlsbackend-openssl.h"
 #include "gtlscertificate-openssl.h"
diff --git a/tls/openssl/gtlsbio.h b/tls/openssl/gtlsbio.h
index 701f5d1..caa1e9b 100644
--- a/tls/openssl/gtlsbio.h
+++ b/tls/openssl/gtlsbio.h
@@ -26,7 +26,7 @@
 #define __G_TLS_BIO_H__
 
 #include <gio/gio.h>
-#include <openssl/bio.h>
+#include "openssl-include.h"
 
 G_BEGIN_DECLS
 
diff --git a/tls/openssl/gtlscertificate-openssl.c b/tls/openssl/gtlscertificate-openssl.c
index 71d1643..83e6e28 100644
--- a/tls/openssl/gtlscertificate-openssl.c
+++ b/tls/openssl/gtlscertificate-openssl.c
@@ -25,9 +25,7 @@
 #include "config.h"
 
 #include <string.h>
-#include <openssl/err.h>
-#include <openssl/x509.h>
-#include <openssl/x509_vfy.h>
+#include "openssl-include.h"
 
 #include "gtlscertificate-openssl.h"
 #include "openssl-util.h"
diff --git a/tls/openssl/gtlscertificate-openssl.h b/tls/openssl/gtlscertificate-openssl.h
index 6b40502..0827c0f 100644
--- a/tls/openssl/gtlscertificate-openssl.h
+++ b/tls/openssl/gtlscertificate-openssl.h
@@ -26,7 +26,7 @@
 #define __G_TLS_CERTIFICATE_OPENSSL_H__
 
 #include <gio/gio.h>
-#include <openssl/ssl.h>
+#include "openssl-include.h"
 
 G_BEGIN_DECLS
 
diff --git a/tls/openssl/gtlsclientconnection-openssl.c b/tls/openssl/gtlsclientconnection-openssl.c
index 57e72bd..b1560c1 100644
--- a/tls/openssl/gtlsclientconnection-openssl.c
+++ b/tls/openssl/gtlsclientconnection-openssl.c
@@ -25,16 +25,10 @@
 #include "config.h"
 #include "glib.h"
 
-#ifdef G_OS_WIN32
-#define WIN32_LEAN_AND_MEAN
-#endif
-
 #include <errno.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#include <openssl/x509_vfy.h>
 #include <string.h>
 
+#include "openssl-include.h"
 #include "gtlsconnection-base.h"
 #include "gtlsclientconnection-openssl.h"
 #include "gtlsbackend-openssl.h"
diff --git a/tls/openssl/gtlsconnection-openssl.c b/tls/openssl/gtlsconnection-openssl.c
index f3ecf4c..fbcb869 100644
--- a/tls/openssl/gtlsconnection-openssl.c
+++ b/tls/openssl/gtlsconnection-openssl.c
@@ -27,12 +27,7 @@
 
 #include <errno.h>
 #include <stdarg.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_OCSP)
-#include <openssl/ocsp.h>
-#endif
-
+#include "openssl-include.h"
 
 #include "gtlsconnection-openssl.h"
 #include "gtlsbackend-openssl.h"
diff --git a/tls/openssl/gtlsconnection-openssl.h b/tls/openssl/gtlsconnection-openssl.h
index 0689189..31eeab3 100644
--- a/tls/openssl/gtlsconnection-openssl.h
+++ b/tls/openssl/gtlsconnection-openssl.h
@@ -28,7 +28,7 @@
 #include <gio/gio.h>
 
 #include "gtlsconnection-base.h"
-#include <openssl/ssl.h>
+#include "openssl-include.h"
 
 G_BEGIN_DECLS
 
diff --git a/tls/openssl/gtlsfiledatabase-openssl.c b/tls/openssl/gtlsfiledatabase-openssl.c
index b80b169..49c3d70 100644
--- a/tls/openssl/gtlsfiledatabase-openssl.c
+++ b/tls/openssl/gtlsfiledatabase-openssl.c
@@ -28,10 +28,7 @@
 
 #include <gio/gio.h>
 #include <glib/gi18n-lib.h>
-#include <openssl/ssl.h>
-#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_OCSP)
-#include <openssl/ocsp.h>
-#endif
+#include "openssl-include.h"
 
 typedef struct _GTlsFileDatabaseOpensslPrivate
 {
diff --git a/tls/openssl/gtlsfiledatabase-openssl.h b/tls/openssl/gtlsfiledatabase-openssl.h
index ebb200f..67086db 100644
--- a/tls/openssl/gtlsfiledatabase-openssl.h
+++ b/tls/openssl/gtlsfiledatabase-openssl.h
@@ -27,10 +27,6 @@
 
 #include <gio/gio.h>
 
-#ifdef G_OS_WIN32
-#define WIN32_LEAN_AND_MEAN
-#endif
-
 #include "gtlsdatabase-openssl.h"
 
 G_BEGIN_DECLS
diff --git a/tls/openssl/gtlsserverconnection-openssl.c b/tls/openssl/gtlsserverconnection-openssl.c
index 73feb94..6a99574 100644
--- a/tls/openssl/gtlsserverconnection-openssl.c
+++ b/tls/openssl/gtlsserverconnection-openssl.c
@@ -27,8 +27,7 @@
 #include "gtlsserverconnection-openssl.h"
 #include "gtlscertificate-openssl.h"
 
-#include <openssl/ssl.h>
-#include <openssl/err.h>
+#include "openssl-include.h"
 #include <glib/gi18n-lib.h>
 
 typedef struct _GTlsServerConnectionOpensslPrivate
diff --git a/tls/openssl/openssl-include.h b/tls/openssl/openssl-include.h
new file mode 100644
index 0000000..7a6a460
--- /dev/null
+++ b/tls/openssl/openssl-include.h
@@ -0,0 +1,58 @@
+/*
+ * gtlscertificate-openssl.h
+ *
+ * Copyright (C) 2015 NICE s.r.l.
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * In addition, when the library is used with OpenSSL, a special
+ * exception applies. Refer to the LICENSE_EXCEPTION file for details.
+ *
+ * Authors: Ignacio Casal Quinteiro
+ *          Christoph Reiter
+ */
+
+/* Due to name clashes between Windows and openssl headers we have to
+ * make sure windows.h is included before openssl and that we undef the
+ * clashing macros.
+ */
+
+#ifndef __G_TLS_OPENSSL_INCLUDE_H__
+#define __G_TLS_OPENSSL_INCLUDE_H__
+
+#include "glib.h"
+
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+/* These are defined by the Windows headers, but clash with openssl */
+#undef X509_NAME
+#undef X509_CERT_PAIR
+#undef X509_EXTENSIONS
+#undef OCSP_REQUEST
+#undef OCSP_RESPONSE
+#endif
+
+#include <openssl/ssl.h>
+#include <openssl/bio.h>
+#include <openssl/err.h>
+#include <openssl/x509.h>
+#include <openssl/x509_vfy.h>
+#include <openssl/x509v3.h>
+#include <openssl/crypto.h>
+#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_OCSP)
+#include <openssl/ocsp.h>
+#endif
+
+#endif /* __G_TLS_OPENSSL_INCLUDE_H__ */
diff --git a/tls/openssl/openssl-util.c b/tls/openssl/openssl-util.c
index 5ba63f1..c78cb6d 100644
--- a/tls/openssl/openssl-util.c
+++ b/tls/openssl/openssl-util.c
@@ -65,7 +65,7 @@
 
 #include "openssl-util.h"
 #include <string.h>
-#include <openssl/x509v3.h>
+#include "openssl-include.h"
 
 #ifdef _MSC_VER
 #define strncasecmp _strnicmp
diff --git a/tls/openssl/openssl-util.h b/tls/openssl/openssl-util.h
index 72cd2c9..10618cc 100644
--- a/tls/openssl/openssl-util.h
+++ b/tls/openssl/openssl-util.h
@@ -64,7 +64,7 @@
 #ifndef __G_TLS_OPENSSL_UTIL_H__
 #define __G_TLS_OPENSSL_UTIL_H__
 
-#include <openssl/x509.h>
+#include "openssl-include.h"
 
 /*
  * Always check subject name for host match even if subject alt names present


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]