diff --git a/client/server.go b/client/server.go index 670a164..8bf1138 100644 --- a/client/server.go +++ b/client/server.go @@ -12,9 +12,10 @@ import ( // Server manages server related operations // - Sending messages for server usage // - Two first steps of an invitation -// - User message sending +// - User message sending with UserKp identification // - Messages lookup requests // - Utility functions for packing/unpacking, encrypting/decrypting messages for server communication +// - Server remote management if ManagerKp is available for that server type Server struct { ServerData meowlib.ServerCard `json:"server_data,omitempty"` Presence bool `json:"presence,omitempty"` @@ -22,7 +23,8 @@ type Server struct { Uptime time.Duration `json:"uptime,omitempty"` Login string `json:"login,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"` AllowedDelay int `json:"allowed_delay,omitempty"` } @@ -38,14 +40,14 @@ func CreateServerFromUrl(url string) *Server { func CreateServerFromServerCard(server *meowlib.ServerCard) *Server { var is Server is.ServerData = *server - is.Me = meowlib.NewKeyPair() + is.UserKp = meowlib.NewKeyPair() return &is } // AsymEncryptMessage prepares a message to send to a specific internal server func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessage, error) { 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 { fmt.Println(err.Error()) return nil, err @@ -55,7 +57,7 @@ func (ints *Server) AsymEncryptMessage(Message []byte) (*meowlib.EncryptedMessag // AsymDecryptMessage reads a message from a specific internal server 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 { fmt.Println(err.Error()) return nil, err @@ -68,7 +70,7 @@ func (ints *Server) BuildToServerMessageFromUserMessage(usermsg *meowlib.PackedU var msg meowlib.ToServerMessage msg.Uuid = uuid.New().String() msg.Type = "1" - msg.From = ints.Me.Public + msg.From = ints.UserKp.Public msg.Messages = append(msg.Messages, usermsg) return &msg } @@ -88,7 +90,7 @@ func (ints *Server) BuildMessageRequestMessage(lookupKeys []string) ([]byte, err var msg meowlib.ToServerMessage msg.Uuid = uuid.New().String() msg.Type = "1" - msg.From = ints.Me.Public + msg.From = ints.UserKp.Public out, err := proto.Marshal(&msg) if err != nil { return nil, err @@ -106,7 +108,7 @@ func (ints *Server) BuildToServerMessageInvitationCreation(invitation *meowlib.C return nil, err } msg.Type = "1" - msg.From = ints.Me.Public + msg.From = ints.UserKp.Public inv.Step = 1 inv.Password = password inv.Timeout = int32(timeout) @@ -121,7 +123,7 @@ func (ints *Server) BuildToServerMessageInvitationRequest(shortcode string, pass var msg meowlib.ToServerMessage var inv meowlib.Invitation msg.Type = "1" - msg.From = ints.Me.Public + msg.From = ints.UserKp.Public inv.Step = 2 inv.Password = password inv.Shortcode = shortcode @@ -132,7 +134,7 @@ func (ints *Server) BuildToServerMessageInvitationRequest(shortcode string, pass // PackServerMessage func (ints *Server) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) { var msg meowlib.PackedServerMessage - msg.From = ints.Me.Public + msg.From = ints.UserKp.Public msg.Payload = payload msg.Signature = signature out, err := proto.Marshal(&msg) diff --git a/server/router.go b/server/router.go index 58ce423..68c36bd 100644 --- a/server/router.go +++ b/server/router.go @@ -29,7 +29,7 @@ func NewRedisRouter(server *Identity, redisUrl string, password string, db int, r.InvitationTimeout = invitationTimeout r.Context = context.Background() // 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 { panic(err) }