Skip to content

Commit c87ce88

Browse files
tiranelprans
authored andcommitted
bpo-43466: Add --with-openssl-rpath configure option (pythonGH-24820)
1 parent 939911b commit c87ce88

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

Doc/using/unix.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,53 @@ some Unices may not have the :program:`env` command, so you may need to hardcode
134134
``/usr/bin/python3`` as the interpreter path.
135135

136136
To use shell commands in your Python scripts, look at the :mod:`subprocess` module.
137+
138+
139+
Custom OpenSSL
140+
==============
141+
142+
1. To use your vendor's OpenSSL configuration and system trust store, locate
143+
the directory with ``openssl.cnf`` file or symlink in ``/etc``. On most
144+
distribution the file is either in ``/etc/ssl`` or ``/etc/pki/tls``. The
145+
directory should also contain a ``cert.pem`` file and/or a ``certs``
146+
directory.
147+
148+
.. code-block:: shell-session
149+
150+
$ find /etc/ -name openssl.cnf -printf "%h\n"
151+
/etc/ssl
152+
153+
2. Download, build, and install OpenSSL. Make sure you use ``install_sw`` and
154+
not ``install``. The ``install_sw`` target does not override
155+
``openssl.cnf``.
156+
157+
.. code-block:: shell-session
158+
159+
$ curl -O https://www.openssl.org/source/openssl-VERSION.tar.gz
160+
$ tar xzf openssl-VERSION
161+
$ pushd openssl-VERSION
162+
$ ./config \
163+
--prefix=/usr/local/custom-openssl \
164+
--openssldir=/etc/ssl
165+
$ make -j1 depend
166+
$ make -j8
167+
$ make install_sw
168+
$ popd
169+
170+
3. Build Python with custom OpenSSL
171+
172+
.. code-block:: shell-session
173+
174+
$ pushd python-3.x.x
175+
$ ./configure -C \
176+
--with-openssl=/usr/local/custom-openssl \
177+
--with-openssl-rpath=auto \
178+
--prefix=/usr/local/python-3.x.x
179+
$ make -j8
180+
$ make altinstall
181+
182+
.. note::
183+
184+
Patch releases of OpenSSL have a backwards compatible ABI. You don't need
185+
to recompile Python to update OpenSSL. It's sufficient to replace the
186+
custom OpenSSL installation with a newer version.

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ ENSUREPIP= @ENSUREPIP@
200200
OPENSSL_INCLUDES=@OPENSSL_INCLUDES@
201201
OPENSSL_LIBS=@OPENSSL_LIBS@
202202
OPENSSL_LDFLAGS=@OPENSSL_LDFLAGS@
203+
OPENSSL_RPATH=@OPENSSL_RPATH@
203204

204205
# Default zoneinfo.TZPATH. Added here to expose it in sysconfig.get_config_var
205206
TZPATH=@TZPATH@

configure

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ ac_includes_default="\
623623
#endif"
624624

625625
ac_subst_vars='LTLIBOBJS
626+
OPENSSL_RPATH
626627
OPENSSL_LDFLAGS
627628
OPENSSL_LIBS
628629
OPENSSL_INCLUDES
@@ -849,6 +850,7 @@ with_platlibdir
849850
with_computed_gotos
850851
with_ensurepip
851852
with_openssl
853+
with_openssl_rpath
852854
with_ssl_default_suites
853855
with_builtin_hashlib_hashes
854856
'
@@ -1578,6 +1580,11 @@ Optional Packages:
15781580
"install" or "upgrade" using bundled pip (default is
15791581
upgrade)
15801582
--with-openssl=DIR root of the OpenSSL directory
1583+
--with-openssl-rpath=[DIR|auto|no]
1584+
Set runtime library directory (rpath) for OpenSSL
1585+
libraries, no (default): don't set rpath, auto:
1586+
auto-detect rpath from --with-openssl and
1587+
pkg-config, DIR: set an explicit rpath
15811588
--with-ssl-default-suites=[python|openssl|STRING]
15821589
override default cipher suites string, python: use
15831590
Python's preferred selection (default), openssl:
@@ -17579,6 +17586,31 @@ $as_echo "#define HAVE_X509_VERIFY_PARAM_SET1_HOST 1" >>confdefs.h
1757917586
LIBS="$save_LIBS"
1758017587
fi
1758117588

