Skip to content

Commit fe3a099

Browse files
geissonatorbradbishop
authored andcommitted
Support optional parameter to not enable ssl
This server can be started in two different ways: 1. Via systemd socket, which can itself come in two different paths: a. Direct bind to external HTTPS port 443 b. Reverse proxy to local port like 8081 2. Via command line call This commit keeps backward compatibility and allows this new --no-ssl option to be passed in when using a proxy. Change-Id: I713b53e492862684eb6db45c602ce3c9e8e2f453 Signed-off-by: Andrew Geissler <[email protected]>
1 parent 313aadb commit fe3a099

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

servers/gevent/phosphor-gevent

+40-19
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,23 @@ try:
2727
except ImportError:
2828
have_wsock = False
2929

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)
3036
if __name__ == '__main__':
37+
3138
if len(sys.argv) < 2:
3239
sys.stderr.write('WSGI application required!')
3340
sys.exit(1)
3441

42+
if (len(sys.argv) > 2) and (sys.argv[2] == "--no-ssl"):
43+
use_ssl = False
44+
else:
45+
use_ssl = True
46+
3547
exec('from obmc.wsgi.apps.%s import App' % sys.argv[1])
3648

3749
default_cert = os.path.join(
@@ -42,33 +54,42 @@ if __name__ == '__main__':
4254
kw['have_wsock'] = True
4355
app = App(**kw)
4456

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
5978

6079
if os.environ.get('LISTEN_PID', None) == str(os.getpid()):
6180
FIRST_SYSTEMD_SOCKET_FD = 3
6281
bind = gevent.socket.fromfd(FIRST_SYSTEMD_SOCKET_FD,
6382
gevent.socket.AF_INET,
6483
gevent.socket.SOCK_STREAM)
6584
else:
66-
bind = ('', 443)
85+
if use_ssl:
86+
bind = ('', 443)
87+
else:
88+
bind = ('', 80)
6789

68-
kw = {}
6990
if have_wsock:
7091
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+
7495
server.serve_forever()

0 commit comments

Comments
 (0)