Skip to content

Commit 295d9c1

Browse files
munnerzjsha
authored andcommitted
va: fix HTTP01 port number issue when redirected (#294)
This fixes the issue described in #293, where the port number to connect to is hardcoded into the custom dialer.
1 parent 35691f8 commit 295d9c1

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

va/va.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,6 @@ func (va VAImpl) fetchHTTP(identifier string, token string) ([]byte, string, *ac
513513
httpRequest.Header.Set("User-Agent", userAgent())
514514
httpRequest.Header.Set("Accept", "*/*")
515515

516-
addrs, err := va.resolveIP(identifier)
517-
518-
if err != nil {
519-
return nil, url.String(), acme.MalformedProblem(
520-
fmt.Sprintf("Error occurred while resolving URL %q: %q", url.String(), err))
521-
}
522-
523-
if len(addrs) == 0 {
524-
return nil, url.String(), acme.MalformedProblem(
525-
fmt.Sprintf("Could not resolve URL %q", url.String()))
526-
}
527-
528516
transport := &http.Transport{
529517
// We don't expect to make multiple requests to a client, so close
530518
// connection immediately.
@@ -537,10 +525,23 @@ func (va VAImpl) fetchHTTP(identifier string, token string) ([]byte, string, *ac
537525
InsecureSkipVerify: true,
538526
},
539527

540-
// Control specifically which IP will be used for this request
541528
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
529+
host, port, err := net.SplitHostPort(addr)
530+
if err != nil {
531+
return nil, err
532+
}
542533
dialer := &net.Dialer{}
543-
return dialer.DialContext(ctx, network, net.JoinHostPort(addrs[0], portString))
534+
535+
// Control specifically which IP will be used for this request
536+
addrs, err := va.resolveIP(host)
537+
if err != nil {
538+
return nil, fmt.Errorf("error occurred while resolving URL %q: %q", url.String(), err)
539+
}
540+
if len(addrs) == 0 {
541+
return nil, fmt.Errorf("could not resolve URL %q", url.String())
542+
}
543+
544+
return dialer.DialContext(ctx, network, net.JoinHostPort(addrs[0], port))
544545
},
545546
}
546547

0 commit comments

Comments
 (0)