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

CHANGE EVERYTHING #4

Merged
merged 15 commits into from Aug 2, 2017
Merged

CHANGE EVERYTHING #4

merged 15 commits into from Aug 2, 2017

Conversation

njsmith
Copy link
Member

@njsmith njsmith commented Jul 18, 2017

Now instead of having methods to return a ssl.SSLContext object, we
have methods that take an ssl.SSLContext object and reconfigure it
in place. This is more flexible and probably fits better into existing
codebases.

Plus, it makes it easy to support PyOpenSSL without lots of awkward
namespacing!

I'm still not 100% happy with the phrasing of

ca.trust(ctx)
server_cert.use(ctx)

because the subject/object seem backwards.

Maybe they should be top-level functions? Or have better names?
ca.trust_me(ctx), cert.use_me(ctx), ca.trusted_by(ctx),
cert.used_by(ctx)?

The old convenience API was a bit too inconvenient. The new one is
more convenient.

Also it now supports PyOpenSSL.
@codecov
Copy link

codecov bot commented Jul 18, 2017

Codecov Report

Merging #4 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master     #4    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files           3      3            
  Lines         117    221   +104     
  Branches        2      9     +7     
======================================
+ Hits          117    221   +104
Impacted Files Coverage Δ
tests/test_trustme.py 100% <100%> (ø) ⬆️
trustme/__init__.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e750dc...6ef9a54. Read the comment docs.

@markrwilliams
Copy link

@njsmith My vote goes for the imperative form, but I'd prefer "this" be the pronoun and not "me", e.g., ca.trust_this(ctx). This lets you read "this" as a determiner, e.g., "CA, trust this context".

@njsmith
Copy link
Member Author

njsmith commented Jul 20, 2017

@markrwilliams: that's the whole problem though -- it's supposed to mean "context, trust this CA"!

This is why I'm kinda leaning towards the ca.trusted_by(ctx) form...

@markrwilliams
Copy link

@njsmith make_trusted_by?

@njsmith
Copy link
Member Author

njsmith commented Jul 20, 2017

ca.inject_trust(ctx), cert.inject_cert(ctx)?

- New names for the context configuration methods: configure_trust and
  configure_cert.
- Switch *_pem to a new convenience class Blob
- Redo tempfile handling to be Windows friendly
- Replace the concatenated cert_chain_pem with a list cert_chain_pems.
@njsmith njsmith changed the title Break convenience API, and add PyOpenSSL support CHANGE EVERYTHING Jul 23, 2017
@njsmith
Copy link
Member Author

njsmith commented Jul 23, 2017

@markrwilliams: Well this branch got a bit out of hand, but see what you think?

@njsmith
Copy link
Member Author

njsmith commented Jul 29, 2017

@markrwilliams Guess you're busy. No worries! But I want to get this off my stack (and hopefully minimize the number of people who start using the 0.1.0 API), so if I don't hear anything I'll probably merge on Monday or so.

Copy link

@markrwilliams markrwilliams left a comment

Choose a reason for hiding this comment

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

The names you chose are good! Some comments for your consideration.

# ----- Using your shiny new certs -----

# You can configure SSL context objects to trust this CA:
ca.configure_trust(ssl_context)

Choose a reason for hiding this comment

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

👍

This is clear if less pithy than the alternatives we discussed.

# You can configure SSL context objects to trust this CA:
ca.configure_trust(ssl_context)
# Or configure them to present the server certificate
server_cert.configure_cert(ssl_context)

Choose a reason for hiding this comment

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

👍


def doit(ca, hostname, server_cert):
# socketpair and ssl don't work together on py2, because... reasons
#raw_client_sock, raw_server_sock = socket.socketpair()

Choose a reason for hiding this comment

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

Why comment code out when you can delete it?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

with ThreadPoolExecutor(2) as tpe:
f1 = tpe.submit(fake_ssl_client, ca, raw_client_sock, hostname)
f2 = tpe.submit(fake_ssl_server, server_cert, raw_server_sock)
f1.result()

Choose a reason for hiding this comment

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

Should there be a timeout here just in case?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we're OK -- the only way this could lock up is something truly weird happens (like -- Python semantics violating weird), and there's not much that can be done to defend against that. Also I'm not sure how to do a timeout here (there's no way to cancel a thread). Worst case Travis times out after 10 minutes or whatever.

@@ -21,6 +23,9 @@
# not 2 seconds.
_KEY_SIZE = 1024

def _smells_like_pyopenssl(ctx):

Choose a reason for hiding this comment

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

I'm not thrilled by this but I don't see a simpler way :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Co-signed.

@njsmith
Copy link
Member Author

njsmith commented Aug 1, 2017

@markrwilliams: okay, pushed changes to address some nits, will merge after travis passes (probably after I wake up). Thanks!

@njsmith njsmith merged commit 0ed9ffa into python-trio:master Aug 2, 2017
@njsmith njsmith deleted the pyopenssl branch August 2, 2017 07:48
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.

None yet

2 participants