Skip to content

Commit 91f8614

Browse files
committed
remove old ACME tls-sni-01 stuff that LetsEncrypt removed March 2019
No point keeping it around. We can look at the git history to do something similar later if we end up doing TLS-ALPN-01 in a similar way.
1 parent 74ca1dc commit 91f8614

File tree

6 files changed

+7
-277
lines changed

6 files changed

+7
-277
lines changed

Diff for: cmd/tlsrouter/acme.go

-101
This file was deleted.

Diff for: cmd/tlsrouter/config.go

-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type Route struct {
3737
type Config struct {
3838
mu sync.Mutex
3939
routes []Route
40-
acme *ACME
4140
}
4241

4342
func dnsRegex(s string) (*regexp.Regexp, error) {
@@ -64,10 +63,6 @@ func (c *Config) Match(hostname string) (string, bool) {
6463
c.mu.Lock()
6564
defer c.mu.Unlock()
6665

67-
if strings.HasSuffix(hostname, ".acme.invalid") {
68-
return c.acme.Match(hostname), false
69-
}
70-
7166
for _, r := range c.routes {
7267
if r.match.MatchString(hostname) {
7368
return r.backend, r.proxyInfo
@@ -123,10 +118,6 @@ func (c *Config) Read(r io.Reader) error {
123118
c.mu.Lock()
124119
defer c.mu.Unlock()
125120
c.routes = routes
126-
c.acme = &ACME{
127-
backends: backends,
128-
cache: make(map[string]acmeCacheEntry),
129-
}
130121
return nil
131122
}
132123

Diff for: cmd/tlsrouter/e2e_test.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ func TestRouting(t *testing.T) {
3434
}
3535
defer s2.Close()
3636

37-
s3, err := serveTLS(t, "server3", false, "blarghblargh.acme.invalid")
38-
if err != nil {
39-
t.Fatalf("server TLS server3: %s", err)
40-
}
41-
defer s3.Close()
42-
4337
s4, err := serveTLS(t, "server4", true, "proxy.design")
4438
if err != nil {
4539
t.Fatalf("server TLS server4: %s", err)
@@ -58,9 +52,8 @@ func TestRouting(t *testing.T) {
5852
if err := p.Config.ReadString(fmt.Sprintf(`
5953
test.com %s
6054
foo.net %s
61-
borkbork.tf %s
6255
proxy.design %s PROXY
63-
`, s1.Addr(), s2.Addr(), s3.Addr(), s4.Addr())); err != nil {
56+
`, s1.Addr(), s2.Addr(), s4.Addr())); err != nil {
6457
t.Fatalf("configure proxy: %s", err)
6558
}
6659

@@ -73,7 +66,6 @@ proxy.design %s PROXY
7366
{"test.com", "server1", s1.Pool, true, false},
7467
{"foo.net", "server2", s2.Pool, true, false},
7568
{"bar.org", "", s1.Pool, false, false},
76-
{"blarghblargh.acme.invalid", "server3", s3.Pool, true, false},
7769
{"proxy.design", "server4", s4.Pool, true, true},
7870
} {
7971
res, transparent, err := getTLS(l.Addr().String(), test.N, test.P)

Diff for: sni.go

-98
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,13 @@ import (
2121
"crypto/tls"
2222
"io"
2323
"net"
24-
"strings"
2524
)
2625

2726
// AddSNIRoute appends a route to the ipPort listener that routes to
2827
// dest if the incoming TLS SNI server name is sni. If it doesn't
2928
// match, rule processing continues for any additional routes on
3029
// ipPort.
3130
//
32-
// By default, the proxy will route all ACME tls-sni-01 challenges
33-
// received on ipPort to all SNI dests. You can disable ACME routing
34-
// with AddStopACMESearch.
35-
//
3631
// The ipPort is any valid net.Listen TCP address.
3732
func (p *Proxy) AddSNIRoute(ipPort, sni string, dest Target) {
3833
p.AddSNIMatchRoute(ipPort, equals(sni), dest)
@@ -43,20 +38,8 @@ func (p *Proxy) AddSNIRoute(ipPort, sni string, dest Target) {
4338
// matcher. If it doesn't match, rule processing continues for any
4439
// additional routes on ipPort.
4540
//
46-
// By default, the proxy will route all ACME tls-sni-01 challenges
47-
// received on ipPort to all SNI dests. You can disable ACME routing
48-
// with AddStopACMESearch.
49-
//
5041
// The ipPort is any valid net.Listen TCP address.
5142
func (p *Proxy) AddSNIMatchRoute(ipPort string, matcher Matcher, dest Target) {
52-
cfg := p.configFor(ipPort)
53-
if !cfg.stopACME {
54-
if len(cfg.acmeTargets) == 0 {
55-
p.addRoute(ipPort, &acmeMatch{cfg})
56-
}
57-
cfg.acmeTargets = append(cfg.acmeTargets, dest)
58-
}
59-
6043
p.addRoute(ipPort, sniMatch{matcher: matcher, target: dest})
6144
}
6245

@@ -69,14 +52,6 @@ func (p *Proxy) AddSNIRouteFunc(ipPort string, fn SNITargetFunc) {
6952
p.addRoute(ipPort, sniMatch{targetFunc: fn})
7053
}
7154

72-
// AddStopACMESearch prevents ACME probing of subsequent SNI routes.
73-
// Any ACME challenges on ipPort for SNI routes previously added
74-
// before this call will still be proxied to all possible SNI
75-
// backends.
76-
func (p *Proxy) AddStopACMESearch(ipPort string) {
77-
p.configFor(ipPort).stopACME = true
78-
}
79-
8055
type sniMatch struct {
8156
matcher Matcher
8257
target Target
@@ -102,79 +77,6 @@ func (m sniMatch) match(br *bufio.Reader) (Target, string) {
10277
return nil, ""
10378
}
10479

105-
// acmeMatch matches "*.acme.invalid" ACME tls-sni-01 challenges and
106-
// searches for a Target in cfg.acmeTargets that has the challenge
107-
// response.
108-
type acmeMatch struct {
109-
cfg *config
110-
}
111-
112-
func (m *acmeMatch) match(br *bufio.Reader) (Target, string) {
113-
sni := clientHelloServerName(br)
114-
if !strings.HasSuffix(sni, ".acme.invalid") {
115-
return nil, ""
116-
}
117-
118-
// TODO: cache. ACME issuers will hit multiple times in a short
119-
// burst for each issuance event. A short TTL cache + singleflight
120-
// should have an excellent hit rate.
121-
// TODO: maybe an acme-specific timeout as well?
122-
// TODO: plumb context upwards?
123-
ctx, cancel := context.WithCancel(context.Background())
124-
defer cancel()
125-
126-
ch := make(chan Target, len(m.cfg.acmeTargets))
127-
for _, target := range m.cfg.acmeTargets {
128-
go tryACME(ctx, ch, target, sni)
129-
}
130-
for range m.cfg.acmeTargets {
131-
if target := <-ch; target != nil {
132-
return target, sni
133-
}
134-
}
135-
136-
// No target was happy with the provided challenge.
137-
return nil, ""
138-
}
139-
140-
func tryACME(ctx context.Context, ch chan<- Target, dest Target, sni string) {
141-
var ret Target
142-
defer func() { ch <- ret }()
143-
144-
conn, targetConn := net.Pipe()
145-
defer conn.Close()
146-
go dest.HandleConn(targetConn)
147-
148-
deadline, ok := ctx.Deadline()
149-
if ok {
150-
conn.SetDeadline(deadline)
151-
}
152-
153-
client := tls.Client(conn, &tls.Config{
154-
ServerName: sni,
155-
InsecureSkipVerify: true,
156-
})
157-
if err := client.Handshake(); err != nil {
158-
// TODO: log?
159-
return
160-
}
161-
certs := client.ConnectionState().PeerCertificates
162-
if len(certs) == 0 {
163-
// TODO: log?
164-
return
165-
}
166-
// acme says the first cert offered by the server must match the
167-
// challenge hostname.
168-
if err := certs[0].VerifyHostname(sni); err != nil {
169-
// TODO: log?
170-
return
171-
}
172-
173-
// Target presented what looks like a valid challenge
174-
// response, send it back to the matcher.
175-
ret = dest
176-
}
177-
17880
// clientHelloServerName returns the SNI server name inside the TLS ClientHello,
17981
// without consuming any bytes from br.
18082
// On any error, the empty string is returned.

Diff for: tcpproxy.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ func equals(want string) Matcher {
9393

9494
// config contains the proxying state for one listener.
9595
type config struct {
96-
routes []route
97-
acmeTargets []Target // accumulates targets that should be probed for acme.
98-
stopACME bool // if true, AddSNIRoute doesn't add targets to acmeTargets.
96+
routes []route
9997
}
10098

10199
// A route matches a connection to a target.

0 commit comments

Comments
 (0)