From ae862b9f44dc0ab0feb525656a85915929a47f34 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 12 Sep 2020 02:25:41 +0300 Subject: [PATCH] Add command for cross-signing current device --- go.mod | 2 +- go.sum | 2 ++ ui/crypto-commands.go | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b8fde17..8ff46aa 100644 --- a/go.mod +++ b/go.mod @@ -29,4 +29,4 @@ require ( ) //replace maunium.net/go/mautrix => ../mautrix-go -replace maunium.net/go/mautrix => github.com/nikofil/mautrix-go v0.5.2-0.20200911223256-b40ab761fadc +replace maunium.net/go/mautrix => github.com/nikofil/mautrix-go v0.5.2-0.20200911232449-6010305aed05 diff --git a/go.sum b/go.sum index 948bff6..50f21d3 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= github.com/nikofil/mautrix-go v0.5.2-0.20200911223256-b40ab761fadc h1:Un166sriSTE07vajPm+iv+oHmBIH3b4PW2LO1fhRyKc= github.com/nikofil/mautrix-go v0.5.2-0.20200911223256-b40ab761fadc/go.mod h1:xd0D0ekVts/UDBbjeDSs4wGlBfcarJDg0MMhVgHbxhs= +github.com/nikofil/mautrix-go v0.5.2-0.20200911232449-6010305aed05 h1:WFyJHdXasAvpno0OSvKgfmZHlq0WoyK+254vxmz4Mag= +github.com/nikofil/mautrix-go v0.5.2-0.20200911232449-6010305aed05/go.mod h1:xd0D0ekVts/UDBbjeDSs4wGlBfcarJDg0MMhVgHbxhs= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/ui/crypto-commands.go b/ui/crypto-commands.go index 04be052..eaf3808 100644 --- a/ui/crypto-commands.go +++ b/ui/crypto-commands.go @@ -424,6 +424,8 @@ Subcommands: Generate and upload new cross-signing keys. This will prompt you to enter your account password. If you already have existing keys, --force is required. +* self-sign + Sign the current device with cached cross-signing keys. * fetch [--save-to-disk] Fetch your cross-signing keys from SSSS and decrypt them. If --save-to-disk is specified, the keys are saved to disk. @@ -450,6 +452,8 @@ func cmdCrossSigning(cmd *Command) { cmdCrossSigningFetch(cmd, mach, saveToDisk) case "upload": cmdCrossSigningUpload(cmd, mach) + case "self-sign": + cmdCrossSigningSelfSign(cmd, mach) default: cmd.Reply(crossSigningHelp, cmd.OrigCommand) } @@ -641,3 +645,18 @@ func cmdCrossSigningUpload(cmd *Command, mach *crypto.OlmMachine) { cmd.Reply("Successfully uploaded cross-signing keys to SSSS") } } + + +func cmdCrossSigningSelfSign(cmd *Command, mach *crypto.OlmMachine) { + if mach.CrossSigningKeys == nil { + cmd.Reply("Cross-signing keys not cached") + return + } + + err := mach.SignOwnDevice(mach.OwnIdentity()) + if err != nil { + cmd.Reply("Failed to self-sign: %v", err) + } else { + cmd.Reply("Successfully self-signed. This device is now trusted by other devices") + } +}