mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-25 08:34:47 +08:00
refactored struct
This commit is contained in:
parent
3483e45beb
commit
ac632a75b7
7 changed files with 29 additions and 17 deletions
|
@ -77,7 +77,7 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object)
|
|||
}
|
||||
// TODO consolidate functionality around files
|
||||
node.NetworkSettings.DefaultServerAddrs = serverAddrs
|
||||
key, keyErr := logic.RetrieveTrafficKey()
|
||||
key, keyErr := logic.RetrievePublicTrafficKey()
|
||||
if keyErr != nil {
|
||||
logger.Log(0, "error retrieving key: ", keyErr.Error())
|
||||
return nil, keyErr
|
||||
|
@ -85,7 +85,7 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object)
|
|||
|
||||
node.TrafficKeys = models.TrafficKeys{
|
||||
Mine: node.TrafficKeys.Mine,
|
||||
Server: key.PublicKey,
|
||||
Server: key,
|
||||
}
|
||||
|
||||
err = logic.CreateNode(&node)
|
||||
|
|
|
@ -210,8 +210,9 @@ func initializeUUID() error {
|
|||
if keyErr != nil {
|
||||
return keyErr
|
||||
}
|
||||
var rsaPublicKey = &rsaPrivKey.PublicKey
|
||||
|
||||
telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKey: *rsaPrivKey}
|
||||
telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKeyPriv: *rsaPrivKey, TrafficKeyPub: *rsaPublicKey}
|
||||
telJSON, err := json.Marshal(&telemetry)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -79,7 +79,8 @@ func setTelemetryTimestamp(telRecord *models.Telemetry) error {
|
|||
var serverTelData = models.Telemetry{
|
||||
UUID: telRecord.UUID,
|
||||
LastSend: lastsend,
|
||||
TrafficKey: telRecord.TrafficKey,
|
||||
TrafficKeyPriv: telRecord.TrafficKeyPriv,
|
||||
TrafficKeyPub: telRecord.TrafficKeyPub,
|
||||
}
|
||||
jsonObj, err := json.Marshal(&serverTelData)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,13 +5,24 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// RetrieveTrafficKey - retrieves public key based on node
|
||||
func RetrieveTrafficKey() (rsa.PrivateKey, error) {
|
||||
// RetrievePrivateTrafficKey - retrieves private key of server
|
||||
func RetrievePrivateTrafficKey() (rsa.PrivateKey, error) {
|
||||
var telRecord, err = fetchTelemetryRecord()
|
||||
if err != nil {
|
||||
return rsa.PrivateKey{}, err
|
||||
}
|
||||
fmt.Printf("fetched key %v \n", telRecord.TrafficKey)
|
||||
fmt.Printf("fetched priv key %v \n", telRecord.TrafficKeyPriv)
|
||||
|
||||
return telRecord.TrafficKey, nil
|
||||
return telRecord.TrafficKeyPriv, nil
|
||||
}
|
||||
|
||||
// RetrievePublicTrafficKey - retrieves public key of server
|
||||
func RetrievePublicTrafficKey() (rsa.PublicKey, error) {
|
||||
var telRecord, err = fetchTelemetryRecord()
|
||||
if err != nil {
|
||||
return rsa.PublicKey{}, err
|
||||
}
|
||||
fmt.Printf("fetched pub key %v \n", telRecord.TrafficKeyPub)
|
||||
|
||||
return telRecord.TrafficKeyPub, nil
|
||||
}
|
||||
|
|
|
@ -172,7 +172,8 @@ type ServerUpdateData struct {
|
|||
type Telemetry struct {
|
||||
UUID string `json:"uuid" bson:"uuid"`
|
||||
LastSend int64 `json:"lastsend" bson:"lastsend"`
|
||||
TrafficKey rsa.PrivateKey `json:"traffickey" bson:"traffickey"`
|
||||
TrafficKeyPriv rsa.PrivateKey `json:"traffickeypriv" bson:"traffickeypriv"`
|
||||
TrafficKeyPub rsa.PublicKey `json:"traffickeypub" bson:"traffickeypub"`
|
||||
}
|
||||
|
||||
// ServerAddr - to pass to clients to tell server addresses and if it's the leader or not
|
||||
|
|
|
@ -3,15 +3,13 @@ package mq
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/logic"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||
)
|
||||
|
||||
func decryptMsg(msg []byte) ([]byte, error) {
|
||||
logger.Log(0, "found message for decryption: %s \n", string(msg))
|
||||
trafficKey, trafficErr := logic.RetrieveTrafficKey()
|
||||
trafficKey, trafficErr := logic.RetrievePrivateTrafficKey()
|
||||
if trafficErr != nil {
|
||||
return nil, trafficErr
|
||||
}
|
||||
|
|
|
@ -566,7 +566,7 @@ func DestructMessage(builtMsg string, priv *rsa.PrivateKey) []byte {
|
|||
|
||||
// BuildMessage Build a message for publishing
|
||||
func BuildMessage(originalMessage []byte, pub *rsa.PublicKey) string {
|
||||
chunks := getSliceChunks(originalMessage, 245)
|
||||
chunks := getSliceChunks(originalMessage, 240)
|
||||
var message = ""
|
||||
for i := 0; i < len(chunks); i++ {
|
||||
var encryptedText, encryptErr = encryptWithPublicKey(chunks[i], pub)
|
||||
|
|
Loading…
Reference in a new issue