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 // TODO consolidate functionality around files
node.NetworkSettings.DefaultServerAddrs = serverAddrs node.NetworkSettings.DefaultServerAddrs = serverAddrs
key, keyErr := logic.RetrievePublicTrafficKey() key, mod, keyErr := logic.RetrievePublicTrafficKey()
if keyErr != nil { if keyErr != nil {
logger.Log(0, "error retrieving key: ", keyErr.Error()) logger.Log(0, "error retrieving key: ", keyErr.Error())
return nil, keyErr return nil, keyErr
} }
key.N = &mod
node.TrafficKeys = models.TrafficKeys{ node.TrafficKeys = models.TrafficKeys{
Mine: node.TrafficKeys.Mine, Mine: node.TrafficKeys.Mine,
Mod: node.TrafficKeys.Mod,
Server: key, Server: key,
} }

View file

@ -5,6 +5,7 @@ import (
"crypto/rsa" "crypto/rsa"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
@ -211,8 +212,9 @@ func initializeUUID() error {
return keyErr return keyErr
} }
var rsaPublicKey = &rsaPrivKey.PublicKey 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) telJSON, err := json.Marshal(&telemetry)
if err != nil { if err != nil {
return err return err

View file

@ -3,6 +3,7 @@ package logic
import ( import (
"crypto/rsa" "crypto/rsa"
"fmt" "fmt"
"math/big"
) )
// RetrievePrivateTrafficKey - retrieves private key of server // RetrievePrivateTrafficKey - retrieves private key of server
@ -17,12 +18,12 @@ func RetrievePrivateTrafficKey() (rsa.PrivateKey, error) {
} }
// RetrievePublicTrafficKey - retrieves public key of server // RetrievePublicTrafficKey - retrieves public key of server
func RetrievePublicTrafficKey() (rsa.PublicKey, error) { func RetrievePublicTrafficKey() (rsa.PublicKey, big.Int, error) {
var telRecord, err = fetchTelemetryRecord() var telRecord, err = fetchTelemetryRecord()
if err != nil { if err != nil {
return rsa.PublicKey{}, err return rsa.PublicKey{}, big.Int{}, err
} }
fmt.Printf("fetched pub key %v \n", telRecord.TrafficKeyPub) 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 ( import (
"crypto/rsa" "crypto/rsa"
"math/big"
jwt "github.com/golang-jwt/jwt/v4" jwt "github.com/golang-jwt/jwt/v4"
) )
@ -174,6 +175,7 @@ type Telemetry struct {
LastSend int64 `json:"lastsend" bson:"lastsend"` LastSend int64 `json:"lastsend" bson:"lastsend"`
TrafficKeyPriv rsa.PrivateKey `json:"traffickeypriv" bson:"traffickeypriv"` TrafficKeyPriv rsa.PrivateKey `json:"traffickeypriv" bson:"traffickeypriv"`
TrafficKeyPub rsa.PublicKey `json:"traffickeypub" bson:"traffickeypub"` 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 // 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 // TrafficKeys - struct to hold public keys
type TrafficKeys struct { type TrafficKeys struct {
Mine rsa.PublicKey `json:"mine" bson:"mine" yaml:"mine"` 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"` 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) { func encrypt(node *models.Node, dest string, msg []byte) ([]byte, error) {
fmt.Printf("original length: %d \n", len(msg)) fmt.Printf("original length: %d \n", len(msg))
node.TrafficKeys.Mine.N = &node.TrafficKeys.Mod
encrypted := ncutils.BuildMessage(msg, &node.TrafficKeys.Mine) encrypted := ncutils.BuildMessage(msg, &node.TrafficKeys.Mine)
if encrypted == "" { if encrypted == "" {
return nil, fmt.Errorf("could not encrypt message") 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, UDPHolePunch: cfg.Node.UDPHolePunch,
TrafficKeys: models.TrafficKeys{ TrafficKeys: models.TrafficKeys{
Mine: rsaPrivKey.PublicKey, Mine: rsaPrivKey.PublicKey,
Mod: *rsaPrivKey.PublicKey.N,
Server: rsa.PublicKey{}, Server: rsa.PublicKey{},
}, },
} }