Skip to content

Commit

Permalink
ensure public key is always send during node registration
Browse files Browse the repository at this point in the history
fixes #649
  • Loading branch information
zaibon committed Mar 31, 2020
1 parent 66b10bf commit 8c4d11a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmds/identityd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ package main

import (
"context"
"encoding/hex"
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"

"github.com/jbenet/go-base58"

"github.com/pkg/errors"
"github.com/threefoldtech/zos/pkg/app"
"github.com/threefoldtech/zos/pkg/flist"
"github.com/threefoldtech/zos/pkg/geoip"
"github.com/threefoldtech/zos/pkg/network"
"github.com/threefoldtech/zos/pkg/stubs"
"github.com/threefoldtech/zos/pkg/upgrade"
"github.com/threefoldtech/zos/tools/explorer/models/generated/directory"
"github.com/threefoldtech/zos/tools/client"
"github.com/threefoldtech/zos/tools/explorer/models/generated/directory"

"github.com/cenkalti/backoff/v3"
"github.com/threefoldtech/zos/pkg"
Expand Down Expand Up @@ -453,6 +456,8 @@ func registerNode(nodeID pkg.Identifier, farmID pkg.FarmID, version string, stor

v1ID, _ := network.NodeIDv1()

publicKeyHex := hex.EncodeToString(base58.Decode(nodeID.Identity()))

err := store.NodeRegister(directory.Node{
NodeId: nodeID.Identity(),
NodeIdV1: v1ID,
Expand All @@ -465,6 +470,7 @@ func registerNode(nodeID pkg.Identifier, farmID pkg.FarmID, version string, stor
Longitude: loc.Longitute,
Latitude: loc.Latitude,
},
PublicKeyHex: publicKeyHex,
})

if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions tools/explorer/pkg/directory/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package types

import (
"context"
"encoding/hex"
"fmt"
"time"

"github.com/jbenet/go-base58"
"github.com/pkg/errors"
"github.com/threefoldtech/zos/pkg/schema"
"github.com/threefoldtech/zos/tools/explorer/models"
Expand Down Expand Up @@ -36,6 +38,19 @@ func (n *Node) Validate() error {
return fmt.Errorf("os_version is required")
}

if len(n.PublicKeyHex) == 0 {
return fmt.Errorf("public_key_hex is required")
}

pk, err := hex.DecodeString(n.PublicKeyHex)
if err != nil {
return errors.Wrap(err, "fail to decode public key")
}

if n.NodeId != base58.Encode(pk) {
return fmt.Errorf("nodeID and public key does not match")
}

// Unfortunately, jsx schema does not support nil types
// so this is the only way to check if values are not set
empty := generated.Location{}
Expand Down

0 comments on commit 8c4d11a

Please sign in to comment.