mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 02:43:05 +00:00
TS2021: Expose the Noise public key over the /key
method
This commit is contained in:
parent
be59e8cc3c
commit
e271851f5c
1 changed files with 37 additions and 4 deletions
41
api.go
41
api.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -21,18 +22,50 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
reservedResponseHeaderSize = 4
|
|
||||||
RegisterMethodAuthKey = "authkey"
|
|
||||||
RegisterMethodOIDC = "oidc"
|
|
||||||
RegisterMethodCLI = "cli"
|
|
||||||
ErrRegisterMethodCLIDoesNotSupportExpire = Error(
|
ErrRegisterMethodCLIDoesNotSupportExpire = Error(
|
||||||
"machines registered with CLI does not support expire",
|
"machines registered with CLI does not support expire",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
reservedResponseHeaderSize = 4
|
||||||
|
RegisterMethodAuthKey = "authkey"
|
||||||
|
RegisterMethodOIDC = "oidc"
|
||||||
|
RegisterMethodCLI = "cli"
|
||||||
|
|
||||||
|
// The CapabilityVersion is used by Tailscale clients to indicate
|
||||||
|
// their codebase version. Tailscale clients can communicate over TS2021
|
||||||
|
// from CapabilityVersion 28.
|
||||||
|
// See https://github.com/tailscale/tailscale/blob/main/tailcfg/tailcfg.go
|
||||||
|
NoiseCapabilityVersion = 28
|
||||||
|
)
|
||||||
|
|
||||||
// KeyHandler provides the Headscale pub key
|
// KeyHandler provides the Headscale pub key
|
||||||
// Listens in /key.
|
// Listens in /key.
|
||||||
func (h *Headscale) KeyHandler(ctx *gin.Context) {
|
func (h *Headscale) KeyHandler(ctx *gin.Context) {
|
||||||
|
// New Tailscale clients send a 'v' parameter to indicate the CurrentCapabilityVersion
|
||||||
|
v := ctx.Query("v")
|
||||||
|
if v != "" {
|
||||||
|
clientCapabilityVersion, err := strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
ctx.String(http.StatusBadRequest, "Invalid version")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if clientCapabilityVersion >= NoiseCapabilityVersion {
|
||||||
|
// Tailscale has a different key for the TS2021 protocol. Not sure why.
|
||||||
|
resp := tailcfg.OverTLSPublicKeyResponse{
|
||||||
|
LegacyPublicKey: h.privateKey.Public(),
|
||||||
|
PublicKey: h.noisePrivateKey.Public(),
|
||||||
|
}
|
||||||
|
ctx.JSON(http.StatusOK, resp)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Old clients don't send a 'v' parameter, so we send the legacy public key
|
||||||
ctx.Data(
|
ctx.Data(
|
||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
"text/plain; charset=utf-8",
|
"text/plain; charset=utf-8",
|
||||||
|
|
Loading…
Reference in a new issue