Skip to content

Finish Validator Class #61

Closed
Closed

Description

@jdkasten

We need to confirm the server is set up correctly after configuration changes are made. This will allow us to enable HSTS with confidence. (Always use HTTPS at this website and never accept anything less :) )

I created a very simple stub of what I believe to be the necessary API (validator.py) This would be a stand-alone project that would be a great way to get involved and learn more!

Activity

  1. martijnbastiaan commented on Jan 12, 2015

    @martijnbastiaan
    Contributor

    I created a very simple stub of what I believe to be the necessary API (validator.py)

    Is this still true? If so, where did you put it? If not, care to make it again? :)

  2. jdkasten commented on Jan 12, 2015

    @jdkasten
    ContributorAuthor

    Hi Martjin,

    This is now an interface in interfaces.py. If you are interested, it would
    be great to get a class that can perform these functions.

    Best,
    James
    On Jan 12, 2015 6:31 AM, "Martijn Bastiaan" [email protected]
    wrote:

    I created a very simple stub of what I believe to be the necessary API
    (validator.py)

    Is this still true? If so, where did you put it? If not, care to make it
    again? :)

    —
    Reply to this email directly or view it on GitHub
    #61 (comment)
    .

  3. martijnbastiaan commented on Jan 12, 2015

    @martijnbastiaan
    Contributor

    Hey James,

    I've hacked together a basic implementation:

    https://github.com/martijnbastiaan/lets-encrypt-preview/blob/c506480b64e755e51ce28b0e43f6f2ec10ada469/letsencrypt/client/validator.py

    I'm not sure about how to use zope properly, I hope this suffices. I wasn't sure about the function signatures either, so I used a (custom defined) ValidationError-exception in order to distinguish between types of errors and returned True if no errors occurred.

    Can you comment on this "work in progress"?

  4. martijnbastiaan commented on Jan 12, 2015

    @martijnbastiaan
    Contributor

    I've hacked some more:

    https://github.com/martijnbastiaan/lets-encrypt-preview/blob/master/letsencrypt/client/validator.py

    • Added OCSP checking
    • Cleaned code somewhat

    I've added examples wrapped in if __name__ == '__main__', which should probably move to unit-tests in the future.

    Yours,
    Martijn

  5. jdkasten commented on Jan 12, 2015

    @jdkasten
    ContributorAuthor

    Great! Thanks for writing this up @martijnbastiaan. 👍 That is just what I had envisioned. It will allow for fully automated integration testing and allow the client to automatically revert changes in case of failure.

    The exact function signatures haven't been solidified yet... and it will probably be dependent on the structure of the final Installer interface - #156. Although I think I do like the idea of throwing an exception in case of an error.

    We would probably add that error to the letsencrypt/client/errors.py file.
    LetsEncryptValidatorError?

    The use of zope is fine. Right now the interface is just allowing for some form of contractual agreement for plugin developers.

    If you are interested in further exploring this aspect of the project, feel free to change/extend the API to validate anything else you might think is helpful to the project, (SPDY, any other extensions/optimizations you would like to see supported by Installer modules (Apache, Nginx, ect..). (You are also free to work on whatever aspect you would like... there is a ton of work to do. I really appreciate the help :)) Once this is finished I will attempt to get the validation moved into client.py.

    Minor formatting change (just so you are aware):
    Our import format is (in alphabetical)
    python imports

    separate package imports

    letsencrypt imports

    Following this imports would be...
    import requests
    import zope.interface

    from letsencrypt.client import interfaces

    Finally, just a typo I noticed while reading....
    *responded
    https://github.com/martijnbastiaan/lets-encrypt-preview/blob/c506480b64e755e51ce28b0e43f6f2ec10ada469/letsencrypt/client/validator.py#L39

  6. martijnbastiaan commented on Jan 13, 2015

    @martijnbastiaan
    Contributor

    Hey James,

    Thanks for the feedback! Our messages crossed a bit, so you might have missed the changes I made. Anyway; I've added support for SPDY, OCSP and cleaned the code quite a bit.

    We would probably add that error to the letsencrypt/client/errors.py file. LetsEncryptValidatorError?

    I'm not sure if I'm in the position to criticise, but I'm not really a fan of that naming scheme. It's (obviously) already defined within letsencrypt, so why append it to the name? Django, for example, doesn't seem to do it. Anyway, I've called it LetsEncryptValidatorError (for now?) and put it in errors.py. It's up to you :).

    To comment on my own code:

    1. I've changed the import statements to match the project's style.
    2. I've added logging when calling openssl. I think it's good style to use this across the project, so we can run letsencrypt with --debug (or something alike) in the future.

    Again, I'd love to get feedback. Any chance of this getting merged?

  7. kuba commented on Jan 13, 2015

    @kuba
    Contributor

    @martijnbastiaan Quick review:

    1. Is it really necessary to call openssl binary? :( Could you please try to find relevant functionality in either already dependent crypto libraries or some others? (If this is absolutely required, then openssl has to be added as dependency in README, debian packaging files, etc.)
    2. There are some compatibility problems with Python 2.6, e.g. {x for x in ...} syntax.
    3. We have decided that especially new functionality pull requests are required to have 100% test coverage. Would you be so kind, please, to include appropriate unitttests? This would e.g. catch problems from point above...
    4. Could you please fix the code style according to the instructions? For example line length, but also strange bool(self._get_nextgen_protocols(name) & SPDY_PROTOCOLS) casting construction... It is also preferred to use "lazy" log.debug("some info: %s", some_arg). pylint will help you to find problems in your code.

    Thanks for your opinion on the naming scheme, and more importantly thank you for sticking to the current conventions (it is really important to do so in all respects, style guide, etc.)! I think you might be right about unnecessary prefix, but I'd say we shall consider it in #44.

    @jdkasten Shall we update the IValidator in respect to the new functionality?

  8. martijnbastiaan commented on Jan 13, 2015

    @martijnbastiaan
    Contributor

    Thanks kuba.

    1. I understand the pain and I really hope I've missed something, but calling the openssl binary seems to be the simplest solution. As you've probably read in my code, the problem is twofold:

      • SPDY: Protocol negotiation happens at the TLS handshake, by using NPN or ALPN. Thus, we need to either highjack the handshake routine of ssl, use another library or roll or own.
        • Most of ssl is written in C, so overriding the "extension header" basically equals rolling your own solution.
        • I found spdylay, which seems to support everything we need. I couldn't, however, get it to work without compiling external source code (on Ubuntu 14.04). The second library, spdy-http doesn't support SSL.
        • Rolling our own solution is... feasible, of course, but gets hairy pretty fast.
      • OCSP: Again, we need to highjack the TLS handshake as OCSP inclusion in ssl is postponed till Python 3.5. I couldn't find any libraries supporting this functionality.

      For both solution I've tried to use the Python bindings for openssl, but failed to find a solution. The documentation does not say anything about ocsp (nor spdy/nextgen). So, all in all, I think calling the openssl binary is the least evil. Btw; openssl is installed by default on both the desktop and server edition of Ubuntu.

    2. OK, will fix.

    3. OCSP and SPDY are hard to unit test for, as we need to be root to run a webserver on port 443. Do you have any suggestions on how to unit test?

    4. I don't think intersection + bool operator to test if a set is empty or not is too strange, but I can see where you're coming from. I'll see if I can write it more clearly. About lazy: noted, will do.

    I'll report back once I've fixed the issues, but that probably won't happen before this weekend :-). (But you never know..)

  9. jdkasten commented on Jan 13, 2015

    @jdkasten
    ContributorAuthor

    @martijnbastiaan Thanks for investigating everything (and thanks for going above and beyond with SPDY).

    I also did a quick search to avoid the openssl binary... but I didn't find anything quickly short of extending an existing crypto library. :( Side-note: This is starting to become a common occurrence, I will try to create an issue with all of the things we wish we had from python crypto libraries and keep track of their current status.

    @kuba, Thanks for reviewing everything. I would hold off on updating the IValidator class until we resolve the Installer "enable/optimize" issue in #156, I assume the enable/vallidate functions should be organized similarly and it would be nice to avoid any unnecessary requirements for plugins.

    @martijnbastiaan Time isn't a major factor on the Validator code right now. It shouldn't conflict with anyone else's work and we haven't incorporated it into the client yet. If you would like to push your code before it is completely ready, you can make a PR for a "Validator" branch. that way the code is available to others that want to use it for reference or finish it up.

    I agree that this code is not the easiest to test. Having unittests go down because of outside network issues isn't really a possibility either.

    My recommendation would be to look into mocking the return values of the network functions with various examples you find from real sites. The idea is that as long as the underlying API of the object you are mocking doesn't change... the tests will continue to work and it wouldn't be reliant on any outside network or setting up any additional services.

    ^ This can be a bit of a pain, so if you are short on time, I would recommend we just push this into a separate letsencrypt-client-preview/validator branch and then we can finish it up and get it fully merged into master later.

    Thanks again for writing up the validator @martijnbastiaan.

  10. jdkasten commented on Jan 14, 2015

    @jdkasten
    ContributorAuthor

    Sorry for the late reply to this, and thanks for the code @martijnbastiaan.

    I did another quick read through...
    https://github.com/martijnbastiaan/lets-encrypt-preview/blob/master/letsencrypt/client/validator.py#L17

    The SPDY 3, 3.1 solution looks like it could be fragile as the protocol develops. The aim is for the validator to work on a multitude of webservers with different versions running. It appears there is already a SPDY 4.0 in alpha and although it is unlikely that the validator should ever have to verify past versions of SPDY, it would be nice if the validator worked for those or rather... raise a more appropriate exception. http://en.wikipedia.org/wiki/SPDY

    I haven't taken a look at the actual output, so I don't know all of the different constraints. However, my natural inclination would be to use a regular expression. Based on their past versioning....something like...

    spdy/\d(\.\d)?`
    

    This is still prone to breaking in the future... but I would guess it would be a bit more resilient. Thoughts?

  11. jdkasten commented on Jan 17, 2015

    @jdkasten
    ContributorAuthor

    @martijnbastiaan FYI: I removed this project from the Wiki. I will merge your code into a separate branch whenever you believe the code to be ready, but no rush... take your time.

  12. martijnbastiaan commented on Jan 22, 2015

    @martijnbastiaan
    Contributor

    Thanks.

    ^ This can be a bit of a pain, so if you are short on time, I would recommend we just push this into a separate letsencrypt-client-preview/validator branch and then we can finish it up and get it fully merged into master later.

    I've included tests based only simple responses. That is, I'm mocking on the application level, not network. I suppose testing the latter would involve setting up a real server, as we need to fool openssl.

    This is still prone to breaking in the future... but I would guess it would be a bit more resilient. Thoughts?

    Seems OK to me, included!

  13. jdkasten commented on Jun 29, 2015

    @jdkasten
    ContributorAuthor

    Thank you for this! We will integrate it soon.

  14. added a commit that references this issue on Jul 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions