This commit is contained in:
Martin Dosch 2022-05-05 23:00:04 +02:00
parent f00ffb2fb9
commit 8b5e9d3881
2 changed files with 36 additions and 22 deletions

47
main.go
View File

@ -276,22 +276,24 @@ func main() {
if *flagChatroom {
msgType = "groupchat"
// Join the MUCs.
println("Joining MUCs")
for _, recipient := range recipients {
for _, recipient := range recipientsList {
if *flagMUCPassword != "" {
dummyTime := time.Now()
_, err = client.JoinProtectedMUC(recipient.Jid, *flagResource,
_, err = client.JoinProtectedMUC(recipient, resource,
*flagMUCPassword, xmpp.NoHistory, 0, &dummyTime)
if err != nil {
fmt.Println("Couldn't join", recipient)
}
} else {
_, err = client.JoinMUCNoHistory(recipient.Jid, *flagResource)
}
if err != nil {
log.Fatal(err)
_, err = client.JoinMUCNoHistory(recipient, resource)
if err != nil {
fmt.Println("Couldn't join", recipient)
}
}
}
}
for _, r := range getopt.Args() {
for _, r := range recipientsList {
var re recipientsType
re.Jid = r
switch {
@ -447,14 +449,11 @@ func main() {
}
}
case *flagListen:
println("listening")
tz := time.Now().Location()
for {
v := <-msgc
println("received a msg")
switch {
case isOxMsg(v) && *flagOx:
println("is Ox")
msg, t, err := oxDecrypt(v, client, iqc, user,
oxPrivKey, groupchat)
if err != nil {
@ -464,14 +463,23 @@ func main() {
if msg == "" {
continue
}
bareFrom := strings.Split(v.Remote, "/")[0]
var bareFrom string
switch v.Type {
case "chat":
bareFrom = strings.Split(v.Remote, "/")[0]
case "groupchat":
bareFrom = v.Remote
default:
bareFrom = strings.Split(v.Remote, "/")[0]
}
// Print any messages if no recipients are specified
if len(recipients) == 0 {
fmt.Println(t.In(tz).Format(time.RFC3339), "[OX]",
bareFrom+":", msg)
} else {
for _, recipient := range recipients {
if bareFrom == strings.ToLower(recipient.Jid) {
if strings.Split(v.Remote, "/")[0] ==
strings.ToLower(recipient.Jid) {
fmt.Println(t.In(tz).Format(time.RFC3339),
"[OX]", bareFrom+":", msg)
}
@ -487,13 +495,22 @@ func main() {
} else {
t = v.Stamp
}
bareFrom := strings.Split(v.Remote, "/")[0]
var bareFrom string
switch v.Type {
case "chat":
bareFrom = strings.Split(v.Remote, "/")[0]
case "groupchat":
bareFrom = v.Remote
default:
bareFrom = strings.Split(v.Remote, "/")[0]
}
// Print any messages if no recipients are specified
if len(recipients) == 0 {
fmt.Println(t.In(tz).Format(time.RFC3339), bareFrom+":", v.Text)
} else {
for _, recipient := range recipients {
if bareFrom == strings.ToLower(recipient.Jid) {
if strings.Split(v.Remote, "/")[0] ==
strings.ToLower(recipient.Jid) {
fmt.Println(t.In(tz).Format(time.RFC3339),
bareFrom+":", v.Text)
}

11
ox.go
View File

@ -127,8 +127,10 @@ func oxDecrypt(m xmpp.Chat, client *xmpp.Client, iqc chan xmpp.IQ,
if jid == nil {
return "error", time.Now(), errors.New("ox: no jid attribute")
}
if strings.Split(jid.Value, "/")[0] != user {
return "error", time.Now(), errors.New("ox: encrypted for wrong user")
if !groupchat {
if strings.Split(jid.Value, "/")[0] != user {
return "error", time.Now(), errors.New("ox: encrypted for wrong user")
}
}
timestamp := signcrypt.SelectElement("time")
if timestamp == nil {
@ -616,19 +618,14 @@ func oxGetPublicKeyRingChatroom(client *xmpp.Client, iqc chan xmpp.IQ,
if jid == nil {
continue
}
println("Jid: ", jid.Value)
memberKeyRing, err := oxGetPublicKeyRing(client, iqc, jid.Value)
if err != nil {
println("error getting key")
continue
}
for _, key := range memberKeyRing.GetKeys() {
err = keyRing.AddKey(key)
if err != nil {
println("error adding key")
continue
} else {
println("key received", jid.Value)
}
}
}