Skip to content

Instantly share code, notes, and snippets.

@mateusza
Created October 22, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mateusza/3429a3946a87876e456e81d4ce7c1591 to your computer and use it in GitHub Desktop.
Save mateusza/3429a3946a87876e456e81d4ce7c1591 to your computer and use it in GitHub Desktop.
#!/bin/bash
n=razi91
openssl genrsa -out $n.key
openssl rsa -pubout -in $n.key -out $n.pub
openssl req -new -sha256 -key $n.key -subj '/CN=127.0.0.1/' -out $n.csr
openssl x509 -req -in $n.csr -signkey $n.key -out $n.crt -days 30
#!/usr/bin/env python
import http.server, socketserver
import socket, ssl
n='razi91'
KLUCZ = '%s.key' % n
CERTYFIKAT = '%s.crt' % n
PORT = 8443
HOST = socket.gethostname()
RH = http.server.SimpleHTTPRequestHandler
https = socketserver.TCPServer(
("0.0.0.0", PORT), RH
)
https.socket = ssl.wrap_socket(
https.socket,
keyfile = KLUCZ,
certfile= CERTYFIKAT
)
print( "Serwer HTTPS", HOST, ":", PORT )
https.serve_forever()
#!/usr/bin/env python
import requests
n='razi91'
URL="https://127.0.0.1:8443/test.txt"
req = requests.get( URL, verify='razi91.crt' )
print( req.text )
#!/usr/bin/env python
import requests
from requests.packages.urllib3.exceptions import SubjectAltNameWarning
requests.packages.urllib3.disable_warnings(SubjectAltNameWarning)
n='razi91'
URL="https://127.0.0.1:8443/test.txt"
req = requests.get( URL, verify=('%s.crt' % n) )
print( req.text )
No i dziala.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment