tracking mod

This commit is contained in:
0xdcarns 2022-01-29 10:06:53 -05:00
parent 7070d16f71
commit aa22afeb95
6 changed files with 15 additions and 5 deletions

View file

@ -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,
}

View file

@ -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

View file

@ -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
}

View file

@ -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"`
}

View file

@ -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")

View file

@ -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{},
},
}