Compare commits

...

2 Commits

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

@ -4,6 +4,9 @@
### Changed ### Changed
- Move private Ox key into JID folder in ~/.local/share/go-sendxmpp. - Move private Ox key into JID folder in ~/.local/share/go-sendxmpp.
### Added
- Add new parameter `--subject`.
## [v0.10.0] 2024-04-13 ## [v0.10.0] 2024-04-13
### Changed ### Changed
- Fixed a race condition in receiving stanzas (requires go-xmpp >= v0.1.5). - 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: the account details via command line options:
```plain ```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. -a, --alias=value Set alias/nicknamefor chatrooms.
-c, --chatroom Send message to a chatroom. -c, --chatroom Send message to a chatroom.
-d, --debug Show debugging info. -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 --scram-mech-pinning=value
Enforce the use of a certain SCRAM authentication mechanism. Enforce the use of a certain SCRAM authentication mechanism.
--ssdp-off Disable XEP-0474: SASL SCRAM Downgrade Protection. --ssdp-off Disable XEP-0474: SASL SCRAM Downgrade Protection.
-s, --subject=value
Set message subject.
--timeout=value --timeout=value
Connection timeout in seconds. [10] Connection timeout in seconds. [10]
-t, --tls Use direct TLS. -t, --tls Use direct TLS.

