From 86f222a7df7eaf58ab415aad35ed3ae2f60c590b Mon Sep 17 00:00:00 2001 From: N Date: Mon, 5 Sep 2022 17:16:11 +0200 Subject: [PATCH] to server encryption --- peer.go | 4 ++-- server.go | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/peer.go b/peer.go index 99d1974..5edadbb 100644 --- a/peer.go +++ b/peer.go @@ -139,7 +139,7 @@ func ReadQr(fielname string) ContactCard { return contact } -func (p *Peer) CreateMessage(Message []byte) (lookupK string, EncryptedMsg []byte, Signature []byte, Servers []Server, err error) { +func (p *Peer) AsymEncryptMessage(Message []byte) (lookupK string, EncryptedMsg []byte, Signature []byte, Servers []Server, err error) { // prepares a message to send to a specific peer contact EncryptedMsg, Signature, err = EncryptAndSign(p.Contact.EncryptionPublicKey, p.Me.Private, Message) if err != nil { @@ -149,7 +149,7 @@ func (p *Peer) CreateMessage(Message []byte) (lookupK string, EncryptedMsg []byt return p.LookupKp.Public, EncryptedMsg, Signature, p.Contact.PullServers, err } -func (p *Peer) ReadMessage(Message []byte, Signature []byte) (DecryptedMsg []byte, err error) { +func (p *Peer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMsg []byte, err error) { // reads a message from a specific peer contact DecryptedMsg, err = DecryptAndCheck(p.Me.Private, p.Contact.ContactPublicKey, Message, Signature) if err != nil { diff --git a/server.go b/server.go index c509f93..62e9799 100644 --- a/server.go +++ b/server.go @@ -1,6 +1,9 @@ package meowlib -import "time" +import ( + "fmt" + "time" +) type InternalServer struct { ServerData Server `json:"server_data,omitempty"` @@ -28,3 +31,23 @@ func (sl *ServerList) AddUrls(urls []string) { sl.Servers = append(sl.Servers, *ServerFromUrl(url)) } } + +func (ints *InternalServer) AsymEncryptMessage(Message []byte) (EncryptedMsg []byte, Signature []byte, err error) { + // prepares a message to send to a specific internal server + EncryptedMsg, Signature, err = EncryptAndSign(ints.ServerData.PublicKey, ints.Me.Private, Message) + if err != nil { + fmt.Println(err.Error()) + return nil, nil, err + } + return EncryptedMsg, Signature, err +} + +func (ints *InternalServer) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMsg []byte, err error) { + // reads a message from a specific internal server + DecryptedMsg, err = DecryptAndCheck(ints.Me.Private, ints.ServerData.PublicKey, Message, Signature) + if err != nil { + fmt.Println(err.Error()) + return nil, err + } + return DecryptedMsg, err +}