Server management keys, and user Kp rename
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
ycc 2023-12-09 20:01:19 +01:00
parent c3ad8d5d2d
commit 535181d669
2 changed files with 13 additions and 11 deletions

View File

@ -12,9 +12,10 @@ import (
// Server manages server related operations // Server manages server related operations
// - Sending messages for server usage // - Sending messages for server usage
// - Two first steps of an invitation // - Two first steps of an invitation
// - User message sending // - User message sending with UserKp identification
// - Messages lookup requests // - Messages lookup requests
// - Utility functions for packing/unpacking, encrypting/decrypting messages for server communication // - Utility functions for packing/unpacking, encrypting/decrypting messages for server communication
// - Server remote management if ManagerKp is available for that server
type Server struct { type Server struct {
ServerData meowlib.ServerCard `json:"server_data,omitempty"` ServerData meowlib.ServerCard `json:"server_data,omitempty"`
Presence bool `json:"presence,omitempty"` Presence bool `json:"presence,omitempty"`
@ -22,7 +23,8 @@ type Server struct {
Uptime time.Duration `json:"uptime,omitempty"` Uptime time.Duration `json:"uptime,omitempty"`
Login string `json:"login,omitempty"` Login string `json:"login,omitempty"`
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
Me meowlib.KeyPair `json:"me,omitempty"` UserKp meowlib.KeyPair `json:"user_kp,omitempty"`
ManagerKp meowlib.KeyPair `json:"manager_kp,omitempty"`
Country string `json:"country,omitempty"` Country string `json:"country,omitempty"`
AllowedDelay int `json:"allowed_delay,omitempty"` AllowedDelay int `json:"allowed_delay,omitempty"`
} }
@ -38,14 +40,14 @@ func CreateServerFromUrl(url string) *Server {
func CreateServerFromServerCard(server *meowlib.ServerCard) *Server { func CreateServerFromServerCard(server *meowlib.ServerCard) *Server {
var is Server var is Server
is.ServerData = *server is.ServerData = *server
is.Me = meowlib.NewKeyPair() is.UserKp = meowlib.NewKeyPair()
return &is return &is
} }
// AsymEncryptMessage prepares a message to send to a specific internal server // AsymEncryptMessage prepares a message to send to a specific internal server
func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) { func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) {
var enc *meowlib.EncryptedMessage var enc *meowlib.EncryptedMessage
enc, err := meowlib.AsymEncryptAndSign(ints.ServerData.PublicKey, ints.Me.Private, Message) enc, err := meowlib.AsymEncryptAndSign(ints.ServerData.PublicKey, ints.UserKp.Private, Message)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return nil, err return nil, err
@ -55,7 +57,7 @@ func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessag
// AsymDecryptMessage reads a message from a specific internal server // AsymDecryptMessage reads a message from a specific internal server
func (ints *Server) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMessage []byte, err error) { func (ints *Server) AsymDecryptMessage(Message []byte, Signature []byte) (DecryptedMessage []byte, err error) {
DecryptedMessage, err = meowlib.AsymDecryptAndCheck(ints.Me.Private, ints.ServerData.PublicKey, Message, Signature) DecryptedMessage, err = meowlib.AsymDecryptAndCheck(ints.UserKp.Private, ints.ServerData.PublicKey, Message, Signature)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return nil, err return nil, err
@ -68,7 +70,7 @@ func (ints *Server) BuildToServerMessageFromUserMessage(usermsg *meowlib.PackedU
var msg meowlib.ToServerMessage var msg meowlib.ToServerMessage
msg.Uuid = uuid.New().String() msg.Uuid = uuid.New().String()
msg.Type = "1" msg.Type = "1"
msg.From = ints.Me.Public msg.From = ints.UserKp.Public
msg.Messages = append(msg.Messages, usermsg) msg.Messages = append(msg.Messages, usermsg)
return &msg return &msg
} }
@ -88,7 +90,7 @@ func (ints *Server) BuildMessageRequestMessage(lookupKeys []string) ([]byte, err
var msg meowlib.ToServerMessage var msg meowlib.ToServerMessage
msg.Uuid = uuid.New().String() msg.Uuid = uuid.New().String()
msg.Type = "1" msg.Type = "1"
msg.From = ints.Me.Public msg.From = ints.UserKp.Public
out, err := proto.Marshal(&msg) out, err := proto.Marshal(&msg)
if err != nil { if err != nil {
return nil, err return nil, err
@ -106,7 +108,7 @@ func (ints *Server) BuildToServerMessageInvitationCreation(invitation *meowlib.C
return nil, err return nil, err
} }
msg.Type = "1" msg.Type = "1"
msg.From = ints.Me.Public msg.From = ints.UserKp.Public
inv.Step = 1 inv.Step = 1
inv.Password = password inv.Password = password
inv.Timeout = int32(timeout) inv.Timeout = int32(timeout)
@ -121,7 +123,7 @@ func (ints *Server) BuildToServerMessageInvitationRequest(shortcode string, pass
var msg meowlib.ToServerMessage var msg meowlib.ToServerMessage
var inv meowlib.Invitation var inv meowlib.Invitation
msg.Type = "1" msg.Type = "1"
msg.From = ints.Me.Public msg.From = ints.UserKp.Public
inv.Step = 2 inv.Step = 2
inv.Password = password inv.Password = password
inv.Shortcode = shortcode inv.Shortcode = shortcode
@ -132,7 +134,7 @@ func (ints *Server) BuildToServerMessageInvitationRequest(shortcode string, pass
// PackServerMessage // PackServerMessage
func (ints *Server) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) { func (ints *Server) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) {
var msg meowlib.PackedServerMessage var msg meowlib.PackedServerMessage
msg.From = ints.Me.Public msg.From = ints.UserKp.Public
msg.Payload = payload msg.Payload = payload
msg.Signature = signature msg.Signature = signature
out, err := proto.Marshal(&msg) out, err := proto.Marshal(&msg)

View File

@ -29,7 +29,7 @@ func NewRedisRouter(server *Identity, redisUrl string, password string, db int,
r.InvitationTimeout = invitationTimeout r.InvitationTimeout = invitationTimeout
r.Context = context.Background() r.Context = context.Background()
// set start for uptime // set start for uptime
err := r.Client.Set("statistics:start", time.Now().Format(time.RFC3339), 0).Err() err := r.Client.Set("statistics:start", time.Now().UTC().Format(time.RFC3339), 0).Err()
if err != nil { if err != nil {
panic(err) panic(err)
} }