Add command to get e2ee fingerprint

This commit is contained in:
Tulir Asokan 2020-05-07 11:56:21 +03:00
parent 2b07b80e64
commit e1b38bb202
6 changed files with 35 additions and 15 deletions

2
go.mod
View File

@ -21,7 +21,7 @@ require (
golang.org/x/net v0.0.0-20200505041828-1ed23360d12c golang.org/x/net v0.0.0-20200505041828-1ed23360d12c
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
gopkg.in/yaml.v2 v2.2.8 gopkg.in/yaml.v2 v2.2.8
maunium.net/go/mautrix v0.3.2 maunium.net/go/mautrix v0.3.3
maunium.net/go/mauview v0.1.1 maunium.net/go/mauview v0.1.1
maunium.net/go/tcell v0.2.0 maunium.net/go/tcell v0.2.0
) )

2
go.sum
View File

@ -95,6 +95,8 @@ maunium.net/go/mautrix v0.3.1 h1:zDhN4PYdWavbssA+9JVoCsUmu/u0LtdHeE647oh3W8c=
maunium.net/go/mautrix v0.3.1/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y= maunium.net/go/mautrix v0.3.1/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y=
maunium.net/go/mautrix v0.3.2 h1:YLTj8euBTxb118XOryghWpsE/aieFI4lG6jCpCmw5HA= maunium.net/go/mautrix v0.3.2 h1:YLTj8euBTxb118XOryghWpsE/aieFI4lG6jCpCmw5HA=
maunium.net/go/mautrix v0.3.2/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y= maunium.net/go/mautrix v0.3.2/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y=
maunium.net/go/mautrix v0.3.3 h1:PV+5oSDaFj3cPTE062O44q/G83x7qfP6gm9kr+BZIgE=
maunium.net/go/mautrix v0.3.3/go.mod h1:SkGZzch8CvU2qKtNpYxtzZ0sQxfVEJ3IsVVLSUBUx9Y=
maunium.net/go/mauview v0.1.0 h1:x2WdkKI2zdriJuPAB0CKlwmnHGE7W9xfM5z6RgG+IIg= maunium.net/go/mauview v0.1.0 h1:x2WdkKI2zdriJuPAB0CKlwmnHGE7W9xfM5z6RgG+IIg=
maunium.net/go/mauview v0.1.0/go.mod h1:og9WbzmWe9SNYNyOFlCv8qa9zMcOvG2nzRJ5vYyud9U= maunium.net/go/mauview v0.1.0/go.mod h1:og9WbzmWe9SNYNyOFlCv8qa9zMcOvG2nzRJ5vYyud9U=
maunium.net/go/mauview v0.1.1 h1:wfTXyPx3LGAGpTskh+UbBv/QItUWnEpaneHmywoYnfY= maunium.net/go/mauview v0.1.1 h1:wfTXyPx3LGAGpTskh+UbBv/QItUWnEpaneHmywoYnfY=

View File

@ -64,4 +64,17 @@ type MatrixContainer interface {
DownloadToDisk(uri id.ContentURI, file *attachment.EncryptedFile, target string) (string, error) DownloadToDisk(uri id.ContentURI, file *attachment.EncryptedFile, target string) (string, error)
GetDownloadURL(uri id.ContentURI) string GetDownloadURL(uri id.ContentURI) string
GetCachePath(uri id.ContentURI) string GetCachePath(uri id.ContentURI) string
Crypto() Crypto
}
type Crypto interface {
Load() error
FlushStore() error
ProcessSyncResponse(resp *mautrix.RespSync, since string)
HandleMemberEvent(*event.Event)
DecryptMegolmEvent(*event.Event) (*event.Event, error)
EncryptMegolmEvent(id.RoomID, event.Type, event.Content) (*event.EncryptedEventContent, error)
ShareGroupSession(id.RoomID, []id.UserID) error
Fingerprint() string
} }

View File

@ -55,7 +55,7 @@ import (
// It is used for all Matrix calls from the UI and Matrix event handlers. // It is used for all Matrix calls from the UI and Matrix event handlers.
type Container struct { type Container struct {
client *mautrix.Client client *mautrix.Client
crypto CryptoInterface crypto ifc.Crypto
syncer *GomuksSyncer syncer *GomuksSyncer
gmx ifc.Gomuks gmx ifc.Gomuks
ui ifc.GomuksUI ui ifc.GomuksUI
@ -89,14 +89,8 @@ func (log mxLogger) Debugfln(message string, args ...interface{}) {
debug.Printf("[Matrix] "+message, args...) debug.Printf("[Matrix] "+message, args...)
} }
type CryptoInterface interface { func (c *Container) Crypto() ifc.Crypto {
Load() error return c.crypto
FlushStore() error
ProcessSyncResponse(resp *mautrix.RespSync, since string)
HandleMemberEvent(*event.Event)
DecryptMegolmEvent(*event.Event) (*event.Event, error)
EncryptMegolmEvent(id.RoomID, event.Type, event.Content) (*event.EncryptedEventContent, error)
ShareGroupSession(id.RoomID, []id.UserID) error
} }
// InitClient initializes the mautrix client and connects to the homeserver specified in the config. // InitClient initializes the mautrix client and connects to the homeserver specified in the config.

View File

@ -134,6 +134,8 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"hprof": cmdHeapProfile, "hprof": cmdHeapProfile,
"cprof": cmdCPUProfile, "cprof": cmdCPUProfile,
"trace": cmdTrace, "trace": cmdTrace,
"fingerprint": cmdFingerprint,
}, },
} }
} }

View File

@ -237,7 +237,7 @@ func cmdTag(cmd *Command) {
err = cmd.Matrix.Client().AddTag(cmd.Room.MxRoom().ID, cmd.Args[0], order) err = cmd.Matrix.Client().AddTag(cmd.Room.MxRoom().ID, cmd.Args[0], order)
} }
if err != nil { if err != nil {
cmd.Reply("Failed to add tag:", err) cmd.Reply("Failed to add tag: %v", err)
} }
} }
@ -248,7 +248,7 @@ func cmdUntag(cmd *Command) {
} }
err := cmd.Matrix.Client().RemoveTag(cmd.Room.MxRoom().ID, cmd.Args[0]) err := cmd.Matrix.Client().RemoveTag(cmd.Room.MxRoom().ID, cmd.Args[0])
if err != nil { if err != nil {
cmd.Reply("Failed to remove tag:", err) cmd.Reply("Failed to remove tag: %v", err)
} }
} }
@ -258,7 +258,16 @@ func cmdRoomNick(cmd *Command) {
member.Displayname = strings.Join(cmd.Args, " ") member.Displayname = strings.Join(cmd.Args, " ")
_, err := cmd.Matrix.Client().SendStateEvent(room.ID, event.StateMember, string(room.SessionUserID), member) _, err := cmd.Matrix.Client().SendStateEvent(room.ID, event.StateMember, string(room.SessionUserID), member)
if err != nil { if err != nil {
cmd.Reply("Failed to set room nick:", err) cmd.Reply("Failed to set room nick: %v", err)
}
}
func cmdFingerprint(cmd *Command) {
c := cmd.Matrix.Crypto()
if c == nil {
cmd.Reply("Encryption support is not enabled")
} else {
cmd.Reply("Device ID: %s\nFingerprint: %s", cmd.Matrix.Client().DeviceID, c.Fingerprint())
} }
} }
@ -440,7 +449,7 @@ func cmdCreateRoom(cmd *Command) {
} }
room, err := cmd.Matrix.CreateRoom(req) room, err := cmd.Matrix.CreateRoom(req)
if err != nil { if err != nil {
cmd.Reply("Failed to create room:", err) cmd.Reply("Failed to create room: %v", err)
return return
} }
cmd.MainView.SwitchRoom("", room) cmd.MainView.SwitchRoom("", room)
@ -465,7 +474,7 @@ func cmdPrivateMessage(cmd *Command) {
} }
room, err := cmd.Matrix.CreateRoom(req) room, err := cmd.Matrix.CreateRoom(req)
if err != nil { if err != nil {
cmd.Reply("Failed to create room:", err) cmd.Reply("Failed to create room: %v", err)
return return
} }
cmd.MainView.SwitchRoom("", room) cmd.MainView.SwitchRoom("", room)