Browse Source

added e..

0xdcarns 3 years ago
parent
commit
3dadb8dcbf

+ 3 - 1
controllers/node_grpc.go

@@ -77,16 +77,18 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object)
 	}
 	// TODO consolidate functionality around files
 	node.NetworkSettings.DefaultServerAddrs = serverAddrs
-	key, mod, keyErr := logic.RetrievePublicTrafficKey()
+	key, mod, e, keyErr := logic.RetrievePublicTrafficKey()
 	if keyErr != nil {
 		logger.Log(0, "error retrieving key: ", keyErr.Error())
 		return nil, keyErr
 	}
 	key.N = &mod
+	key.E = e
 
 	node.TrafficKeys = models.TrafficKeys{
 		Mine:   node.TrafficKeys.Mine,
 		Mod:    node.TrafficKeys.Mod,
+		E:      node.TrafficKeys.E,
 		Server: key,
 	}
 

+ 8 - 3
database/database.go

@@ -212,9 +212,14 @@ 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, PubMod: *rsaPublicKey.N}
+	fmt.Printf("E: %d \n", rsaPublicKey.E)
+	telemetry := models.Telemetry{
+		UUID:           uuid.NewString(),
+		TrafficKeyPriv: *rsaPrivKey,
+		TrafficKeyPub:  *rsaPublicKey,
+		PubMod:         *rsaPublicKey.N,
+		PubE:           rsaPublicKey.E,
+	}
 	telJSON, err := json.Marshal(&telemetry)
 	if err != nil {
 		return err

+ 3 - 3
logic/traffic.go

@@ -18,12 +18,12 @@ func RetrievePrivateTrafficKey() (rsa.PrivateKey, error) {
 }
 
 // RetrievePublicTrafficKey - retrieves public key of server
-func RetrievePublicTrafficKey() (rsa.PublicKey, big.Int, error) {
+func RetrievePublicTrafficKey() (rsa.PublicKey, big.Int, int, error) {
 	var telRecord, err = fetchTelemetryRecord()
 	if err != nil {
-		return rsa.PublicKey{}, big.Int{}, err
+		return rsa.PublicKey{}, big.Int{}, 0, err
 	}
 	fmt.Printf("fetched pub key %v \n", telRecord.TrafficKeyPub)
 
-	return telRecord.TrafficKeyPub, telRecord.PubMod, nil
+	return telRecord.TrafficKeyPub, telRecord.PubMod, telRecord.PubE, nil
 }

+ 2 - 0
models/structs.go

@@ -176,6 +176,7 @@ type Telemetry struct {
 	TrafficKeyPriv rsa.PrivateKey `json:"traffickeypriv" bson:"traffickeypriv"`
 	TrafficKeyPub  rsa.PublicKey  `json:"traffickeypub" bson:"traffickeypub"`
 	PubMod         big.Int        `json:"pubmod" bson:"pubmod"`
+	PubE           int            `json:"pube" bson:"pube"`
 }
 
 // ServerAddr - to pass to clients to tell server addresses and if it's the leader or not
@@ -188,5 +189,6 @@ type ServerAddr struct {
 type TrafficKeys struct {
 	Mine   rsa.PublicKey `json:"mine" bson:"mine" yaml:"mine"`
 	Mod    big.Int       `json:"mod" bson:"mod" yaml:"mod"`
+	E      int           `json:"e" bson:"e" yaml:"e"`
 	Server rsa.PublicKey `json:"server" bson:"server" yaml:"server"`
 }

+ 1 - 0
mq/util.go

@@ -19,6 +19,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
+	node.TrafficKeys.Mine.E = node.TrafficKeys.E
 	encrypted := ncutils.BuildMessage(msg, &node.TrafficKeys.Mine)
 	if encrypted == "" {
 		return nil, fmt.Errorf("could not encrypt message")

+ 1 - 0
netclient/functions/join.go

@@ -138,6 +138,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
 		TrafficKeys: models.TrafficKeys{
 			Mine:   rsaPrivKey.PublicKey,
 			Mod:    *rsaPrivKey.PublicKey.N,
+			E:      rsaPrivKey.PublicKey.E,
 			Server: rsa.PublicKey{},
 		},
 	}

+ 1 - 1
netclient/ncutils/netclientutils.go

@@ -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, 240)
+	chunks := getSliceChunks(originalMessage, 228)
 	var message = ""
 	for i := 0; i < len(chunks); i++ {
 		var encryptedText, encryptErr = encryptWithPublicKey(chunks[i], pub)