mirror of
				https://github.com/gravitl/netmaker.git
				synced 2025-10-31 04:06:37 +08:00 
			
		
		
		
	refactored struct
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -77,9 +77,10 @@ func fetchTelemetryData() (telemetryData, error) { | ||||
| func setTelemetryTimestamp(telRecord *models.Telemetry) error { | ||||
| 	lastsend := time.Now().Unix() | ||||
| 	var serverTelData = models.Telemetry{ | ||||
| 		UUID:       telRecord.UUID, | ||||
| 		LastSend:   lastsend, | ||||
| 		TrafficKey: telRecord.TrafficKey, | ||||
| 		UUID:           telRecord.UUID, | ||||
| 		LastSend:       lastsend, | ||||
| 		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 | ||||
| } | ||||
|   | ||||
| @@ -170,9 +170,10 @@ 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"` | ||||
| 	TrafficKey rsa.PrivateKey `json:"traffickey" bson:"traffickey"` | ||||
| 	UUID           string         `json:"uuid" bson:"uuid"` | ||||
| 	LastSend       int64          `json:"lastsend" bson:"lastsend"` | ||||
| 	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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 0xdcarns
					0xdcarns