Skip to content

Commit 1969ca3

Browse files
committed
issue2551219 - use of PEM file with roundup-server
Document requirements of PEM file when using roundup-server in SSL/TLS mode in the config.ini generated by roundup-server --save-config. Trap errors produced by missing cert or key when reading a pem file and try to produce a more useful error. Man page already had correct documentation. However because man pages are justified, the marker lines get additional internal spacing. Use example macros to prevent this spacing in case somebody cuts/pastes the marker lines.
1 parent d760059 commit 1969ca3

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ Fixed:
170170
requests where the file is not modified. (John Rouillard)
171171
- Update JWT example in rest.py to use replacement for
172172
datetime.datetime.utcnow(). (John Rouillard)
173+
- issue2551219 - document requirements of PEM file when using
174+
roundup-server in SSL/TLS mode. Report better error messages
175+
when PEM file is missing certificate or private key. (John
176+
Rouillard)
173177

174178
Features:
175179

roundup/scripts/roundup_server.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,18 @@ def __init__(self, server_address, HandlerClass, ssl_pem=None):
137137
self.socket = socket.socket(self.address_family, self.socket_type)
138138
if ssl_pem:
139139
ctx = SSL.Context(SSL.TLSv1_2_METHOD)
140-
ctx.use_privatekey_file(ssl_pem)
141-
ctx.use_certificate_file(ssl_pem)
140+
try:
141+
ctx.use_privatekey_file(ssl_pem)
142+
except SSL.Error:
143+
print(_("Unable to find/use key from file: %(pemfile)s") % {"pemfile": ssl_pem})
144+
print(_("Does it have a private key surrounded by '-----BEGIN PRIVATE KEY-----' and\n '-----END PRIVATE KEY-----' markers?"))
145+
exit()
146+
try:
147+
ctx.use_certificate_file(ssl_pem)
148+
except SSL.Error:
149+
print(_("Unable to find/use certificate from file: %(pemfile)s") % {"pemfile": ssl_pem})
150+
print(_("Does it have a certificate surrounded by '-----BEGIN CERTIFICATE-----' and\n '-----END CERTIFICATE-----' markers?"))
151+
exit()
142152
else:
143153
ctx = auto_ssl()
144154
self.ssl_context = ctx
@@ -677,8 +687,13 @@ class ServerConfig(configuration.Config):
677687
(configuration.BooleanOption, "ssl", "no",
678688
"Enable SSL support (requires pyopenssl)"),
679689
(configuration.NullableFilePathOption, "pem", "",
680-
"PEM file used for SSL. A temporary self-signed certificate\n"
681-
"will be used if left blank."),
690+
"PEM file used for SSL. The PEM file must include\n"
691+
"both the private key and certificate with appropriate\n"
692+
'headers (i.e. "-----BEGIN PRIVATE KEY-----",\n'
693+
'"-----END PRIVATE KEY-----" and '
694+
'"-----BEGIN CERTIFICATE-----",\n'
695+
'"-----END CERTIFICATE-----". A temporary self-signed\n'
696+
"certificate will be used if left blank."),
682697
(configuration.WordListOption, "include_headers", "",
683698
"Comma separated list of extra headers that should\n"
684699
"be copied into the CGI environment.\n"

share/man/man1/roundup-server.1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,21 @@ roundup-server.
5959
\fB-e\fP \fIfile\fP
6060
Sets a filename containing the PEM file to use for SSL. The PEM file
6161
must include both the private key and certificate with appropriate
62-
headers (e.g. "-----BEGIN PRIVATE KEY-----", "-----END PRIVATE
63-
KEY-----" and "-----BEGIN CERTIFICATE-----", "-----END
64-
CERTIFICATE-----". If no file is specified, a temporary self-signed
62+
header/trailer markers:
63+
64+
.EX
65+
-----BEGIN PRIVATE KEY-----
66+
-----END PRIVATE KEY-----
67+
.EE
68+
69+
and
70+
71+
.EX
72+
-----BEGIN CERTIFICATE-----
73+
-----END CERTIFICATE-----
74+
.EE
75+
76+
If no file is specified, a temporary self-signed
6577
certificate will be used.
6678
.TP
6779
\fB-N\fP

0 commit comments

Comments
 (0)