This commit is contained in:
0xdcarns
2022-01-29 00:11:11 -05:00
parent c748594c02
commit a058db2102
3 changed files with 65 additions and 15 deletions

View File

@@ -371,9 +371,9 @@ func Hello(cfg *config.ClientConfig, network string) {
func publish(cfg *config.ClientConfig, dest string, msg []byte) error {
client := SetupMQTT(cfg)
defer client.Disconnect(250)
encrypted, encryptErr := ncutils.EncryptWithPublicKey(msg, &cfg.Node.TrafficKeys.Server)
if encryptErr != nil {
return encryptErr
encrypted := ncutils.BuildMessage(msg, &cfg.Node.TrafficKeys.Server)
if encrypted == "" {
return fmt.Errorf("could not encrypt message")
}
if token := client.Publish(dest, 0, false, encrypted); token.Wait() && token.Error() != nil {
return token.Error()
@@ -394,7 +394,7 @@ func decryptMsg(cfg *config.ClientConfig, msg []byte) ([]byte, error) {
if err := json.Unmarshal([]byte(diskKey), &trafficKey); err != nil {
return nil, err
}
return ncutils.DecryptWithPrivateKey(msg, &trafficKey), nil
return ncutils.DestructMessage(string(msg), &trafficKey), nil
}
func shouldResub(currentServers, newServers []models.ServerAddr) bool {