diff --git a/controllers/node_grpc.go b/controllers/node_grpc.go index bd2bb7f2..a35dfc48 100644 --- a/controllers/node_grpc.go +++ b/controllers/node_grpc.go @@ -77,14 +77,16 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object) } // TODO consolidate functionality around files node.NetworkSettings.DefaultServerAddrs = serverAddrs - key, keyErr := logic.RetrievePublicTrafficKey() + key, mod, keyErr := logic.RetrievePublicTrafficKey() if keyErr != nil { logger.Log(0, "error retrieving key: ", keyErr.Error()) return nil, keyErr } + key.N = &mod node.TrafficKeys = models.TrafficKeys{ Mine: node.TrafficKeys.Mine, + Mod: node.TrafficKeys.Mod, Server: key, } diff --git a/database/database.go b/database/database.go index c3ba3a25..d644cefc 100644 --- a/database/database.go +++ b/database/database.go @@ -5,6 +5,7 @@ import ( "crypto/rsa" "encoding/json" "errors" + "fmt" "time" "github.com/google/uuid" @@ -211,8 +212,9 @@ func initializeUUID() error { return keyErr } var rsaPublicKey = &rsaPrivKey.PublicKey + fmt.Printf("found modulus: %d \n", rsaPublicKey.N) - telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKeyPriv: *rsaPrivKey, TrafficKeyPub: *rsaPublicKey} + telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKeyPriv: *rsaPrivKey, TrafficKeyPub: *rsaPublicKey, PubMod: *rsaPublicKey.N} telJSON, err := json.Marshal(&telemetry) if err != nil { return err diff --git a/logic/traffic.go b/logic/traffic.go index 4b9ae686..3ea01a0a 100644 --- a/logic/traffic.go +++ b/logic/traffic.go @@ -3,6 +3,7 @@ package logic import ( "crypto/rsa" "fmt" + "math/big" ) // RetrievePrivateTrafficKey - retrieves private key of server @@ -17,12 +18,12 @@ func RetrievePrivateTrafficKey() (rsa.PrivateKey, error) { } // RetrievePublicTrafficKey - retrieves public key of server -func RetrievePublicTrafficKey() (rsa.PublicKey, error) { +func RetrievePublicTrafficKey() (rsa.PublicKey, big.Int, error) { var telRecord, err = fetchTelemetryRecord() if err != nil { - return rsa.PublicKey{}, err + return rsa.PublicKey{}, big.Int{}, err } fmt.Printf("fetched pub key %v \n", telRecord.TrafficKeyPub) - return telRecord.TrafficKeyPub, nil + return telRecord.TrafficKeyPub, telRecord.PubMod, nil } diff --git a/models/structs.go b/models/structs.go index 739d81d5..f5d16d1a 100644 --- a/models/structs.go +++ b/models/structs.go @@ -2,6 +2,7 @@ package models import ( "crypto/rsa" + "math/big" jwt "github.com/golang-jwt/jwt/v4" ) @@ -174,6 +175,7 @@ type Telemetry struct { LastSend int64 `json:"lastsend" bson:"lastsend"` TrafficKeyPriv rsa.PrivateKey `json:"traffickeypriv" bson:"traffickeypriv"` TrafficKeyPub rsa.PublicKey `json:"traffickeypub" bson:"traffickeypub"` + PubMod big.Int `json:"pubmod" bson:"pubmod"` } // ServerAddr - to pass to clients to tell server addresses and if it's the leader or not @@ -185,5 +187,6 @@ type ServerAddr struct { // TrafficKeys - struct to hold public keys type TrafficKeys struct { Mine rsa.PublicKey `json:"mine" bson:"mine" yaml:"mine"` + Mod big.Int `json:"mod" bson:"mod" yaml:"mod"` Server rsa.PublicKey `json:"server" bson:"server" yaml:"server"` } diff --git a/mq/util.go b/mq/util.go index 4614b603..1351e411 100644 --- a/mq/util.go +++ b/mq/util.go @@ -18,6 +18,7 @@ func decryptMsg(msg []byte) ([]byte, error) { func encrypt(node *models.Node, dest string, msg []byte) ([]byte, error) { fmt.Printf("original length: %d \n", len(msg)) + node.TrafficKeys.Mine.N = &node.TrafficKeys.Mod encrypted := ncutils.BuildMessage(msg, &node.TrafficKeys.Mine) if encrypted == "" { return nil, fmt.Errorf("could not encrypt message") diff --git a/netclient/functions/join.go b/netclient/functions/join.go index 6bb755be..caaf75cd 100644 --- a/netclient/functions/join.go +++ b/netclient/functions/join.go @@ -137,6 +137,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error { UDPHolePunch: cfg.Node.UDPHolePunch, TrafficKeys: models.TrafficKeys{ Mine: rsaPrivKey.PublicKey, + Mod: *rsaPrivKey.PublicKey.N, Server: rsa.PublicKey{}, }, }