cmd/derper: use new node key type.

Updates #3206

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2021-10-27 17:29:43 -07:00 committed by Dave Anderson
parent bc89a796ec
commit a47158e14d

View File

@ -31,7 +31,6 @@
"tailscale.com/net/stun" "tailscale.com/net/stun"
"tailscale.com/tsweb" "tailscale.com/tsweb"
"tailscale.com/types/key" "tailscale.com/types/key"
"tailscale.com/types/wgkey"
) )
var ( var (
@ -70,12 +69,12 @@ func init() {
} }
type config struct { type config struct {
PrivateKey wgkey.Private PrivateKey key.NodePrivate
} }
func loadConfig() config { func loadConfig() config {
if *dev { if *dev {
return config{PrivateKey: mustNewKey()} return config{PrivateKey: key.NewNode()}
} }
if *configPath == "" { if *configPath == "" {
if os.Getuid() == 0 { if os.Getuid() == 0 {
@ -101,21 +100,13 @@ func loadConfig() config {
} }
} }
func mustNewKey() wgkey.Private {
key, err := wgkey.NewPrivate()
if err != nil {
log.Fatal(err)
}
return key
}
func writeNewConfig() config { func writeNewConfig() config {
key := mustNewKey() k := key.NewNode()
if err := os.MkdirAll(filepath.Dir(*configPath), 0777); err != nil { if err := os.MkdirAll(filepath.Dir(*configPath), 0777); err != nil {
log.Fatal(err) log.Fatal(err)
} }
cfg := config{ cfg := config{
PrivateKey: key, PrivateKey: k,
} }
b, err := json.MarshalIndent(cfg, "", "\t") b, err := json.MarshalIndent(cfg, "", "\t")
if err != nil { if err != nil {
@ -152,7 +143,7 @@ func main() {
serveTLS := tsweb.IsProd443(*addr) serveTLS := tsweb.IsProd443(*addr)
s := derp.NewServer(key.Private(cfg.PrivateKey), log.Printf) s := derp.NewServer(cfg.PrivateKey.AsPrivate(), log.Printf)
s.SetVerifyClient(*verifyClients) s.SetVerifyClient(*verifyClients)
if *meshPSKFile != "" { if *meshPSKFile != "" {