This example was tested under Ubuntu 18.04.2 with python 3.6.8.
Open the terminal and enter the following commands:
user@pc:~$ sudo apt install git -y
user@pc:~$ git clone https://github.com/arthurazs/python-tls
The first command install git, the second command downloads this repository.
Note that user@pc:~$
represents your username and computer name. You should type into the terminal only the text after the dollar sign, e.g. sudo apt install git -y
.
Open the terminal and enter the following commands:
user@pc:~$ cd python-tls
user@pc:~/python-tls$ openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout key.pem -subj "/C=BR/ST=Rio de Janeiro/L=Niteroi/O=UFF/OU=Midiacom/CN=example.org/[email protected]"
The first command changes the directory to the downloaded repository, the second command generates the certificate and private key.
Note that you can change some parameters:
- C, which is a 2 letter code for a country;
- ST, which is a state or province name;
- L (optional), which is a city name;
- O, which is an organization name;
- OU (optional), which is an organizational unit name;
- CN, which is the hostname:
- Warning If you change the CN value, you have to change the hostname under client.py to reflect the new hostname.
- emailAddress (optional), which is an email address.
Open the terminal and enter the following commands:
user@pc:~$ cd python-tls
user@pc:~/python-tls$ python3 server.py
Open the terminal and enter the following commands:
user@pc:~$ cd python-tls
user@pc:~/python-tls$ python3 client.py