summaryrefslogtreecommitdiff
path: root/sni.go
diff options
context:
space:
mode:
authorNathan Johnson <[email protected]>2018-06-07 17:11:22 -0500
committerBrad Fitzpatrick <[email protected]>2018-06-07 15:11:22 -0700
commitdbc151467a20b4513174bb3d6b1283e9419eb0f9 (patch)
tree3ee70fb558b3c4ec256dbb030eb069699dd40c84 /sni.go
parent2b928d9b07d782cc1a94736979d012792810658f (diff)
Adding the HostName field to the Conn struct (#18)
Changing the internal-only match interface to return any parsed hostnames. It can be useful for implementers of Target to be able to inspect the already-parsed SNI header (in the case of TLS) or host header (in the case of http) to know what host was asked for by the client in order to make additional routing decisions. This can be used by transparent reverse proxies where the destination is not known in advance.
Diffstat (limited to 'sni.go')
-rw-r--r--sni.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/sni.go b/sni.go
index 44f5796..53b53c2 100644
--- a/sni.go
+++ b/sni.go
@@ -73,11 +73,12 @@ type sniMatch struct {
target Target
}
-func (m sniMatch) match(br *bufio.Reader) Target {
- if m.matcher(context.TODO(), clientHelloServerName(br)) {
- return m.target
+func (m sniMatch) match(br *bufio.Reader) (Target, string) {
+ sni := clientHelloServerName(br)
+ if m.matcher(context.TODO(), sni) {
+ return m.target, sni
}
- return nil
+ return nil, ""
}
// acmeMatch matches "*.acme.invalid" ACME tls-sni-01 challenges and
@@ -87,10 +88,10 @@ type acmeMatch struct {
cfg *config
}
-func (m *acmeMatch) match(br *bufio.Reader) Target {
+func (m *acmeMatch) match(br *bufio.Reader) (Target, string) {
sni := clientHelloServerName(br)
if !strings.HasSuffix(sni, ".acme.invalid") {
- return nil
+ return nil, ""
}
// TODO: cache. ACME issuers will hit multiple times in a short
@@ -107,12 +108,12 @@ func (m *acmeMatch) match(br *bufio.Reader) Target {
}
for range m.cfg.acmeTargets {
if target := <-ch; target != nil {
- return target
+ return target, sni
}
}
// No target was happy with the provided challenge.
- return nil
+ return nil, ""
}
func tryACME(ctx context.Context, ch chan<- Target, dest Target, sni string) {