Server inbound processing

This commit is contained in:
ycc 2022-09-19 14:58:26 +02:00
parent 1c3118ff48
commit 37f6d7b93a

View File

@ -7,6 +7,7 @@ import (
"forge.redroom.link/yves/meowlib"
"github.com/ProtonMail/gopenpgp/v2/helper"
"google.golang.org/protobuf/proto"
)
const key = "3pw0c8#6ZG8{75b5;3?fe80$2"
@ -51,14 +52,17 @@ func (id *Identity) Save(file string) error {
return err
}
// AsymEncryptMessage prepares a message to send to a specific client contact
func (id *Identity) AsymEncryptMessage(ClientPublicKey string, Message []byte) (EncryptedMsg []byte, Signature []byte, err error) {
EncryptedMsg, Signature, err = meowlib.AsymEncryptAndSign(ClientPublicKey, id.ServerKp.Private, Message)
if err != nil {
fmt.Println(err.Error())
return nil, nil, err
//
// Inbound processing chain
//
// Unpack a protobuf received packed message
func (id *Identity) UnpackReceived(message []byte) (fromPublicKey string, encryptedMessage []byte, signature []byte, err error) {
pmsg := &meowlib.PackedServerMessage{}
if err := proto.Unmarshal(message, pmsg); err != nil {
return "", nil, nil, err
}
return EncryptedMsg, Signature, err
return pmsg.From, pmsg.Payload, pmsg.Signature, nil
}
// AsymDecryptMessage reads a message from a specific client contact
@ -70,3 +74,26 @@ func (id *Identity) AsymDecryptMessage(ClientPublicKey string, Message []byte, S
}
return DecryptedMsg, err
}
// Decode decrypted ToServerMessage
func (id *Identity) DecodeToServerMessage(toServerMessage []byte) (*meowlib.ToServerMessage, error) {
tsmsg := &meowlib.ToServerMessage{}
if err := proto.Unmarshal(toServerMessage, tsmsg); err != nil {
return nil, err
}
return tsmsg, nil
}
//
// Outbound processing chain
//
// AsymEncryptMessage prepares a message to send to a specific client contact
func (id *Identity) AsymEncryptMessage(ClientPublicKey string, Message []byte) (EncryptedMsg []byte, Signature []byte, err error) {
EncryptedMsg, Signature, err = meowlib.AsymEncryptAndSign(ClientPublicKey, id.ServerKp.Private, Message)
if err != nil {
fmt.Println(err.Error())
return nil, nil, err
}
return EncryptedMsg, Signature, err
}