mirror of
https://github.com/juanfont/headscale.git
synced 2025-01-19 10:20:05 +09:00
clean up rejection of old clients
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
b93c0744a3
commit
0890dd69c5
1 changed files with 27 additions and 30 deletions
|
@ -3,6 +3,7 @@ package hscontrol
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -115,18 +116,8 @@ func (h *Headscale) NoiseUpgradeHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *noiseServer) earlyNoise(protocolVersion int, writer io.Writer) error {
|
func (ns *noiseServer) earlyNoise(protocolVersion int, writer io.Writer) error {
|
||||||
log.Trace().
|
if !isSupportedVersion(tailcfg.CapabilityVersion(protocolVersion)) {
|
||||||
Caller().
|
return fmt.Errorf("unsupported client version: %d", protocolVersion)
|
||||||
Int("protocol_version", protocolVersion).
|
|
||||||
Str("challenge", ns.challenge.Public().String()).
|
|
||||||
Msg("earlyNoise called")
|
|
||||||
|
|
||||||
if protocolVersion < earlyNoiseCapabilityVersion {
|
|
||||||
log.Trace().
|
|
||||||
Caller().
|
|
||||||
Msgf("protocol version %d does not support early noise", protocolVersion)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
earlyJSON, err := json.Marshal(&tailcfg.EarlyNoise{
|
earlyJSON, err := json.Marshal(&tailcfg.EarlyNoise{
|
||||||
|
@ -162,6 +153,26 @@ const (
|
||||||
MinimumCapVersion tailcfg.CapabilityVersion = 82
|
MinimumCapVersion tailcfg.CapabilityVersion = 82
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func isSupportedVersion(version tailcfg.CapabilityVersion) bool {
|
||||||
|
return version >= MinimumCapVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
func rejectUnsupported(writer http.ResponseWriter, version tailcfg.CapabilityVersion) bool {
|
||||||
|
// Reject unsupported versions
|
||||||
|
if !isSupportedVersion(version) {
|
||||||
|
log.Info().
|
||||||
|
Caller().
|
||||||
|
Int("min_version", int(MinimumCapVersion)).
|
||||||
|
Int("client_version", int(version)).
|
||||||
|
Msg("unsupported client connected")
|
||||||
|
http.Error(writer, "unsupported client version", http.StatusBadRequest)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// NoisePollNetMapHandler takes care of /machine/:id/map using the Noise protocol
|
// NoisePollNetMapHandler takes care of /machine/:id/map using the Noise protocol
|
||||||
//
|
//
|
||||||
// This is the busiest endpoint, as it keeps the HTTP long poll that updates
|
// This is the busiest endpoint, as it keeps the HTTP long poll that updates
|
||||||
|
@ -177,7 +188,7 @@ func (ns *noiseServer) NoisePollNetMapHandler(
|
||||||
) {
|
) {
|
||||||
body, _ := io.ReadAll(req.Body)
|
body, _ := io.ReadAll(req.Body)
|
||||||
|
|
||||||
mapRequest := tailcfg.MapRequest{}
|
var mapRequest tailcfg.MapRequest
|
||||||
if err := json.Unmarshal(body, &mapRequest); err != nil {
|
if err := json.Unmarshal(body, &mapRequest); err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
Caller().
|
Caller().
|
||||||
|
@ -197,14 +208,7 @@ func (ns *noiseServer) NoisePollNetMapHandler(
|
||||||
Msg("PollNetMapHandler called")
|
Msg("PollNetMapHandler called")
|
||||||
|
|
||||||
// Reject unsupported versions
|
// Reject unsupported versions
|
||||||
if mapRequest.Version < MinimumCapVersion {
|
if rejectUnsupported(writer, mapRequest.Version) {
|
||||||
log.Info().
|
|
||||||
Caller().
|
|
||||||
Int("min_version", int(MinimumCapVersion)).
|
|
||||||
Int("client_version", int(mapRequest.Version)).
|
|
||||||
Msg("unsupported client connected")
|
|
||||||
http.Error(writer, "Internal error", http.StatusBadRequest)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +255,7 @@ func (ns *noiseServer) NoiseRegistrationHandler(
|
||||||
Msg("Headers")
|
Msg("Headers")
|
||||||
|
|
||||||
body, _ := io.ReadAll(req.Body)
|
body, _ := io.ReadAll(req.Body)
|
||||||
registerRequest := tailcfg.RegisterRequest{}
|
var registerRequest tailcfg.RegisterRequest
|
||||||
if err := json.Unmarshal(body, ®isterRequest); err != nil {
|
if err := json.Unmarshal(body, ®isterRequest); err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
Caller().
|
Caller().
|
||||||
|
@ -263,14 +267,7 @@ func (ns *noiseServer) NoiseRegistrationHandler(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject unsupported versions
|
// Reject unsupported versions
|
||||||
if registerRequest.Version < MinimumCapVersion {
|
if rejectUnsupported(writer, registerRequest.Version) {
|
||||||
log.Info().
|
|
||||||
Caller().
|
|
||||||
Int("min_version", int(MinimumCapVersion)).
|
|
||||||
Int("client_version", int(registerRequest.Version)).
|
|
||||||
Msg("unsupported client connected")
|
|
||||||
http.Error(writer, "unsupported client version", http.StatusBadRequest)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue