Wednesday, October 5, 2016

create a simple https server for testing

1- install packages
$ sudo apt-get install easy-rsa

2- create certification for https server
$ cd /usr/share/easy-rsa
$ mkdir keys
$ touch keys/index.txt
$ echo 01 > keys/serial
$ source ./vars
$ export PATH=$PATH:/usr/share/easy-rsa
$ pkitool --initca
$ pkitool --server server1


3- create pem file from the certificate and key file
$ sudo cat keys/server1.crt keys/server1.key > keys/server1.pem

4- copy the server1.pem file to directory https
$ sudo mkdir ~/https
$ cp /usr/share/easy-rsa/keys/server1.pem ~/https

5- create the https.py file that will start https server, the file store in ~/https/https.py it content is below

import BaseHTTPServer, SimpleHTTPServer
import ssl
import sys

if len(sys.argv) == 1:
 port = 443
else:
 port = int(sys.argv[1])

certfile = "./server1.pem"
httpd = BaseHTTPServer.HTTPServer(('localhost', port), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile=certfile, server_side=True)
httpd.serve_forever()



6- start the server
- by default it will listen on port 443,
$ sudo python https.py

- we you want to change port use command below
$ sudo python https.py 4443

- snapshot of access the https that we run above

No comments:

Post a Comment