From 7fe78927641c9068982357073e0ea4f96b2181a0 Mon Sep 17 00:00:00 2001 From: ycc Date: Sat, 29 Oct 2022 20:07:35 +0200 Subject: [PATCH] Additions for client side dev --- asymcrypt_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ client/identity.go | 3 +++ client/peer.go | 2 ++ pb/protogen.sh | 4 +++- server/identity.go | 13 ++++++++----- 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/asymcrypt_test.go b/asymcrypt_test.go index 6e31d4b..fd15ede 100644 --- a/asymcrypt_test.go +++ b/asymcrypt_test.go @@ -9,6 +9,38 @@ import ( "github.com/stretchr/testify/assert" ) +var privateKeyECC = `-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: openpgp-mobile + +xVgEY1j9rBYJKwYBBAHaRw8BAQdAk3jWTLSrUqL+vyeEv63DTLlp03IcMExucmFE +RG+IbZgAAQDgQazOcCioSeZWQ16Vn/TMYiAgXgsAlL5b5NZWgyTNzA/+zSFUZXN0 +IChzYW1wbGUpIDxzYW1wbGVAc2FtcGxlLmNvbT7CiwQTFggAPQUCY1j9rAmQCUTp +H7mMc3UWIQSDHOWl4MeCw6GJdvkJROkfuYxzdQIbAwIeAQIZAQILBwIVCAMWAAIC +IgEAAKj5AP4x9KvZFpriLd2K97CaZs5Mzb4r4jeL/q0pMV6d6SvJ+QEAtrqfQovO +hEtadCopy1R3gepIdeX4Fh7tHNYi3pOO5wjHXQRjWP2sEgorBgEEAZdVAQUBAQdA +j48HXuKTfojSYLslNmAtCj6MkwFpj4TR2b5KkKD29kgDAQoJAAD/SulDoAyVe/VR +6dY5Xe887TZSOCKCk5KNTzBtfMj0nhAQzMJ4BBgWCAAqBQJjWP2sCZAJROkfuYxz +dRYhBIMc5aXgx4LDoYl2+QlE6R+5jHN1AhsMAAB0gAEAz9sGgXtTsfJiEMZhKNj8 +XAbymYPQCrsmEBea1uqbB8UA/iKqk0cOabVYTzwBA53G0Tx0C67Xqy46mAtR+W4O +CfMK +=CJ/U +-----END PGP PRIVATE KEY BLOCK-----` + +var publicKeyECC = `-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: openpgp-mobile + +xjMEY1j9rBYJKwYBBAHaRw8BAQdAk3jWTLSrUqL+vyeEv63DTLlp03IcMExucmFE +RG+IbZjNIVRlc3QgKHNhbXBsZSkgPHNhbXBsZUBzYW1wbGUuY29tPsKLBBMWCAA9 +BQJjWP2sCZAJROkfuYxzdRYhBIMc5aXgx4LDoYl2+QlE6R+5jHN1AhsDAh4BAhkB +AgsHAhUIAxYAAgIiAQAAqPkA/jH0q9kWmuIt3Yr3sJpmzkzNviviN4v+rSkxXp3p +K8n5AQC2up9Ci86ES1p0KinLVHeB6kh15fgWHu0c1iLek47nCM44BGNY/awSCisG +AQQBl1UBBQEBB0CPjwde4pN+iNJguyU2YC0KPoyTAWmPhNHZvkqQoPb2SAMBCgnC +eAQYFggAKgUCY1j9rAmQCUTpH7mMc3UWIQSDHOWl4MeCw6GJdvkJROkfuYxzdQIb +DAAAdIABAM/bBoF7U7HyYhDGYSjY/FwG8pmD0Aq7JhAXmtbqmwfFAP4iqpNHDmm1 +WE88AQOdxtE8dAuu16suOpgLUfluDgnzCg== +=oWIw +-----END PGP PUBLIC KEY BLOCK-----` + func TestNewKeyPair(t *testing.T) { kp := NewKeyPair() fmt.Println(kp.Public) @@ -60,3 +92,16 @@ func TestAsymEncryptDecryptSigned(t *testing.T) { } assert.Equal(t, foo, string(decMess), "The two messages should be the same.") } + +func TestFlutterCompat(t *testing.T) { + pub := base64.StdEncoding.EncodeToString([]byte(publicKeyECC)) + priv := base64.StdEncoding.EncodeToString([]byte(privateKeyECC)) + + encMess, sign, err := AsymEncryptAndSign(pub, priv, []byte("Hello")) + if err != nil { + log.Println(err.Error()) + } + + println(base64.StdEncoding.EncodeToString(encMess)) + println(base64.StdEncoding.EncodeToString(sign)) +} diff --git a/client/identity.go b/client/identity.go index 839636b..e75fac7 100644 --- a/client/identity.go +++ b/client/identity.go @@ -17,8 +17,11 @@ type Identity struct { Peers PeerList `json:"peers,omitempty"` KnownServers InternalServerList `json:"known_servers,omitempty"` MessageServers InternalServerList `json:"message_servers,omitempty"` + ArchiveServers InternalServerList `json:"archive_servers,omitempty"` + OwnedServers InternalServerList `json:"owned_servers,omitempty"` DefaultDbPassword string `json:"default_db_password,omitempty"` DbPasswordStore bool `json:"db_password_store,omitempty"` + OwnedDevices PeerList `json:"owned_devices,omitempty"` } func CreateIdentity(nickname string) *Identity { diff --git a/client/peer.go b/client/peer.go index f575c1e..9a384c8 100644 --- a/client/peer.go +++ b/client/peer.go @@ -5,6 +5,7 @@ import ( "time" "forge.redroom.link/yves/meowlib" + "github.com/google/uuid" "google.golang.org/protobuf/proto" ) @@ -59,6 +60,7 @@ func (p *Peer) BuildSimpleUserUMessage(message []byte) (*meowlib.UserMessage, er msg.From = p.Me.Public msg.Data = message msg.Type = "1" + msg.Status.LocalUuid = uuid.New().String() return &msg, nil } diff --git a/pb/protogen.sh b/pb/protogen.sh index 85b255e..b980157 100755 --- a/pb/protogen.sh +++ b/pb/protogen.sh @@ -1,4 +1,6 @@ #!/bin/bash protoc -I=. --go_out=.. messages.proto mv ../forge.redroom.link/yves/meowlib/messages.pb.go ../ -rm -rf ../forge.redroom.link \ No newline at end of file +rm -rf ../forge.redroom.link + +protoc -I=. --dart_out=../../../flutter/meowlib/lib/ messages.proto diff --git a/server/identity.go b/server/identity.go index 2578207..182309e 100644 --- a/server/identity.go +++ b/server/identity.go @@ -13,11 +13,14 @@ import ( 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"` - Status string `json:"status,omitempty"` - // KnownServers ServerList `json:"known_servers,omitempty"` + ServerName string `json:"servername,omitempty"` + ServerDesc string `json:"serverdesc,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"` + ArchiveClients []string `json:"archive_clients,omitempty"` + KnownServers []meowlib.Server `json:"known_servers,omitempty"` } func CreateIdentity(ServerName string, ServerDesc string) *Identity {