Repository navigation
Use Challtestsrv for HTTP-01 integration tests, add redirect tests - #3960
Conversation
The VA code activated by the `SimplifiedHTTP01` flag had a regression that constructed validation URLs for HTTP-01 challenge redirects to a HTTPS host incorrectly. The regression is fixed and the unit tests are updated to cover this case. An integration test is not included in this commit but will be done as follow-up work since it requires adjusting existing integration tests for HTTP-01 to use the challtestrv instead of Certbot's ACME standalone server.
| // responses | ||
| tlsALPNOne map[string]string | ||
|
|
||
| // redirects is a map of paths to URLs. When an HTTP challenge server receives |
There was a problem hiding this comment.
"HTTP challenge servers respond to requests for these paths with a 301 to the corresponding URL." (active voice vs passive)
| ) | ||
|
|
||
| // addHTTP01 handles an HTTP POST request to add a new HTTP-01 challenge | ||
| // addHTTP01 handles a HTTP POST request to add a new HTTP-01 challenge |
There was a problem hiding this comment.
Interesting! I had always used "an HTTP Post" because I pronounce it "an aych tee tee pee". Is this a Canadian / American distinction?
There was a problem hiding this comment.
Not sure! I'm happy to leave it if you think it makes sense as an. It seemed wrong in my reading
There was a problem hiding this comment.
I tried to find an answer and like most things involving the English language the answer depends on who you ask 😆 The nearest available Canadian I could find that isn't me says she uses "a HTTP".
acking through our codebase and deps it seems like there's a slight preference for "an HTTP" so I'll revert this change:
$ ack -c --no-filename "an HTTP"
68
$ ack -c --no-filename "a HTTP"
58
| requestPath := r.URL.Path | ||
|
|
||
| // If the request was not over HTTPS and we have a redirect, serve it. | ||
| // Redirects are ignored over HTTPS so we can easily do an HTTP->HTTPS |
There was a problem hiding this comment.
This is an example of a great comment, IMO, since it answers a "why" question.
| challengePath = "/.well-known/acme-challenge/{0}".format(token) | ||
| add_http_redirect( | ||
| challengePath, | ||
| "http://challtestsrv{0}".format(challengePath)) |
There was a problem hiding this comment.
Why use challtestsrv instead of d? Seems like the latter would be slightly more straightforward (would not require explaining).
| challengePath, | ||
| "http://challtestsrv{0}".format(challengePath)) | ||
|
|
||
| # Authorizing the domain should fail because of the invalid port. |
There was a problem hiding this comment.
I think this comment is wrong.
|
|
||
| def cleanup(): | ||
| remove_http_redirect(challengePath) | ||
| return cleanup |
There was a problem hiding this comment.
Returning a cleanup function doesn't do anything for test_* functions, called by integration_test.py. The do_x_challenges return a cleanup function because their caller expects it, and will call that cleanup function in a finally block whether the validation succeeds or fails. For this function and the similar ones below we should just call, e.g. remove_http_redirect directly.
There was a problem hiding this comment.
Good catch, will adjust 👍
| challengePath, | ||
| "http://challtestsrv:1337{0}".format(challengePath)) | ||
|
|
||
| # Issuing for the name should cause a connection error from reaching too |
| "gopher://challtestsrv{0}".format(challengePath)) | ||
|
|
||
| # Issuing for the name should cause a connection error because the redirect | ||
| # domain name is an IP address. |
There was a problem hiding this comment.
Thanks, missed this one. Fixed in 9f75607
| add_http01_response("http-redirect", keyauth) | ||
|
|
||
| # Create a HTTP redirect from the challenge's validation path to some other | ||
| # token path where we'll register the key authorization. |
| def test_http_challenge(): | ||
| chisel2.auth_and_issue([random_domain(), random_domain()], chall_type="http-01") | ||
|
|
||
| def rand_http_chall(client): |
There was a problem hiding this comment.
I think this chunk is all the same as integration-test.py, but s/chisel/chisel2/. So please update after making the fixes above.
|
@jsha I believe all of your feedback has been resolved as of 0df6f8a I'd like to try to do a small cleanup pass after @rolandshoemaker's Akamai purger testfix PR lands. I think there's a good bit of duplication between the v1/v2 files that could be reduced using the approach he took in that PR. |
| func (s *ChallSrv) ServeChallengeCertFunc(k *ecdsa.PrivateKey) func(*tls.ClientHelloInfo) (*tls.Certificate, error) { | ||
| return func(hello *tls.ClientHelloInfo) (*tls.Certificate, error) { | ||
| if len(hello.SupportedProtos) != 1 || hello.SupportedProtos[0] != va.ACMETLS1Protocol { | ||
| return nil, fmt.Errorf("ALPN failed, ClientHelloInfo.SupportedProtos: %s", hello.SupportedProtos) |
There was a problem hiding this comment.
@rolandshoemaker correctly pointed out that this design removes an error that is valuable for integration tests of TLS-ALPN-01 challenges.
Consensus is that its OK to take this small hit to our confidence in the TLS-ALPN-01 integration test to land this PR, and we'll fix it in a follow-up: #3962
Note to reviewers: This builds on #3959 and you may want to review that first.
To complete #3956 the
challtestsrvis updated such that its existing TLS-ALPN-01 challenge test server will serve HTTP-01 responses with a self-signed certificate when a non-TLS-ALPN-01 request arrives. This lets the TLS-ALPN-01 challenge server double as a HTTPS version of the HTTP challenge server. Thechalltestsrvnow also supports adding/remove redirects that will be served to clients when requesting matching paths.The existing chisel/chisel2 integration tests are updated to use the
challtestsrvinstead of starting their own standalone servers. This centralizes our mock challenge responses and lets us bind thechalltestsrvto the VA's HTTP port instartservers.pywithout clashing ports later on.New integration tests are added for HTTP-01 redirect scenarios using the updated
challtestserv. These test cases cover:The new integration tests shook out two fixes that were required for the legacy VA HTTP-01 code (afad22b) and one fix for the challtestsrv mock DNS (59b7d6d).
Resolves #3956