diff --git a/bridge/config/config.go b/bridge/config/config.go index 16d2abd644..f1b147e1df 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -196,6 +196,7 @@ type Protocol struct { ShowTopicChange bool // slack ShowUserTyping bool // slack ShowEmbeds bool // discord + SkipEncrypted bool // xmpp SkipTLSVerify bool // IRC, mattermost SkipVersionCheck bool // mattermost StripNick bool // all protocols diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 6a291c5ad4..ff13aa5a8a 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -450,6 +450,30 @@ func (b *Bxmpp) parseChannel(remote string) string { return "" } +// isEncrypted reports whether the message is end-to-end encrypted and therefore +// cannot be relayed as readable text. +func isEncrypted(message xmpp.Chat) bool { + // OTR rides inside the plaintext body + if strings.HasPrefix(message.Text, "?OTR") { + return true + } + for _, e := range message.OtherElem { + switch { + case e.XMLName.Local == "encrypted" && + (e.XMLName.Space == "eu.siacs.conversations.axolotl" || + e.XMLName.Space == "urn:xmpp:omemo:2"): + return true // OMEMO + case e.XMLName.Local == "openpgp" && + e.XMLName.Space == "urn:xmpp:openpgp:0": + return true // OX (XEP-0373) + case e.XMLName.Local == "x" && + e.XMLName.Space == "jabber:x:encrypted": + return true // legacy OpenPGP (XEP-0027) + } + } + return false +} + // skipMessage skips messages that need to be skipped func (b *Bxmpp) skipMessage(message xmpp.Chat) bool { // skip messages from ourselves @@ -467,6 +491,11 @@ func (b *Bxmpp) skipMessage(message xmpp.Chat) bool { return true } + // skip encrypted messages if configured to do so + if b.GetBool("SkipEncrypted") && isEncrypted(message) { + return true + } + // do not show subjects on connect #732 if strings.Contains(message.Text, "has set the subject to:") && time.Since(b.startTime) < time.Second*5 { return true diff --git a/changelog.md b/changelog.md index 2df18c0269..3a43911215 100644 --- a/changelog.md +++ b/changelog.md @@ -40,6 +40,7 @@ - Log message type='error' as warnings for easier debugging ([#173](https://github.com/matterbridge-org/matterbridge/pull/173)) - Can now upload files from bytes in addition to sharing attachement URLs ([#23](https://github.com/matterbridge-org/matterbridge/pull/23/)) - Can now receive and download OOB attachments from XMPP channels to share with other bridges ([#23](https://github.com/matterbridge-org/matterbridge/pull/23/)) + - New setting `SkipEncrypted` to ignore encrypted messages (OTR, PGP, OMEMO) ([#217](https://github.com/matterbridge-org/matterbridge/pull/217/)) - discord - Replies will be included inline ([#124](https://github.com/matterbridge-org/matterbridge/pull/124), thanks @lekoOwO), by default like "(re name: message)". This is useful when bridging to destinations that do not understand replies, but distracting when the destination does. Can be disabled with `QuoteDisable=true` under your `[discord]` config. - New setting `EditMaxDays` to ignore edits of older messages. ([#199](https://github.com/matterbridge-org/matterbridge/pull/199)) diff --git a/docs/protocols/xmpp/settings.md b/docs/protocols/xmpp/settings.md index 3128af0406..a4ab48abad 100644 --- a/docs/protocols/xmpp/settings.md +++ b/docs/protocols/xmpp/settings.md @@ -61,6 +61,18 @@ Your nick in the rooms NoTLS=true ``` +## SkipEncrypted + +Do not relay encrypted messages (OTR, PGP, OMEMO). + +- Setting: **OPTIONAL** +- Format: *boolean* +- Example: + ```toml + SkipEncrypted=true + ``` + + ## UseDirectTLS Enables direct TLS connection to your server. Most servers by default only support StartTLS, diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 14d077b3ef..551529c603 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -273,6 +273,11 @@ SkipTLSVerify=true #OPTIONAL (default false) NoTLS=true +#Drop end-to-end encrypted messages (OMEMO, OTR, OpenPGP) instead of relaying +#their unusable plaintext fallback to other bridges. +#OPTIONAL (default false) +SkipEncrypted=false + ## RELOADABLE SETTINGS ## Settings below can be reloaded by editing the file