mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 22:47:30 +00:00
cmd/{derp,derpprobe},prober,derp: add mesh support to derpprobe (#15414)
Add mesh key support to derpprobe for probing derpers with verify set to true. Move MeshKey checking to central point for code reuse. Fix a bad error fmt msg. Fixes tailscale/corp#27294 Fixes tailscale/corp#25756 Signed-off-by: Mike O'Driscoll <mikeo@tailscale.com>
This commit is contained in:
@@ -6,6 +6,7 @@ package key
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -23,6 +24,27 @@ type DERPMesh struct {
|
||||
k [32]byte // 64-digit hexadecimal numbers fit in 32 bytes
|
||||
}
|
||||
|
||||
// MarshalJSON implements the [encoding/json.Marshaler] interface.
|
||||
func (k DERPMesh) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(k.String())
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the [encoding/json.Unmarshaler] interface.
|
||||
func (k *DERPMesh) UnmarshalJSON(data []byte) error {
|
||||
var s string
|
||||
json.Unmarshal(data, &s)
|
||||
|
||||
if hex.DecodedLen(len(s)) != len(k.k) {
|
||||
return fmt.Errorf("types/key/derp: cannot unmarshal, incorrect size mesh key len: %d, must be %d, %w", hex.DecodedLen(len(s)), len(k.k), ErrInvalidMeshKey)
|
||||
}
|
||||
_, err := hex.Decode(k.k[:], []byte(s))
|
||||
if err != nil {
|
||||
return fmt.Errorf("types/key/derp: cannot unmarshal, invalid mesh key: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DERPMeshFromRaw32 parses a 32-byte raw value as a DERP mesh key.
|
||||
func DERPMeshFromRaw32(raw mem.RO) DERPMesh {
|
||||
if raw.Len() != 32 {
|
||||
|
Reference in New Issue
Block a user