From c0e86de6dba921e320b47f51df9df7bf62bb53d7 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 27 Mar 2020 17:25:05 -0700 Subject: [PATCH] Forgot one spot. --- go/pkg/zerotier/api.go | 12 ++++++++---- go/pkg/zerotier/network.go | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/go/pkg/zerotier/api.go b/go/pkg/zerotier/api.go index 52dfaeeab..8e71c4947 100644 --- a/go/pkg/zerotier/api.go +++ b/go/pkg/zerotier/api.go @@ -456,11 +456,15 @@ func createAPIServer(basePath string, node *Node) (*http.Server, *http.Server, e if apiReadObj(out, req, &nw) == nil { n := node.GetNetwork(nw.ID) if n == nil { - n, err := node.Join(nw.ID, nw.Settings, nil) - if err != nil { - _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual networks can be added or modified with POST/PUT"}) + if nw.ControllerFingerprint != nil && nw.ControllerFingerprint.Address != nw.ID.Controller() { + _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"fingerprint's address does not match what should be the controller's address"}) } else { - _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n)) + n, err := node.Join(nw.ID, nw.ControllerFingerprint, nw.Settings, nil) + if err != nil { + _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual networks can be added or modified with POST/PUT"}) + } else { + _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n)) + } } } else { if nw.Settings != nil { diff --git a/go/pkg/zerotier/network.go b/go/pkg/zerotier/network.go index a182f6f47..42f490969 100644 --- a/go/pkg/zerotier/network.go +++ b/go/pkg/zerotier/network.go @@ -43,6 +43,11 @@ func NewNetworkIDFromBytes(b []byte) (NetworkID, error) { return NetworkID(binary.BigEndian.Uint64(b)), nil } +// Controller gets the Address of this network's controller. +func (n NetworkID) Controller() Address { + return Address(uint64(n) >> 24) +} + // String returns this network ID's 16-digit hex identifier func (n NetworkID) String() string { return fmt.Sprintf("%.16x", uint64(n))