Skip to content

Commit

Permalink
Implement Ignore command
Browse files Browse the repository at this point in the history
Closes #19.
  • Loading branch information
mmilata committed Apr 10, 2014
1 parent 120bf6e commit fff7a54
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 10 deletions.
36 changes: 28 additions & 8 deletions README.mediawiki
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
= otr =

This module allows you to encrypt private conversations using the
[https://otr.cypherpunks.ca/ OTR protocol]. Several popular
[https://otr.cypherpunks.ca/software.php IRC clients] support OTR (usually requiring a plugin).
Expand Down Expand Up @@ -57,7 +55,7 @@ Shows the table of known fingerprints. The table has five columns:
Example:
<pre>
<alice> info
/msg *otr info
<*otr> +-------+-----------+----------------------------------------------+-----+---------------+
<*otr> | Peer | State | Fingerprint | Act | Trust |
<*otr> +-------+-----------+----------------------------------------------+-----+---------------+
Expand Down Expand Up @@ -85,9 +83,9 @@ phone, in person) that it is indeed the fingerprint used by your peer.

Example:
<pre>
<alice> trust bob
/msg *otr trust bob
<*otr> [bob] Fingerprint 94A1353B 60A58E73 82CE8999 CBBD7B92 5E9EBB87 trusted!
<alice> trust 378A8445 3FC3933C 73C917C8 BFE4C18B 5CE65CFC
/msg *otr trust 378A8445 3FC3933C 73C917C8 BFE4C18B 5CE65CFC
<*otr> [carol] Fingerprint 378A8445 3FC3933C 73C917C8 BFE4C18B 5CE65CFC trusted!
</pre>

Expand All @@ -110,14 +108,14 @@ disclosing it to each other.

This command is also used to reply to authentication requests started by the other side.

Example:
Example (you are alice):
<pre>
<alice> Let's authenticate with the answer to following question: what is my favorite book?
<alice> No capitals or punctuation.
<bob> OK.
</pre>
<pre>
<alice> auth bob the old man and the sea
/msg *otr auth bob the old man and the sea
<*otr> [bob] Initiated authentication.
(bob now does something similar in his client)
<*otr> [bob] Peer replied to authentication request.
Expand All @@ -136,7 +134,7 @@ clients that support OTRv3.

Example:
<pre>
<alice> authq bob [What is my favorite book (no caps)?] the old man and the sea
/msg *otr authq bob [What is my favorite book (no caps)?] the old man and the sea
<*otr> [bob] Initiated authentication.
(bob's client displays the question and he types the answer)
<*otr> [bob] Peer replied to authentication request.
Expand All @@ -153,6 +151,28 @@ key is automatically generated the first time it is needed.
Use with the '''--overwrite''' parameter to throw away the old key and generate
a new one.

==== ignore [--remove] [nick] ====
This command is used to maintain list of nicks for which all OTR functionality is disabled.
Wildcards can be used to match multiple nicks.

Useful when the other side does not like the whitespace OTR advertisements (e.g. NickServ on
freenode) or when their OTR plugin is broken and causes crashes.

Example:
<pre>
/msg *otr ignore
<*otr> OTR is disabled for following nicks:
<*otr> carol
<*otr> elvis
/msg *otr ignore Guest*
<*otr> Added Guest* to OTR ignore list.
/msg *otr ignore --remove carol
<*otr> Removed carol from OTR ignore list
/msg *otr ignore
<*otr> elvis
<*otr> Guest*
</pre>

== Security considerations ==
* In most cases it is best not to use this ZNC module and use OTR directly on the client you use to connect to the bouncer instead. This way you don't have to rely on the security of the server, which might be difficult to achieve.
* Use SSL to connect to the bouncer, otherwise the messages can be intercepted between ZNC and the client.
Expand Down
85 changes: 83 additions & 2 deletions otr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ friend class COtrGenKeyTimer;
CString m_sFPPath;
CString m_sInsTagPath;
list<CString> m_Buffer;
VCString m_vsIgnored;

CMutex m_GenKeyMutex;
// following members are protected by the mutex
Expand Down Expand Up @@ -492,6 +493,74 @@ friend class COtrGenKeyTimer;
GenerateKey(bOverwrite);
}

void SaveIgnores() {
CString sFlat = "";
bool bFirst = true;

for (VCString::const_iterator it = m_vsIgnored.begin();
it != m_vsIgnored.end();
it++) {
if (bFirst) {
bFirst = false;
} else {
sFlat += " ";
}
sFlat += *it;
}
SetNV("ignore", sFlat, true);
}

bool IsIgnored(const CString& sNick) {
for (VCString::const_iterator it = m_vsIgnored.begin();
it != m_vsIgnored.end();
it++) {
if (sNick.WildCmp(*it)) {
return true;
}
}
return false;
}

void CmdIgnore(const CString& sLine) {
if (sLine.Token(1).Equals("")) {
PutModuleBuffered("OTR is disabled for following nicks:");
for (VCString::const_iterator it = m_vsIgnored.begin();
it != m_vsIgnored.end();
it++) {
PutModuleBuffered(*it);
}
} else if (sLine.Token(1).Equals("--remove")) {
CString sNick = sLine.Token(2);
if (sNick.Equals("")) {
PutModuleBuffered("Usage: ignore --remove nick");
return;
}

bool bFound = false;
for (VCString::iterator it = m_vsIgnored.begin();
it != m_vsIgnored.end();
it++) {
if (it->Equals(sNick)) {
m_vsIgnored.erase(it);
bFound = true;
break;
}
}

if (bFound) {
SaveIgnores();
PutModuleBuffered("Removed " + Clr(Bold, sNick) + " from OTR ignore list.");
} else {
PutModuleBuffered("Not on OTR ignore list: " + sNick);
}
} else {
CString sNick = sLine.Token(1);
m_vsIgnored.push_back(sNick);
SaveIgnores();
PutModuleBuffered("Added " + Clr(Bold, sNick) + " to OTR ignore list.");
}
}

virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
// Initialize libgcrypt for multithreaded usage
gcry_error_t err;
Expand Down Expand Up @@ -578,10 +647,17 @@ friend class COtrGenKeyTimer;
AddCommand("AuthAbort", static_cast<CModCommand::ModCmdFunc>(&COtrMod::CmdAuthAbort),
"<nick>",
"Abort authentication with peer.");
AddCommand("Ignore", static_cast<CModCommand::ModCmdFunc>(&COtrMod::CmdIgnore),
"[--remove] [nick]",
"Manage list of nicks excluded from OTR encryption. "
"Accepts wildcards.");
AddCommand("GenKey", static_cast<CModCommand::ModCmdFunc>(&COtrMod::CmdGenKey),
"[--overwrite]",
"Generate new private key.");

// Load list of ignored nicks
GetNV("ignore").Split(" ", m_vsIgnored, false);

// Warn if we are not an administrator
// We should check if we are the only administrator but the user map may not be
// fully populated at this time.
Expand Down Expand Up @@ -666,15 +742,15 @@ friend class COtrGenKeyTimer;

virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) {
// Do not pass the message to libotr if sTarget is a channel
if (TargetIsChan(sTarget)) {
if (TargetIsChan(sTarget) || IsIgnored(sTarget)) {
return CONTINUE;
}

return SendEncrypted(sTarget, sMessage);
}

virtual EModRet OnUserAction(CString& sTarget, CString& sMessage) {
if (TargetIsChan(sTarget)) {
if (TargetIsChan(sTarget) || IsIgnored(sTarget)) {
return CONTINUE;
}

Expand All @@ -694,6 +770,11 @@ friend class COtrGenKeyTimer;
char *newmessage = NULL;
OtrlTLV *tlvs = NULL;
ConnContext *ctx = NULL;

if (IsIgnored(Nick.GetNick())) {
return CONTINUE;
}

const char *accountname = GetUser()->GetUserName().c_str();
res = otrl_message_receiving(m_pUserState, &m_xOtrOps, this, accountname,
PROTOCOL_ID, Nick.GetNick().c_str() /* @server? */,
Expand Down

0 comments on commit fff7a54

Please sign in to comment.