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