Skip to content
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
wants to merge 6 commits into from
Closed

SSL client validation (certificate-based authentication) #295

wants to merge 6 commits into from

Conversation

hoehermann
Copy link
Contributor

@hoehermann hoehermann commented Aug 29, 2017

I don't like passwords. But I love public key authentication. That is why I added SSL client validation to websockify (specifically for use with noVNC). I know this won't make it into upstream due to compatibility issues as discussed in #190, but other people might want to know this feature now exists in at least one fork of Python websockify. For maximum ease of use, I recommend certificates by letsencrypt as mentioned in #207.

The test test_do_handshake_ssl_error_eof_raises_close_error fails since the ssl module does not actually accept the fake socket of the FakeSocket type (there is an explicit type check).

@samhed
Copy link
Member

samhed commented Aug 31, 2017

The python requirement comment doesn't mean it's impossible. Just make sure that it doesn't break on systems with old python. You can add an 'if' that checks the version and just return if its too old.

…ication.

Renamed SSL client certificate authentication plugin to match its function (checking common names) more closely.
…t. This commit now incorporates #190 without breaking compatibility towards old Python versions.

Removed test that cannot not work with new ssl.create_default_context.
@hoehermann
Copy link
Contributor Author

hoehermann commented Sep 3, 2017

Fallback is added in 8cb3acd.

Please note that I cheated by removing test_do_handshake_ssl_error_eof_raises_close_error as I do not want to re-implement a low-level socket class for the tests. But maybe someone else knows how to adapt this test to work with a socket wrapped by ssl.create_default_context().wrap_socket().
Update: I was told how this is supposed to work. All tests are in place again.

Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but please go over your commit messages and make sure they are properly formatted. I see cropped titles everywhere.

parser.add_option("--cafile", metavar="FILE",
help="file of concatenated certificates of authorities trusted "
"for validating clients (only effective with --verify-client). "
"If omitted, system default list of CAs is used.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't completely true, is it? The code suggests that system CAs will always be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I should move the call to context.set_default_verify_paths() into the else alternative.

@@ -82,7 +82,7 @@ def authenticate(self, headers, target_host, target_port):
if origin is None or origin not in self.source:
raise InvalidOriginError(expected=self.source, actual=origin)

class ClientCertAuth(object):
class ClientCertCNAuth(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge this commit with the earlier ones.

sock,
server_side=True)
except AttributeError as ae:
if str(ae) != "'module' object has no attribute 'create_default_context'":
Copy link
Member

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.

if hasattr(ssl, 'create_default_context'):

sock,
server_side=True)
except AttributeError as ae:
if str(ae) != "'module' object has no attribute 'create_default_context'":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When fixed this should also be merged in to the original commit.

self.stubs.Set(ssl, 'wrap_socket', fake_wrap_socket)
self.assertRaises(
websockifyserver.WebSockifyServer.EClose, server.do_handshake,
sock, '127.0.0.1')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge this in to the first commit as well.

@hoehermann
Copy link
Contributor Author

Requested changes made in new pull request #308.

@hoehermann hoehermann closed this Oct 26, 2017
@hoehermann hoehermann deleted the ssl_client_validation branch October 31, 2017 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants