Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create self signed SSL certificates in Python

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.

like image 644
Niklas Avatar asked Sep 09 '11 10:09

Niklas


People also ask

How do I create a self-signed certificate in Python?

First, you will generate a private key. For this example we will be using RSA having a key size of 2048, the lowest recommended bit size. Next, generate the self signed certificate. The certificate will contain data about who you are and who your organization is.

Which command can be used to create a self signed SSL certificate?

You can create a self-signed key and certificate pair with OpenSSL in a single command: sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.


1 Answers

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.

like image 160
jfs Avatar answered Oct 03 '22 08:10

jfs