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 ALPN support. #120

Merged
merged 20 commits into from
Apr 14, 2015
Merged

Add ALPN support. #120

merged 20 commits into from
Apr 14, 2015

Conversation

Lukasa
Copy link
Member

@Lukasa Lukasa commented Jun 7, 2014

This pull request adds support for Application Layer Protocol Negotiation, the spec-standardised version of NPN.

This was added to OpenSSL in v1.0.2. The keen eye might detect that OpenSSL v1.0.2 is only in beta at the moment, which means that unsurprisingly this doesn't work right now. I'm opening this Pull Request to track the work: I don't expect it to be merged any time soon.

The relevant cryptography support was merged in pyca/cryptography#1105.

This is the second half of #79.

:param callback: The callback function. It will be invoked with two
arguments: the Connection, and a list of offered protocols as
bytestrings, e.g ``[b'http/1.1', b'spdy/2']``. It should return
one of those bytestrings, then chosen protocol.

Choose a reason for hiding this comment

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

'the chosen protocol'

@tbetbetbe
Copy link

FYI: ALPN support landed in the recent 1.0.2 version release of openssl.

@Lukasa
Copy link
Member Author

Lukasa commented Apr 12, 2015

Alright, I believe I've cleaned up this patch now. The tests are a problem because OpenSSL 1.0.2 isn't present. I'd be happy to add a conditional test skip, but I think we need Travis to test against 1.0.2 before that's a good idea.

@Lukasa
Copy link
Member Author

Lukasa commented Apr 12, 2015

Also, thanks @rbtcollins for your feedback, I've integrated all of it. 🍰

@Lukasa
Copy link
Member Author

Lukasa commented Apr 12, 2015

@reaperhulk As promised, my patch.

@reaperhulk
Copy link
Member

Thanks @Lukasa!

@reaperhulk
Copy link
Member

There are a few avenues to get 1.0.2 coverage, but the easiest will probably be to ask Travis to enable us for OS X and linux. Then we can run builds against homebrew OpenSSL.

@Lukasa
Copy link
Member Author

Lukasa commented Apr 12, 2015

If we can do that in the next two days I'll happily add the skips.

@exarkun
Copy link
Member

exarkun commented Apr 12, 2015

pyOpenSSL also has an 0.9.8 builder set up on travis already. It relies on an 0.9.8 Ubuntu package existing and being installable so I'm not sure if the same solution can necessarily be applied to testing 1.0.2 - but if so, it might be easier than roping in the Travis folks (or maybe not, if someone already has an in with them; fwiw, I heard some rumors that they had reached capacity for OS X and weren't accepting more projects for that - but it was third-hand at least).

@alex
Copy link
Member

alex commented Apr 12, 2015

pyca/pyopenssl is now white listed for OS X

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.29%) to 92.5% when pulling e46fa84 on Lukasa:alpn into 4ca37f7 on pyca:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.27%) to 92.51% when pulling e46fa84 on Lukasa:alpn into 4ca37f7 on pyca:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.35%) to 92.44% when pulling 93134db on Lukasa:alpn into 4ca37f7 on pyca:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.35%) to 92.44% when pulling 93134db on Lukasa:alpn into 4ca37f7 on pyca:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.35%) to 92.44% when pulling 93134db on Lukasa:alpn into 4ca37f7 on pyca:master.



def get_alpn_proto_negotiated(self):
"""Get the protocol that was negotiated by ALPN."""
Copy link
Member

Choose a reason for hiding this comment

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

I know PEP8 says to use this single-line style of docstring. Can you change this to put the triple quotes on their own lines, anyway? (I recognize what a jerk-like comment this is). (This message approved by Hynek, future king of pyOpenSSL)


def test_alpn_success(self):
"""
Tests that clients and servers that agree on the negotiated ALPN
Copy link
Member

Choose a reason for hiding this comment

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

Can strike the "Tests that ..." part of this and other test method docstrings if you want. I think pyOpenSSL is currently inconsistent about this but the most-recently-preferred style assumes the reader can figure out this is a test without the extra hint. 😄

def test_alpn_no_server(self):
"""
Tests that when clients and servers cannot agree on what protocol
to use next because the server doesn't offer ALPN.
Copy link
Member

Choose a reason for hiding this comment

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

When this happens, what's the expected behavior?

conn.set_alpn_protos,
]
for method in fail_methods:
self.assertRaises(NotImplementedError, method)
Copy link
Member

Choose a reason for hiding this comment

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

Loops in test methods are a bit annoying (sometimes hard to see which iteration of the loop has failed; often information about failures that might have happened in later iterations is lost).

I'd probably split this into three test methods (one for each of the methods being tested). Failing that, just calling each of the three methods explicitly/directly rather than in a loop probably makes the test a little bit more maintainable (and maybe someday pyOpenSSL will use a testing library that supports some kind of parameterized or multi-result testing to make it possible to express this test better).

.. py:method:: Context.set_alpn_protos(protos)

Specify the protocols that the client is prepared to speak after the TLS
connection has been negotiated, using Application Layer Protocol
Copy link
Member

Choose a reason for hiding this comment

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

Gratuitous , on this line

@rbtcollins
Copy link

Cool. BTW stock unittest/unittest2 can do test parameterisation if you test_require testscenarios

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.3%) to 92.49% when pulling e58a93a on Lukasa:alpn into 4ca37f7 on pyca:master.

reaperhulk added a commit that referenced this pull request Apr 14, 2015
@reaperhulk reaperhulk merged commit 2187374 into pyca:master Apr 14, 2015
@Lukasa Lukasa deleted the alpn branch April 14, 2015 11:09
@Lukasa
Copy link
Member Author

Lukasa commented Apr 14, 2015

\o/ :sparkles: :shipit:

Big thanks @reaperhulk @hynek @exarkun! 10/10 would sprint with again.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants