mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-16 22:01:19 +08:00
added e..
This commit is contained in:
@@ -77,16 +77,18 @@ 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, mod, keyErr := logic.RetrievePublicTrafficKey()
|
key, mod, e, 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
|
key.N = &mod
|
||||||
|
key.E = e
|
||||||
|
|
||||||
node.TrafficKeys = models.TrafficKeys{
|
node.TrafficKeys = models.TrafficKeys{
|
||||||
Mine: node.TrafficKeys.Mine,
|
Mine: node.TrafficKeys.Mine,
|
||||||
Mod: node.TrafficKeys.Mod,
|
Mod: node.TrafficKeys.Mod,
|
||||||
|
E: node.TrafficKeys.E,
|
||||||
Server: key,
|
Server: key,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -212,9 +212,14 @@ func initializeUUID() error {
|
|||||||
return keyErr
|
return keyErr
|
||||||
}
|
}
|
||||||
var rsaPublicKey = &rsaPrivKey.PublicKey
|
var rsaPublicKey = &rsaPrivKey.PublicKey
|
||||||
fmt.Printf("found modulus: %d \n", rsaPublicKey.N)
|
fmt.Printf("E: %d \n", rsaPublicKey.E)
|
||||||
|
telemetry := models.Telemetry{
|
||||||
telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKeyPriv: *rsaPrivKey, TrafficKeyPub: *rsaPublicKey, PubMod: *rsaPublicKey.N}
|
UUID: uuid.NewString(),
|
||||||
|
TrafficKeyPriv: *rsaPrivKey,
|
||||||
|
TrafficKeyPub: *rsaPublicKey,
|
||||||
|
PubMod: *rsaPublicKey.N,
|
||||||
|
PubE: rsaPublicKey.E,
|
||||||
|
}
|
||||||
telJSON, err := json.Marshal(&telemetry)
|
telJSON, err := json.Marshal(&telemetry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -18,12 +18,12 @@ func RetrievePrivateTrafficKey() (rsa.PrivateKey, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RetrievePublicTrafficKey - retrieves public key of server
|
// 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()
|
var telRecord, err = fetchTelemetryRecord()
|
||||||
if err != nil {
|
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)
|
fmt.Printf("fetched pub key %v \n", telRecord.TrafficKeyPub)
|
||||||
|
|
||||||
return telRecord.TrafficKeyPub, telRecord.PubMod, nil
|
return telRecord.TrafficKeyPub, telRecord.PubMod, telRecord.PubE, nil
|
||||||
}
|
}
|
||||||
|
@@ -176,6 +176,7 @@ type Telemetry struct {
|
|||||||
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"`
|
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
|
// 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 {
|
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"`
|
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"`
|
Server rsa.PublicKey `json:"server" bson:"server" yaml:"server"`
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,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
|
node.TrafficKeys.Mine.N = &node.TrafficKeys.Mod
|
||||||
|
node.TrafficKeys.Mine.E = node.TrafficKeys.E
|
||||||
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")
|
||||||
|
@@ -138,6 +138,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
|
|||||||
TrafficKeys: models.TrafficKeys{
|
TrafficKeys: models.TrafficKeys{
|
||||||
Mine: rsaPrivKey.PublicKey,
|
Mine: rsaPrivKey.PublicKey,
|
||||||
Mod: *rsaPrivKey.PublicKey.N,
|
Mod: *rsaPrivKey.PublicKey.N,
|
||||||
|
E: rsaPrivKey.PublicKey.E,
|
||||||
Server: rsa.PublicKey{},
|
Server: rsa.PublicKey{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -566,7 +566,7 @@ func DestructMessage(builtMsg string, priv *rsa.PrivateKey) []byte {
|
|||||||
|
|
||||||
// BuildMessage Build a message for publishing
|
// BuildMessage Build a message for publishing
|
||||||
func BuildMessage(originalMessage []byte, pub *rsa.PublicKey) string {
|
func BuildMessage(originalMessage []byte, pub *rsa.PublicKey) string {
|
||||||
chunks := getSliceChunks(originalMessage, 240)
|
chunks := getSliceChunks(originalMessage, 228)
|
||||||
var message = ""
|
var message = ""
|
||||||
for i := 0; i < len(chunks); i++ {
|
for i := 0; i < len(chunks); i++ {
|
||||||
var encryptedText, encryptErr = encryptWithPublicKey(chunks[i], pub)
|
var encryptedText, encryptErr = encryptWithPublicKey(chunks[i], pub)
|
||||||
|
Reference in New Issue
Block a user