Create a self-signed certificate in python

I want to create a self-signed certificate in Python. I poked around a bit and found some places and other questions that basically say to import things from OpenSSL. I'm familiar with openssl's command line utilities so I figured that sounds like a good place to start. However, when I import OpenSSL I get ImportError: No module named 'OpenSSL'. When I tried pip install --user OpenSSL I got No matching distribution found for OpenSSL

I am using python3 version 3.5 on one machine and 3.7 on another machine. It doesn't matter if it's specifically openssl, just as long as it's secure and well maintained and capable of generating valid certs for TLSv1.2 and preferably also TLSv1.3

I guess I could go run os.system('openssl ...') but I'd rather have it all in python or libraries instead of creating another process.

1 answer

  • answered 2018-10-16 21:14 inetknght

    The trouble was that I needed to install the pyopenssl library. pip install --user pyopenssl was needed rather than pip install --user OpenSSL. After that, import OpenSSL worked just fine.

    It's rather frustrating that the library name and import name aren't the same!