From b092039ac33c10c7e9392bd002c1755ee841c727 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Tue, 26 Apr 2022 19:47:22 +0200 Subject: [PATCH] Ox: Allow also RSA key generation. --- README.md | 11 +++++++---- main.go | 27 +++++++++++++++++++++------ man/go-sendxmpp.1 | 6 +++++- man/go-sendxmpp.1.html | 14 ++++++++++++-- man/go-sendxmpp.1.ronn | 14 ++++++++++++-- ox.go | 5 +++-- 6 files changed, 60 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b43a66d..07a7f86 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ If no configuration file is present or if the values should be overridden it is the account details via command line options: ```plain -Usage: go-sendxmpp [-cdilnt] [-f value] [--help] [--http-upload value] [-j value] [-m value] [--muc-password value] [--ox] [--ox-genprivkey] [--ox-import-privkey value] [--ox-passphrase value] [-p value] [--raw] [-r value] [--timeout value] [--tls-version value] [-u value] [--version] [parameters ...] +Usage: go-sendxmpp [-cdilnt] [-f value] [--help] [--http-upload value] [-j value] [-m value] [--muc-password value] [--ox] [--ox-genprivkey-rsa] [--ox-genprivkey-x25519] [--ox-import-privkey value] [--ox-passphrase value] [-p value] [--raw] [-r value] [--timeout value] [--tls-version value] [-u value] [--version] [parameters ...] -c, --chatroom Send message to a chatroom. -d, --debug Show debugging info. -f, --file=value Set configuration file. (Default: @@ -102,9 +102,12 @@ Usage: go-sendxmpp [-cdilnt] [-f value] [--help] [--http-upload value] [-j value -n, --no-tls-verify Skip verification of TLS certificates (not recommended). --ox Use "OpenPGP for XMPP" encryption (experimental). - --ox-genprivkey - Generate a public OpenPGP key for the given JID and publish - the corresponding public key. + --ox-genprivkey-rsa + Generate a public OpenPGP key (RSA 4096 bit) for the given + JID and publish the corresponding public key. + --ox-genprivkey-x25519 + Generate a public OpenPGP key (x25519) for the given JID and + publish the corresponding public key. --ox-import-privkey=value Import an existing private OpenPGP key. --ox-passphrase=value diff --git a/main.go b/main.go index eb32535..e3e35cd 100644 --- a/main.go +++ b/main.go @@ -107,8 +107,12 @@ func main() { flagVersion := getopt.BoolLong("version", 0, "Show version information.") flagMUCPassword := getopt.StringLong("muc-password", 0, "", "Password for password protected MUCs.") flagOx := getopt.BoolLong("ox", 0, "Use \"OpenPGP for XMPP\" encryption (experimental).") - flagOxGenPrivKey := getopt.BoolLong("ox-genprivkey", 0, - "Generate a public OpenPGP key for the given JID and publish the corresponding public key.") + flagOxGenPrivKeyRSA := getopt.BoolLong("ox-genprivkey-rsa", 0, + "Generate a public OpenPGP key (RSA 4096 bit) for the given JID and publish the "+ + "corresponding public key.") + flagOxGenPrivKeyX25519 := getopt.BoolLong("ox-genprivkey-x25519", 0, + "Generate a public OpenPGP key (x25519) for the given JID and publish the "+ + "corresponding public key.") flagOxPassphrase := getopt.StringLong("ox-passphrase", 0, "", "Passphrase for locking and unlocking the private OpenPGP key.") flagOxImportPrivKey := getopt.StringLong("ox-import-privkey", 0, "", @@ -147,8 +151,9 @@ func main() { // For listening or sending raw XML it's not required to specify a recipient except // when sending raw messages to MUCs (go-sendxmpp will join the MUC automatically). recipientsList := getopt.Args() - if (len(recipientsList) == 0 && !*flagRaw && !*flagListen && !*flagOxGenPrivKey && - *flagOxImportPrivKey == "") || (len(recipientsList) == 0 && *flagChatroom) { + if (len(recipientsList) == 0 && !*flagRaw && !*flagListen && !*flagOxGenPrivKeyX25519 && + !*flagOxGenPrivKeyRSA && *flagOxImportPrivKey == "") || + (len(recipientsList) == 0 && *flagChatroom) { log.Fatal("No recipient specified.") } @@ -270,12 +275,22 @@ func main() { } switch { - case *flagOxGenPrivKey: + case *flagOxGenPrivKeyX25519: validatedOwnJid, err := MarshalJID(user) if err != nil { log.Fatal(err) } - err = oxGenPrivKey(validatedOwnJid, client, *flagOxPassphrase) + err = oxGenPrivKey(validatedOwnJid, client, *flagOxPassphrase, "x25519") + if err != nil { + log.Fatal(err) + } + os.Exit(0) + case *flagOxGenPrivKeyRSA: + validatedOwnJid, err := MarshalJID(user) + if err != nil { + log.Fatal(err) + } + err = oxGenPrivKey(validatedOwnJid, client, *flagOxPassphrase, "rsa") if err != nil { log.Fatal(err) } diff --git a/man/go-sendxmpp.1 b/man/go-sendxmpp.1 index a2a23b3..9958cdd 100644 --- a/man/go-sendxmpp.1 +++ b/man/go-sendxmpp.1 @@ -38,7 +38,11 @@ You can either pipe a programs output to \fBgo\-sendxmpp\fR, write in your termi .br There is also no check whether the recipients key is trusted as there is no local keyring used\. Go\-sendxmpp just uses the most recent key that is provided via pubsub and checks that it is not expired\. .P -\fB\-\-ox\-genprivkey\fR: Generate a public OpenPGP key for the given JID and publish the corresponding public key\. Go\-sendxmpp will save the key in \fB$XDG_DATA_HOME/go\-sendxmpp/oxprivkeys\fR or \fB$HOME/\.local/share/go\-sendxmpp/oxprivkeys\fR\. To protect the key a passphrase might be set using \fB\-\-ox\-passphrase\fR while generating the key\. +\fB\-\-ox\-genprivkey\-rsa\fR: Generate a private OpenPGP key (RSA 4096 bit) for the configured account (via config file or \fB\-u\fR and \fB\-p\fR) and publish the corresponding public key\. Go\-sendxmpp will save the key in \fB$XDG_DATA_HOME/go\-sendxmpp/oxprivkeys\fR or \fB$HOME/\.local/share/go\-sendxmpp/oxprivkeys\fR\. To protect the key a passphrase might be set using \fB\-\-ox\-passphrase\fR while generating the key\. +.br +If there is an existing private key for "OpenPGP for XMPP" created by another client (e\.g\. profanity) it might be imported using \fB\-\-ox\-import\-privkey\fR\. +.P +\fB\-\-ox\-genprivkey\-x25519\fR: Generate a private OpenPGP key (X25519) for the configured account (via config file or \fB\-u\fR and \fB\-p\fR) and publish the corresponding public key\. Go\-sendxmpp will save the key in \fB$XDG_DATA_HOME/go\-sendxmpp/oxprivkeys\fR or \fB$HOME/\.local/share/go\-sendxmpp/oxprivkeys\fR\. To protect the key a passphrase might be set using \fB\-\-ox\-passphrase\fR while generating the key\. .br If there is an existing private key for "OpenPGP for XMPP" created by another client (e\.g\. profanity) it might be imported using \fB\-\-ox\-import\-privkey\fR\. .P diff --git a/man/go-sendxmpp.1.html b/man/go-sendxmpp.1.html index 9a0a03e..dd82b0b 100644 --- a/man/go-sendxmpp.1.html +++ b/man/go-sendxmpp.1.html @@ -134,8 +134,18 @@ file location is specified with -f or --file.

Go-sendxmpp just uses the most recent key that is provided via pubsub and checks that it is not expired.

-

--ox-genprivkey: - Generate a public OpenPGP key for the given JID and publish the corresponding public key. +

--ox-genprivkey-rsa: + Generate a private OpenPGP key (RSA 4096 bit) for the configured account (via config file or -u and -p) + and publish the corresponding public key. + Go-sendxmpp will save the key in $XDG_DATA_HOME/go-sendxmpp/oxprivkeys or + $HOME/.local/share/go-sendxmpp/oxprivkeys. To protect the key a passphrase might be set + using --ox-passphrase while generating the key.
+ If there is an existing private key for "OpenPGP for XMPP" created by another client (e.g. profanity) + it might be imported using --ox-import-privkey.

+ +

--ox-genprivkey-x25519: + Generate a private OpenPGP key (X25519) for the configured account (via config file or -u and -p) + and publish the corresponding public key. Go-sendxmpp will save the key in $XDG_DATA_HOME/go-sendxmpp/oxprivkeys or $HOME/.local/share/go-sendxmpp/oxprivkeys. To protect the key a passphrase might be set using --ox-passphrase while generating the key.
diff --git a/man/go-sendxmpp.1.ronn b/man/go-sendxmpp.1.ronn index 80282ba..104e032 100644 --- a/man/go-sendxmpp.1.ronn +++ b/man/go-sendxmpp.1.ronn @@ -59,8 +59,18 @@ file location is specified with `-f` or `--file`. Go-sendxmpp just uses the most recent key that is provided via pubsub and checks that it is not expired. - `--ox-genprivkey`: - Generate a public OpenPGP key for the given JID and publish the corresponding public key. + `--ox-genprivkey-rsa`: + Generate a private OpenPGP key (RSA 4096 bit) for the configured account (via config file or `-u` and `-p`) + and publish the corresponding public key. + Go-sendxmpp will save the key in `$XDG_DATA_HOME/go-sendxmpp/oxprivkeys` or + `$HOME/.local/share/go-sendxmpp/oxprivkeys`. To protect the key a passphrase might be set + using `--ox-passphrase` while generating the key. + If there is an existing private key for "OpenPGP for XMPP" created by another client (e.g. profanity) + it might be imported using `--ox-import-privkey`. + + `--ox-genprivkey-x25519`: + Generate a private OpenPGP key (X25519) for the configured account (via config file or `-u` and `-p`) + and publish the corresponding public key. Go-sendxmpp will save the key in `$XDG_DATA_HOME/go-sendxmpp/oxprivkeys` or `$HOME/.local/share/go-sendxmpp/oxprivkeys`. To protect the key a passphrase might be set using `--ox-passphrase` while generating the key. diff --git a/ox.go b/ox.go index fa6264e..e536903 100644 --- a/ox.go +++ b/ox.go @@ -186,9 +186,10 @@ func oxStoreKey(location string, key string) error { return nil } -func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string) error { +func oxGenPrivKey(jid string, client *xmpp.Client, passphrase string, + keyType string) error { xmppURI := "xmpp:" + jid - key, err := crypto.GenerateKey(xmppURI, "", "x25519", 0) + key, err := crypto.GenerateKey(xmppURI, "", keyType, 4096) if err != nil { return err }