Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How can I tell if my python has SSL?

Tags:

python

ssl

How can I tell if my source-built python has SSL enabled? either

  • after running configure, but before compiling (best).
  • after compiling, when I can run the python.

Context:

  • a script that populates a bare linux box.
  • Prerequisite is to install openssl, so that Python can do https.
  • trying to detect if this prerequisite is not met.
like image 292
Mark Harrison Avatar asked May 05 '16 16:05

Mark Harrison


People also ask

What is ssl Python?

Source code: Lib/ssl.py. This module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption and peer authentication facilities for network sockets, both client-side and server-side. This module uses the OpenSSL library.

What version of OpenSSL does Python use?

Currently Python versions 3.6 to 3.9 are compatible with OpenSSL 1.0. 2, 1.1. 0, and 1.1. 1.

Does Python use OpenSSL?

For example, python itself uses openssl, while conda uses pyopenssl.


1 Answers

If all you want to do is figure out if openssl is installed, you can parse the output of openssl version:

$ openssl version
OpenSSL 1.0.2g-fips  1 Mar 2016

You can get all sorts of information from version, for example, the directory where its stored:

$ openssl version -d
OPENSSLDIR: "/usr/lib/ssl"

As far as Python goes, I'm not sure how you can tell before running configure (maybe check the contents of config.log?) but once Python is installed; simply parse the output of ssl.OPENSSL_VERSION, like this:

$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2g-fips  1 Mar 2016

For even more information, have a play with the sysconfig module, for example:

$ python -c "import sysconfig; print(sysconfig.get_config_var('CONFIG_ARGS'))"
'--enable-shared' '--prefix=/usr' '--enable-ipv6' '--enable-unicode=ucs4' '--with-dbmliborder=bdb:gdbm' '--with-system-expat' '--with-computed-gotos' '--with-system-ffi' '--with-fpectl' 'CC=x86_64-linux-gnu-gcc' 'CFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security ' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'
like image 136
Burhan Khalid Avatar answered Oct 04 '22 19:10

Burhan Khalid