diff --git a/main.go b/main.go index 72ab94f..2b5e558 100644 --- a/main.go +++ b/main.go @@ -16,9 +16,9 @@ import ( "strings" "time" - "github.com/ProtonMail/gopenpgp/v2/crypto" // MIT License - "github.com/mattn/go-xmpp" // BSD-3-Clause - "github.com/pborman/getopt/v2" // BSD-3-Clause + _ "github.com/ProtonMail/gopenpgp/v2/crypto" // MIT License + "github.com/mattn/go-xmpp" // BSD-3-Clause + "github.com/pborman/getopt/v2" // BSD-3-Clause ) type configuration struct { @@ -258,18 +258,14 @@ func main() { } if *flagOxGenPrivKey != "" { - var oxPrivKey *crypto.Key validatedOwnJid, err := MarshalJID(*flagOxGenPrivKey) if err != nil { - // log.Fatal("Invalid JID:", *flagOxGenPrivKey) log.Fatal(err) } - oxPrivKey, err = oxGenPrivKey(validatedOwnJid, client) + err = oxGenPrivKey(validatedOwnJid, client) if err != nil { log.Fatal(err) } - // Print oxPrivKey to be able to compile as it is not yet used. - println(oxPrivKey) os.Exit(0) } diff --git a/ox.go b/ox.go index 3f95b67..8ce913e 100644 --- a/ox.go +++ b/ox.go @@ -72,25 +72,24 @@ func oxStorePrivKey(jid string, privKey string) error { return nil } -func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) { +func oxGenPrivKey(jid string, client *xmpp.Client) error { var iqOxPublishKey IQoxPublishKeyType var iqOxPublishKeyList IQoxPublishKeyListType xmppUri := "xmpp:" + jid key, err := crypto.GenerateKey(xmppUri, xmppUri, "x25519", 0) if err != nil { - return nil, err + return err } keySerialized, _ := key.Serialize() pubKey, err := key.GetPublicKey() if err != nil { - return nil, err + return err } pubKeyBase64 := base64.StdEncoding.EncodeToString(pubKey) err = oxStorePrivKey(jid, base64.StdEncoding.EncodeToString(keySerialized)) if err != nil { - // return nil, errors.New("Couldn't store private key:") log.Fatal(err) } fingerprint := key.GetFingerprint() @@ -109,14 +108,14 @@ func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) { opk, err := xml.Marshal(iqOxPublishKey) if err != nil { - return nil, err + return err } iqReply, err := sendIQ(client, jid, "set", string(opk)) if err != nil { - return nil, err + return err } if iqReply.Type != "result" { - return nil, errors.New("Error whil publishing public key.") + return errors.New("Error whil publishing public key.") } // TODO: Split GetPublicKey in GetPublicKeyList and GetPublicKey @@ -125,14 +124,14 @@ func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) { // upload. ownPubKeyFromPubsub, err := oxRecvPublicKey(client, jid, fingerprint) if err != nil { - return nil, errors.New("Couldn't successfully verify public key upload.") + return errors.New("Couldn't successfully verify public key upload.") } ownPubKeyFromPubsubSerialized, err := ownPubKeyFromPubsub.Serialize() if err != nil { - return nil, errors.New("Couldn't successfully verify public key upload.") + return errors.New("Couldn't successfully verify public key upload.") } if pubKeyBase64 != base64.StdEncoding.EncodeToString(ownPubKeyFromPubsubSerialized) { - return nil, errors.New("Couldn't successfully verify public key upload.") + return errors.New("Couldn't successfully verify public key upload.") } iqOxPublishKeyList.Xmlns = nsPubsub @@ -150,17 +149,17 @@ func oxGenPrivKey(jid string, client *xmpp.Client) (*crypto.Key, error) { opkl, err := xml.Marshal(iqOxPublishKeyList) if err != nil { - return nil, err + return err } iqReply, err = sendIQ(client, jid, "set", string(opkl)) if err != nil { - return nil, err + return err } if iqReply.Type != "result" { - return nil, errors.New("Error while publishing public key list.") + return errors.New("Error while publishing public key list.") } - return key, nil + return nil } func oxRecvPublicKey(client *xmpp.Client, recipient string, fingerprint string) (*crypto.Key, error) {