errwrp
Martin Dosch 11 months ago
parent 1def52c15c
commit 620130aded
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -14,7 +14,6 @@ import (
)
func connect(options xmpp.Options, directTLS bool) (*xmpp.Client, error) {
// Look up SRV records if server is not specified manually.
if options.Host == "" {
server := options.User[strings.Index(options.User, "@")+1:]

@ -21,7 +21,8 @@ import (
)
func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ,
jserver string, filePath string) string {
jserver string, filePath string,
) string {
var uploadComponent string
var maxFileSize int64

@ -17,7 +17,6 @@ import (
// and return it marshaled. Shamelessly stolen from
// mellium.im/xmpp/jid
func MarshalJID(input string) (string, error) {
var (
err error
localpart string

@ -432,7 +432,7 @@ func main() {
}
case *flagInteractive:
// Send in endless loop (for usage with e.g. "tail -f").
var reader = bufio.NewReader(os.Stdin)
reader := bufio.NewReader(os.Stdin)
for {
message, err = reader.ReadString('\n')
if err != nil {
@ -462,8 +462,10 @@ func main() {
log.Fatal(err)
}
default:
_, err = client.Send(xmpp.Chat{Remote: recipient.Jid,
Type: msgType, Text: message})
_, err = client.Send(xmpp.Chat{
Remote: recipient.Jid,
Type: msgType, Text: message,
})
if err != nil {
log.Fatal(err)
}
@ -546,8 +548,10 @@ func main() {
}
switch {
case *flagHTTPUpload != "":
_, err = client.Send(xmpp.Chat{Remote: recipient.Jid,
Type: msgType, Ooburl: message, Text: message})
_, err = client.Send(xmpp.Chat{
Remote: recipient.Jid,
Type: msgType, Ooburl: message, Text: message,
})
if err != nil {
fmt.Println("Couldn't send message to",
recipient.Jid)
@ -577,8 +581,10 @@ func main() {
log.Fatal(err)
}
default:
_, err = client.Send(xmpp.Chat{Remote: recipient.Jid,
Type: msgType, Text: message})
_, err = client.Send(xmpp.Chat{
Remote: recipient.Jid,
Type: msgType, Text: message,
})
if err != nil {
log.Fatal(err)
}

38
ox.go

@ -20,7 +20,8 @@ import (
)
func oxDeleteNodes(jid string, client *xmpp.Client,
iqc chan xmpp.IQ) error {
iqc chan xmpp.IQ,
) error {
nodeListRequest := etree.NewDocument()
nodeListRequest.WriteSettings.AttrSingleQuote = true
query := nodeListRequest.CreateElement("query")
@ -73,14 +74,14 @@ func oxDeleteNodes(jid string, client *xmpp.Client,
}
func oxDecrypt(m xmpp.Chat, client *xmpp.Client, iqc chan xmpp.IQ,
user string, oxPrivKey *crypto.Key) (string, time.Time, error) {
user string, oxPrivKey *crypto.Key,
) (string, time.Time, error) {
var cryptMsgByte []byte
var err error
sender := strings.Split(m.Remote, "/")[0]
for _, r := range m.OtherElem {
if r.XMLName.Space == nsOx {
cryptMsgByte, err =
base64.StdEncoding.DecodeString(r.InnerXML)
cryptMsgByte, err = base64.StdEncoding.DecodeString(r.InnerXML)
if err != nil {
return strError, time.Now(), err
}
@ -155,7 +156,8 @@ func isOxMsg(m xmpp.Chat) bool {
}
func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client,
iqc chan xmpp.IQ) error {
iqc chan xmpp.IQ,
) error {
xmppURI := "xmpp:" + jid
buffer, err := readFile(privKeyLocation)
if err != nil {
@ -225,7 +227,8 @@ func oxImportPrivKey(jid string, privKeyLocation string, client *xmpp.Client,
}
func oxPublishPubKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
pubKey *crypto.Key) error {
pubKey *crypto.Key,
) error {
keyCreated := time.Now().UTC().Format("2006-01-02T15:04:05Z")
fingerprint := strings.ToUpper(pubKey.GetFingerprint())
keySerialized, err := pubKey.Serialize()
@ -344,7 +347,7 @@ func oxGetPrivKeyLoc(jid string) (string, error) {
}
dataDir += "/go-sendxmpp/oxprivkeys/"
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
err = os.MkdirAll(dataDir, 0700)
err = os.MkdirAll(dataDir, 0o700)
if err != nil {
return strError, err
}
@ -377,7 +380,7 @@ func oxGetPubKeyLoc(fingerprint string) (string, error) {
}
dataDir += "/go-sendxmpp/oxpubkeys/"
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
err = os.MkdirAll(dataDir, 0700)
err = os.MkdirAll(dataDir, 0o700)
if err != nil {
return strError, err
}
@ -430,9 +433,9 @@ func oxStoreKey(location string, key string) error {
return err
}
if runtime.GOOS != "windows" {
_ = file.Chmod(os.FileMode(0600))
_ = file.Chmod(os.FileMode(0o600))
} else {
_ = file.Chmod(os.FileMode(0200))
_ = file.Chmod(os.FileMode(0o200))
}
_, err = file.Write([]byte(key))
if err != nil {
@ -446,7 +449,8 @@ func oxStoreKey(location string, key string) error {
}
func oxGenPrivKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
passphrase string, keyType string) error {
passphrase string, keyType string,
) error {
xmppURI := "xmpp:" + jid
key, err := crypto.GenerateKey(xmppURI, "", keyType, 4096)
if err != nil {
@ -487,7 +491,8 @@ func oxGenPrivKey(jid string, client *xmpp.Client, iqc chan xmpp.IQ,
}
func oxRecvPublicKeys(client *xmpp.Client, iqc chan xmpp.IQ, recipient string,
fingerprint string) (*crypto.KeyRing, error) {
fingerprint string,
) (*crypto.KeyRing, error) {
opkr := etree.NewDocument()
opkr.WriteSettings.AttrSingleQuote = true
opkrPs := opkr.CreateElement("pubsub")
@ -557,7 +562,8 @@ func oxRecvPublicKeys(client *xmpp.Client, iqc chan xmpp.IQ, recipient string,
}
func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ,
recipient string) (*crypto.KeyRing, error) {
recipient string,
) (*crypto.KeyRing, error) {
publicKeyRing, err := crypto.NewKeyRing(nil)
if err != nil {
return nil, err
@ -610,8 +616,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ,
if oxPubKeyListXMLPubsubItemsItemPkl == nil {
return nil, errors.New("ox: no keblic-keys-list element")
}
oxPubKeyListXMLPubsubItemsItemPklPm :=
oxPubKeyListXMLPubsubItemsItemPkl.SelectElements("pubkey-metadata")
oxPubKeyListXMLPubsubItemsItemPklPm := oxPubKeyListXMLPubsubItemsItemPkl.SelectElements("pubkey-metadata")
for _, r := range oxPubKeyListXMLPubsubItemsItemPklPm {
date := r.SelectAttr("date")
if date == nil {
@ -701,7 +706,8 @@ func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ,
}
func oxEncrypt(client *xmpp.Client, iqc chan xmpp.IQ, oxPrivKey *crypto.Key,
recipient string, keyRing *crypto.KeyRing, message string) (string, error) {
recipient string, keyRing *crypto.KeyRing, message string,
) (string, error) {
if message == "" {
return "", nil
}

@ -32,9 +32,11 @@ func findConfig() (string, error) {
if osConfigDir == "" {
osConfigDir = home + "/.config"
}
configFiles := [3]string{osConfigDir + "/go-sendxmpp/config",
configFiles := [3]string{
osConfigDir + "/go-sendxmpp/config",
osConfigDir + "/go-sendxmpp/sendxmpprc", home +
"/.sendxmpprc"}
"/.sendxmpprc",
}
for _, r := range configFiles {
// Check that the config file is existing.
@ -49,7 +51,6 @@ func findConfig() (string, error) {
// Opens the config file and returns the specified values
// for username, server and port.
func parseConfig(configPath string) (configuration, error) {
var (
output configuration
err error

@ -12,7 +12,8 @@ import (
)
func sendIQ(client *xmpp.Client, iqc chan xmpp.IQ, target string,
iQtype string, content string) (xmpp.IQ, error) {
iQtype string, content string,
) (xmpp.IQ, error) {
var iq xmpp.IQ
id := getID()
c := make(chan xmpp.IQ)
@ -27,7 +28,8 @@ func sendIQ(client *xmpp.Client, iqc chan xmpp.IQ, target string,
}
func getIQ(id string, c chan xmpp.IQ,
iqc chan xmpp.IQ) {
iqc chan xmpp.IQ,
) {
for {
iq := <-iqc
if iq.ID == id {

Loading…
Cancel
Save