@ -37,7 +37,10 @@ func validUTF8(s string) string {
func validURI(s string) (*url.URL, error) { func validURI(s string) (*url.URL, error) {
// Check if URI is valid // Check if URI is valid
uri, err := url.ParseRequestURI(s) 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) { func readFile(path string) (*bytes.Buffer, error) {

@ -136,6 +136,7 @@ func main() {
flagHeadline := getopt.BoolLong("headline", 0, "Send message as type headline.") 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.") 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.") 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. // Parse command line flags.
getopt.Parse() getopt.Parse()
@ -581,7 +582,7 @@ func main() {
continue continue
} }
oxMessage, err := oxEncrypt(client, oxPrivKey, oxMessage, err := oxEncrypt(client, oxPrivKey,
recipient.Jid, recipient.OxKeyRing, message) recipient.Jid, recipient.OxKeyRing, message, *flagSubject)
if err != nil { if err != nil {
fmt.Println("Ox: couldn't encrypt to", fmt.Println("Ox: couldn't encrypt to",
recipient.Jid) recipient.Jid)
@ -596,6 +597,7 @@ func main() {
_, err = client.Send(xmpp.Chat{ _, err = client.Send(xmpp.Chat{
Remote: recipient.Jid, Remote: recipient.Jid,
Type: msgType, Text: message, Type: msgType, Text: message,
Subject: *flagSubject,
}) })
if err != nil { if err != nil {
cancel() cancel()
@ -692,6 +694,7 @@ func main() {
_, err = client.Send(xmpp.Chat{ _, err = client.Send(xmpp.Chat{
Remote: recipient.Jid, Remote: recipient.Jid,
Type: msgType, Ooburl: message, Text: message, Type: msgType, Ooburl: message, Text: message,
Subject: *flagSubject,
}) })
if err != nil { if err != nil {
fmt.Println("Couldn't send message to", fmt.Println("Couldn't send message to",
@ -700,9 +703,15 @@ func main() {
// (Hopefully) temporary workaround due to go-xmpp choking on URL encoding. // (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. // Once this is fixed in the lib the http-upload case above can be reused.
case *flagOOBFile != "": case *flagOOBFile != "":
_, err = client.SendOrg("<message to='" + recipient.Jid + "' type='" + var msg string
msgType + "'><body>" + message + "</body><x xmlns='jabber:x:oob'><url>" + if *flagSubject != "" {
message + "</url></x></message>") 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 { if err != nil {
fmt.Println("Couldn't send message to", fmt.Println("Couldn't send message to",
recipient.Jid) recipient.Jid)
@ -712,7 +721,7 @@ func main() {
continue continue
} }
oxMessage, err := oxEncrypt(client, oxPrivKey, oxMessage, err := oxEncrypt(client, oxPrivKey,
recipient.Jid, recipient.OxKeyRing, message) recipient.Jid, recipient.OxKeyRing, message, *flagSubject)
if err != nil { if err != nil {
fmt.Println("Ox: couldn't encrypt to", recipient.Jid) fmt.Println("Ox: couldn't encrypt to", recipient.Jid)
continue continue
@ -726,6 +735,7 @@ func main() {
_, err = client.Send(xmpp.Chat{ _, err = client.Send(xmpp.Chat{
Remote: recipient.Jid, Remote: recipient.Jid,
Type: msgType, Text: message, Type: msgType, Text: message,
Subject: *flagSubject,
}) })
if err != nil { if err != nil {
cancel() cancel()

@ -1,10 +1,10 @@
.\" generated with Ronn-NG/v0.9.1 .\" generated with Ronn-NG/v0.9.1
.\" http://github.com/apjanke/ronn-ng/tree/0.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" .SH "NAME"
\fBgo\-sendxmpp\fR \- A tool to send messages to an XMPP contact or MUC\. \fBgo\-sendxmpp\fR \- A tool to send messages to an XMPP contact or MUC\.
.SH "SYNOPSIS" .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" .SH "DESCRIPTION"
A tool to send messages to an XMPP contact or MUC inspired by \fBsendxmpp\fR\. A tool to send messages to an XMPP contact or MUC inspired by \fBsendxmpp\fR\.
.br .br
@ -92,6 +92,9 @@ Enforce the use of a certain SCRAM authentication mechanism\. Currently go\-send
\fB\-\-ssdp\-off\fR \fB\-\-ssdp\-off\fR
Disable XEP\-0474: SASL SCRAM Downgrade Protection\. Disable XEP\-0474: SASL SCRAM Downgrade Protection\.
.TP .TP
\fB\-s\fR, \fB\-\-subject\fR=[\fIvalue\fR]
Set message subject\.
.TP
\fB\-\-timeout=\fR[\fIvalue\fR] \fB\-\-timeout=\fR[\fIvalue\fR]
Connection timeout in seconds\. (Default: 10) Connection timeout in seconds\. (Default: 10)
.TP .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] <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] [--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] [--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [-s value] [--timeout value]
[--version] [recipients…]</code></p> [--tls-version value] [-u value] [--version] [recipients…]</code></p>
<h2 id="DESCRIPTION">DESCRIPTION</h2> <h2 id="DESCRIPTION">DESCRIPTION</h2>
@ -195,6 +195,9 @@ to prevent downgrade attacks (needs server support).</dd>
<dt><code>--ssdp-off</code></dt> <dt><code>--ssdp-off</code></dt>
<dd>Disable XEP-0474: SASL SCRAM Downgrade Protection.</dd> <dd>Disable XEP-0474: SASL SCRAM Downgrade Protection.</dd>
<dt> <dt>
<code>-s</code>, <code>--subject</code>=[<var>value</var>]</dt>
<dd>Set message subject.</dd>
<dt>
<code>--timeout=</code>[<var>value</var>]</dt> <code>--timeout=</code>[<var>value</var>]</dt>
<dd>Connection timeout in seconds. (Default: 10)</dd> <dd>Connection timeout in seconds. (Default: 10)</dd>
<dt> <dt>
@ -279,7 +282,7 @@ License: BSD 2-clause License</p>
<ol class='man-decor man-foot man foot'> <ol class='man-decor man-foot man foot'>
<li class='tl'></li> <li class='tl'></li>
<li class='tc'>April 2024</li> <li class='tc'>May 2024</li>
<li class='tr'>go-sendxmpp(1)</li> <li class='tr'>go-sendxmpp(1)</li>
</ol> </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] `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] [--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] [--ox-passphrase value] [-p value] [--raw] [--scram-mech-pinning value] [--ssdp-off] [-s value] [--timeout value]
[--version] [recipients…]` [--tls-version value] [-u value] [--version] [recipients…]`
## DESCRIPTION ## DESCRIPTION
@ -120,6 +120,9 @@ to prevent downgrade attacks (needs server support).
* `--ssdp-off`: * `--ssdp-off`:
Disable XEP-0474: SASL SCRAM Downgrade Protection. Disable XEP-0474: SASL SCRAM Downgrade Protection.
* `-s`, `--subject`=[<value>]:
Set message subject.
* `--timeout=`[<value>]: * `--timeout=`[<value>]:
Connection timeout in seconds. (Default: 10) Connection timeout in seconds. (Default: 10)

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

Loading…
Cancel
Save