Skip to content

Commit

Permalink
Add option to run flask server over SSL + sample key/certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
jywsn committed Jan 22, 2014
1 parent e59b22d commit 8e39239
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
22 changes: 20 additions & 2 deletions website/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import sys
import os

#if __name__ == "__main__":
# Add current directory to sys.path
site_dir = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -88,4 +87,23 @@ def catch_all(path='index.html'):


if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=True)
import getopt

ssl_context = None

try:
opts, args = getopt.getopt(sys.argv[1:], "s", [])
for opt, arg in opts:
if opt == '-s':
from OpenSSL import SSL
ssl_context = SSL.Context(SSL.SSLv23_METHOD)
ssl_context.use_privatekey_file(os.path.join(site_dir, 'website.key'))
ssl_context.use_certificate_file(os.path.join(site_dir, 'website.crt'))
else:
print 'Usage: app.py [-s]'
sys.exit(1)
except getopt.GetoptError:
print 'Usage: app.py [-s]'
sys.exit(1)

app.run(host='0.0.0.0', port=5000, debug=True, ssl_context=ssl_context)
11 changes: 11 additions & 0 deletions website/website.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN CERTIFICATE-----
MIIBjTCCARcCCCznE7POI8AAMA0GCSqGSIb3DQEBBAUAMDQxHDAaBgNVBAMTE1Vu
dHJ1c3RlZCBBdXRob3JpdHkxFDASBgNVBAoTC1NlbGYtU2lnbmVkMB4XDTE0MDEy
MjE2MTcxOVoXDTE1MDEyMjE2MTcxOVowKDEKMAgGA1UEAxQBKjEaMBgGA1UEChMR
RHVtbXkgQ2VydGlmaWNhdGUwfDANBgkqhkiG9w0BAQEFAANrADBoAmEA4H70o/cV
7tW3z8bGRt4iWhrUor84TbLeHV3traB5opOieBupYmvafiuYIW8+abVPu/QSv51S
3vtYj84aqjC9/20hgYaM3fXDRsBfAAeVBBjgOLTYknWT4MqwcW2+GmQfAgMBAAEw
DQYJKoZIhvcNAQEEBQADYQBss/J6fZtSdvYtz9myPdK8dpCxWUqEOo1t9RcoboeX
l6PBWoBX9ne3xbHAjasugwGPfcpnZ0h2635nQXNkRspE5JYlnw+rNYZKTTq3DviY
qKnA8xPy/UUKVNp+j+num2o=
-----END CERTIFICATE-----
12 changes: 12 additions & 0 deletions website/website.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN RSA PRIVATE KEY-----
MIIBywIBAAJhAOB+9KP3Fe7Vt8/GxkbeIloa1KK/OE2y3h1d7a2geaKTongbqWJr
2n4rmCFvPmm1T7v0Er+dUt77WI/OGqowvf9tIYGGjN31w0bAXwAHlQQY4Di02JJ1
k+DKsHFtvhpkHwIDAQABAmA0Zy4wAANMpvKrO5kY/c1C/zRXcQ9xg6k5ba2HdAgw
nQm1w688XDS6cu6mD1OgVUQBjNTSilRQ9lATEi7bI9IDEyCBAQymC8KGQIJCYPYZ
mbzJzhgB4h53bqbqPmKQolECMQDx+jXresfi8GE5RrIu0kfyaHfyfyo/GORbewJh
FCxqSdEAplThgVxDHni1HQ7OpdUCMQDtgWdMTQAAhF9NHrhZUf3Zyt6SDGlLwPtm
hJM5/Vc4pxd1uWhH7Y0aDl/zHV022CMCMQCqVGpoG8FgabzGSJFcjADBDfCA7iqa
x7bW/juqgjzRhKxuPKc7JYgAZw6ozo+BvxECMQDr/ZuFbjElUmJbf73PSrAAmxqC
ZgCuO+fRGsQrZ7Yl3alq2Tpr1fdRP51JNREs8J8CMHCnIymHxP/FjRHM9taDyoR8
7TPbG8SVnk882KIeu5gigiAMCTeFnPXQCJSsrLKUoA==
-----END RSA PRIVATE KEY-----

0 comments on commit 8e39239

Please sign in to comment.