Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Dosch b98a071472
Add new parameter subject. 3 weeks ago
Martin Dosch 953de9c86d
Fix check for valid URIs. 3 weeks ago

@ -4,6 +4,9 @@
### Changed
- Move private Ox key into JID folder in ~/.local/share/go-sendxmpp.
### Added
- Add new parameter `--subject`.
## [v0.10.0] 2024-04-13
### Changed
- Fixed a race condition in receiving stanzas (requires go-xmpp >= v0.1.5).

@ -75,7 +75,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] [-a value] [-f value] [--headline] [--help] [-h value] [-j value] [-m value] [--muc-password value] [--oob-file value] [--ox] [--ox-delete-nodes] [--ox-genprivkey-rsa] [--ox-genprivkey-x25519] [--ox-import-privkey value] [--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [--timeout value] [--tls-version value] [-u value] [--version] [recipients…]
Usage: go-sendxmpp [-cdilnt] [-a value] [-f value] [--headline] [--help] [-h value] [-j value] [-m value] [--muc-password value] [--oob-file value] [--ox] [--ox-delete-nodes] [--ox-genprivkey-rsa] [--ox-genprivkey-x25519] [--ox-import-privkey value] [--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [-s value] [--timeout value] [--tls-version value] [-u value] [--version] [recipients…]
-a, --alias=value Set alias/nicknamefor chatrooms.
-c, --chatroom Send message to a chatroom.
-d, --debug Show debugging info.
@ -117,6 +117,8 @@ Usage: go-sendxmpp [-cdilnt] [-a value] [-f value] [--headline] [--help] [-h val
--scram-mech-pinning=value
Enforce the use of a certain SCRAM authentication mechanism.
--ssdp-off Disable XEP-0474: SASL SCRAM Downgrade Protection.
-s, --subject=value
Set message subject.
--timeout=value
Connection timeout in seconds. [10]
-t, --tls Use direct TLS.

@ -37,7 +37,10 @@ func validUTF8(s string) string {
func validURI(s string) (*url.URL, error) {
// Check if URI is valid
uri, err := url.ParseRequestURI(s)
return uri, fmt.Errorf("validURI: %w", err)
if err != nil {
return uri, fmt.Errorf("validURI: %w", err)
}
return uri, nil
}
func readFile(path string) (*bytes.Buffer, error) {

@ -136,6 +136,7 @@ func main() {
flagHeadline := getopt.BoolLong("headline", 0, "Send message as type headline.")
flagSCRAMPinning := getopt.StringLong("scram-mech-pinning", 0, "", "Enforce the use of a certain SCRAM authentication mechanism.")
flagSSDPOff := getopt.BoolLong("ssdp-off", 0, "Disable XEP-0474: SASL SCRAM Downgrade Protection.")
flagSubject := getopt.StringLong("subject", 's', "", "Set message subject.")
// Parse command line flags.
getopt.Parse()
@ -581,7 +582,7 @@ func main() {
continue
}
oxMessage, err := oxEncrypt(client, oxPrivKey,
recipient.Jid, recipient.OxKeyRing, message)
recipient.Jid, recipient.OxKeyRing, message, *flagSubject)
if err != nil {
fmt.Println("Ox: couldn't encrypt to",
recipient.Jid)
@ -596,6 +597,7 @@ func main() {
_, err = client.Send(xmpp.Chat{
Remote: recipient.Jid,
Type: msgType, Text: message,
Subject: *flagSubject,
})
if err != nil {
cancel()
@ -692,6 +694,7 @@ func main() {
_, err = client.Send(xmpp.Chat{
Remote: recipient.Jid,
Type: msgType, Ooburl: message, Text: message,
Subject: *flagSubject,
})
if err != nil {
fmt.Println("Couldn't send message to",
@ -700,9 +703,15 @@ func main() {
// (Hopefully) temporary workaround due to go-xmpp choking on URL encoding.
// Once this is fixed in the lib the http-upload case above can be reused.
case *flagOOBFile != "":
_, err = client.SendOrg("<message to='" + recipient.Jid + "' type='" +
msgType + "'><body>" + message + "</body><x xmlns='jabber:x:oob'><url>" +
message + "</url></x></message>")
var msg string
if *flagSubject != "" {
msg = fmt.Sprintf("<message to='%s' type='%s'><subject>%s</subject><body>%s</body><x xmlns='jabber:x:oob'><url>%s</url></x></message>",
recipient.Jid, msgType, *flagSubject, message, message)
} else {
msg = fmt.Sprintf("<message to='%s' type='%s'><body>%s</body><x xmlns='jabber:x:oob'><url>%s</url></x></message>",
recipient.Jid, msgType, message, message)
}
_, err = client.SendOrg(msg)
if err != nil {
fmt.Println("Couldn't send message to",
recipient.Jid)
@ -712,7 +721,7 @@ func main() {
continue
}
oxMessage, err := oxEncrypt(client, oxPrivKey,
recipient.Jid, recipient.OxKeyRing, message)
recipient.Jid, recipient.OxKeyRing, message, *flagSubject)
if err != nil {
fmt.Println("Ox: couldn't encrypt to", recipient.Jid)
continue
@ -726,6 +735,7 @@ func main() {
_, err = client.Send(xmpp.Chat{
Remote: recipient.Jid,
Type: msgType, Text: message,
Subject: *flagSubject,
})
if err != nil {
cancel()

@ -1,10 +1,10 @@
.\" generated with Ronn-NG/v0.9.1
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
.TH "GO\-SENDXMPP" "1" "April 2024" ""
.TH "GO\-SENDXMPP" "1" "May 2024" ""
.SH "NAME"
\fBgo\-sendxmpp\fR \- A tool to send messages to an XMPP contact or MUC\.
.SH "SYNOPSIS"
\fBgo\-sendxmpp [\-cdilnt] [\-a value] [\-f value] [\-\-headline] [\-\-help] [\-h value] [\-j value] [\-m value] [\-\-muc\-password value] [\-\-oob\-file value] [\-\-ox] [\-\-ox\-delete\-nodes] [\-\-ox\-genprivkey\-rsa] [\-\-ox\-genprivkey\-x25519] [\-\-ox\-import\-privkey value] [\-\-ox\-passphrase value] [\-p value] [\-\-raw] [\-\-scram\-mech\-pinning value] [\-\-ssdp\-off] [\-\-timeout value] [\-\-tls\-version value] [\-u value] [\-\-version] [recipients…]\fR
\fBgo\-sendxmpp [\-cdilnt] [\-a value] [\-f value] [\-\-headline] [\-\-help] [\-h value] [\-j value] [\-m value] [\-\-muc\-password value] [\-\-oob\-file value] [\-\-ox] [\-\-ox\-delete\-nodes] [\-\-ox\-genprivkey\-rsa] [\-\-ox\-genprivkey\-x25519] [\-\-ox\-import\-privkey value] [\-\-ox\-passphrase value] [\-p value] [\-\-raw] [\-\-scram\-mech\-pinning value] [\-\-ssdp\-off] [\-s value] [\-\-timeout value] [\-\-tls\-version value] [\-u value] [\-\-version] [recipients…]\fR
.SH "DESCRIPTION"
A tool to send messages to an XMPP contact or MUC inspired by \fBsendxmpp\fR\.
.br
@ -92,6 +92,9 @@ Enforce the use of a certain SCRAM authentication mechanism\. Currently go\-send
\fB\-\-ssdp\-off\fR
Disable XEP\-0474: SASL SCRAM Downgrade Protection\.
.TP
\fB\-s\fR, \fB\-\-subject\fR=[\fIvalue\fR]
Set message subject\.
.TP
\fB\-\-timeout=\fR[\fIvalue\fR]
Connection timeout in seconds\. (Default: 10)
.TP

@ -83,8 +83,8 @@
<p><code>go-sendxmpp [-cdilnt] [-a value] [-f value] [--headline] [--help] [-h value] [-j value] [-m value] [--muc-password value]
[--oob-file value] [--ox] [--ox-delete-nodes] [--ox-genprivkey-rsa] [--ox-genprivkey-x25519] [--ox-import-privkey value]
[--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [--timeout value] [--tls-version value] [-u value]
[--version] [recipients…]</code></p>
[--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [-s value] [--timeout value]
[--tls-version value] [-u value] [--version] [recipients…]</code></p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
@ -195,6 +195,9 @@ to prevent downgrade attacks (needs server support).</dd>
<dt><code>--ssdp-off</code></dt>
<dd>Disable XEP-0474: SASL SCRAM Downgrade Protection.</dd>
<dt>
<code>-s</code>, <code>--subject</code>=[<var>value</var>]</dt>
<dd>Set message subject.</dd>
<dt>
<code>--timeout=</code>[<var>value</var>]</dt>
<dd>Connection timeout in seconds. (Default: 10)</dd>
<dt>
@ -279,7 +282,7 @@ License: BSD 2-clause License</p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>April 2024</li>
<li class='tc'>May 2024</li>
<li class='tr'>go-sendxmpp(1)</li>
</ol>

@ -5,8 +5,8 @@ go-sendxmpp(1) -- A tool to send messages to an XMPP contact or MUC.
`go-sendxmpp [-cdilnt] [-a value] [-f value] [--headline] [--help] [-h value] [-j value] [-m value] [--muc-password value]
[--oob-file value] [--ox] [--ox-delete-nodes] [--ox-genprivkey-rsa] [--ox-genprivkey-x25519] [--ox-import-privkey value]
[--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [--timeout value] [--tls-version value] [-u value]
[--version] [recipients…]`
[--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [-s value] [--timeout value]
[--tls-version value] [-u value] [--version] [recipients…]`
## DESCRIPTION
@ -120,6 +120,9 @@ to prevent downgrade attacks (needs server support).
* `--ssdp-off`:
Disable XEP-0474: SASL SCRAM Downgrade Protection.
* `-s`, `--subject`=[<value>]:
Set message subject.
* `--timeout=`[<value>]:
Connection timeout in seconds. (Default: 10)

@ -669,7 +669,7 @@ func oxGetPublicKeyRing(client *xmpp.Client, iqc chan xmpp.IQ, recipient string)
return pubKeyRing, nil
}
func oxEncrypt(client *xmpp.Client, oxPrivKey *crypto.Key, recipient string, keyRing *crypto.KeyRing, message string) (string, error) {
func oxEncrypt(client *xmpp.Client, oxPrivKey *crypto.Key, recipient string, keyRing *crypto.KeyRing, message string, subject string) (string, error) {
if message == "" {
return "", nil
}
@ -696,6 +696,10 @@ func oxEncrypt(client *xmpp.Client, oxPrivKey *crypto.Key, recipient string, key
oxCryptMessageScRpad := oxCryptMessageSc.CreateElement("rpad")
oxCryptMessageScRpad.CreateText(getRpad(len(message)))
oxCryptMessageScPayload := oxCryptMessageSc.CreateElement("payload")
if subject != "" {
oxCryptMessageScPayloadSub := oxCryptMessageScPayload.CreateElement("subject")
oxCryptMessageScPayloadSub.CreateText(subject)
}
oxCryptMessageScPayloadBody := oxCryptMessageScPayload.CreateElement("body")
oxCryptMessageScPayloadBody.CreateAttr("xmlns", nsJabberClient)
oxCryptMessageScPayloadBody.CreateText(message)

Loading…
Cancel
Save