17589+
# rpath to libssl and libcrypto
17590+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-openssl-rpath" >&5
17591+
$as_echo_n "checking for --with-openssl-rpath... " >&6; }
17592+
17593+
# Check whether --with-openssl-rpath was given.
17594+
if test "${with_openssl_rpath+set}" = set; then :
17595+
withval=$with_openssl_rpath;
17596+
else
17597+
with_openssl_rpath=no
17598+
17599+
fi
17600+
17601+
case $with_openssl_rpath in #(
17602+
auto|yes) :
17603+
OPENSSL_RPATH=auto ;; #(
17604+
no) :
17605+
OPENSSL_RPATH= ;; #(
17606+
*) :
17607+
OPENSSL_RPATH="$with_openssl_rpath"
17608+
;;
17609+
esac
17610+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPENSSL_RPATH" >&5
17611+
$as_echo "$OPENSSL_RPATH" >&6; }
17612+
17613+
1758217614
# ssl module default cipher suite string
1758317615

1758417616

configure.ac

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5763,6 +5763,26 @@ if test "$have_openssl" = yes; then
57635763
LIBS="$save_LIBS"
57645764
fi
57655765

5766+
# rpath to libssl and libcrypto
5767+
AC_MSG_CHECKING(for --with-openssl-rpath)
5768+
AC_ARG_WITH(openssl-rpath,
5769+
AS_HELP_STRING([--with-openssl-rpath=@<:@DIR|auto|no@:>@],
5770+
[Set runtime library directory (rpath) for OpenSSL libraries,
5771+
no (default): don't set rpath,
5772+
auto: auto-detect rpath from --with-openssl and pkg-config,
5773+
DIR: set an explicit rpath
5774+
]),
5775+
[],
5776+
[with_openssl_rpath=no]
5777+
)
5778+
AS_CASE($with_openssl_rpath,
5779+
[auto|yes],[OPENSSL_RPATH=auto],
5780+
[no],[OPENSSL_RPATH=],
5781+
[OPENSSL_RPATH="$with_openssl_rpath"]
5782+
)
5783+
AC_MSG_RESULT($OPENSSL_RPATH)
5784+
AC_SUBST([OPENSSL_RPATH])
5785+
57665786
# ssl module default cipher suite string
57675787
AH_TEMPLATE(PY_SSL_DEFAULT_CIPHERS,
57685788
[Default cipher suites list for ssl module.

setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ def print_three_column(lst):
538538
"libssl with X509_VERIFY_PARAM_set1_host().")
539539
print("LibreSSL 2.6.4 and earlier do not provide the necessary "
540540
"APIs, https://github.com/libressl-portable/portable/issues/381")
541+
if sysconfig.get_config_var("OPENSSL_LDFLAGS"):
542+
print("Custom linker flags may require --with-openssl-rpath=auto")
541543
print()
542544

543545
def build_extension(self, ext):
@@ -2324,6 +2326,7 @@ def split_var(name, sep):
23242326
openssl_includes = split_var('OPENSSL_INCLUDES', '-I')
23252327
openssl_libdirs = split_var('OPENSSL_LDFLAGS', '-L')
23262328
openssl_libs = split_var('OPENSSL_LIBS', '-l')
2329+
openssl_rpath = config_vars.get('OPENSSL_RPATH')
23272330
if not openssl_libs:
23282331
# libssl and libcrypto not found
23292332
self.missing.extend(['_ssl', '_hashlib'])
@@ -2345,12 +2348,20 @@ def split_var(name, sep):
23452348
if krb5_h:
23462349
ssl_incs.extend(krb5_h)
23472350

2351+
if openssl_rpath == 'auto':
2352+
runtime_library_dirs = openssl_libdirs[:]
2353+
elif not openssl_rpath:
2354+
runtime_library_dirs = []
2355+
else:
2356+
runtime_library_dirs = [openssl_rpath]
2357+
23482358
if config_vars.get("HAVE_X509_VERIFY_PARAM_SET1_HOST"):
23492359
self.add(Extension(
23502360
'_ssl', ['_ssl.c'],
23512361
include_dirs=openssl_includes,
23522362
library_dirs=openssl_libdirs,
23532363
libraries=openssl_libs,
2364+
runtime_library_dirs=runtime_library_dirs,
23542365
depends=[
23552366
'socketmodule.h',
23562367
'_ssl/debughelpers.c',
@@ -2365,6 +2376,7 @@ def split_var(name, sep):
23652376
depends=['hashlib.h'],
23662377
include_dirs=openssl_includes,
23672378
library_dirs=openssl_libdirs,
2379+
runtime_library_dirs=runtime_library_dirs,
23682380
libraries=openssl_libs))
23692381

23702382
def detect_hash_builtins(self):

0 commit comments

Comments
 (0)