Skip to content

Instantly share code, notes, and snippets.

@gearbox
Forked from vpack/flask_ssl_app.py
Created April 4, 2020 18:42
Show Gist options
  • Save gearbox/b9ff52ca4d288943f508f9a14985fc7e to your computer and use it in GitHub Desktop.
Save gearbox/b9ff52ca4d288943f508f9a14985fc7e to your computer and use it in GitHub Desktop.
Flask SSL Sample APP
from flask import Flask
from flask_sslify import SSLify
"""
Option 1 : (pip install pyopenssl)
from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('web.key')
context.use_certificate_file('web.crt')
Option 2 : (OOB : No install)
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain('web.crt', 'web.key')
Option 3 : Native Flask (No imports needed)
"""
app = Flask(__name__)
context = ('web.crt', 'web.key')
sslify = SSLify(app)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
context = ('web.crt', 'web.key')
app.run( debug = True, ssl_context = context)
#app.run( debug = True, ssl_context = 'adhoc') # Generate Adhoc Certs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment