Skip to content

Use Challtestsrv for HTTP-01 integration tests, add redirect tests - #3960

Merged
cpu merged 12 commits into
masterfrom
cpu-http01-redirect-bug-yes-inttests
Nov 30, 2018
Merged

cpu merged 12 commits into
masterfrom
cpu-http01-redirect-bug-yes-inttests

Conversation

@cpu

@cpu cpu commented Nov 29, 2018

Copy link
Copy Markdown
Contributor

Note to reviewers: This builds on #3959 and you may want to review that first.

To complete #3956 the challtestsrv is 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. The challtestsrv now 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 challtestsrv instead of starting their own standalone servers. This centralizes our mock challenge responses and lets us bind the challtestsrv to the VA's HTTP port in startservers.py without clashing ports later on.

New integration tests are added for HTTP-01 redirect scenarios using the updated challtestserv. These test cases cover:

  • valid HTTP -> HTTP redirect
  • valid HTTP -> HTTPS redirect
  • Invalid HTTP -> non-HTTP/HTTPS port redirect
  • Invalid HTTP-> non-HTTP/HTTPS protocol scheme redirect
  • Invalid HTTP-> bare IP redirect
  • Invalid HTTP redirect loop

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

Daniel added 6 commits November 29, 2018 11:51
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.
@cpu
cpu requested a review from a team as a code owner November 29, 2018 20:55
Comment thread test/challtestsrv/challenge-servers.go Outdated
// responses
tlsALPNOne map[string]string

// redirects is a map of paths to URLs. When an HTTP challenge server receives

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting! I had always used "an HTTP Post" because I pronounce it "an aych tee tee pee". Is this a Canadian / American distinction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure! I'm happy to leave it if you think it makes sense as an. It seemed wrong in my reading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an example of a great comment, IMO, since it answers a "why" question.

Comment thread test/integration-test.py Outdated
challengePath = "/.well-known/acme-challenge/{0}".format(token)
add_http_redirect(
challengePath,
"http://challtestsrv{0}".format(challengePath))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why use challtestsrv instead of d? Seems like the latter would be slightly more straightforward (would not require explaining).

Comment thread test/integration-test.py Outdated
challengePath,
"http://challtestsrv{0}".format(challengePath))

# Authorizing the domain should fail because of the invalid port.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this comment is wrong.

Comment thread test/integration-test.py Outdated

def cleanup():
remove_http_redirect(challengePath)
return cleanup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, will adjust 👍

Comment thread test/integration-test.py Outdated
challengePath,
"http://challtestsrv:1337{0}".format(challengePath))

# Issuing for the name should cause a connection error from reaching too

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is incorrect.

Comment thread test/integration-test.py Outdated
"gopher://challtestsrv{0}".format(challengePath))

# Issuing for the name should cause a connection error because the redirect
# domain name is an IP address.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is incorrect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ping.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, missed this one. Fixed in 9f75607

Comment thread test/integration-test.py Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"where we have registered"

Comment thread test/v2_integration.py
def test_http_challenge():
chisel2.auth_and_issue([random_domain(), random_domain()], chall_type="http-01")

def rand_http_chall(client):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this chunk is all the same as integration-test.py, but s/chisel/chisel2/. So please update after making the fixes above.

@cpu

cpu commented Nov 30, 2018

Copy link
Copy Markdown
Contributor Author

@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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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

@cpu
cpu merged commit bd4c254 into master Nov 30, 2018
@cpu
cpu deleted the cpu-http01-redirect-bug-yes-inttests branch November 30, 2018 22:20
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.

SimplifiedVAHTTP breaks HTTP->HTTPS redirects.

3 participants