27
27
except ImportError :
28
28
have_wsock = False
29
29
30
+ # Parameters
31
+ # <wsgi application> REQUIRED Application to import and run (e.g. rest_dbus)
32
+ # <--no-ssl> OPTIONAL Don't use SSL
33
+ #
34
+ # NOTE: If not activated via a systemd socket then this server will bind
35
+ # by default to all address's at port 443 or 80(--no-ssl)
30
36
if __name__ == '__main__' :
37
+
31
38
if len (sys .argv ) < 2 :
32
39
sys .stderr .write ('WSGI application required!' )
33
40
sys .exit (1 )
34
41
42
+ if (len (sys .argv ) > 2 ) and (sys .argv [2 ] == "--no-ssl" ):
43
+ use_ssl = False
44
+ else :
45
+ use_ssl = True
46
+
35
47
exec ('from obmc.wsgi.apps.%s import App' % sys .argv [1 ])
36
48
37
49
default_cert = os .path .join (
@@ -42,33 +54,42 @@ if __name__ == '__main__':
42
54
kw ['have_wsock' ] = True
43
55
app = App (** kw )
44
56
45
- # ECDH - Allow Elliptic Curve Diffie Hellman
46
- # kDH - Allow Key Exchange algorithm as Diffie Hellman
47
- # kEDH - Allow Key Exchange algorithm as Ephemeral Diffie Hellman
48
- # kRSA - Allow Key Exchange algorithm as RSA
49
- # !SSLv3 - Disallows any ciphers specific to SSLv3
50
- # !SSLv2 - Disallows any ciphers specific to SSLv2 protocol
51
- # !aNULL - Disallows anonymous authentication or no authentication
52
- # !eNULL - Disallows connection with NULL encryption
53
- # !LOW - Disallows any low strength ciphers
54
- # !MEDIUM- Disallows medium strength ciphers
55
-
56
- ssl_ciphers = (
57
- 'ECDH:kDH:kEDH:kRSA:!SSLv3:!SSLv2:!aNULL:!eNULL:!LOW:!MEDIUM:@STRENGTH'
58
- )
57
+ # repurpose for WSGIServer usage below
58
+ kw = {}
59
+
60
+ if use_ssl :
61
+ # ECDH - Allow Elliptic Curve Diffie Hellman
62
+ # kDH - Allow Key Exchange algorithm as Diffie Hellman
63
+ # kEDH - Allow Key Exchange algorithm as Ephemeral Diffie Hellman
64
+ # kRSA - Allow Key Exchange algorithm as RSA
65
+ # !SSLv3 - Disallows any ciphers specific to SSLv3
66
+ # !SSLv2 - Disallows any ciphers specific to SSLv2 protocol
67
+ # !aNULL - Disallows anonymous authentication or no authentication
68
+ # !eNULL - Disallows connection with NULL encryption
69
+ # !LOW - Disallows any low strength ciphers
70
+ # !MEDIUM- Disallows medium strength ciphers
71
+
72
+ kw ['ciphers' ] = (
73
+ 'ECDH:kDH:kEDH:kRSA:!SSLv3:!SSLv2:!aNULL:!eNULL:!LOW:!MEDIUM:@STRENGTH'
74
+ )
75
+
76
+ kw ['keyfile' ] = default_cert
77
+ kw ['certfile' ] = default_cert
59
78
60
79
if os .environ .get ('LISTEN_PID' , None ) == str (os .getpid ()):
61
80
FIRST_SYSTEMD_SOCKET_FD = 3
62
81
bind = gevent .socket .fromfd (FIRST_SYSTEMD_SOCKET_FD ,
63
82
gevent .socket .AF_INET ,
64
83
gevent .socket .SOCK_STREAM )
65
84
else :
66
- bind = ('' , 443 )
85
+ if use_ssl :
86
+ bind = ('' , 443 )
87
+ else :
88
+ bind = ('' , 80 )
67
89
68
- kw = {}
69
90
if have_wsock :
70
91
kw ['handler_class' ] = WebSocketHandler
71
- server = WSGIServer (
72
- bind , app , keyfile = default_cert , certfile = default_cert ,
73
- ciphers = ssl_ciphers , ** kw )
92
+
93
+ server = WSGIServer ( bind , app , ** kw )
94
+
74
95
server .serve_forever ()
0 commit comments