-
-
Save gearbox/b9ff52ca4d288943f508f9a14985fc7e to your computer and use it in GitHub Desktop.
Flask SSL Sample APP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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