Skip to content

Commit 0768ab5

Browse files
committed
fix (M2Crypto): work around symbol export bug
1 parent fad1532 commit 0768ab5

File tree

1 file changed

+30
-15
lines changed
  • src/DIRAC/Core/DISET/private/Transports/SSL

1 file changed

+30
-15
lines changed

src/DIRAC/Core/DISET/private/Transports/SSL/M2Utils.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
"""
55
import os
66
import tempfile
7+
import M2Crypto
8+
from packaging.version import Version
79
from M2Crypto import SSL, m2, X509
810

11+
912
from DIRAC.Core.DISET import DEFAULT_SSL_CIPHERS, DEFAULT_SSL_METHODS
1013
from DIRAC.Core.Security import Locations
1114
from DIRAC.Core.Security.m2crypto.X509Chain import X509Chain
@@ -15,6 +18,30 @@
1518
DEBUG_M2CRYPTO = os.getenv("DIRAC_DEBUG_M2CRYPTO", "No").lower() in ("yes", "true")
1619

1720

21+
VERIFY_ALLOW_PROXY_CERTS = 0
22+
23+
# If the version of M2Crypto is recent enough, there is an API
24+
# to accept proxy certificate, and we do not need to rely on
25+
# OPENSSL_ALLOW_PROXY_CERT environment variable
26+
# which was removed as of openssl 1.1
27+
# We need this to be merged in M2Crypto: https://gitlab.com/m2crypto/m2crypto/merge_requests/236
28+
# We set the proper verify flag to the X509Store of the context
29+
# as described here https://www.openssl.org/docs/man1.1.1/man7/proxy-certificates.html
30+
if hasattr(SSL, "verify_allow_proxy_certs"):
31+
VERIFY_ALLOW_PROXY_CERTS = SSL.verify_allow_proxy_certs # pylint: disable=no-member
32+
# As of M2Crypto 0.37, the `verify_allow_proxy_certs` flag was moved
33+
# to X509 (https://gitlab.com/m2crypto/m2crypto/-/merge_requests/238)
34+
# It is more consistent with all the other flags,
35+
# but pySSL had it in SSL. Well...
36+
elif hasattr(X509, "verify_allow_proxy_certs"):
37+
VERIFY_ALLOW_PROXY_CERTS = X509.verify_allow_proxy_certs # pylint: disable=no-member
38+
# As of M2Crypto 0.38, M2Crypto did not export the symbol correctly
39+
# Anymore
40+
# https://gitlab.com/m2crypto/m2crypto/-/issues/298
41+
elif Version(M2Crypto.__version__) >= Version("0.38.0"):
42+
VERIFY_ALLOW_PROXY_CERTS = 64
43+
44+
1845
def __loadM2SSLCTXHostcert(ctx):
1946
"""Load hostcert & key from the default location and set them as the
2047
credentials for SSL context ctx.
@@ -125,21 +152,9 @@ def getM2SSLContext(ctx=None, **kwargs):
125152
raise RuntimeError(f"CA path ({caPath}) is not a valid directory")
126153
ctx.load_verify_locations(capath=caPath)
127154

128-
# If the version of M2Crypto is recent enough, there is an API
129-
# to accept proxy certificate, and we do not need to rely on
130-
# OPENSSL_ALLOW_PROXY_CERT environment variable
131-
# which was removed as of openssl 1.1
132-
# We need this to be merged in M2Crypto: https://gitlab.com/m2crypto/m2crypto/merge_requests/236
133-
# We set the proper verify flag to the X509Store of the context
134-
# as described here https://www.openssl.org/docs/man1.1.1/man7/proxy-certificates.html
135-
if hasattr(SSL, "verify_allow_proxy_certs"):
136-
ctx.get_cert_store().set_flags(SSL.verify_allow_proxy_certs) # pylint: disable=no-member
137-
# As of M2Crypto 0.37, the `verify_allow_proxy_certs` flag was moved
138-
# to X509 (https://gitlab.com/m2crypto/m2crypto/-/merge_requests/238)
139-
# It is more consistent with all the other flags,
140-
# but pySSL had it in SSL. Well...
141-
if hasattr(X509, "verify_allow_proxy_certs"):
142-
ctx.get_cert_store().set_flags(X509.verify_allow_proxy_certs) # pylint: disable=no-member
155+
# Allow proxy certificates to be used
156+
if VERIFY_ALLOW_PROXY_CERTS:
157+
ctx.get_cert_store().set_flags(VERIFY_ALLOW_PROXY_CERTS)
143158

144159
# Other parameters
145160
sslMethods = kwargs.get("sslMethods", DEFAULT_SSL_METHODS)

0 commit comments

Comments
 (0)