mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-06 21:24:16 +08:00
debugging
This commit is contained in:
parent
03b05f7d7c
commit
d27dee0691
6 changed files with 32 additions and 40 deletions
|
@ -2,10 +2,9 @@ package controller
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
nodepb "github.com/gravitl/netmaker/grpc"
|
||||
|
@ -13,7 +12,6 @@ import (
|
|||
"github.com/gravitl/netmaker/logic"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/gravitl/netmaker/mq"
|
||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
)
|
||||
|
||||
|
@ -80,20 +78,18 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object)
|
|||
}
|
||||
// TODO consolidate functionality around files
|
||||
node.NetworkSettings.DefaultServerAddrs = serverAddrs
|
||||
var rsaPrivKey, keyErr = rsa.GenerateKey(rand.Reader, ncutils.KEY_SIZE)
|
||||
key, keyErr := logic.RetrieveTrafficKey()
|
||||
if keyErr != nil {
|
||||
return nil, keyErr
|
||||
}
|
||||
err = logic.StoreTrafficKey(node.ID, (*rsaPrivKey))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node.TrafficKeys = models.TrafficKeys{
|
||||
Mine: node.TrafficKeys.Mine,
|
||||
Server: rsaPrivKey.PublicKey,
|
||||
Server: key.PublicKey,
|
||||
}
|
||||
|
||||
fmt.Printf("finished created node: %v \n", node)
|
||||
|
||||
err = logic.CreateNode(&node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -209,7 +212,15 @@ func initializeUUID() error {
|
|||
} else if len(records) > 0 {
|
||||
return nil
|
||||
}
|
||||
telemetry := models.Telemetry{UUID: uuid.NewString()}
|
||||
var rsaPrivKey, keyErr = rsa.GenerateKey(rand.Reader, 32)
|
||||
if keyErr != nil {
|
||||
return keyErr
|
||||
}
|
||||
|
||||
fmt.Printf("key generated: %v \n", rsaPrivKey)
|
||||
fmt.Printf("pub key generate: %v \n", rsaPrivKey.PublicKey)
|
||||
|
||||
telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKey: *rsaPrivKey}
|
||||
telJSON, err := json.Marshal(&telemetry)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -2,35 +2,13 @@ package logic
|
|||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gravitl/netmaker/database"
|
||||
)
|
||||
|
||||
type trafficKey struct {
|
||||
Key rsa.PrivateKey `json:"key" bson:"key"`
|
||||
}
|
||||
|
||||
// RetrieveTrafficKey - retrieves key based on node
|
||||
func RetrieveTrafficKey(nodeid string) (rsa.PrivateKey, error) {
|
||||
var record, err = database.FetchRecord(database.TRAFFIC_TABLE_NAME, nodeid)
|
||||
func RetrieveTrafficKey() (rsa.PrivateKey, error) {
|
||||
var telRecord, err = fetchTelemetryRecord()
|
||||
if err != nil {
|
||||
return rsa.PrivateKey{}, err
|
||||
}
|
||||
var result trafficKey
|
||||
if err = json.Unmarshal([]byte(record), &result); err != nil {
|
||||
return rsa.PrivateKey{}, err
|
||||
}
|
||||
return result.Key, nil
|
||||
}
|
||||
|
||||
// StoreTrafficKey - stores key based on node
|
||||
func StoreTrafficKey(nodeid string, key rsa.PrivateKey) error {
|
||||
var data, err = json.Marshal(trafficKey{
|
||||
Key: key,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return database.Insert(nodeid, string(data), database.TRAFFIC_TABLE_NAME)
|
||||
return telRecord.TrafficKey, nil
|
||||
}
|
||||
|
|
|
@ -170,8 +170,9 @@ type ServerUpdateData struct {
|
|||
|
||||
// Telemetry - contains UUID of the server and timestamp of last send to posthog
|
||||
type Telemetry struct {
|
||||
UUID string `json:"uuid" bson:"uuid"`
|
||||
LastSend int64 `json:"lastsend" bson:"lastsend"`
|
||||
UUID string `json:"uuid" bson:"uuid"`
|
||||
LastSend int64 `json:"lastsend" bson:"lastsend"`
|
||||
TrafficKey rsa.PrivateKey `json:"traffickey" bson:"traffickey"`
|
||||
}
|
||||
|
||||
// ServerAddr - to pass to clients to tell server addresses and if it's the leader or not
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package mq
|
||||
|
||||
import (
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/logic"
|
||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||
)
|
||||
|
||||
func decryptMsg(nodeid string, msg []byte) ([]byte, error) {
|
||||
trafficKey, trafficErr := logic.RetrieveTrafficKey(nodeid)
|
||||
logger.Log(0, "found message for decryption: %s \n", string(msg))
|
||||
trafficKey, trafficErr := logic.RetrieveTrafficKey()
|
||||
if trafficErr != nil {
|
||||
return nil, trafficErr
|
||||
}
|
||||
|
|
|
@ -48,12 +48,16 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||
if errGen != nil {
|
||||
return errGen
|
||||
}
|
||||
auth.StoreSecret(cfg.Node.Password, cfg.Node.Network)
|
||||
if err = auth.StoreSecret(cfg.Node.Password, cfg.Node.Network); err != nil {
|
||||
return err
|
||||
}
|
||||
var keyData, errKeyData = json.Marshal(&rsaPrivKey)
|
||||
if errKeyData != nil {
|
||||
return errKeyData
|
||||
}
|
||||
auth.StoreTrafficKey(string(keyData), cfg.Node.Network)
|
||||
if err = auth.StoreTrafficKey(string(keyData), cfg.Node.Network); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cfg.Node.LocalRange != "" && cfg.Node.LocalAddress == "" {
|
||||
log.Println("local vpn, getting local address from range: " + cfg.Node.LocalRange)
|
||||
|
|
Loading…
Add table
Reference in a new issue