added e..

This commit is contained in:
0xdcarns 2022-01-29 10:18:13 -05:00
parent aa22afeb95
commit 3dadb8dcbf
7 changed files with 19 additions and 8 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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