keypair err mgt + shorturl random improve
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -16,3 +16,5 @@ client/test.cfg
|
||||
meowlib-sources.jar
|
||||
meowlib.aar
|
||||
client/test.db
|
||||
CLAUDE.md
|
||||
CODE_REVIEW.md
|
||||
|
||||
15
asymcrypt.go
15
asymcrypt.go
@@ -2,6 +2,7 @@ package meowlib
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
@@ -18,24 +19,24 @@ type KeyPair struct {
|
||||
|
||||
type KeysArray []KeyPair
|
||||
|
||||
func NewKeyPair() KeyPair {
|
||||
func NewKeyPair() (*KeyPair, error) { // Return error!
|
||||
var kp KeyPair
|
||||
keys, err := crypto.GenerateKey("name", "mail", "x25519", 0)
|
||||
if err != nil {
|
||||
log.Error().Msg("Key generation failed")
|
||||
return nil, fmt.Errorf("key generation failed: %w", err)
|
||||
}
|
||||
kp.Generated = time.Now()
|
||||
pub, err := keys.GetArmoredPublicKey()
|
||||
if err != nil {
|
||||
log.Error().Msg("Public key extraction failed")
|
||||
return nil, fmt.Errorf("failed to get public key: %w", err)
|
||||
}
|
||||
kp.Public = base64.StdEncoding.EncodeToString([]byte(pub))
|
||||
priv, err := keys.Armor()
|
||||
if err != nil {
|
||||
log.Error().Msg("Private key extraction failed")
|
||||
return nil, fmt.Errorf("failed to armor private key: %w", err)
|
||||
}
|
||||
kp.Public = base64.StdEncoding.EncodeToString([]byte(pub))
|
||||
kp.Private = base64.StdEncoding.EncodeToString([]byte(priv))
|
||||
return kp
|
||||
kp.Generated = time.Now()
|
||||
return &kp, nil
|
||||
}
|
||||
|
||||
func (Kp *KeyPair) GetCryptoKeyObject() *crypto.Key {
|
||||
|
||||
@@ -42,13 +42,19 @@ WE88AQOdxtE8dAuu16suOpgLUfluDgnzCg==
|
||||
-----END PGP PUBLIC KEY BLOCK-----`
|
||||
|
||||
func TestNewKeyPair(t *testing.T) {
|
||||
kp := NewKeyPair()
|
||||
kp, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Println(kp.Public)
|
||||
fmt.Println(kp.Private)
|
||||
}
|
||||
|
||||
func TestGetKey(t *testing.T) {
|
||||
kp := NewKeyPair()
|
||||
kp, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// fmt.Println(kp.Public)
|
||||
// fmt.Println(kp.Private)
|
||||
key := kp.GetCryptoKeyObject()
|
||||
@@ -65,7 +71,10 @@ func TestGetKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAsymEncryptDecrypt(t *testing.T) {
|
||||
kp := NewKeyPair()
|
||||
kp, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foo := []byte("!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~")
|
||||
encMess, err := AsymEncrypt(kp.Public, foo)
|
||||
if err != nil {
|
||||
@@ -80,7 +89,10 @@ func TestAsymEncryptDecrypt(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAsymEncryptDecryptSigned(t *testing.T) {
|
||||
kp := NewKeyPair()
|
||||
kp, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foo := "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~"
|
||||
enc, err := AsymEncryptAndSign(kp.Public, kp.Private, []byte(foo))
|
||||
if err != nil {
|
||||
@@ -94,7 +106,10 @@ func TestAsymEncryptDecryptSigned(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAsymEncryptDecryptSigned2(t *testing.T) {
|
||||
kp := NewKeyPair()
|
||||
kp, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foo := "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~"
|
||||
enc, err := AsymEncryptAndSign(kp.Public, kp.Private, []byte(foo))
|
||||
if err != nil {
|
||||
|
||||
@@ -24,7 +24,10 @@ func InvitationAnswer(cc *meowlib.ContactCard, nickname string, myNickname strin
|
||||
}
|
||||
|
||||
// build my contact card for that friend
|
||||
peer := client.GetConfig().GetIdentity().AnswerInvitation(mynick, nickname, serverUids, cc)
|
||||
peer, err := client.GetConfig().GetIdentity().AnswerInvitation(mynick, nickname, serverUids, cc)
|
||||
if err != nil {
|
||||
return nil, "InvitationAnswer: AnswerInvitation", err
|
||||
}
|
||||
|
||||
//peerstr, err := json.Marshal(peer)
|
||||
//fmt.Println("InvitationAnswer: " + string(peerstr))
|
||||
@@ -71,7 +74,10 @@ func InvitationAnswerFile(invitationFile string, nickname string, myNickname str
|
||||
mynick = client.GetConfig().GetIdentity().Nickname
|
||||
}
|
||||
|
||||
response := identity.AnswerInvitation(mynick, nickname, serverUids, cc)
|
||||
response, err := identity.AnswerInvitation(mynick, nickname, serverUids, cc)
|
||||
if err != nil {
|
||||
return "InvitationAnswerFile : AnswerInvitation", err
|
||||
}
|
||||
fmt.Fprintln(os.Stdout, "Invitation sent by "+received)
|
||||
if format == "qr" {
|
||||
filename = c.StoragePath + string(os.PathSeparator) + mynick + "-" + nickname + ".png"
|
||||
|
||||
@@ -64,7 +64,10 @@ func InvitationGetMessage(invitationUrl string, serverPublicKey string, invitati
|
||||
meowurl := strings.Split(invitationUrl, "?")
|
||||
|
||||
shortcode := meowurl[1]
|
||||
srv := client.CreateServerFromMeowUrl(meowurl[0])
|
||||
srv, err := client.CreateServerFromMeowUrl(meowurl[0])
|
||||
if err != nil {
|
||||
return nil, "InvitationGetMessage: CreateServerFromMeowUrl", err
|
||||
}
|
||||
// check if already in msg servers
|
||||
dbsrv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srv.Url)
|
||||
if err != nil {
|
||||
@@ -73,7 +76,11 @@ func InvitationGetMessage(invitationUrl string, serverPublicKey string, invitati
|
||||
if dbsrv == nil {
|
||||
// create a server object with url & pubkey
|
||||
srv.PublicKey = serverPublicKey
|
||||
srv.UserKp = meowlib.NewKeyPair()
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, "InvitationGetMessage: NewKeyPair", err
|
||||
}
|
||||
srv.UserKp = k
|
||||
// save it
|
||||
err = client.GetConfig().GetIdentity().MessageServers.StoreServer(srv)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,36 +16,37 @@ import (
|
||||
const maxHiddenCount = 30
|
||||
|
||||
type Identity struct {
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
DefaultAvatar string `json:"default_avatar,omitempty"`
|
||||
Avatars []Avatar `json:"avatars,omitempty"`
|
||||
RootKp meowlib.KeyPair `json:"id_kp,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Peers PeerStorage `json:"peers,omitempty"`
|
||||
HiddenPeers [][]byte `json:"hidden_peers,omitempty"`
|
||||
Personae PeerList `json:"faces,omitempty"`
|
||||
Device meowlib.KeyPair `json:"device,omitempty"`
|
||||
KnownServers ServerList `json:"known_servers,omitempty"`
|
||||
MessageServers ServerStorage `json:"message_servers,omitempty"`
|
||||
DefaultDbPassword string `json:"default_db_password,omitempty"`
|
||||
DbPasswordStore bool `json:"db_password_store,omitempty"`
|
||||
OwnedDevices PeerList `json:"owned_devices,omitempty"`
|
||||
StaticMtkServerPaths []ServerList `json:"static_mtk_server_paths,omitempty"`
|
||||
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
|
||||
InvitationTimeout int `json:"invitation_timeout,omitempty"`
|
||||
Uuid string `json:"uuid,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
DefaultAvatar string `json:"default_avatar,omitempty"`
|
||||
Avatars []Avatar `json:"avatars,omitempty"`
|
||||
RootKp *meowlib.KeyPair `json:"id_kp,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Peers PeerStorage `json:"peers,omitempty"`
|
||||
HiddenPeers [][]byte `json:"hidden_peers,omitempty"`
|
||||
Personae PeerList `json:"faces,omitempty"`
|
||||
Device *meowlib.KeyPair `json:"device,omitempty"`
|
||||
KnownServers ServerList `json:"known_servers,omitempty"`
|
||||
MessageServers ServerStorage `json:"message_servers,omitempty"`
|
||||
DefaultDbPassword string `json:"default_db_password,omitempty"`
|
||||
DbPasswordStore bool `json:"db_password_store,omitempty"`
|
||||
OwnedDevices PeerList `json:"owned_devices,omitempty"`
|
||||
StaticMtkServerPaths []ServerList `json:"static_mtk_server_paths,omitempty"`
|
||||
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
|
||||
InvitationTimeout int `json:"invitation_timeout,omitempty"`
|
||||
Uuid string `json:"uuid,omitempty"`
|
||||
unlockedHiddenPeers PeerList
|
||||
}
|
||||
|
||||
func CreateIdentity(nickname string) (*Identity, error) {
|
||||
var id Identity
|
||||
var err error
|
||||
id.Nickname = nickname
|
||||
id.Uuid = uuid.New().String()
|
||||
id.RootKp = meowlib.NewKeyPair()
|
||||
id.RootKp, err = meowlib.NewKeyPair()
|
||||
GetConfig().me = &id
|
||||
id.MessageServers = ServerStorage{DbFile: uuid.NewString()}
|
||||
id.generateRandomHiddenStuff()
|
||||
err := id.CreateFolder()
|
||||
err = id.CreateFolder()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -71,10 +72,20 @@ func (id *Identity) WipeFolder() error {
|
||||
// Creates an invitation for a peer, returns the newly created peer including infos to provide a ContactCard
|
||||
func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerUids []string, InvitationMessage string) (*Peer, error) {
|
||||
var peer Peer
|
||||
var err error
|
||||
peer.Uid = uuid.New().String()
|
||||
peer.MyIdentity = meowlib.NewKeyPair()
|
||||
peer.MyEncryptionKp = meowlib.NewKeyPair()
|
||||
peer.MyLookupKp = meowlib.NewKeyPair()
|
||||
peer.MyIdentity, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
peer.MyEncryptionKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
peer.MyLookupKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
peer.Name = ContactName
|
||||
peer.InvitationId = uuid.New().String() // todo as param to identify then update url
|
||||
/* if id.MessageServers.Servers == nil {
|
||||
@@ -116,13 +127,24 @@ func (id *Identity) CheckInvitation(ReceivedContact *meowlib.ContactCard) (isAns
|
||||
}
|
||||
|
||||
// Answers an invitation, returns the newly created peer including infos to provide a ContactCard
|
||||
func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageServerIdxs []string, ReceivedContact *meowlib.ContactCard) *Peer {
|
||||
func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageServerIdxs []string, ReceivedContact *meowlib.ContactCard) (*Peer, error) {
|
||||
var peer Peer
|
||||
var err error
|
||||
var newsrv *Server
|
||||
//var myContactCard meowlib.ContactCard
|
||||
peer.Uid = uuid.New().String()
|
||||
peer.MyIdentity = meowlib.NewKeyPair()
|
||||
peer.MyEncryptionKp = meowlib.NewKeyPair()
|
||||
peer.MyLookupKp = meowlib.NewKeyPair()
|
||||
peer.MyIdentity, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
peer.MyEncryptionKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
peer.MyLookupKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ContactName != "" {
|
||||
peer.Name = ContactName
|
||||
} else {
|
||||
@@ -135,7 +157,8 @@ func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageS
|
||||
peer.InvitationMessage = ReceivedContact.InvitationMessage
|
||||
for srv := range ReceivedContact.PullServers {
|
||||
peer.ContactPullServers = append(peer.ContactPullServers, ReceivedContact.PullServers[srv].GetUid())
|
||||
id.MessageServers.StoreServerIfNotExists(CreateServerFromUid(ReceivedContact.PullServers[srv].GetUid()))
|
||||
newsrv, err = CreateServerFromUid(ReceivedContact.PullServers[srv].GetUid())
|
||||
id.MessageServers.StoreServerIfNotExists(newsrv)
|
||||
}
|
||||
/* for _, i := range MessageServerIdxs {
|
||||
srv := id.MessageServers.Servers[i].GetServerCard()
|
||||
@@ -150,11 +173,13 @@ func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageS
|
||||
peer.InvitationId = ReceivedContact.InvitationId
|
||||
id.Peers.StorePeer(&peer)
|
||||
|
||||
return &peer
|
||||
return &peer, nil
|
||||
}
|
||||
|
||||
// Finalizes an invitation, returns nil if successful
|
||||
func (id *Identity) FinalizeInvitation(ReceivedContact *meowlib.ContactCard) error {
|
||||
var err error
|
||||
var newsrv *Server
|
||||
/*for i, p := range id.Peers {
|
||||
if p.InvitationId == ReceivedContact.InvitationId {
|
||||
//id.Peers[i].Name = ReceivedContact.Name
|
||||
@@ -171,7 +196,11 @@ func (id *Identity) FinalizeInvitation(ReceivedContact *meowlib.ContactCard) err
|
||||
}
|
||||
return errors.New("no matching contact found for invitationId " + ReceivedContact.InvitationId)*/
|
||||
for srv := range ReceivedContact.PullServers {
|
||||
id.MessageServers.StoreServerIfNotExists(CreateServerFromUid(ReceivedContact.PullServers[srv].GetUid()))
|
||||
newsrv, err = CreateServerFromUid(ReceivedContact.PullServers[srv].GetUid())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id.MessageServers.StoreServerIfNotExists(newsrv)
|
||||
}
|
||||
return id.Peers.FinalizeInvitation(ReceivedContact)
|
||||
}
|
||||
@@ -251,16 +280,26 @@ func (id *Identity) HidePeer(peerIdx int, password string) error {
|
||||
return nil
|
||||
}*/
|
||||
|
||||
func (id *Identity) generateRandomHiddenStuff() {
|
||||
func (id *Identity) generateRandomHiddenStuff() error {
|
||||
var err error
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
count := r.Intn(maxHiddenCount) + 1
|
||||
for i := 1; i < count; i++ {
|
||||
var p Peer
|
||||
p.Uid = uuid.New().String()
|
||||
p.Name = randomLenString(4, 20)
|
||||
p.MyEncryptionKp = meowlib.NewKeyPair()
|
||||
p.MyIdentity = meowlib.NewKeyPair()
|
||||
p.MyLookupKp = meowlib.NewKeyPair()
|
||||
p.MyEncryptionKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.MyIdentity, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.MyLookupKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Name = randomLenString(4, 20)
|
||||
p.ContactPublicKey = p.MyLookupKp.Public
|
||||
p.ContactEncryption = p.MyIdentity.Public
|
||||
@@ -271,17 +310,18 @@ func (id *Identity) generateRandomHiddenStuff() {
|
||||
//id.HidePeer(0, randomLenString(8, 14))
|
||||
// TODO Add random conversations
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BackgroundJob struct {
|
||||
RootPublic string `json:"root_public,omitempty"`
|
||||
Device meowlib.KeyPair `json:"device,omitempty"`
|
||||
Jobs []RequestsJob `json:"jobs,omitempty"`
|
||||
RootPublic string `json:"root_public,omitempty"`
|
||||
Device *meowlib.KeyPair `json:"device,omitempty"`
|
||||
Jobs []RequestsJob `json:"jobs,omitempty"`
|
||||
}
|
||||
|
||||
type RequestsJob struct {
|
||||
Server *Server `json:"server,omitempty"`
|
||||
LookupKeys []meowlib.KeyPair `json:"lookup_keys,omitempty"`
|
||||
Server *Server `json:"server,omitempty"`
|
||||
LookupKeys []*meowlib.KeyPair `json:"lookup_keys,omitempty"`
|
||||
}
|
||||
|
||||
func (id *Identity) GetRequestJobs() []RequestsJob {
|
||||
|
||||
@@ -19,7 +19,7 @@ func exists(filename string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func createId() *Identity {
|
||||
func createId(t *testing.T) *Identity {
|
||||
config := GetConfig()
|
||||
config.IdentityFile = "test.id"
|
||||
config.memoryPassword = "generalPassword"
|
||||
@@ -37,13 +37,34 @@ func createId() *Identity {
|
||||
var p Peer
|
||||
p.Uid = uuid.New().String()
|
||||
p.Name = "testName_" + strconv.Itoa(i)
|
||||
p.MyEncryptionKp = meowlib.NewKeyPair()
|
||||
p.MyIdentity = meowlib.NewKeyPair()
|
||||
p.MyLookupKp = meowlib.NewKeyPair()
|
||||
p.MyEncryptionKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.MyIdentity, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.MyLookupKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.Name = "foo_" + strconv.Itoa(i)
|
||||
p.ContactPublicKey = meowlib.NewKeyPair().Public
|
||||
p.ContactEncryption = meowlib.NewKeyPair().Public
|
||||
p.ContactLookupKey = meowlib.NewKeyPair().Public
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.ContactPublicKey = k.Public
|
||||
k, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.ContactEncryption = k.Public
|
||||
k, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.ContactLookupKey = k.Public
|
||||
p.MyPullServers = []string{"server1", "server2"}
|
||||
//p.Contact.AddUrls([]string{"http:/127.0.0.1/meow", "tcp://localhost:1234"}) //todo add servers
|
||||
id.Peers.StorePeer(&p)
|
||||
@@ -98,7 +119,7 @@ func TestHidePeer(t *testing.T) {
|
||||
// test GetRequestJobs
|
||||
func TestGetRequestJobs(t *testing.T) {
|
||||
// Create a mock Identity object
|
||||
id := createId()
|
||||
id := createId(t)
|
||||
id.MessageServers = ServerStorage{
|
||||
DbFile: "test.db",
|
||||
}
|
||||
@@ -106,7 +127,10 @@ func TestGetRequestJobs(t *testing.T) {
|
||||
GetConfig().SetIdentity(id)
|
||||
for i := 1; i < 10; i++ {
|
||||
// initialize a Server with name "server+i"
|
||||
srv := CreateServerFromUrl("server" + strconv.Itoa(i))
|
||||
srv, err := CreateServerFromUrl("server" + strconv.Itoa(i))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id.MessageServers.StoreServer(srv)
|
||||
}
|
||||
// Call GetRequestJobs
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
func ProcessForOutput(usermessage *meowlib.UserMessage, peer *Peer, servers *ServerList, trackingLookupKey string) ([]byte, error) {
|
||||
lastIdx := len(servers.Servers) - 1
|
||||
// LAST SERVER : Message delivery as usual
|
||||
srv := &servers.Servers[lastIdx]
|
||||
srv := servers.Servers[lastIdx]
|
||||
// Prepare cyphered + packed user message
|
||||
packedMsg, err := peer.ProcessOutboundUserMessage(usermessage)
|
||||
if err != nil {
|
||||
@@ -23,7 +23,7 @@ func ProcessForOutput(usermessage *meowlib.UserMessage, peer *Peer, servers *Ser
|
||||
lastuuid := uuid.NewString()
|
||||
// ALL PREVIOUS SERVERS
|
||||
for i := lastIdx - 1; i >= 0; i-- {
|
||||
srv = &servers.Servers[i]
|
||||
srv = servers.Servers[i]
|
||||
var toServerMessage meowlib.ToServerMessage
|
||||
toServerMessage.MatriochkaMessage.Data = lastmsg
|
||||
toServerMessage.MatriochkaMessage.Next.Url = servers.Servers[i+1].Url
|
||||
|
||||
@@ -30,7 +30,11 @@ func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, filenames []stri
|
||||
}
|
||||
file.Close()
|
||||
peer.DbIds = append(peer.DbIds, dbid)
|
||||
sqliteDatabase, _ := sql.Open("sqlite3", filepath.Join(cfg.StoragePath, identity.Uuid, dbid+GetConfig().DbSuffix)) // Open the created SQLite File
|
||||
sqliteDatabase, err := sql.Open("sqlite3", filepath.Join(cfg.StoragePath, identity.Uuid, dbid+GetConfig().DbSuffix))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sqliteDatabase.Close()
|
||||
err = createMessageTable(sqliteDatabase)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestStoreMessage(t *testing.T) {
|
||||
id := createId()
|
||||
id := createId(t)
|
||||
var um meowlib.UserMessage
|
||||
um.Data = []byte("blabla")
|
||||
peers, err := id.Peers.GetPeers()
|
||||
@@ -45,7 +45,7 @@ func TestStoreMessage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestManyStoreMessage(t *testing.T) {
|
||||
id := createId()
|
||||
id := createId(t)
|
||||
peers, err := id.Peers.GetPeers()
|
||||
// test with zero messages
|
||||
messages, err := GetMessagesHistory(peers[0], 0, 0, 10, GetConfig().memoryPassword)
|
||||
|
||||
@@ -23,10 +23,10 @@ type Peer struct {
|
||||
MyAvatar string `json:"my_avatar,omitempty"`
|
||||
// Conversation []InternalMessage `json:"conversation,omitempty"`
|
||||
// My own keys for that peer
|
||||
MyIdentity meowlib.KeyPair `json:"my_identity,omitempty"`
|
||||
MyEncryptionKp meowlib.KeyPair `json:"my_encryption_kp,omitempty"`
|
||||
MyLookupKp meowlib.KeyPair `json:"my_lookup_kp,omitempty"`
|
||||
MyPullServers []string `json:"my_pull_servers,omitempty"`
|
||||
MyIdentity *meowlib.KeyPair `json:"my_identity,omitempty"`
|
||||
MyEncryptionKp *meowlib.KeyPair `json:"my_encryption_kp,omitempty"`
|
||||
MyLookupKp *meowlib.KeyPair `json:"my_lookup_kp,omitempty"`
|
||||
MyPullServers []string `json:"my_pull_servers,omitempty"`
|
||||
// Peer keys and infos
|
||||
//Contact meowlib.ContactCard `json:"contact,omitempty"` // todo : remove
|
||||
ContactPublicKey string `json:"contact_public_key,omitempty"`
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestOpen(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStorePeer(t *testing.T) {
|
||||
id := createId()
|
||||
id := createId(t)
|
||||
GetConfig().SetMemPass("test")
|
||||
GetConfig().SetIdentity(id)
|
||||
ps := &PeerStorage{
|
||||
|
||||
@@ -18,38 +18,46 @@ import (
|
||||
// - Server remote management if ManagerKp is available for that server
|
||||
type Server struct {
|
||||
//ServerCard meowlib.ServerCard `json:"server_data,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PublicKey string `json:"public_key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Login string `json:"login,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Presence bool `json:"presence,omitempty"`
|
||||
LastCheck time.Time `json:"last_check,omitempty"`
|
||||
Uptime time.Duration `json:"uptime,omitempty"`
|
||||
UserKp meowlib.KeyPair `json:"user_kp,omitempty"`
|
||||
ManagerKp meowlib.KeyPair `json:"manager_kp,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
AllowedDelay int `json:"allowed_delay,omitempty"`
|
||||
Backup bool `json:"backup,omitempty"`
|
||||
WebRTC bool `json:"webrtc,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PublicKey string `json:"public_key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Login string `json:"login,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Presence bool `json:"presence,omitempty"`
|
||||
LastCheck time.Time `json:"last_check,omitempty"`
|
||||
Uptime time.Duration `json:"uptime,omitempty"`
|
||||
UserKp *meowlib.KeyPair `json:"user_kp,omitempty"`
|
||||
ManagerKp *meowlib.KeyPair `json:"manager_kp,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
AllowedDelay int `json:"allowed_delay,omitempty"`
|
||||
Backup bool `json:"backup,omitempty"`
|
||||
WebRTC bool `json:"webrtc,omitempty"`
|
||||
}
|
||||
|
||||
// CreateServerFromUrl creates a server from a basic url, ex : https://my.meowserver.example:8443/meow/
|
||||
func CreateServerFromUrl(url string) *Server {
|
||||
func CreateServerFromUrl(url string) (*Server, error) {
|
||||
var is Server
|
||||
var err error
|
||||
is.Name = url
|
||||
is.Url = url
|
||||
is.UserKp = meowlib.NewKeyPair()
|
||||
return &is
|
||||
is.UserKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &is, nil
|
||||
}
|
||||
|
||||
// CreateServerFromUid creates a server from a uid string, ex : mylogin:mypassword@https://my.meowserver.example:8443/meow/
|
||||
func CreateServerFromUid(uid string) *Server {
|
||||
func CreateServerFromUid(uid string) (*Server, error) {
|
||||
var is Server
|
||||
var err error
|
||||
uidTable := strings.Split(uid, "@") //! Weak test, use regexp
|
||||
is.Name = uid
|
||||
is.UserKp = meowlib.NewKeyPair()
|
||||
is.UserKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(uidTable) == 2 {
|
||||
loginpw := strings.Split(uidTable[0], ":")
|
||||
is.Url = uidTable[1]
|
||||
@@ -58,17 +66,17 @@ func CreateServerFromUid(uid string) *Server {
|
||||
} else {
|
||||
is.Url = uidTable[0]
|
||||
}
|
||||
return &is
|
||||
return &is, nil
|
||||
}
|
||||
|
||||
// CreateServerFromMeowUrl creates a server from a meow url, ex : meow://mylogin:mypassword@https://my.meowserver.example:8443/meow/
|
||||
func CreateServerFromMeowUrl(meowurl string) *Server {
|
||||
func CreateServerFromMeowUrl(meowurl string) (*Server, error) {
|
||||
uid := strings.Replace(meowurl[7:], "//", "://", 1)
|
||||
return CreateServerFromUid(uid)
|
||||
}
|
||||
|
||||
// CreateServerFromInvitationLink creates a server from a meow url, ex : meow://mylogin:mypassword@https://my.meowserver.example:8443/meow?invitationCode
|
||||
func CreateServerFromInvitationLink(meowurl string) *Server {
|
||||
func CreateServerFromInvitationLink(meowurl string) (*Server, error) {
|
||||
// remove the invitation code, last token after a /
|
||||
meowurlTable := strings.Split(meowurl, "?")
|
||||
// join all elements with / except the last one
|
||||
@@ -103,16 +111,20 @@ func (sc *Server) GetMeowUrl() string {
|
||||
}
|
||||
|
||||
// Create a server from a server card
|
||||
func CreateServerFromServerCard(server *meowlib.ServerCard) *Server {
|
||||
func CreateServerFromServerCard(server *meowlib.ServerCard) (*Server, error) {
|
||||
var is Server
|
||||
var err error
|
||||
is.Name = server.Name
|
||||
is.PublicKey = server.PublicKey
|
||||
is.Description = server.Description
|
||||
is.Url = server.Url
|
||||
is.Login = server.Login
|
||||
is.Password = server.Password
|
||||
is.UserKp = meowlib.NewKeyPair()
|
||||
return &is
|
||||
is.UserKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &is, nil
|
||||
}
|
||||
|
||||
// AsymEncryptMessage prepares a message to send to a specific internal server
|
||||
|
||||
@@ -8,13 +8,13 @@ import "errors"
|
||||
// - Owned servers lists
|
||||
// - Matriochka paths
|
||||
type ServerList struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Servers []Server `json:"servers,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Servers []*Server `json:"servers,omitempty"`
|
||||
}
|
||||
|
||||
// FilterByIdxs returns a filtered server list filtered according to an index list
|
||||
func (sl *ServerList) FilterByIdxs(MessageServerIdxs []int) (filtered *ServerList, err error) {
|
||||
filtered.Servers = []Server{}
|
||||
filtered.Servers = []*Server{}
|
||||
for _, i := range MessageServerIdxs {
|
||||
if i > len(sl.Servers)-1 {
|
||||
return nil, errors.New("requested server out of range of defined message servers")
|
||||
@@ -31,22 +31,27 @@ func (sl *ServerList) GetServerByIdx(idx int) (server *Server, err error) {
|
||||
if idx > len(sl.Servers)-1 {
|
||||
return nil, errors.New("requested server out of range of defined message servers")
|
||||
}
|
||||
return &sl.Servers[idx], nil
|
||||
return sl.Servers[idx], nil
|
||||
}
|
||||
|
||||
// GetServerByPubkey returns a server from it's public key
|
||||
func (sl *ServerList) GetServerByPubkey(pubkey string) (filtered *Server) {
|
||||
for _, srv := range sl.Servers {
|
||||
if srv.PublicKey == pubkey {
|
||||
return &srv
|
||||
return srv
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddUrls is a simple utility functon used mainly as a shortcut for testing purposes
|
||||
func (sl *ServerList) AddUrls(urls []string) {
|
||||
func (sl *ServerList) AddUrls(urls []string) error {
|
||||
for _, url := range urls {
|
||||
sl.Servers = append(sl.Servers, *CreateServerFromUrl(url))
|
||||
srvnew, err := CreateServerFromUrl(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sl.Servers = append(sl.Servers, srvnew)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,10 +9,14 @@ import (
|
||||
)
|
||||
|
||||
func TestGetUid(t *testing.T) {
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := Server{
|
||||
Name: "test",
|
||||
Url: "http://127.0.0.1:8080",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
uid := srv.GetUid()
|
||||
if uid != "http://127.0.0.1:8080" {
|
||||
@@ -21,14 +25,18 @@ func TestGetUid(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStoreServer(t *testing.T) {
|
||||
createId()
|
||||
createId(t)
|
||||
ss := ServerStorage{DbFile: "test.db"}
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := Server{
|
||||
Name: "test",
|
||||
Url: "http://127.0.0.1",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
err := ss.StoreServer(&srv)
|
||||
err = ss.StoreServer(&srv)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -49,15 +57,19 @@ func TestStoreServer(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadServersFromUids(t *testing.T) {
|
||||
createId()
|
||||
createId(t)
|
||||
GetConfig().SetMemPass("test")
|
||||
ss := ServerStorage{DbFile: "test.db"}
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := Server{
|
||||
Name: "test",
|
||||
Url: "http://localhost:8080",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
err := ss.StoreServer(&srv)
|
||||
err = ss.StoreServer(&srv)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -77,14 +89,18 @@ func TestLoadServersFromUids(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadServerCardsFromUids(t *testing.T) {
|
||||
createId()
|
||||
createId(t)
|
||||
ss := ServerStorage{DbFile: "test.db"}
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := Server{
|
||||
Name: "test",
|
||||
Url: "http://localhost:8080",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
err := ss.StoreServer(&srv)
|
||||
err = ss.StoreServer(&srv)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -104,13 +120,16 @@ func TestLoadServerCardsFromUids(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServerExists(t *testing.T) {
|
||||
createId()
|
||||
createId(t)
|
||||
ss := ServerStorage{DbFile: "test.db"}
|
||||
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server := &Server{
|
||||
Name: "test",
|
||||
Url: "http://localhost:8080",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
|
||||
// Check if server exists before storing it
|
||||
@@ -142,13 +161,16 @@ func TestServerExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStoreServerIfNotExists(t *testing.T) {
|
||||
createId()
|
||||
createId(t)
|
||||
ss := ServerStorage{DbFile: "test.db"}
|
||||
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server := &Server{
|
||||
Name: "test",
|
||||
Url: "http://localhost:8080",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
|
||||
// Check if server exists before storing it
|
||||
@@ -181,26 +203,32 @@ func TestStoreServerIfNotExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStoreServerIfNotExists_ServerExists(t *testing.T) {
|
||||
createId()
|
||||
createId(t)
|
||||
ss := ServerStorage{DbFile: "test.db"}
|
||||
|
||||
k, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server := &Server{
|
||||
Name: "test",
|
||||
Url: "http://localhost:8080",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
|
||||
// Store the server
|
||||
err := ss.StoreServer(server)
|
||||
err = ss.StoreServer(server)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to store server: %v", err)
|
||||
}
|
||||
|
||||
k, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Store the server again with a different public key
|
||||
newServer := &Server{
|
||||
Name: "test",
|
||||
Url: "http://localhost:8080",
|
||||
PublicKey: meowlib.NewKeyPair().Public,
|
||||
PublicKey: k.Public,
|
||||
}
|
||||
|
||||
err = ss.StoreServerIfNotExists(newServer)
|
||||
|
||||
@@ -8,9 +8,18 @@ import (
|
||||
)
|
||||
|
||||
func TestCompressAndJson(t *testing.T) {
|
||||
kp1 := NewKeyPair()
|
||||
kp2 := NewKeyPair()
|
||||
kp3 := NewKeyPair()
|
||||
kp1, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kp2, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kp3, err := NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var cc ContactCard
|
||||
cc.Name = "My Full Name And It's loooong"
|
||||
cc.ContactPublicKey = kp1.Public
|
||||
|
||||
@@ -58,15 +58,25 @@ func TestEndToEnd(t *testing.T) {
|
||||
var ReceivedContact meowlib.ContactCard
|
||||
|
||||
// Friend simulated invitation
|
||||
FirstFriendContactKp := meowlib.NewKeyPair()
|
||||
FirstFriendEncryptionKp := meowlib.NewKeyPair()
|
||||
FirstFriendLookupKp := meowlib.NewKeyPair()
|
||||
FirstFriendContactKp, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
FirstFriendEncryptionKp, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
FirstFriendLookupKp, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ReceivedContact.Name = "I'm the friend"
|
||||
ReceivedContact.ContactPublicKey = FirstFriendContactKp.Public
|
||||
ReceivedContact.EncryptionPublicKey = FirstFriendEncryptionKp.Public
|
||||
ReceivedContact.LookupPublicKey = FirstFriendLookupKp.Public
|
||||
ReceivedContact.InvitationId = peer.GetMyContact().InvitationId
|
||||
FriendServer1KP := meowlib.NewKeyPair()
|
||||
FriendServer1KP, err := meowlib.NewKeyPair()
|
||||
|
||||
FriendServer1 := meowlib.ServerCard{Name: "FriendServer1", Url: "http://myfriend.org/meow/", PublicKey: FriendServer1KP.Public, Description: "Fancy description"}
|
||||
ReceivedContact.PullServers = append(ReceivedContact.PullServers, &FriendServer1)
|
||||
|
||||
@@ -76,9 +86,8 @@ func TestEndToEnd(t *testing.T) {
|
||||
Me.FinalizeInvitation(&ReceivedContact)
|
||||
err = Me.Save()
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a, _ = json.Marshal(Me)
|
||||
os.WriteFile("id.json", a, 0644)
|
||||
fmt.Println(string(a))
|
||||
@@ -91,16 +100,16 @@ func TestEndToEnd(t *testing.T) {
|
||||
// Creating User message
|
||||
usermessage, err := MyFirstFriend.BuildSimpleUserMessage([]byte(textmessage))
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
serializedMessage, err := MyFirstFriend.SerializeUserMessage(usermessage)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Encrypting it
|
||||
enc, err := MyFirstFriend.AsymEncryptMessage(serializedMessage)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Packing it
|
||||
@@ -108,22 +117,22 @@ func TestEndToEnd(t *testing.T) {
|
||||
|
||||
intS1, err := Me.MessageServers.LoadServer("http://127.0.0.1/meow/")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Creating Server message for transporting the user message
|
||||
toServerMessage, err := intS1.BuildMessageSendingMessage(packedMsg)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Encrypting it
|
||||
encToServer, err := intS1.AsymEncryptMessage(toServerMessage)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Packing it
|
||||
protoPackedServerMsg, err := intS1.PackServerMessage(encToServer.Data, encToServer.Signature)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
///////////////////////
|
||||
// Sending to server //
|
||||
@@ -143,34 +152,34 @@ func TestEndToEnd(t *testing.T) {
|
||||
// Unpack
|
||||
srv_from, srv_encmsg, srv_signature, err := server1.UnpackReceived(protoPackedServerMsg)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Decrypt
|
||||
srv_clear, err := server1.AsymDecryptMessage(srv_from, srv_encmsg, srv_signature)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Decode msg
|
||||
srv_msg, err := server1.DeserializeToServerMessage(srv_clear)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Response : Ack received message
|
||||
srv_fromServerMessage, err := server1.BuildSimpleAckResponseMessage(srv_msg.Uuid)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
encoded_srv_fromServerMessage, err := server1.SerializeFromServerMessage(srv_fromServerMessage)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv_resp, err := server1.AsymEncryptMessage(srv_from, encoded_srv_fromServerMessage)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, err := server1.PackForSending(srv_resp.Data, srv_resp.Signature)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
t.Fatal(err)
|
||||
}
|
||||
print(resp)
|
||||
//////////////////////////////////////////////
|
||||
|
||||
35
go.sum
35
go.sum
@@ -3,15 +3,10 @@ github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOv
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
|
||||
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
|
||||
github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
|
||||
github.com/ProtonMail/go-crypto v1.2.0 h1:+PhXXn4SPGd+qk76TlEePBfOfivE0zkWFenhGhFLzWs=
|
||||
github.com/ProtonMail/go-crypto v1.2.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
|
||||
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k=
|
||||
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw=
|
||||
github.com/ProtonMail/gopenpgp/v2 v2.7.5 h1:STOY3vgES59gNgoOt2w0nyHBjKViB/qSg7NjbQWPJkA=
|
||||
github.com/ProtonMail/gopenpgp/v2 v2.7.5/go.mod h1:IhkNEDaxec6NyzSI0PlxapinnwPVIESk8/76da3Ct3g=
|
||||
github.com/ProtonMail/gopenpgp/v2 v2.8.3 h1:1jHlELwCR00qovx2B50DkL/FjYwt/P91RnlsqeOp2Hs=
|
||||
github.com/ProtonMail/gopenpgp/v2 v2.8.3/go.mod h1:LiuOTbnJit8w9ZzOoLscj0kmdALY7hfoCVh5Qlb0bcg=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
@@ -19,14 +14,10 @@ github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz
|
||||
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
|
||||
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
|
||||
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
|
||||
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
|
||||
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
@@ -117,7 +108,6 @@ github.com/livekit/psrpc v0.5.3-0.20240228172457-3724cb4adbc4/go.mod h1:CQUBSPfY
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/makiuchi-d/gozxing v0.1.1 h1:xxqijhoedi+/lZlhINteGbywIrewVdVv2wl9r5O9S1I=
|
||||
github.com/makiuchi-d/gozxing v0.1.1/go.mod h1:eRIHbOjX7QWxLIDJoQuMLhuXg9LAuw6znsUtRkNw9DU=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
@@ -200,10 +190,7 @@ github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
|
||||
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
|
||||
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
@@ -244,11 +231,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
|
||||
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
|
||||
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
|
||||
@@ -263,9 +246,7 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
|
||||
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
@@ -274,8 +255,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
|
||||
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -292,32 +273,24 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||
@@ -330,8 +303,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
|
||||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
|
||||
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY=
|
||||
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo=
|
||||
@@ -346,8 +317,6 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
1273
messages.pb.go
1273
messages.pb.go
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ const key = "3pw0c8#6ZG8{75b5;3?fe80$2"
|
||||
type Identity struct {
|
||||
ServerName string `json:"servername,omitempty"`
|
||||
ServerDesc string `json:"serverdesc,omitempty"`
|
||||
ServerKp meowlib.KeyPair `json:"server_kp,omitempty"`
|
||||
ServerKp *meowlib.KeyPair `json:"server_kp,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
OwnerName string `json:"owner_name,omitempty"`
|
||||
OwnerPublicKey string `json:"owner_public_key,omitempty"`
|
||||
@@ -27,9 +27,13 @@ type Identity struct {
|
||||
|
||||
func CreateIdentity(ServerName string, ServerDesc string) *Identity {
|
||||
var id Identity
|
||||
var err error
|
||||
id.ServerName = ServerName
|
||||
id.ServerDesc = ServerDesc
|
||||
id.ServerKp = meowlib.NewKeyPair()
|
||||
id.ServerKp, err = meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return &id
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
)
|
||||
|
||||
func (r *RedisRouter) StoreInvitation(invitation []byte, timeout int, password string, serverTimeout int, urlLen int) (string, time.Time) {
|
||||
id := r.createShortId(urlLen)
|
||||
func (r *RedisRouter) StoreInvitation(invitation []byte, timeout int, password string, serverTimeout int, urlLen int) (string, time.Time, error) {
|
||||
id, err := r.createShortId(urlLen)
|
||||
if err != nil {
|
||||
return "", time.Time{}, fmt.Errorf("failed to create invitation ID: %w", err)
|
||||
}
|
||||
if timeout > serverTimeout {
|
||||
timeout = serverTimeout
|
||||
}
|
||||
@@ -17,7 +23,7 @@ func (r *RedisRouter) StoreInvitation(invitation []byte, timeout int, password s
|
||||
if len(password) > 0 {
|
||||
r.Client.Set("mwpw:"+id, password, 0) //, time.Duration(timeout*1000000))
|
||||
}
|
||||
return id, time.Now().Add(time.Duration(timeout * 1000000)).UTC()
|
||||
return id, time.Now().Add(time.Duration(timeout * 1000000)).UTC(), nil
|
||||
}
|
||||
|
||||
func (r *RedisRouter) GetInvitation(id string, password string) ([]byte, error) {
|
||||
@@ -54,17 +60,26 @@ func (r *RedisRouter) GetAnswerToInvitation(id string) ([]byte, error) {
|
||||
return []byte(mwan), nil
|
||||
}
|
||||
|
||||
func (r *RedisRouter) createShortId(length int) string {
|
||||
id := ""
|
||||
func (r *RedisRouter) createShortId(length int) (string, error) {
|
||||
alphabet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
alphabetLen := big.NewInt(int64(len(alphabet)))
|
||||
|
||||
// for not in redis
|
||||
for {
|
||||
for i := 1; i <= length; i++ {
|
||||
id += string(alphabet[rand.Intn(61)])
|
||||
var id strings.Builder
|
||||
id.Grow(length)
|
||||
|
||||
for i := 0; i < length; i++ {
|
||||
n, err := rand.Int(rand.Reader, alphabetLen)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("random generation failed: %w", err)
|
||||
}
|
||||
id.WriteByte(alphabet[n.Int64()])
|
||||
}
|
||||
if r.Client.Get("mwiv:"+id).Err() == redis.Nil {
|
||||
break
|
||||
|
||||
idStr := id.String()
|
||||
if r.Client.Get("mwiv:"+idStr).Err() == redis.Nil {
|
||||
return idStr, nil
|
||||
}
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
@@ -272,7 +272,10 @@ func (r *RedisRouter) handleInvitation(msg *meowlib.ToServerMessage) (*meowlib.F
|
||||
switch msg.Invitation.Step {
|
||||
// create invitation => provide shortcode and expiry
|
||||
case 1:
|
||||
url, expiry := r.StoreInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.ShortcodeLen))
|
||||
url, expiry, err := r.StoreInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.ShortcodeLen))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
from_server.Invitation = &meowlib.Invitation{}
|
||||
from_server.Invitation.Shortcode = url
|
||||
from_server.Invitation.Expiry = expiry.UTC().Unix()
|
||||
|
||||
4
setup_req.sh
Executable file
4
setup_req.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
sudo apt install -y protobuf-compiler
|
||||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
|
||||
Reference in New Issue
Block a user