Skip to content

Instantly share code, notes, and snippets.

@h007
Forked from 0xBADCA7/ssl_server.py
Last active January 11, 2022 09:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h007/196575c0d68d3832d246f1a32c07e6fd to your computer and use it in GitHub Desktop.
Save h007/196575c0d68d3832d246f1a32c07e6fd to your computer and use it in GitHub Desktop.
Simple HTTPS server in Python 3
#!/usr/bin/env python3
from http.server import HTTPServer,SimpleHTTPRequestHandler
from socketserver import BaseServer
import ssl
httpd = HTTPServer(('0.0.0.0', 1443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='certificate.pem', keyfile='privatekey.pem', server_side=True)
httpd.serve_forever()
@h007
Copy link
Author

h007 commented Jul 6, 2018

https://github.com/FiloSottile/mkcert

On Linux, install certutil
sudo apt-get update

sudo apt install libnss3-tools

https://github.com/FiloSottile/mkcert/releases
https://github.com/FiloSottile/mkcert/releases/download/v0.9.1/mkcert-v0.9.1-linux-amd64

chmod 755 mkcert-v0.9.1-linux-amd64

mkcert -install

mkcert example.com '*.example.org' myapp.dev localhost 127.0.0.1 ::1

使用 firefox 证书导入
about:preferences#advanced
Certificate Manager
Authorities
import
rootCA.pem (公钥)

root@kali:~/.local/share# cd mkcert/
root@kali:~/.local/share/mkcert# ls
rootCA-key.pem  rootCA.pem

有趣的互联网工具 #003 使用 mkcert 生成本地 SSL 证书 Use mkcert to generate a local SSL certificate

解决Could not get lock /var/cache/apt/archives/lock
在ubuntu apt-get upgrade的时候,遇到:

E: Could not get lock /var/cache/

apt/archives/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the download directory

解决办法如下:

sudo rm -rf /var/cache/apt/archives/lock
sudo apt-get update

然后apt-get就恢复正常了。



python3 -m http.server 8000

cd /var/www/

$ python -m SimpleHTTPServer

https://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3

sudo apt-get install python-pip
sudo apt-get install python3-pip

@dncpax
Copy link

dncpax commented Dec 8, 2021

to create the cert without installing anything:

openssl genrsa > privatekey.pem
openssl req -new -x509 -key privatekey.pem -out certificate.pem -days 365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment