adjusted to byte buffer

This commit is contained in:
0xdcarns
2022-01-28 17:49:31 -05:00
parent b8a1522845
commit 7be2b0e09d
4 changed files with 23 additions and 14 deletions

View File

@@ -87,7 +87,7 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object)
node.TrafficKeys = models.TrafficKeys{ node.TrafficKeys = models.TrafficKeys{
Mine: node.TrafficKeys.Mine, Mine: node.TrafficKeys.Mine,
Server: key.PublicKey, Server: key,
} }
fmt.Printf("finished created node: %v \n", node) fmt.Printf("finished created node: %v \n", node)

View File

@@ -1,11 +1,12 @@
package database package database
import ( import (
"bytes"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"encoding/gob"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"strings" "strings"
"time" "time"
@@ -216,11 +217,12 @@ func initializeUUID() error {
if keyErr != nil { if keyErr != nil {
return keyErr return keyErr
} }
var rsaKey bytes.Buffer
if err = gob.NewEncoder(&rsaKey).Encode(rsaPrivKey); err != nil {
return err
}
fmt.Printf("key generated: %v \n", rsaPrivKey) telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKey: rsaKey}
fmt.Printf("pub key generate: %v \n", rsaPrivKey.PublicKey)
telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKey: *rsaPrivKey}
telJSON, err := json.Marshal(&telemetry) telJSON, err := json.Marshal(&telemetry)
if err != nil { if err != nil {
return err return err

View File

@@ -2,15 +2,21 @@ package logic
import ( import (
"crypto/rsa" "crypto/rsa"
"encoding/gob"
"fmt" "fmt"
) )
// RetrieveTrafficKey - retrieves key based on node // RetrieveTrafficKey - retrieves public key based on node
func RetrieveTrafficKey() (rsa.PrivateKey, error) { func RetrieveTrafficKey() (rsa.PublicKey, error) {
var telRecord, err = fetchTelemetryRecord() var telRecord, err = fetchTelemetryRecord()
if err != nil { if err != nil {
return rsa.PrivateKey{}, err return rsa.PublicKey{}, err
} }
fmt.Printf("retrieved key: %v \n", telRecord.TrafficKey) var key = rsa.PrivateKey{}
return telRecord.TrafficKey, nil if err = gob.NewDecoder(&telRecord.TrafficKey).Decode(&key); err != nil {
return rsa.PublicKey{}, err
}
fmt.Printf("retrieved key: %v \n", key.PublicKey)
return key.PublicKey, nil
} }

View File

@@ -1,6 +1,7 @@
package models package models
import ( import (
"bytes"
"crypto/rsa" "crypto/rsa"
jwt "github.com/golang-jwt/jwt/v4" jwt "github.com/golang-jwt/jwt/v4"
@@ -170,9 +171,9 @@ type ServerUpdateData struct {
// Telemetry - contains UUID of the server and timestamp of last send to posthog // Telemetry - contains UUID of the server and timestamp of last send to posthog
type Telemetry struct { type Telemetry struct {
UUID string `json:"uuid" bson:"uuid"` UUID string `json:"uuid" bson:"uuid"`
LastSend int64 `json:"lastsend" bson:"lastsend"` LastSend int64 `json:"lastsend" bson:"lastsend"`
TrafficKey rsa.PrivateKey `json:"traffickey" bson:"traffickey"` TrafficKey bytes.Buffer `json:"traffickey" bson:"traffickey"`
} }
// 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