Skip to content

Commit e2d9c99

Browse files
committed
cmd/hello: migrate to hello.ts.net as the hostname
But still support hello.ipn.dev for a bit. Updates tailscale/corp#1327 Change-Id: Iab59cca0b260d69858af16f4e42677e54f9fe54a Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent 01a9906 commit e2d9c99

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

cmd/hello/hello.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// The hello binary runs hello.ipn.dev.
5+
// The hello binary runs hello.ts.net.
66
package main // import "tailscale.com/cmd/hello"
77

88
import (
99
"context"
10+
"crypto/tls"
1011
_ "embed"
1112
"encoding/json"
13+
"errors"
1214
"flag"
1315
"html/template"
1416
"io/ioutil"
1517
"log"
1618
"net/http"
1719
"os"
1820
"strings"
21+
"time"
1922

2023
"tailscale.com/client/tailscale"
2124
"tailscale.com/client/tailscale/apitype"
@@ -69,11 +72,31 @@ func main() {
6972
if *httpsAddr != "" {
7073
log.Printf("running HTTPS server on %s", *httpsAddr)
7174
go func() {
72-
errc <- http.ListenAndServeTLS(*httpsAddr,
73-
"/etc/hello/hello.ipn.dev.crt",
74-
"/etc/hello/hello.ipn.dev.key",
75-
nil,
76-
)
75+
hs := &http.Server{
76+
Addr: *httpsAddr,
77+
TLSConfig: &tls.Config{
78+
GetCertificate: func(hi *tls.ClientHelloInfo) (*tls.Certificate, error) {
79+
switch hi.ServerName {
80+
case "hello.ts.net":
81+
return tailscale.GetCertificate(hi)
82+
case "hello.ipn.dev":
83+
c, err := tls.LoadX509KeyPair(
84+
"/etc/hello/hello.ipn.dev.crt",
85+
"/etc/hello/hello.ipn.dev.key",
86+
)
87+
if err != nil {
88+
return nil, err
89+
}
90+
return &c, nil
91+
}
92+
return nil, errors.New("invalid SNI name")
93+
},
94+
},
95+
IdleTimeout: 30 * time.Second,
96+
ReadHeaderTimeout: 20 * time.Second,
97+
MaxHeaderBytes: 10 << 10,
98+
}
99+
errc <- hs.ListenAndServeTLS("", "")
77100
}()
78101
}
79102
log.Fatal(<-errc)
@@ -127,8 +150,9 @@ func tailscaleIP(who *apitype.WhoIsResponse) string {
127150
func root(w http.ResponseWriter, r *http.Request) {
128151
if r.TLS == nil && *httpsAddr != "" {
129152
host := r.Host
130-
if strings.Contains(r.Host, "100.101.102.103") {
131-
host = "hello.ipn.dev"
153+
if strings.Contains(r.Host, "100.101.102.103") ||
154+
strings.Contains(r.Host, "hello.ipn.dev") {
155+
host = "hello.ts.net"
132156
}
133157
http.Redirect(w, r, "https://"+host, http.StatusFound)
134158
return

0 commit comments

Comments
 (0)