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

add support for TCPConnector param verify_fingerprint #361

Closed
wants to merge 0 commits into from

Conversation

requiredfield
Copy link
Contributor

Not yet ready to merge but starting a PR now to incorporate any early feedback. Thanks for any review!

@asvetlov
Copy link
Member

Please go ahead!
But you need to make tests also

cert = sock.getpeercert(True)
digest = self._hashfunc(cert).digest()
if digest != self._fingerprint_bytes:
raise FingerprintMismatch
Copy link
Member

Choose a reason for hiding this comment

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

Use at least FingerprintMismatch(). Maybe later you'll add info about failing host:port pair -- it is helpful for understanding the source of problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Addressed this in the latest commit. Also storing the expected vs. got fingerprint.

@requiredfield requiredfield force-pushed the master branch 2 times, most recently from 62668ab to 2fbbb9c Compare May 14, 2015 17:39
@requiredfield
Copy link
Contributor Author

requiredfield commented May 14, 2015

@asvetlov Thanks for reviewing! Just pushed a new patch with tests. Would you mind taking a peek at the latest patch?

self.assertFalse(conn.resolve)
self.assertEqual(conn.family, socket.AF_INET)
self.assertEqual(conn.resolved_hosts, {})

def test_tcp_connector_verify_fingerprint(self):
exc_handler = unittest.mock.Mock()
self.loop.set_exception_handler(exc_handler)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wasn't sure if I needed these two lines with the exc_handler

@requiredfield requiredfield force-pushed the master branch 2 times, most recently from b59208d to c27f6fb Compare May 14, 2015 22:38
@@ -4,6 +4,8 @@ CHANGES
0.16.0 (XX-XX-XXXX)
------------------

- Support `verify_fingerprint` param of TCPConnector

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated changelog

@requiredfield requiredfield changed the title first pass at verify_fingerprint add support for TCPConnector param verify_fingerprint May 14, 2015
@requiredfield requiredfield force-pushed the master branch 3 times, most recently from ae68bb1 to a9674ce Compare May 15, 2015 02:39
@requiredfield
Copy link
Contributor Author

requiredfield commented May 15, 2015

Pushed another improved version. Please let me know if there's anything left to do before this is good to merge. Thanks again for reviewing!

if self._verify_fingerprint:
sock = conn[0]._sock
# gives DER-encoded cert as a sequence of bytes (or None)
cert = sock.getpeercert(binary_form=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asvetlov Do these two lines (502 and 504) look good to you? The conn[0]._sock makes me feel the need to check because of the private member access. As for sock.getpeercert, if sock is a regular socket.socket rather than an SSLSocket this will cause AttributeError, but I think that would only happen if the user tries to use verify_fingerprint with a non-SSL connection. I can code this more defensively though if that would be better.

Copy link
Member

Choose a reason for hiding this comment

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

conn is (transport, protocol) pair.
For getting socket object from transport please call transport.get_extra_info('socket').
Also you have skip certificate check for non-ssl socket (request.ssl is False).

@lock
Copy link

lock bot commented Oct 30, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 30, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants