Create self signed SSL certificates in Python

Niklas picture Niklas · Sep 9, 2011 · Viewed 11.4k times · Source

I am trying to generate self signed SSL certificates using Python, so that it is platform independent. My target is the *.pem format.

I found this script that generates certificates, but no information how to self-sign them.

Answer

jfs picture jfs · Sep 9, 2011

The script you've linked doesn't create self-signed certificate; it only creates a request.

To create self-signed certificate you could use openssl it is available on all major OSes.

$ openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095

If you'd like to do it using M2Crypto then take a look at X509TestCase.test_mkcert() method.