Cleanup + proto update + Peers functions

This commit is contained in:
ycc 2022-09-18 18:09:27 +02:00
parent 4b20844e51
commit 01aec23f76
7 changed files with 451 additions and 602 deletions

3
.gitignore vendored
View File

@ -6,3 +6,6 @@ doc/protocol.pdf
doc/protocol.synctex.gz doc/protocol.synctex.gz
out/doc/general_deployment/general_deployment.png out/doc/general_deployment/general_deployment.png
out/doc/server_deployment/server_deployment.png out/doc/server_deployment/server_deployment.png
*.json
test
id.enc

View File

@ -11,12 +11,14 @@ import (
const key = "3pw0c8#6ZG8{75b5;3?fe80$2" const key = "3pw0c8#6ZG8{75b5;3?fe80$2"
type Identity struct { type Identity struct {
Nickname string `json:"nickname,omitempty"` Nickname string `json:"nickname,omitempty"`
RootKp meowlib.KeyPair `json:"id_kp,omitempty"` RootKp meowlib.KeyPair `json:"id_kp,omitempty"`
Status string `json:"status,omitempty"` Status string `json:"status,omitempty"`
Peers PeerList `json:"peers,omitempty"` Peers PeerList `json:"peers,omitempty"`
KnownServers InternalServerList `json:"known_servers,omitempty"` KnownServers InternalServerList `json:"known_servers,omitempty"`
MessageServers InternalServerList `json:"message_servers,omitempty"` MessageServers InternalServerList `json:"message_servers,omitempty"`
DefaultDbPassword string `json:"default_db_password,omitempty"`
DbPasswordStore bool `json:"db_password_store,omitempty"`
} }
func CreateIdentity(nickname string) *Identity { func CreateIdentity(nickname string) *Identity {

View File

@ -24,6 +24,8 @@ type Peer struct {
MessageNotification string `json:"message_notification,omitempty"` MessageNotification string `json:"message_notification,omitempty"`
OnionMode bool `json:"onion_mode,omitempty"` OnionMode bool `json:"onion_mode,omitempty"`
LastMessage time.Time `json:"last_message,omitempty"` LastMessage time.Time `json:"last_message,omitempty"`
MessageDb string `json:"message_db,omitempty"` // sql url for messages storage
DbPassword string `json:"db_password,omitempty"`
} }
type PeerList []Peer type PeerList []Peer
@ -52,14 +54,14 @@ func (pl *PeerList) GetFromName(name string) *Peer {
} }
// AsymEncryptMessage prepares a message to send to a specific peer contact // AsymEncryptMessage prepares a message to send to a specific peer contact
func (p *Peer) AsymEncryptMessage(Message []byte) (LookupPublicKey string, EncryptedMessage []byte, Signature []byte, Servers []*meowlib.Server, err error) { func (p *Peer) AsymEncryptMessage(Message []byte) (EncryptedMessage []byte, Signature []byte, Servers []*meowlib.Server, err error) {
EncryptedMessage, Signature, err = meowlib.EncryptAndSign(p.Contact.EncryptionPublicKey, p.Me.Private, Message) EncryptedMessage, Signature, err = meowlib.EncryptAndSign(p.Contact.EncryptionPublicKey, p.Me.Private, Message)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return "", nil, nil, nil, err return nil, nil, nil, err
} }
return p.LookupKp.Public, EncryptedMessage, Signature, p.Contact.PullServers, err return EncryptedMessage, Signature, p.Contact.PullServers, err
} }
// AsymDecryptMessage reads a message from a specific peer contact // AsymDecryptMessage reads a message from a specific peer contact
@ -71,3 +73,34 @@ func (p *Peer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMe
} }
return DecryptedMessage, err return DecryptedMessage, err
} }
// Pack will package the previously encrypted message for sending it to the peer in protobuff format
func (p *Peer) Pack(message []byte, signature []byte) meowlib.PackedUserMessage {
var msg meowlib.PackedUserMessage
msg.Destination = p.Contact.LookupPublicKey
msg.From = p.Me.Public
msg.Payload = message
msg.Signature = signature
return msg
}
func (p *Peer) GetConversationRequest() meowlib.ToServerMessage_ConversationRequest {
var cr meowlib.ToServerMessage_ConversationRequest
return cr
}
func (p *Peer) StoreMessage(msg []byte) {
}
func (p *Peer) LoadMessage(uid string) {
}
func (p *Peer) LoadLastMessages(qty int) {
}
func (p *Peer) GetLastMessageUid(msg []byte) {
}

View File

@ -5,6 +5,7 @@ import (
"time" "time"
"forge.redroom.link/yves/meowlib" "forge.redroom.link/yves/meowlib"
"google.golang.org/protobuf/proto"
) )
type InternalServer struct { type InternalServer struct {
@ -53,3 +54,29 @@ func (ints *InternalServer) AsymDecryptMessage(Message []byte, Signature []byte)
} }
return DecryptedMessage, err return DecryptedMessage, err
} }
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
func (ints *InternalServer) CreateMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) {
var msg meowlib.ToServerMessage
msg.Type = "1"
msg.From = ints.Me.Public
msg.Messages = append(msg.Messages, usermsg)
out, err := proto.Marshal(&msg)
if err != nil {
return nil, err
}
return out, nil
}
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
func (ints *InternalServer) CreateMessageRequestMessage(lookupKeys []string) ([]byte, error) {
var msg meowlib.ToServerMessage
msg.Type = "1"
msg.From = ints.Me.Public
out, err := proto.Marshal(&msg)
if err != nil {
return nil, err
}
return out, nil
}

View File

@ -69,11 +69,11 @@ func TestEndToEnd(t *testing.T) {
// create message to simulated friend // create message to simulated friend
sentmessage := "Hello friend!" sentmessage := "Hello friend!"
lookupK, EncMsg, Signature, Servers, err := MyFirstFriend.AsymEncryptMessage([]byte(sentmessage)) EncMsg, Signature, Servers, err := MyFirstFriend.AsymEncryptMessage([]byte(sentmessage))
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
fmt.Println(lookupK)
fmt.Println(len(Servers)) fmt.Println(len(Servers))
// simulated friend decoding the message // simulated friend decoding the message
//ReadMessage //ReadMessage
@ -85,11 +85,11 @@ func TestEndToEnd(t *testing.T) {
if err2 != nil { if err2 != nil {
fmt.Println(err2.Error()) fmt.Println(err2.Error())
} }
fmt.Println(decMess)
// simulates a new server to send a message to // simulates a new server to send a message to
var intS1 client.InternalServer var intS1 client.InternalServer
intS1.ServerData.Name = "IntS1" intS1.ServerData.Name = "My friend's Server 1"
intS1.ServerData.Description = "Internal Serveur 1" intS1.ServerData.Description = "My friend's Server 1"
intS1.Me = meowlib.NewKeyPair() intS1.Me = meowlib.NewKeyPair()
intS1.ServerData.Url = "http://myfriend.org/meow/" intS1.ServerData.Url = "http://myfriend.org/meow/"
KP := meowlib.NewKeyPair() KP := meowlib.NewKeyPair()

File diff suppressed because it is too large Load Diff

View File

@ -2,93 +2,86 @@ syntax = "proto3";
package meowlib; package meowlib;
option go_package = "forge.redroom.link/yves/meowlib"; option go_package = "forge.redroom.link/yves/meowlib";
// structure for sending a message intended for server use in protobuf format // structure definnig a message as received by a server in protobuf format
message PackedServerMessage { message PackedServerMessage {
string From = 1; string from = 1; // The client public key for that server to get an answer
bytes Payload = 2; bytes payload = 2; // The ToServerMessage encrypted with the server public key
bytes Signature = 3; bytes signature = 3; // The message signature with the client public key
} }
// structure for sending a message to be forwarded to another user in protobuf format // structure defining a message for a server, that will be encrypted, then sent in a "packedmessage" payload
message PackedUserMessage {
string From = 1;
string Destination=2;
bytes Payload=3;
bytes Signature=4;
}
// structure defining a message encrypted, then sent in a "packedmessage" payload
message ToServerMessage { message ToServerMessage {
string Type = 1; // Type string type = 1; // Type
string ServerPubKey = 2 ; // My pub key for the server to send me an encrypter answer string from = 2 ; // My pub key for the server to send me an encrypter answer
bytes Payload = 3 ; // optional payload for server bytes payload = 3 ; // optional payload for server
message ConversationRequest { // Structure for requestion incoming messages // structure for requesting incoming messages
message ConversationRequest {
string lookupKey = 1; // lookup key for a conversation string lookupKey = 1; // lookup key for a conversation
string LastServerUuidOK = 2; // Last Server message UUID received (send me all after that one) string lastServerUuidOK = 2; // Last Server message UUID received (send me all after that one)
bool PublishOnline = 3; // ?? Publish my online status for that contact ? bool publishOnline = 3; // ?? Publish my online status for that contact ?
string lookupSignature = 4; // prove that I own the private key by signing that block string lookupSignature = 4; // prove that I own the private key by signing that block
} }
repeated ConversationRequest PullRequest = 7; repeated ConversationRequest pullRequest = 4;
repeated PackedUserMessage messages = 5;
repeated Server knownServers = 6;
message PostedMessage{
string lookupKey= 1;
repeated PackedUserMessage Messages = 2;
}
repeated PostedMessage Messages = 9;
string NextServerKey = 10;
string Url = 11;
} }
// structure defining a from serve receiver message decrypted from a "packedmessage" payload // structure defining a from server receiver message decrypted from a "packedmessage" payload
message FromServerMessage { message FromServerMessage {
string Type = 1; // Type string type = 1; // Type
string ServerPubKey = 2 ; // My pub key for the server to send me an encrypter answer string serverPubKey = 2 ; // My pub key for the server to send me an encrypter answer
bytes Payload = 3 ; // bytes payload = 3 ; //
uint64 ServerReceived = 4 ; uint64 serverReceived = 4 ;
string ServerUuid = 5 ; string serverUuid = 5 ;
message ConversationResponse { message ConversationResponse {
repeated string MessageUuids = 1; repeated string messageUuids = 1;
} }
map<string,ConversationResponse> PullResponse = 8; map<string,ConversationResponse> pullResponse = 6;
message PostedMessage{ message PostedMessage{
string lookupKey= 1; string lookupKey= 1;
repeated PackedUserMessage Messages = 2; repeated PackedUserMessage messages = 2;
} }
repeated PostedMessage Messages = 9; repeated PostedMessage chat = 7;
string NextServerKey = 10;
string Url = 11;
} }
// structure describing required server attributes
message Server { message Server {
string Name = 1; string name = 1;
string Description=2; string description=2;
string PublicKey = 3; string publicKey = 3;
string Url = 4; string url = 4;
int32 ConfidenceLevel = 5; int32 confidenceLevel = 5;
} }
// structure describing a user contact card ie the minimum set of attributes for exchanging identities
message ContactCard { message ContactCard {
string name=1; string name=1;
string contactPublicKey =2; string contactPublicKey =2;
string encryptionPublicKey= 3; string encryptionPublicKey= 3;
string lookupPublicKey =4; string lookupPublicKey =4;
repeated Server PullServers =5; repeated Server pullServers =5;
int32 version = 6;
} }
// structure for sending a message to be forwarded to another user in protobuf format
message MinimalContact { message PackedUserMessage {
string name=1; string from = 1; // the client identity public key as known by the destination peer
string publicKey=2; string destination=2; // the peer's current conversation lookup public key
repeated Server TrustedServers = 3; bytes payload=3; // the message UserMessage encrypted with the destination peer's public key
bytes signature=4; // the payload signature with the client identity private key
} }
// structure defining information that might be exchanged between two peers.
message UserMessage { message UserMessage {
string Destination = 1; string Destination = 1;
string From = 2; string From = 2;
string Type = 3; string Type = 3;
@ -99,21 +92,18 @@ message UserMessage {
uint64 Sent = 3 ; uint64 Sent = 3 ;
uint64 Received = 4; uint64 Received = 4;
uint64 Processed = 5; uint64 Processed = 5;
string NextCkey = 6; // contact key ContactCard myNextIdentity = 6;
bool NextCkeyAck = 7; // false when proposing a new id, true for accepting it int32 peerNextIdentityAck = 7; // version of the new peed accepted id
string NextEkey = 8; // encryption key }
bool NextKeyEkeyAck = 9; // false when proposing a new key, true for accpeting it
string NextLkey = 10; // lookup key
bool NextLkeyAck = 11; // false when proposing a new id, true for accepting it
}
ConversationStatus Status = 5; ConversationStatus Status = 5;
ContactCard contact = 6;
MinimalContact contact = 6; Server knownServers = 7;
message Group{ message Group{
string name=1; string name=1;
repeated MinimalContact members = 2; repeated ContactCard members = 2;
} }
Group group = 7; Group group = 8;
} }