-
Notifications
You must be signed in to change notification settings - Fork 776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSL client validation (certificate-based authentication) #295
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
090eaa0
Added SSL-certificate-based client authentication.
hoehermann 554a822
Added manual for certificate-based client authentication.
hoehermann a426020
Added hints to which Python versions allow client certificate authent…
hoehermann 8cb3acd
Kept ssl.create_default_context, but added fallback to ssl.wrap_socke…
hoehermann dfd50db
Improved `test_do_handshake_ssl_error_eof_raises_close_error` so it w…
hoehermann 8bad0ca
Improve test so it does not test methods that do not exist in old Pyt…
hoehermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,12 +89,27 @@ Here is an example of using websockify to wrap the vncserver command (which back | |
|
||
`./websockify 5901 --wrap-mode=ignore -- vncserver -geometry 1024x768 :1` | ||
|
||
Here is an example of wrapping telnetd (from krb5-telnetd).telnetd exits after the connection closes so the wrap mode is set to respawn the command: | ||
Here is an example of wrapping telnetd (from krb5-telnetd). telnetd exits after the connection closes so the wrap mode is set to respawn the command: | ||
|
||
`sudo ./websockify 2023 --wrap-mode=respawn -- telnetd -debug 2023` | ||
|
||
The wstelnet.html page demonstrates a simple WebSockets based telnet client. | ||
|
||
.SS Use client certificate verification | ||
|
||
This feature requires Python 2.7.9 or newer or Python 3.4 or newer. | ||
|
||
The --verify-client option makes the server ask the client for a SSL certificate. Presenting a valid (not expired and trusted by any supplied certificate authority) certificate is required for the client connection. With -auth-plugin=ClientCertCNAuth, the client certificate can be checked against a list of authorised certificate users. Non-encrypted connection attempts always fail during authentication. | ||
|
||
Here is an example of a vncsevrer with password-less, certificate-driven authentication: | ||
|
||
`./websockify 5901 --cert=fullchain.pem --key=privkey.pem --ssl-only --verify-client --cafile=ca-certificates.crt --auth-plugin=ClientCertCNAuth --auth-source='[email protected] Joe User9824510' --web=noVNC/ --wrap-mode=ignore -- vncserver :1 -geometry 1024x768 -SecurityTypes=None` | ||
|
||
The --auth-source option takes a white-space separated list of common names. Depending on your clients certificates they can be verified email addresses, user-names or any other string used for identification. | ||
|
||
The --cafile option selects a file containing concatenated certificates of authorities trusted for validating clients. If this option is omitted, system default list of CAs is used. Upon connect, the client should supply the whole certificate chain. If your clients are known not to send intermediate certificates, they can be appended to the ca-file as well. | ||
|
||
Note: Most browsers ask the user to select a certificate only while connecting via HTTPS, not WebSockets. Connecting directly to the SSL secured WebSocket may cause the browser to abort the connection. If you want to connect via noVNC, the --web option should point to a copy of noVNC, so it is loaded from the same host. | ||
|
||
.SH AUTHOR | ||
Joel Martin ([email protected]) | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,6 +319,7 @@ class Terminate(Exception): | |
def __init__(self, RequestHandlerClass, listen_fd=None, | ||
listen_host='', listen_port=None, source_is_ipv6=False, | ||
verbose=False, cert='', key='', ssl_only=None, | ||
verify_client=False, cafile=None, | ||
daemon=False, record='', web='', | ||
file_only=False, | ||
run_once=False, timeout=0, idle_timeout=0, traffic=False, | ||
|
@@ -333,6 +334,7 @@ def __init__(self, RequestHandlerClass, listen_fd=None, | |
self.listen_port = listen_port | ||
self.prefer_ipv6 = source_is_ipv6 | ||
self.ssl_only = ssl_only | ||
self.verify_client = verify_client | ||
self.daemon = daemon | ||
self.run_once = run_once | ||
self.timeout = timeout | ||
|
@@ -352,13 +354,15 @@ def __init__(self, RequestHandlerClass, listen_fd=None, | |
|
||
# Make paths settings absolute | ||
self.cert = os.path.abspath(cert) | ||
self.key = self.web = self.record = '' | ||
self.key = self.web = self.record = self.cafile = '' | ||
if key: | ||
self.key = os.path.abspath(key) | ||
if web: | ||
self.web = os.path.abspath(web) | ||
if record: | ||
self.record = os.path.abspath(record) | ||
if cafile: | ||
self.cafile = os.path.abspath(cafile) | ||
|
||
if self.web: | ||
os.chdir(self.web) | ||
|
@@ -518,7 +522,6 @@ def do_handshake(self, sock, address): | |
""" | ||
ready = select.select([sock], [], [], 3)[0] | ||
|
||
|
||
if not ready: | ||
raise self.EClose("ignoring socket not ready") | ||
# Peek, but do not read the data so that we have a opportunity | ||
|
@@ -538,11 +541,31 @@ def do_handshake(self, sock, address): | |
% self.cert) | ||
retsock = None | ||
try: | ||
retsock = ssl.wrap_socket( | ||
sock, | ||
server_side=True, | ||
certfile=self.cert, | ||
keyfile=self.key) | ||
try: | ||
# try creating new-style SSL wrapping for extended features | ||
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) | ||
context.load_cert_chain(certfile=self.cert, keyfile=self.key) | ||
if self.verify_client: | ||
context.verify_mode = ssl.CERT_REQUIRED | ||
context.set_default_verify_paths() | ||
if self.cafile: | ||
context.load_verify_locations(cafile=self.cafile) | ||
retsock = context.wrap_socket( | ||
sock, | ||
server_side=True) | ||
except AttributeError as ae: | ||
if str(ae) != "'module' object has no attribute 'create_default_context'": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When fixed this should also be merged in to the original commit. |
||
# this exception is not caused by create_default_context not existing in old version. re-raise exception to be handled somewhere elese. | ||
raise | ||
elif self.verify_client: | ||
raise self.EClose("Client certificate verification requested, but not Python is too old.") | ||
else: | ||
# new-style SSL wrapping is not needed, falling back to old style | ||
retsock = ssl.wrap_socket( | ||
sock, | ||
server_side=True, | ||
certfile=self.cert, | ||
keyfile=self.key) | ||
except ssl.SSLError: | ||
_, x, _ = sys.exc_info() | ||
if x.args[0] == ssl.SSL_ERROR_EOF: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done a lot cleaner. E.g.