errwrp
Martin Dosch 12 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) { func connect(options xmpp.Options, directTLS bool) (*xmpp.Client, error) {
// Look up SRV records if server is not specified manually. // Look up SRV records if server is not specified manually.
if options.Host == "" { if options.Host == "" {
server := options.User[strings.Index(options.User, "@")+1:] server := options.User[strings.Index(options.User, "@")+1:]

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

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

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

38
ox.go

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

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

@ -12,7 +12,8 @@ import (
) )
func sendIQ(client *xmpp.Client, iqc chan xmpp.IQ, target string, 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 var iq xmpp.IQ
id := getID() id := getID()
c := make(chan xmpp.IQ) 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, func getIQ(id string, c chan xmpp.IQ,
iqc chan xmpp.IQ) { iqc chan xmpp.IQ,
) {
for { for {
iq := <-iqc iq := <-iqc
if iq.ID == id { if iq.ID == id {

Loading…
Cancel
Save