Allow any port for HTTPS when using Noise over TLS
Signed-off-by: Juan Font Alonso <juanfontalonso@gmail.com>pull/5375/head
parent
25865f81ee
commit
64d482ff48
|
@ -1329,7 +1329,7 @@ func (c *Direct) setDNSNoise(ctx context.Context, req *tailcfg.SetDNSRequest) er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
res, err := np.Post(fmt.Sprintf("https://%v/%v", np.serverHost, "machine/set-dns"), "application/json", bytes.NewReader(bodyData))
|
res, err := np.Post(fmt.Sprintf("https://%v/%v", np.host, "machine/set-dns"), "application/json", bytes.NewReader(bodyData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ package controlclient
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -50,7 +49,9 @@ type noiseClient struct {
|
||||||
dialer *tsdial.Dialer
|
dialer *tsdial.Dialer
|
||||||
privKey key.MachinePrivate
|
privKey key.MachinePrivate
|
||||||
serverPubKey key.MachinePublic
|
serverPubKey key.MachinePublic
|
||||||
serverHost string // the host:port part of serverURL
|
host string // the host part of serverURL
|
||||||
|
httpPort string // the default port to call
|
||||||
|
httpsPort string // the fallback Noise-over-https port
|
||||||
|
|
||||||
// mu only protects the following variables.
|
// mu only protects the following variables.
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
@ -65,18 +66,28 @@ func newNoiseClient(priKey key.MachinePrivate, serverPubKey key.MachinePublic, s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var host string
|
var httpPort string
|
||||||
|
var httpsPort string
|
||||||
if u.Port() != "" {
|
if u.Port() != "" {
|
||||||
// If there is an explicit port specified use it.
|
// If there is an explicit port specified, trust the scheme and hope for the best
|
||||||
host = u.Host
|
if u.Scheme == "http" {
|
||||||
|
httpPort = u.Port()
|
||||||
|
httpsPort = "443"
|
||||||
|
} else {
|
||||||
|
httpPort = "80"
|
||||||
|
httpsPort = u.Port()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, controlhttp.Dial expects an http endpoint.
|
// Otherwise, use the standard ports
|
||||||
host = fmt.Sprintf("%v:80", u.Hostname())
|
httpPort = "80"
|
||||||
|
httpsPort = "443"
|
||||||
}
|
}
|
||||||
np := &noiseClient{
|
np := &noiseClient{
|
||||||
serverPubKey: serverPubKey,
|
serverPubKey: serverPubKey,
|
||||||
privKey: priKey,
|
privKey: priKey,
|
||||||
serverHost: host,
|
host: u.Hostname(),
|
||||||
|
httpPort: httpPort,
|
||||||
|
httpsPort: httpsPort,
|
||||||
dialer: dialer,
|
dialer: dialer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +165,7 @@ func (nc *noiseClient) dial(_, _ string, _ *tls.Config) (net.Conn, error) {
|
||||||
// thousand version numbers before getting to this point.
|
// thousand version numbers before getting to this point.
|
||||||
panic("capability version is too high to fit in the wire protocol")
|
panic("capability version is too high to fit in the wire protocol")
|
||||||
}
|
}
|
||||||
conn, err := controlhttp.Dial(ctx, nc.serverHost, nc.privKey, nc.serverPubKey, uint16(tailcfg.CurrentCapabilityVersion), nc.dialer.SystemDial)
|
conn, err := controlhttp.Dial(ctx, nc.host, nc.httpPort, nc.httpsPort, nc.privKey, nc.serverPubKey, uint16(tailcfg.CurrentCapabilityVersion), nc.dialer.SystemDial)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,24 +43,20 @@ import (
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Dial connects to the HTTP server at addr, requests to switch to the
|
// Dial connects to the HTTP server at host:httpPort, requests to switch to the
|
||||||
// Tailscale control protocol, and returns an established control
|
// Tailscale control protocol, and returns an established control
|
||||||
// protocol connection.
|
// protocol connection.
|
||||||
//
|
//
|
||||||
// If Dial fails to connect using addr, it also tries to tunnel over
|
// If Dial fails to connect using addr, it also tries to tunnel over
|
||||||
// TLS to <addr's host>:443 as a compatibility fallback.
|
// TLS to host:httpsPort as a compatibility fallback.
|
||||||
//
|
//
|
||||||
// The provided ctx is only used for the initial connection, until
|
// The provided ctx is only used for the initial connection, until
|
||||||
// Dial returns. It does not affect the connection once established.
|
// Dial returns. It does not affect the connection once established.
|
||||||
func Dial(ctx context.Context, addr string, machineKey key.MachinePrivate, controlKey key.MachinePublic, protocolVersion uint16, dialer dnscache.DialContextFunc) (*controlbase.Conn, error) {
|
func Dial(ctx context.Context, host string, httpPort string, httpsPort string, machineKey key.MachinePrivate, controlKey key.MachinePublic, protocolVersion uint16, dialer dnscache.DialContextFunc) (*controlbase.Conn, error) {
|
||||||
host, port, err := net.SplitHostPort(addr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
a := &dialParams{
|
a := &dialParams{
|
||||||
host: host,
|
host: host,
|
||||||
httpPort: port,
|
httpPort: httpPort,
|
||||||
httpsPort: "443",
|
httpsPort: httpsPort,
|
||||||
machineKey: machineKey,
|
machineKey: machineKey,
|
||||||
controlKey: controlKey,
|
controlKey: controlKey,
|
||||||
version: protocolVersion,
|
version: protocolVersion,
|
||||||
|
|
Loading…
Reference in New Issue