hide peers, add drone ci, doc update
This commit is contained in:
@ -3,13 +3,17 @@ package client
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"forge.redroom.link/yves/meowlib"
|
||||
"github.com/ProtonMail/gopenpgp/v2/helper"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const maxHiddenCount = 30
|
||||
|
||||
type Identity struct {
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
RootKp meowlib.KeyPair `json:"id_kp,omitempty"`
|
||||
@ -34,6 +38,7 @@ func CreateIdentity(nickname string) *Identity {
|
||||
id.Nickname = nickname
|
||||
id.RootKp = meowlib.NewKeyPair()
|
||||
GetConfig().me = &id
|
||||
id.generateRandomHiddenStuff()
|
||||
return &id
|
||||
}
|
||||
|
||||
@ -159,3 +164,54 @@ func (id *Identity) TryUnlockHidden(password string) error {
|
||||
}
|
||||
return errors.New("no peer found")
|
||||
}
|
||||
|
||||
func (id *Identity) HidePeer(peerIdx int, password string) error {
|
||||
serializedPeer, err := json.Marshal(id.Peers[peerIdx])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
encrypted, err := meowlib.SymEncrypt(password, serializedPeer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// add encrypted peer data
|
||||
id.HiddenPeers = append(id.HiddenPeers, encrypted)
|
||||
// remove clear text peer
|
||||
id.Peers = append(id.Peers[:peerIdx], id.Peers[peerIdx+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (id *Identity) generateRandomHiddenStuff() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
count := rand.Intn(maxHiddenCount) + 1
|
||||
for i := 1; i < count; i++ {
|
||||
var p Peer
|
||||
p.Name = randomLenString(4, 20)
|
||||
p.MyEncryptionKp = meowlib.NewKeyPair()
|
||||
p.MyIdentity = meowlib.NewKeyPair()
|
||||
p.MyLookupKp = meowlib.NewKeyPair()
|
||||
p.Contact.Name = randomLenString(4, 20)
|
||||
p.Contact.ContactPublicKey = p.MyLookupKp.Public
|
||||
p.Contact.EncryptionPublicKey = p.MyIdentity.Public
|
||||
p.Contact.LookupPublicKey = p.MyEncryptionKp.Public
|
||||
p.Contact.AddUrls([]string{randomLenString(14, 60), randomLenString(14, 60)})
|
||||
id.Peers = append(id.Peers, p)
|
||||
id.HidePeer(0, randomLenString(8, 14))
|
||||
// TODO Add conversations
|
||||
}
|
||||
}
|
||||
|
||||
func randomLenString(min int, max int) string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
n := rand.Intn(max-min) + min
|
||||
return randomString(n)
|
||||
}
|
||||
|
||||
func randomString(n int) string {
|
||||
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
s := make([]rune, n)
|
||||
for i := range s {
|
||||
s[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(s)
|
||||
}
|
||||
|
Reference in New Issue
Block a user