[packages/znc] Update to 1.2
aredridel
aredridel at pld-linux.org
Thu Jan 2 23:14:07 CET 2014
commit aed364b3d66eec3a334ef965c9f31fd4f514c83f
Author: Aria Stewart <aredridel at nbtsc.org>
Date: Wed Jan 1 21:29:55 2014 -0700
Update to 1.2
znc-crox-svn-fish.cpp => fish.c | 1225 +++++++++++++++++++++------------------
znc-crox-svn-admin.cpp | 228 --------
znc-crox-svn-antiidle.cpp | 93 ---
znc-crox-svn-statupdate.cpp | 103 ----
znc.spec | 100 +---
5 files changed, 672 insertions(+), 1077 deletions(-)
---
diff --git a/znc.spec b/znc.spec
index e616c4e..180f6cd 100644
--- a/znc.spec
+++ b/znc.spec
@@ -7,19 +7,14 @@
%bcond_with debug # Build debugging binaries.
Summary: An advanced IRC bouncer
Name: znc
-Version: 0.052
+Version: 1.2
Release: 0.1
License: GPL v2
Group: Daemons
URL: http://znc.sf.net/
-Source0: http://dl.sourceforge.net/znc/%{name}-%{version}.tar.gz
-# Source0-md5: 726046e3b44d811ededf4e850b5e0f06
-Source1: %{name}-crox-svn-admin.cpp
-Source2: %{name}-crox-svn-antiidle.cpp
-Source3: %{name}-crox-svn-fish.cpp
-Source4: %{name}-crox-svn-statupdate.cpp
-Source5: %{name}-cnu-log.cpp
-Patch0: %{name}-0.052-add_denysetvhost2.diff
+Source0: http://znc.in/releases/%{name}-%{version}.tar.gz
+# Source0-md5: ef18e5402a82cc3fcab5c2ac5c2e6f3b
+Source3: fish.c
%{?with_sasl:BuildRequires: cyrus-sasl-devel}
BuildRequires: libstdc++-devel
%{?with_ssl:BuildRequires: openssl-devel >= 0.9.8}
@@ -68,12 +63,12 @@ Requires: %{name} = %{version}-%{release}
A global module for the znc IRC bouncer. Allows ZNC users to join
internal channels and query other ZNC users on the same ZNC.
-%package module-saslauth
-Summary: znc saslauth global module
+%package module-sasl
+Summary: znc saslglobal module
Group: Daemons
Requires: %{name} = %{version}-%{release}
-%description module-saslauth
+%description module-sasl
A global module for the znc IRC bouncer. Allow users to authenticate
via SASL.
@@ -86,14 +81,6 @@ Requires: %{name} = %{version}-%{release}
A global module for the znc IRC bouncer. Allows you to add/remove/edit
users and settings on the fly via a web browser.
-%package module-antiidle
-Summary: znc antiidle user module
-Group: Daemons
-Requires: %{name} = %{version}-%{release}
-
-%description module-antiidle
-A user module for the znc IRC bouncer. Hides your idle time.
-
%package module-autoattach
Summary: znc autoattach user module
Group: Daemons
@@ -111,15 +98,6 @@ Requires: %{name} = %{version}-%{release}
%description module-autoop
A user module for the znc IRC bouncer. Auto op the good guys.
-%package module-away
-Summary: znc away user module
-Group: Daemons
-Requires: %{name} = %{version}-%{release}
-
-%description module-away
-A user module for the znc IRC bouncer. Stores messages while away,
-also auto away.
-
%package module-awaynick
Summary: znc awaynick user module
Group: Daemons
@@ -147,15 +125,6 @@ Requires: %{name} = %{version}-%{release}
A user module for the znc IRC bouncer. Encryption for channel/private
messages.
-%package module-email
-Summary: znc email user module
-Group: Daemons
-Requires: %{name} = %{version}-%{release}
-
-%description module-email
-A user module for the znc IRC bouncer. Monitors email activity on
-local disk /var/mail/user.
-
%package module-fish
Summary: znc fish user module
Group: Daemons
@@ -234,15 +203,6 @@ Requires: %{name} = %{version}-%{release}
A user module for the znc IRC bouncer. Have your unix shell in a query
window right inside of your IRC client.
-%package module-statupdate
-Summary: znc statupdate user module
-Group: Daemons
-Requires: %{name} = %{version}-%{release}
-
-%description module-statupdate
-A user module for the znc IRC bouncer. StatUpdate writes users online
-status into a text file.
-
%package module-stickychan
Summary: znc stickychan user module
Group: Daemons
@@ -273,12 +233,7 @@ modules.
%prep
%setup -q
-%patch0 -p1
-cp %{SOURCE1} modules/admin.cpp
-cp %{SOURCE2} modules/antiidle.cpp
cp %{SOURCE3} modules/fish.cpp
-cp %{SOURCE4} modules/statupdate.cpp
-cp %{SOURCE5} modules/log.cpp
mv modules/sample.cpp .
%build
@@ -286,7 +241,7 @@ mv modules/sample.cpp .
--with-module-prefix=%{_libdir}/znc \
%{!?with_ssl:--disable-openssl} \
%{?with_sasl:--enable-sasl} \
- %{!?with_perl:--disable-perl} \
+ %{?with_perl:--enable-perl} \
%{?with_ipv6:--enable-ipv6} \
%{?with_debug:--enable-debug}
%{__make}
@@ -301,12 +256,9 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(644,root,root,755)
-%doc AUTHORS LICENSE README znc.conf
+%doc AUTHORS LICENSE README.md
%attr(755,root,root) %{_bindir}/znc
-
-%files module-admin
-%defattr(644,root,root,755)
-%{_libdir}/znc/admin.so
+%{_mandir}/man1/znc.1*
%files module-imapauth
%defattr(644,root,root,755)
@@ -315,8 +267,11 @@ rm -rf $RPM_BUILD_ROOT
%if %{with perl}
%files module-modperl
%defattr(644,root,root,755)
-%{_libdir}/znc/modperl.pm
+%{_libdir}/znc/modperl/ZNC.pm
+%{_libdir}/znc/perleval.pm
%{_libdir}/znc/modperl.so
+%{_libdir}/znc/modperl/ZNC.so
+%{_libdir}/znc/modperl/startup.pl
%endif
%files module-partyline
@@ -324,19 +279,16 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/znc/partyline.so
%if %{with sasl}
-%files module-saslauth
+%files module-sasl
%defattr(644,root,root,755)
-%{_libdir}/znc/saslauth.so
+%{_libdir}/znc/sasl.so
%endif
%files module-webadmin
%defattr(644,root,root,755)
%{_libdir}/znc/webadmin.so
-%{_libdir}/znc/webadmin/skins/*
-
-%files module-antiidle
-%defattr(644,root,root,755)
-%{_libdir}/znc/antiidle.so
+%{_datadir}/znc/webskins
+%{_datadir}/znc/modules/webadmin/
%files module-autoattach
%defattr(644,root,root,755)
@@ -346,12 +298,6 @@ rm -rf $RPM_BUILD_ROOT
%defattr(644,root,root,755)
%{_libdir}/znc/autoop.so
-%if %{with ssl}
-%files module-away
-%defattr(644,root,root,755)
-%{_libdir}/znc/away.so
-%endif
-
%files module-awaynick
%defattr(644,root,root,755)
%{_libdir}/znc/awaynick.so
@@ -366,10 +312,6 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/znc/crypt.so
%endif
-%files module-email
-%defattr(644,root,root,755)
-%{_libdir}/znc/email.so
-
%if %{with ssl}
%files module-fish
%defattr(644,root,root,755)
@@ -412,10 +354,6 @@ rm -rf $RPM_BUILD_ROOT
%defattr(644,root,root,755)
%{_libdir}/znc/shell.so
-%files module-statupdate
-%defattr(644,root,root,755)
-%{_libdir}/znc/statupdate.so
-
%files module-stickychan
%defattr(644,root,root,755)
%{_libdir}/znc/stickychan.so
@@ -428,5 +366,5 @@ rm -rf $RPM_BUILD_ROOT
%defattr(644,root,root,755)
%doc sample.cpp
%attr(755,root,root) %{_bindir}/znc-buildmod
-%attr(755,root,root) %{_bindir}/znc-config
+%{_mandir}/man1/znc-buildmod.1*
%{_includedir}/znc
diff --git a/znc-crox-svn-fish.cpp b/fish.c
similarity index 69%
rename from znc-crox-svn-fish.cpp
rename to fish.c
index 7e9c071..1c16bc9 100644
--- a/znc-crox-svn-fish.cpp
+++ b/fish.c
@@ -1,572 +1,653 @@
-#include "main.h"
-#include "User.h"
-#include "Nick.h"
-#include "Modules.h"
-#include "Chan.h"
-#include "String.h"
-
-#include <string.h>
-
-#include <netinet/in.h>
-
-#include <openssl/opensslv.h>
-#include <openssl/blowfish.h>
-
-#define REQUIRESSL 1
-
-#if (OPENSSL_VERSION_NUMBER < 0x0090800f)
-#error "We require openssl >= 0.9.8"
-#endif
-
-/*
- Public Base64 conversion tables
-*/
-unsigned char B64ABC[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-unsigned char b64buf[256];
-
-
-/*
- void initb64();
- Initializes the base64->base16 conversion tab.
- Call this function once when your program starts.
- and always after your B64 table has been changed.
-*/
-void initb64(){
- unsigned int i;
- for (i=0; i<256; i++) b64buf[i]=0x00;
- for (i=0; i<64; i++) b64buf[(B64ABC[i])]=i;
-}
-
-/*
- int b64toh(lpBase64String, lpDestinationBuffer);
- Converts base64 string b to hexnumber d.
- Returns size of hexnumber in bytes.
-*/
-int b64toh(char *b, char *d){
- unsigned int i,k,l;
-
- l=strlen(b);
- if (l<2) return 0;
- for (i=l-1;i>-1;i--){
- if (b64buf[(b[i])]==0) l--;
- else break;
- }
-
- if (l<2) return 0;
- i=0, k=0;
- while (1) {
- i++;
- if (k+1<l) d[i-1]=((b64buf[(b[k])])<<2);
- else break;
- k++;
- if (k<l) d[i-1]|=((b64buf[(b[k])])>>4);
- else break;
- i++;
- if (k+1<l) d[i-1]=((b64buf[(b[k])])<<4);
- else break;
- k++;
- if (k<l) d[i-1]|=((b64buf[(b[k])])>>2);
- else break;
- i++;
- if (k+1<l) d[i-1]=((b64buf[(b[k])])<<6);
- else break;
- k++;
- if (k<l) d[i-1]|=(b64buf[(b[k])]);
- else break;
- k++;
- }
- return i-1;
-}
-
-/*
- int htob64(lpHexNumber, lpDestinationBuffer);
- Converts hexnumber h (with length l bytes) to base64 string d.
- Returns length of base64 string.
-*/
-int htob64(char *h, char *d, unsigned int l){
- unsigned int i,j,k;
- unsigned char m,t;
-
- if (!l) return 0;
- l<<=3; // no. bits
- m=0x80;
- for (i=0,j=0,k=0,t=0; i<l; i++){
- if (h[(i>>3)]&m) t|=1;
- j++;
- if (!(m>>=1)) m=0x80;
- if (!(j%6)) {
- d[k]=B64ABC[t];
- t&=0;
- k++;
- }
- t<<=1;
- }
- m=5-(j%6);
- t<<=m;
- if (m) {
- d[k]=B64ABC[t];
- k++;
- }
- d[k]&=0;
- return strlen(d);
-}
-
-unsigned char B64[]="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
-char *prime1080="FBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783EB68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE299EFA7BA66DEAFEFBEFBF0B7D8B";
-
-int base64dec(char c)
-{
- int i;
-
- for (i = 0; i < 64; i++)
- if (B64[i] == c) return i;
-
- return 0;
-}
-
-char *encrypts(char *key,char *str) {
- char *result;
- unsigned int length;
- unsigned int left,right;
- char *s,*d;
- unsigned char *p;
- BF_KEY bfkey;
- int i;
-
- if(key==NULL||str==NULL) return NULL;
-
- length=strlen(str);
- BF_set_key(&bfkey, strlen(key), (const unsigned char *)key);
-
- s=(char *)malloc(length+9);
-
- strncpy(s,str,length);
- memset(s+length,0,9);
-
- result=(char *)malloc(((length%8==0) ? length/8*12 : 12+length/8*12)+1);
-
- p=(unsigned char *)s;
- d=result;
-
- while(*p) {
- BF_ecb_encrypt((const unsigned char *)p, (unsigned char *)p, &bfkey, BF_ENCRYPT);
- left = ((*p++) << 24);
- left += ((*p++) << 16);
- left += ((*p++) << 8);
- left += (*p++);
- right = ((*p++) << 24);
- right += ((*p++) << 16);
- right += ((*p++) << 8);
- right += (*p++);
- for (i = 0; i < 6; i++) {
- *d++=B64[right & 0x3f];
- right = (right >> 6);
- }
-
- for (i = 0; i < 6; i++) {
- *d++=B64[left & 0x3f];
- left = (left >> 6);
- }
- }
- *d = '\0';
-
- memset(s,0,length+9);
- free(s);
- return result;
-}
-
-char *decrypts(char *key, char *str) {
- char *result;
- unsigned int length;
- unsigned int left,right;
- int i;
- char *d;
- unsigned char *c;
- BF_KEY bfkey;
-
- if(key==NULL||str==NULL) return NULL;
-
- length=strlen(str);
- BF_set_key(&bfkey,strlen(key),(const unsigned char *)key);
-
- result=(char *)malloc(length/12*8);
- c=(unsigned char *)result;
- d=str;
- while(*d) {
- right=0;
- left=0;
- for (i = 0; i < 6; i++) right |= (base64dec(*d++)) << (i * 6);
- for (i = 0; i < 6; i++) left |= (base64dec(*d++)) << (i * 6);
- right=htonl(right);
- left=htonl(left);
- memcpy(c,&left,4);
- memcpy(c+4,&right,4);
- BF_ecb_encrypt(c,c,&bfkey,BF_DECRYPT);
- c+=8;
- }
- *c='\0';
- return result;
-}
-
-class CKeyExchangeTimer : public CTimer {
-public:
- CKeyExchangeTimer(CModule* pModule)
- : CTimer(pModule, 5, 0, "KeyExchangeTimer", "Key exchange timer removes stale exchanges") {}
-
-protected:
- virtual void RunJob();
-};
-
-class CFishMod : public CModule {
-public:
- MODCONSTRUCTOR(CFishMod) {}
- virtual ~CFishMod() {
- }
-
- virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage) {
- CString command = sMessage.Token(0);
-
- if (command.CaseCmp("DH1080_INIT") == 0) {
- CString sPriv_Key;
- CString sPub_Key;
- CString sOtherPub_Key;
- CString sSecretKey;
-
- PutModule("Received DH1080 public key from " + Nick.GetNick() + ", sending mine...");
- DH1080_gen(sPriv_Key, sPub_Key);
- sOtherPub_Key = sMessage.Token(1);
- PutIRC("NOTICE " + Nick.GetNick() + " :DH1080_FINISH " + sPub_Key);
- DH1080_comp(sPriv_Key, sOtherPub_Key, sSecretKey);
- SetNV(Nick.GetNick().AsLower(), sSecretKey);
- PutModule("Key for " + Nick.GetNick() + " successfully set.");
- return HALT;
- } else if (command.CaseCmp("DH1080_FINISH") == 0) {
- CString sPriv_Key;
- CString sOtherPub_Key;
- CString sSecretKey;
-
- sOtherPub_Key = sMessage.Token(1);
- map<CString, pair<time_t, CString> >::iterator it = m_msKeyExchange.find(Nick.GetNick().AsLower());
- if (it == m_msKeyExchange.end()) {
- PutModule("Received unexpected DH1080_FINISH from " + Nick.GetNick() + ".");
- } else {
- sPriv_Key = it->second.second;
- DH1080_comp(sPriv_Key, sOtherPub_Key, sSecretKey);
- SetNV(Nick.GetNick().AsLower(), sSecretKey);
- PutModule("Key for " + Nick.GetNick() + " successfully set.");
- m_msKeyExchange.erase(Nick.GetNick().AsLower());
- }
- return HALT;
- } else {
- FilterIncoming(Nick.GetNick(), Nick, sMessage);
- }
-
- return CONTINUE;
- }
-
- virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) {
- MCString::iterator it = FindNV(sTarget.AsLower());
-
- if (it != EndNV()) {
- CChan* pChan = m_pUser->FindChan(sTarget);
- if ((pChan) && (pChan->KeepBuffer())) {
- pChan->AddBuffer(":" + m_pUser->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage);
- }
- char * cMsg = encrypts((char *)it->second.c_str(), (char *)sMessage.c_str());
-
- CString sMsg = "+OK " + CString(cMsg);
- PutIRC("PRIVMSG " + sTarget + " :" + sMsg);
-
- free(cMsg);
- return HALTCORE;
- }
-
- return CONTINUE;
- }
-
- virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage) {
- MCString::iterator it = FindNV(sTarget.AsLower());
-
- if (it != EndNV()) {
- CChan* pChan = m_pUser->FindChan(sTarget);
- if ((pChan) && (pChan->KeepBuffer())) {
- pChan->AddBuffer(":" + m_pUser->GetIRCNick().GetNickMask() + " NOTICE " + sTarget + " :" + sMessage);
- }
- char * cMsg = encrypts((char *)it->second.c_str(), (char *)sMessage.c_str());
-
- CString sMsg = "+OK " + CString(cMsg);
- PutIRC("NOTICE " + sTarget + " :" + sMsg);
-
- free(cMsg);
- return HALTCORE;
- }
-
- return CONTINUE;
-
- }
-
- virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) {
- FilterIncoming(Nick.GetNick(), Nick, sMessage);
- return CONTINUE;
- }
-
- virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) {
- FilterIncoming(Channel.GetName(), Nick, sMessage);
- return CONTINUE;
- }
-
- void FilterIncoming(const CString& sTarget, CNick& Nick, CString& sMessage) {
- if (sMessage.Left(4) == "+OK " || sMessage.Left(5) == "mcps ") {
- MCString::iterator it = FindNV(sTarget.AsLower());
-
- if (it != EndNV()) {
- if (sMessage.Left(4) == "+OK ") {
- sMessage.LeftChomp(4);
- } else if (sMessage.Left(5) == "mcps ") {
- sMessage.LeftChomp(5);
- }
-
- unsigned int msg_len = strlen(sMessage.c_str());
-
- if ((strspn(sMessage.c_str(), (char *)B64) != msg_len) || msg_len < 12) {
- return;
- }
-
- unsigned int mark_broken_block = 0;
-
- if (msg_len != (msg_len/12)*12) {
- msg_len = msg_len - (msg_len/12)*12;
- sMessage.RightChomp(msg_len);
- mark_broken_block = 1;
- }
-
- char *cMsg = decrypts((char *)it->second.c_str(), (char *)sMessage.c_str());
- sMessage = CString(cMsg);
-
- if (mark_broken_block) {
- sMessage += " \002&\002";
- }
-
- free(cMsg);
- }
- }
- }
-
- virtual void OnModCommand(const CString& sCommand) {
- CString sCmd = sCommand.Token(0);
-
- if (sCmd.CaseCmp("DELKEY") == 0) {
- CString sTarget = sCommand.Token(1);
-
- if (!sTarget.empty()) {
- if (DelNV(sTarget.AsLower())) {
- PutModule("Target [" + sTarget + "] deleted");
- } else {
- PutModule("Target [" + sTarget + "] not found");
- }
- } else {
- PutModule("Usage DelKey <#chan|Nick>");
- }
- } else if (sCmd.CaseCmp("SETKEY") == 0) {
- CString sTarget = sCommand.Token(1);
- CString sKey = sCommand.Token(2, true);
-
- if (!sKey.empty()) {
- SetNV(sTarget.AsLower(), sKey);
- PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
- } else {
- PutModule("Usage: SetKey <#chan|Nick> <Key>");
- }
- } else if (sCmd.CaseCmp("SHOWKEY") == 0) {
- CString sTarget = sCommand.Token(1);
-
- if (!sTarget.empty()) {
- MCString::iterator it = FindNV(sTarget.AsLower());
-
- if (it != EndNV()) {
- PutModule("Target key is " + it->second);
- } else {
- PutModule("Target not found.");
- }
- } else {
- PutModule("Usage ShowKey <#chan|Nick>");
- }
- } else if (sCmd.CaseCmp("LISTKEYS") == 0) {
- if (BeginNV() == EndNV()) {
- PutModule("You have no encryption keys set.");
- } else {
- CTable Table;
- Table.AddColumn("Target");
- Table.AddColumn("Key");
-
- for (MCString::iterator it = BeginNV(); it != EndNV(); it++) {
- Table.AddRow();
- Table.SetCell("Target", it->first);
- Table.SetCell("Key", it->second);
- }
-
- if (Table.size()) {
- unsigned int uTableIdx = 0;
- CString sLine;
-
- while (Table.GetLine(uTableIdx++, sLine)) {
- PutModule(sLine);
- }
- }
- }
- } else if (sCmd.CaseCmp("KEYX") == 0) {
- CString sTarget = sCommand.Token(1);
-
- if (sTarget.empty()) {
- PutModule("You did not specify a target for the key exchange.");
- } else {
- map<CString, pair<time_t, CString> >::iterator it = m_msKeyExchange.find(sTarget.AsLower());
- if (it != m_msKeyExchange.end()) {
- PutModule("Keyexchange with " + sTarget + " already in progress.");
- } else {
- CString sPriv_Key;
- CString sPub_Key;
-
- DH1080_gen(sPriv_Key, sPub_Key);
- m_msKeyExchange.insert(make_pair(sTarget, make_pair(time(NULL), sPriv_Key)));
- PutIRC("NOTICE " + sTarget + " :DH1080_INIT " + sPub_Key);
- PutModule("Sent my DH1080 public key to " + sTarget + ", waiting for reply ...");
- if (FindTimer("KeyExchangeTimer") == NULL) {
- AddTimer(new CKeyExchangeTimer(this));
- }
- }
- }
- } else if (sCmd.CaseCmp("HELP") == 0) {
- PutModule("Try: SetKey, DelKey, ShowKey, ListKeys");
- } else {
- PutModule("Unknown command, try 'Help'");
- }
- }
-
- void DelStaleKeyExchanges(time_t iTime) {
- for (map<CString, pair<time_t, CString> >::const_iterator it = m_msKeyExchange.begin(); it != m_msKeyExchange.end(); it++) {
- if (iTime - 5 >= it->second.first) {
- PutModule("Keyexchange with " + it->first + " did expire before completition.");
- m_msKeyExchange.erase(it->first);
- }
- }
- if (m_msKeyExchange.size() <= 0) {
- RemTimer("KeyExchangeTimer");
- }
- }
-
-private:
-
- void DH1080_gen(CString& sPriv_Key, CString& sPub_Key) {
- sPriv_Key = "";
- sPub_Key = "";
-
- unsigned char raw_buf[200];
- unsigned long len;
- unsigned char *a, *b;
-
- DH *dh;
- BIGNUM *b_prime=NULL;
- BIGNUM *b_generator=NULL;
-
- initb64();
-
- dh=DH_new();
-
- if (!BN_hex2bn(&b_prime, prime1080)) {
- return;
- }
-
- if (!BN_dec2bn(&b_generator, "2")) {
- return;
- }
-
- dh->p=b_prime;
- dh->g=b_generator;
-
- if (!DH_generate_key(dh)) {
- return;
- }
-
- len = BN_num_bytes(dh->priv_key);
- a = (unsigned char *)malloc(len);
- BN_bn2bin(dh->priv_key,a);
-
- memset(raw_buf, 0, 200);
- htob64((char *)a, (char *)raw_buf, len);
- sPriv_Key = CString((char *)raw_buf);
- len=BN_num_bytes(dh->pub_key);
- b = (unsigned char *)malloc(len);
- BN_bn2bin(dh->pub_key,b);
- memset(raw_buf, 0, 200);
- htob64((char *)b, (char *)raw_buf, len);
- sPub_Key = CString((char *)raw_buf);
- DH_free(dh);
- free(a);
- free(b);
- }
-
-
- void DH1080_comp(CString& sPriv_Key, CString& sOtherPub_Key, CString& sSecret_Key) {
- int len;
- unsigned char SHA256digest[32];
- char *key;
- BIGNUM *b_prime=NULL;
- BIGNUM *b_myPrivkey=NULL;
- BIGNUM *b_HisPubkey=NULL;
- BIGNUM *b_generator=NULL;
- DH *dh;
- CString sSHA256digest;
- unsigned char raw_buf[200];
-
- if (!BN_hex2bn(&b_prime, prime1080)) {
- return;
- }
-
- if (!BN_dec2bn(&b_generator, "2")) {
- return;
- }
-
- dh=DH_new();
- dh->p=b_prime;
- dh->g=b_generator;
-
- memset(raw_buf, 0, 200);
- len = b64toh((char *)sPriv_Key.c_str(), (char *)raw_buf);
- b_myPrivkey=BN_bin2bn(raw_buf, len, NULL);
- dh->priv_key=b_myPrivkey;
-
- memset(raw_buf, 0, 200);
- len = b64toh((char *)sOtherPub_Key.c_str(), (char *)raw_buf);
-
- b_HisPubkey=BN_bin2bn(raw_buf, len, NULL);
-
- key=(char *)malloc(DH_size(dh));
- memset(key, 0, DH_size(dh));
- len=DH_compute_key((unsigned char *)key, b_HisPubkey, dh);
- SHA256_CTX c;
- SHA256_Init(&c);
- memset(SHA256digest, 0, 32);
- SHA256_Update(&c, key, len);
- SHA256_Final(SHA256digest, &c);
- memset(raw_buf, 0, 200);
- len = htob64((char *)SHA256digest, (char *)raw_buf, 32);
- sSecret_Key = "";
- sSecret_Key.append((char *)raw_buf, len);
-
- DH_free(dh);
- BN_clear_free(b_HisPubkey);
- free(key);
- }
-
- map<CString, pair<time_t, CString> > m_msKeyExchange;
-
-};
-
-void CKeyExchangeTimer::RunJob() {
- CFishMod *p = (CFishMod *)m_pModule;
- p->DelStaleKeyExchanges(time(NULL));
-}
-
-MODULEDEFS(CFishMod, "FiSH encryption for channel/private messages")
+#include "znc/main.h"
+#include "znc/User.h"
+#include "znc/Nick.h"
+#include "znc/Modules.h"
+#include "znc/Chan.h"
+#include "znc/IRCNetwork.h"
+
+#include <string.h>
+using std::pair;
+using std::map;
+
+#include <netinet/in.h>
+
+#include <openssl/opensslv.h>
+#include <openssl/blowfish.h>
+
+#define REQUIRESSL 1
+
+#if (OPENSSL_VERSION_NUMBER < 0x0090800f)
+#error "We require openssl >= 0.9.8"
+#endif
+
+/*
+ Public Base64 conversion tables
+*/
+unsigned char B64ABC[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+unsigned char b64buf[256];
+
+
+/*
+ void initb64();
+ Initializes the base64->base16 conversion tab.
+ Call this function once when your program starts.
+ and always after your B64 table has been changed.
+*/
+void initb64(){
+ unsigned int i;
+ for (i=0; i<256; i++) b64buf[i]=0x00;
+ for (i=0; i<64; i++) b64buf[(B64ABC[i])]=i;
+}
+
+/*
+ int b64toh(lpBase64String, lpDestinationBuffer);
+ Converts base64 string b to hexnumber d.
+ Returns size of hexnumber in bytes.
+*/
+int b64toh(char *b, char *d){
+ int i,k,l;
+
+ l=strlen(b);
+ if (l<2) return 0;
+ for (i=l-1;i>-1;i--){
+ if (b64buf[(unsigned char)(b[i])]==0) l--;
+ else break;
+ }
+
+ if (l<2) return 0;
+ i=0, k=0;
+ while (1) {
+ i++;
+ if (k+1<l) d[i-1]=((b64buf[(unsigned char)(b[k])])<<2);
+ else break;
+ k++;
+ if (k<l) d[i-1]|=((b64buf[(unsigned char)(b[k])])>>4);
+ else break;
+ i++;
+ if (k+1<l) d[i-1]=((b64buf[(unsigned char)(b[k])])<<4);
+ else break;
+ k++;
+ if (k<l) d[i-1]|=((b64buf[(unsigned char)(b[k])])>>2);
+ else break;
+ i++;
+ if (k+1<l) d[i-1]=((b64buf[(unsigned char)(b[k])])<<6);
+ else break;
+ k++;
+ if (k<l) d[i-1]|=(b64buf[(unsigned char)(b[k])]);
+ else break;
+ k++;
+ }
+ return i-1;
+}
+
+/*
+ int htob64(lpHexNumber, lpDestinationBuffer);
+ Converts hexnumber h (with length l bytes) to base64 string d.
+ Returns length of base64 string.
+*/
+int htob64(char *h, char *d, unsigned int l){
+ unsigned int i,j,k;
+ unsigned char m,t;
+
+ if (!l) return 0;
+ l<<=3; // no. bits
+ m=0x80;
+ for (i=0,j=0,k=0,t=0; i<l; i++){
+ if (h[(i>>3)]&m) t|=1;
+ j++;
+ if (!(m>>=1)) m=0x80;
+ if (!(j%6)) {
+ d[k]=B64ABC[t];
+ t&=0;
+ k++;
+ }
+ t<<=1;
+ }
+ m=5-(j%6);
+ t<<=m;
+ if (m) {
+ d[k]=B64ABC[t];
+ k++;
+ }
+ d[k]&=0;
+ return strlen(d);
+}
+
+unsigned char B64[]="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+const char *prime1080="FBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783EB68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE299EFA7BA66DEAFEFBEFBF0B7D8B";
+
+int base64dec(char c)
+{
+ int i;
+
+ for (i = 0; i < 64; i++)
+ if (B64[i] == c) return i;
+
+ return 0;
+}
+
+char *encrypts(char *key,char *str) {
+ char *result;
+ unsigned int length;
+ unsigned int left,right;
+ char *s,*d;
+ unsigned char *p;
+ BF_KEY bfkey;
+ int i;
+
+ if(key==NULL||str==NULL) return NULL;
+
+ length=strlen(str);
+ BF_set_key(&bfkey, strlen(key), (const unsigned char *)key);
+
+ s=(char *)malloc(length+9);
+
+ strncpy(s,str,length);
+ memset(s+length,0,9);
+
+ result=(char *)malloc(((length%8==0) ? length/8*12 : 12+length/8*12)+1);
+
+ p=(unsigned char *)s;
+ d=result;
+
+ while(*p) {
+ BF_ecb_encrypt((const unsigned char *)p, (unsigned char *)p, &bfkey, BF_ENCRYPT);
+ left = ((*p++) << 24);
+ left += ((*p++) << 16);
+ left += ((*p++) << 8);
+ left += (*p++);
+ right = ((*p++) << 24);
+ right += ((*p++) << 16);
+ right += ((*p++) << 8);
+ right += (*p++);
+ for (i = 0; i < 6; i++) {
+ *d++=B64[right & 0x3f];
+ right = (right >> 6);
+ }
+
+ for (i = 0; i < 6; i++) {
+ *d++=B64[left & 0x3f];
+ left = (left >> 6);
+ }
+ }
+ *d = '\0';
+
+ memset(s,0,length+9);
+ free(s);
+ return result;
+}
+
+char *decrypts(char *key, char *str) {
+ char *result;
+ unsigned int length;
+ unsigned int left,right;
+ int i;
+ char *d;
+ unsigned char *c;
+ BF_KEY bfkey;
+
+ if(key==NULL||str==NULL) return NULL;
+
+ length=strlen(str);
+ BF_set_key(&bfkey,strlen(key),(const unsigned char *)key);
+
+ result=(char *)malloc((length/12*8)+1);
+ c=(unsigned char *)result;
+ d=str;
+ while(*d) {
+ right=0;
+ left=0;
+ for (i = 0; i < 6; i++) right |= (base64dec(*d++)) << (i * 6);
+ for (i = 0; i < 6; i++) left |= (base64dec(*d++)) << (i * 6);
+ right=htonl(right);
+ left=htonl(left);
+ memcpy(c,&left,4);
+ memcpy(c+4,&right,4);
+ BF_ecb_encrypt(c,c,&bfkey,BF_DECRYPT);
+ c+=8;
+ }
+ *c='\0';
+ return result;
+}
+
+class CKeyExchangeTimer : public CTimer {
+public:
+ CKeyExchangeTimer(CModule* pModule)
+ : CTimer(pModule, 5, 0, "KeyExchangeTimer", "Key exchange timer removes stale exchanges") {}
+
+protected:
+ virtual void RunJob();
+};
+
+class CFishMod : public CModule {
+public:
+ MODCONSTRUCTOR(CFishMod) {}
+ virtual ~CFishMod() {
+ }
+
+ virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage) {
+ CString command = sMessage.Token(0);
+ CString sOtherPub_Key = sMessage.Token(1);
+
+ if (command.CaseCmp("DH1080_INIT") == 0 && !sOtherPub_Key.empty()) {
+ CString sPriv_Key;
+ CString sPub_Key;
+ CString sSecretKey;
+
+ DH1080_gen(sPriv_Key, sPub_Key);
+ if (!DH1080_comp(sPriv_Key, sOtherPub_Key, sSecretKey)) {
+ PutModule("Error in DH1080 with " + Nick.GetNick() + ": " + sSecretKey);
+ return CONTINUE;
+ }
+ PutModule("Received DH1080 public key from " + Nick.GetNick() + ", sending mine...");
+ PutIRC("NOTICE " + Nick.GetNick() + " :DH1080_FINISH " + sPub_Key);
+ SetNV(Nick.GetNick().AsLower(), sSecretKey);
+ PutModule("Key for " + Nick.GetNick() + " successfully set.");
+ return HALT;
+ } else if (command.CaseCmp("DH1080_FINISH") == 0 && !sOtherPub_Key.empty()) {
+ CString sPriv_Key;
+ CString sSecretKey;
+
+ map<CString, pair<time_t, CString> >::iterator it = m_msKeyExchange.find(Nick.GetNick().AsLower());
+ if (it == m_msKeyExchange.end()) {
+ PutModule("Received unexpected DH1080_FINISH from " + Nick.GetNick() + ".");
+ } else {
+ sPriv_Key = it->second.second;
+ if (DH1080_comp(sPriv_Key, sOtherPub_Key, sSecretKey)) {
+ SetNV(Nick.GetNick().AsLower(), sSecretKey);
+ PutModule("Key for " + Nick.GetNick() + " successfully set.");
+ m_msKeyExchange.erase(Nick.GetNick().AsLower());
+ }
+ }
+ return HALT;
+ } else {
+ FilterIncoming(Nick.GetNick(), Nick, sMessage);
+ }
+
+ return CONTINUE;
+ }
+
+ virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) {
+ MCString::iterator it = FindNV(sTarget.AsLower());
+
+ if (it != EndNV()) {
+ CChan* pChan = m_pNetwork->FindChan(sTarget);
+ if ((pChan) && (pChan->AutoClearChanBuffer())) {
+ pChan->AddBuffer(":" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage);
+ }
+ char * cMsg = encrypts((char *)it->second.c_str(), (char *)sMessage.c_str());
+
+ CString sMsg = "+OK " + CString(cMsg);
+ PutIRC("PRIVMSG " + sTarget + " :" + sMsg);
+ m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage, NULL, m_pClient);
+
+ free(cMsg);
+ return HALTCORE;
+ }
+
+ return CONTINUE;
+ }
+
+ virtual EModRet OnUserAction(CString& sTarget, CString& sMessage) {
+ MCString::iterator it = FindNV(sTarget.AsLower());
+
+ if (it != EndNV()) {
+ CChan* pChan = m_pNetwork->FindChan(sTarget);
+ if ((pChan) && (pChan->AutoClearChanBuffer())) {
+ pChan->AddBuffer(":" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :\001ACTION " + sMessage + "\001");
+ }
+ char * cMsg = encrypts((char *)it->second.c_str(), (char *)sMessage.c_str());
+
+ CString sMsg = "+OK " + CString(cMsg);
+ PutIRC("PRIVMSG " + sTarget + " :\001ACTION " + sMsg + "\001");
+ m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :\001ACTION " + sMessage + "\001", NULL, m_pClient);
+
+ free(cMsg);
+ return HALTCORE;
+ }
+
+ return CONTINUE;
+ }
+
+ virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage) {
+ MCString::iterator it = FindNV(sTarget.AsLower());
+
+ if (it != EndNV()) {
+ CChan* pChan = m_pNetwork->FindChan(sTarget);
+ if ((pChan) && (pChan->AutoClearChanBuffer())) {
+ pChan->AddBuffer(":" + m_pNetwork->GetIRCNick().GetNickMask() + " NOTICE " + sTarget + " :" + sMessage);
+ }
+ char * cMsg = encrypts((char *)it->second.c_str(), (char *)sMessage.c_str());
+
+ CString sMsg = "+OK " + CString(cMsg);
+ PutIRC("NOTICE " + sTarget + " :" + sMsg);
+ m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() + " NOTICE " + sTarget + " :" + sMessage, NULL, m_pClient);
+
+ free(cMsg);
+ return HALTCORE;
+ }
+
+ return CONTINUE;
+
+ }
+
+ virtual EModRet OnUserTopic(CString& sChannel, CString& sTopic) {
+ if (!sTopic.empty()) {
+ MCString::iterator it = FindNV(sChannel.AsLower());
+ if (it != EndNV()) {
+ char * cTopic = encrypts((char *)it->second.c_str(), (char *)sTopic.c_str());
+ sTopic = "+OK " + CString(cTopic);
+ free(cTopic);
+ }
+ }
+
+ return CONTINUE;
+ }
+
+ virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) {
+ FilterIncoming(Nick.GetNick(), Nick, sMessage);
+ return CONTINUE;
+ }
+
+ virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) {
+ FilterIncoming(Channel.GetName(), Nick, sMessage);
+ return CONTINUE;
+ }
+
+ virtual EModRet OnPrivAction(CNick& Nick, CString& sMessage) {
+ FilterIncoming(Nick.GetNick(), Nick, sMessage);
+ return CONTINUE;
+ }
+
+ virtual EModRet OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage) {
+ FilterIncoming(Channel.GetName(), Nick, sMessage);
+ return CONTINUE;
+ }
+
+ virtual EModRet OnTopic(CNick& Nick, CChan& Channel, CString& sTopic) {
+ FilterIncoming(Channel.GetName(), Nick, sTopic);
+ return CONTINUE;
+ }
+
+ virtual EModRet OnRaw(CString& sLine) {
+ if (sLine.WildCmp(":* 332 *") && sLine.Token(1) == "332") {
+ CChan* pChan = m_pNetwork->FindChan(sLine.Token(3));
+ if (pChan) {
+ CNick Nick(sLine.Token(2));
+ CString sTopic = sLine.Token(4, true);
+ sTopic.LeftChomp();
+ FilterIncoming(pChan->GetName(), Nick, sTopic);
+ sLine = sLine.Token(0) + " " + sLine.Token(1) + " " + sLine.Token(2) + " " + pChan->GetName() + " :" + sTopic;
+ }
+ }
+ return CONTINUE;
+ }
+
+ void FilterIncoming(const CString& sTarget, CNick& Nick, CString& sMessage) {
+ if (sMessage.Left(4) == "+OK " || sMessage.Left(5) == "mcps ") {
+ MCString::iterator it = FindNV(sTarget.AsLower());
+
+ if (it != EndNV()) {
+ if (sMessage.Left(4) == "+OK ") {
+ sMessage.LeftChomp(4);
+ } else if (sMessage.Left(5) == "mcps ") {
+ sMessage.LeftChomp(5);
+ }
+
+ unsigned int msg_len = strlen(sMessage.c_str());
+
+ if ((strspn(sMessage.c_str(), (char *)B64) != msg_len) || msg_len < 12) {
+ return;
+ }
+
+ unsigned int mark_broken_block = 0;
+
+ if (msg_len != (msg_len/12)*12) {
+ msg_len = msg_len - (msg_len/12)*12;
+ sMessage.RightChomp(msg_len);
+ mark_broken_block = 1;
+ }
+
+ char *cMsg = decrypts((char *)it->second.c_str(), (char *)sMessage.c_str());
+ sMessage = CString(cMsg);
+
+ if (mark_broken_block) {
+ sMessage += " \002&\002";
+ }
+
+ free(cMsg);
+ }
+ }
+ }
+
+ virtual void OnModCommand(const CString& sCommand) {
+ CString sCmd = sCommand.Token(0);
+
+ if (sCmd.CaseCmp("DELKEY") == 0) {
+ CString sTarget = sCommand.Token(1);
+
+ if (!sTarget.empty()) {
+ if (DelNV(sTarget.AsLower())) {
+ PutModule("Target [" + sTarget + "] deleted");
+ } else {
+ PutModule("Target [" + sTarget + "] not found");
+ }
+ } else {
+ PutModule("Usage DelKey <#chan|Nick>");
+ }
+ } else if (sCmd.CaseCmp("SETKEY") == 0) {
+ CString sTarget = sCommand.Token(1);
+ CString sKey = sCommand.Token(2, true);
+
+ if (!sKey.empty()) {
+ SetNV(sTarget.AsLower(), sKey);
+ PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
+ } else {
+ PutModule("Usage: SetKey <#chan|Nick> <Key>");
+ }
+ } else if (sCmd.CaseCmp("SHOWKEY") == 0) {
+ CString sTarget = sCommand.Token(1);
+
+ if (!sTarget.empty()) {
+ MCString::iterator it = FindNV(sTarget.AsLower());
+
+ if (it != EndNV()) {
+ PutModule("Target key is " + it->second);
+ } else {
+ PutModule("Target not found.");
+ }
+ } else {
+ PutModule("Usage ShowKey <#chan|Nick>");
+ }
+ } else if (sCmd.CaseCmp("LISTKEYS") == 0) {
+ if (BeginNV() == EndNV()) {
+ PutModule("You have no encryption keys set.");
+ } else {
+ CTable Table;
+ Table.AddColumn("Target");
+ Table.AddColumn("Key");
+
+ for (MCString::iterator it = BeginNV(); it != EndNV(); it++) {
+ Table.AddRow();
+ Table.SetCell("Target", it->first);
+ Table.SetCell("Key", it->second);
+ }
+
+ if (Table.size()) {
+ unsigned int uTableIdx = 0;
+ CString sLine;
+
+ while (Table.GetLine(uTableIdx++, sLine)) {
+ PutModule(sLine);
+ }
+ }
+ }
+ } else if (sCmd.CaseCmp("KEYX") == 0) {
+ CString sTarget = sCommand.Token(1);
+
+ if (sTarget.empty()) {
+ PutModule("You did not specify a target for the key exchange.");
+ } else {
+ map<CString, pair<time_t, CString> >::iterator it = m_msKeyExchange.find(sTarget.AsLower());
+ if (it != m_msKeyExchange.end()) {
+ PutModule("Keyexchange with " + sTarget + " already in progress.");
+ } else {
+ CString sPriv_Key;
+ CString sPub_Key;
+
+ DH1080_gen(sPriv_Key, sPub_Key);
+ m_msKeyExchange.insert(make_pair(sTarget.AsLower(), make_pair(time(NULL), sPriv_Key)));
+ PutIRC("NOTICE " + sTarget + " :DH1080_INIT " + sPub_Key);
+ PutModule("Sent my DH1080 public key to " + sTarget + ", waiting for reply ...");
+ if (FindTimer("KeyExchangeTimer") == NULL) {
+ AddTimer(new CKeyExchangeTimer(this));
+ }
+ }
+ }
+ } else if (sCmd.CaseCmp("HELP") == 0) {
+ PutModule("Try: SetKey <target> <key>, DelKey <target>, ShowKey <target>, ListKeys, KeyX <target>");
+ } else {
+ PutModule("Unknown command, try 'Help'");
+ }
+ }
+
+ void DelStaleKeyExchanges(time_t iTime) {
+ for (map<CString, pair<time_t, CString> >::const_iterator it = m_msKeyExchange.begin(); it != m_msKeyExchange.end(); it++) {
+ if (iTime - 5 >= it->second.first) {
+ PutModule("Keyexchange with " + it->first + " did expire before completition.");
+ m_msKeyExchange.erase(it->first);
+ }
+ }
+ if (m_msKeyExchange.size() <= 0) {
+ RemTimer("KeyExchangeTimer");
+ }
+ }
+
+private:
+
+ void DH1080_gen(CString& sPriv_Key, CString& sPub_Key) {
+ sPriv_Key = "";
+ sPub_Key = "";
+
+ unsigned char raw_buf[200];
+ unsigned long len;
+ unsigned char *a, *b;
+
+ DH *dh;
+ BIGNUM *b_prime=NULL;
+ BIGNUM *b_generator=NULL;
+
+ initb64();
+
+ dh=DH_new();
+
+ if (!BN_hex2bn(&b_prime, prime1080)) {
+ return;
+ }
+
+ if (!BN_dec2bn(&b_generator, "2")) {
+ return;
+ }
+
+ dh->p=b_prime;
+ dh->g=b_generator;
+
+ if (!DH_generate_key(dh)) {
+ return;
+ }
+
+ len = BN_num_bytes(dh->priv_key);
+ a = (unsigned char *)malloc(len);
+ BN_bn2bin(dh->priv_key,a);
+
+ memset(raw_buf, 0, 200);
+ htob64((char *)a, (char *)raw_buf, len);
+ sPriv_Key = CString((char *)raw_buf);
+ len=BN_num_bytes(dh->pub_key);
+ b = (unsigned char *)malloc(len);
+ BN_bn2bin(dh->pub_key,b);
+ memset(raw_buf, 0, 200);
+ htob64((char *)b, (char *)raw_buf, len);
+ sPub_Key = CString((char *)raw_buf);
+ DH_free(dh);
+ free(a);
+ free(b);
+ }
+
+
+ bool DH1080_comp(CString& sPriv_Key, CString& sOtherPub_Key, CString& sSecret_Key) {
+ int len;
+ unsigned char SHA256digest[32];
+ char *key;
+ BIGNUM *b_prime=NULL;
+ BIGNUM *b_myPrivkey=NULL;
+ BIGNUM *b_HisPubkey=NULL;
+ BIGNUM *b_generator=NULL;
+ DH *dh;
+ CString sSHA256digest;
+ unsigned char raw_buf[200];
+
+ if (!BN_hex2bn(&b_prime, prime1080)) {
+ return false;
+ }
+
+ if (!BN_dec2bn(&b_generator, "2")) {
+ return false;
+ }
+
+ dh=DH_new();
+ dh->p=b_prime;
+ dh->g=b_generator;
+
+ memset(raw_buf, 0, 200);
+ len = b64toh((char *)sPriv_Key.c_str(), (char *)raw_buf);
+ b_myPrivkey=BN_bin2bn(raw_buf, len, NULL);
+ dh->priv_key=b_myPrivkey;
+
+ memset(raw_buf, 0, 200);
+ len = b64toh((char *)sOtherPub_Key.c_str(), (char *)raw_buf);
+
+ b_HisPubkey=BN_bin2bn(raw_buf, len, NULL);
+
+ key=(char *)malloc(DH_size(dh));
+ memset(key, 0, DH_size(dh));
+ len=DH_compute_key((unsigned char *)key, b_HisPubkey, dh);
+ if (len == -1) {
+ // Bad pub key
+ unsigned long err = ERR_get_error();
+ DEBUG("** DH Error:" << ERR_error_string(err,NULL));
+ DH_free(dh);
+ BN_clear_free(b_HisPubkey);
+ free(key);
+
+ sSecret_Key = CString(ERR_error_string(err,NULL)).Token(4,true,":");
+ return false;
+ }
+
+ SHA256_CTX c;
+ SHA256_Init(&c);
+ memset(SHA256digest, 0, 32);
+ SHA256_Update(&c, key, len);
+ SHA256_Final(SHA256digest, &c);
+ memset(raw_buf, 0, 200);
+ len = htob64((char *)SHA256digest, (char *)raw_buf, 32);
+ sSecret_Key = "";
+ sSecret_Key.append((char *)raw_buf, len);
+
+ DH_free(dh);
+ BN_clear_free(b_HisPubkey);
+ free(key);
+ return true;
+ }
+
+ map<CString, pair<time_t, CString> > m_msKeyExchange;
+
+};
+
+void CKeyExchangeTimer::RunJob() {
+ CFishMod *p = (CFishMod *)m_pModule;
+ p->DelStaleKeyExchanges(time(NULL));
+}
+
+MODULEDEFS(CFishMod, "FiSH encryption for channel/private messages")
\ No newline at end of file
diff --git a/znc-crox-svn-admin.cpp b/znc-crox-svn-admin.cpp
deleted file mode 100644
index 4c999d4..0000000
--- a/znc-crox-svn-admin.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
-#include <main.h>
-#include <znc.h>
-#include <User.h>
-#include <Modules.h>
-
-class CAdminMod : public CGlobalModule
-{
-public:
- GLOBALMODCONSTRUCTOR( CAdminMod )
- {
- }
-
- virtual ~CAdminMod()
- {
- }
-
- virtual void OnModCommand(const CString& sLine)
- {
- if (!m_pUser)
- return;
-
- CString sCommand = sLine.Token(0);
- cout << sCommand << endl;
-
- if (m_pUser->IsAdmin() && sCommand.CaseCmp("LISTUSERS") == 0) {
- cout << "LISTUSERS!" << endl;
-
- const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap();
- CTable Table;
- Table.AddColumn("Username");
- Table.AddColumn("Realname");
- Table.AddColumn("IsAdmin");
- Table.AddColumn("Nick");
- Table.AddColumn("AltNick");
- Table.AddColumn("Ident");
- Table.AddColumn("VHost");
-
- for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it !=
- msUsers.end(); it++) {
- Table.AddRow();
- Table.SetCell("Username", it->first);
- Table.SetCell("Realname", it->second->GetRealName());
- if (!it->second->IsAdmin()) {
- Table.SetCell("IsAdmin", "No");
- } else {
- Table.SetCell("IsAdmin", "Yes");
- }
- Table.SetCell("Nick", it->second->GetNick());
- Table.SetCell("AltNick", it->second->GetAltNick());
- Table.SetCell("Ident", it->second->GetIdent());
- Table.SetCell("VHost", it->second->GetVHost());
- }
-
- if (Table.size()) {
- unsigned int uTableIdx = 0;
- CString sLine;
- while (Table.GetLine(uTableIdx++, sLine)) {
- PutModule(sLine);
- }
- }
- return;
- // LISTUSERS
- } else if (sCommand.CaseCmp("HELP") == 0) {
- CTable Table;
- Table.AddColumn("Command");
- Table.AddColumn("Arguments");
- Table.AddColumn("Description");
-
- Table.AddRow();
- Table.SetCell("Command", "GetNick");
- Table.SetCell("Arguments","[username]");
- Table.SetCell("Description","Prints (current) users nick");
-
- Table.AddRow();
- Table.SetCell("Command", "GetAltNick");
- Table.SetCell("Arguments","[username]");
- Table.SetCell("Description","Prints (current) users alternative nick");
-
- Table.AddRow();
- Table.SetCell("Command", "");
- Table.SetCell("Arguments","");
- Table.SetCell("Description","");
-
- if (Table.size()) {
- unsigned int uTableIdx = 0;
- CString sLine;
- while (Table.GetLine(uTableIdx++, sLine)) {
- PutModule(sLine);
- }
- }
- return;
- // HELP
- } else if (sCommand.CaseCmp("ADDUSER") == 0 && m_pUser->IsAdmin()) {
- CString sUsername = sLine.Token(1);
- CString sPassword = sLine.Token(2);
-// CString sIRCServer = sLine.Token(3, true);
- if (sUsername.empty() || sPassword.empty() /* || sIRCServer.empty() */ ) {
- PutModule("Usage: adduser <username> <password> <ircserver>");
- return;
- }
-
- if (CZNC::Get().FindUser(sUsername)) {
- PutModule("User " + sUsername + " already exists!");
- return;
- }
-
- CString sErr;
- CUser* pNewUser = new CUser(sUsername);
- pNewUser->SetPass(sPassword.MD5(), true);
-// pNewUser->AddServer(sIRCServer);
- if (!CZNC::Get().AddUser(pNewUser, sErr)) {
- delete pNewUser;
- PutModule("User not added [" + sErr + "]!");
- return;
- }
-
- PutModule("User " + sUsername + " added!");
- return;
- // ADDUSER
- }
-
- CUser* pUser = NULL;
- CString user = sLine.Token(1);
- CString value = sLine.Token(2);
-
- if (!m_pUser->IsAdmin() || value.empty()) {
- pUser = m_pUser;
- value = user;
- } else {
- pUser = CZNC::Get().FindUser(user);
- }
-
- if (!pUser) {
- PutModule("User not found!");
- return;
- }
-
- if (sCommand.CaseCmp("GETNICK") == 0) {
- PutModule("Nick is " + pUser->GetNick());
- // GETNICK
- } else if (sCommand.CaseCmp("GETALTNICK") == 0) {
- PutModule("AltNick is " + pUser->GetAltNick());
- // GETALTNICK
-// } else if (sCommand.CaseCmp("GETAWAYSUFFIX") == 0) {
-// PutModule("AwaySuffix is " + pUser->GetAwaySuffix());
- // GETAWAYSUFFIX
- } else if (value.empty()) {
- PutModule("Usage: command [username] value");
- return;
- } else if (sCommand.CaseCmp("SETNICK") == 0) {
- pUser->SetNick(value);
- PutModule("Nick set to " + value);
- // SETNICK
- } else if (sCommand.CaseCmp("SETALTNICK") == 0) {
- pUser->SetAltNick(value);
- PutModule("AltNick set to " + value);
- // SETALTNICK
-// } else if (sCommand.CaseCmp("SETAWAYSUFFIX") == 0) {
-// pUser->SetAwaySuffix(value);
-// PutModule("AwaySuffix set to " + value);
- // SETAWAYSUFFIX
- } else if (sCommand.CaseCmp("SETIDENT") == 0) {
- pUser->SetIdent(value);
- PutModule("Ident set to " + value);
- // SETIDENT
- } else if (sCommand.CaseCmp("SETREALNAME") == 0) {
- pUser->SetRealName(value);
- PutModule("RealName set to " + value);
- // SETREALNAME
- } else if (sCommand.CaseCmp("SETVHOST") == 0) {
- pUser->SetVHost(value);
- PutModule("VHost set to " + value);
- // SETVHOST
- } else if (sCommand.CaseCmp("SETMULTICLIENTS") == 0) {
- pUser->SetMultiClients(value.CaseCmp("TRUE") == 0 ? true : false);
- PutModule("MultiClients set to " + (value.CaseCmp("TRUE") == 0) ? "true"
- : "false");
- // SETMULTICLIENTS
- } else if (sCommand.CaseCmp("SETBOUNCEDCCS") == 0) {
- pUser->SetBounceDCCs(true);
- PutModule("BounceDCCs set to " + value);
- // SETBOUNCEDCCS
- } else if (sCommand.CaseCmp("SETUSECLIENTIP") == 0) {
- pUser->SetUseClientIP(true);
- PutModule("UseClientIP set to " + value);
- // SETUSECLIENTIP
- } else if (sCommand.CaseCmp("SETKEEPNICK") == 0) {
- pUser->SetKeepNick(true);
- PutModule("KeepNick set to " + value);
- // SETKEEPNICK
- } else if (sCommand.CaseCmp("SETDENYLOADMOD") == 0) {
- pUser->SetDenyLoadMod(true);
- PutModule("DenyLoadMod set to " + value);
- // SETDENYLOADMOD
- } else if (sCommand.CaseCmp("SETDEFAULTCHANMODES") == 0) {
- pUser->SetDefaultChanModes(value);
- PutModule("DefaultChanModes set to " + value);
- // SETDEFAULTCHANMODES
- } else if (sCommand.CaseCmp("ADDIRCSERVER") == 0) {
- PutModule("user: " + pUser->GetUserName());
- pUser->AddServer(value);
- PutModule("IRC Server added " + value);
-// cout << "x: " << pUser->CountServers() << endl;
-// PutModule("Server count: " + CString(pUser->CountServers()));
- // ADDIRCSERVER
- } else if (sCommand.CaseCmp("SETQUITMSG") == 0) {
- pUser->SetQuitMsg(value);
- PutModule("Quit Message set to " + value);
- // SETQUITMSG
- } else if (sCommand.CaseCmp("SETBUFFERCOUNT") == 0) {
- pUser->SetBufferCount(0);
- PutModule("Buffer count set to " + value);
- // SETBUFFERCOUNT
- } else if (sCommand.CaseCmp("SETKEEPBUFFER") == 0) {
- pUser->SetKeepBuffer(true);
- PutModule("Keep buffer set to " + value);
- // SETKEEPBUFFER
- } else if (sCommand.CaseCmp("SETAUTOCYCLE") == 0) {
- pUser->SetAutoCycle(true);
- PutModule("AutoCycle set to " + value);
- // SETAUTOCYCLE
- } else {
- PutModule("Unknown command.");
- }
- }
-};
-
-GLOBALMODULEDEFS( CAdminMod, "Dynamic configuration of users/settings through irc" )
diff --git a/znc-crox-svn-antiidle.cpp b/znc-crox-svn-antiidle.cpp
deleted file mode 100644
index 27ba644..0000000
--- a/znc-crox-svn-antiidle.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-#include "main.h"
-#include "User.h"
-#include "Nick.h"
-#include "Modules.h"
-
-class CAntiIdle;
-
-class CAntiIdleJob : public CTimer
-{
-public:
- CAntiIdleJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription)
- : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {}
-
- virtual ~CAntiIdleJob() {}
-
-protected:
- virtual void RunJob();
-};
-
-class CAntiIdle : public CModule
-{
-public:
- MODCONSTRUCTOR(CAntiIdle) {
- SetInterval(30);
- }
-
- virtual ~CAntiIdle() { }
-
- virtual bool OnLoad(const CString& sArgs, CString& sMessage)
- {
- if(!sArgs.Trim_n().empty())
- SetInterval(sArgs.ToInt());
-
- return true;
- }
-
- virtual void OnModCommand( const CString& sCommand )
- {
- CString sCmdName = sCommand.Token(0).AsLower();
- if(sCmdName == "set")
- {
- CString sInterval = sCommand.Token(1, true);
- SetInterval(sInterval.ToInt());
-
- if(m_uiInterval == 0)
- PutModule("AntiIdle is now turned off.");
- else
- PutModule("AntiIdle is now set to " + CString(m_uiInterval) + " seconds.");
- } else if(sCmdName == "off") {
- SetInterval(0);
- PutModule("AntiIdle is now turned off");
- } else if(sCmdName == "show") {
- if(m_uiInterval == 0)
- PutModule("AntiIdle is turned off.");
- else
- PutModule("AntiIdle is set to " + CString(m_uiInterval) + " seconds.");
- } else
- {
- PutModule("Commands: set, off, show");
- }
- }
-
- virtual EModRet OnPrivMsg(CNick &Nick, CString &sMessage) {
- if(Nick.GetNick() == GetUser()->GetIRCNick().GetNick()
- && sMessage == "\xAE")
- return HALTCORE;
-
- return CONTINUE;
- }
-
-private:
- void SetInterval(uint i) {
- m_uiInterval = i;
-
- RemTimer("AntiIdle");
-
- if(m_uiInterval == 0) {
- return;
- }
-
- AddTimer(new CAntiIdleJob(this, m_uiInterval, 0, "AntiIdle", "Periodically sends a msg to the user"));
- }
-
- unsigned int m_uiInterval;
-};
-
-//! This function sends a query with (r) back to the user
-void CAntiIdleJob::RunJob() {
- CString sNick = GetModule()->GetUser()->GetIRCNick().GetNick();
- GetModule()->PutIRC("PRIVMSG " + sNick + " :\xAE");
-}
-
-MODULEDEFS(CAntiIdle, "Hides your real idle time")
diff --git a/znc-crox-svn-statupdate.cpp b/znc-crox-svn-statupdate.cpp
deleted file mode 100644
index ae8590b..0000000
--- a/znc-crox-svn-statupdate.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "main.h"
-#include "User.h"
-#include "Nick.h"
-#include "Modules.h"
-#include "Chan.h"
-#include "znc.h"
-#include "Server.h"
-
-class CStatUpdateMod : public CGlobalModule {
-private:
- CString m_sPath;
- char epoch_str[64];
-
-public:
- GLOBALMODCONSTRUCTOR(CStatUpdateMod) { }
-
- virtual ~CStatUpdateMod () {}
-
- virtual void UpdateStatFile ()
- {
- // Create filestream
- FILE *file = fopen (m_sPath.c_str(), "w+");
-
- if (file == NULL)
- return;
-
- sprintf(epoch_str, "%i", (int)time(NULL));
-
- // Setup time
- fputs ("STATUPDATE_TIME;", file);
- fputs (epoch_str, file);
- fputs ("\n", file);
-
- const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap();
- for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); it++)
- {
- CUser& User = *it->second;
- const CString& sNick = User.GetUserName();
-
- fputs (sNick.c_str(), file);
- fputs (";", file);
-
- if (User.IsUserAttached())
- {
- fputs ("online\n", file);
- }
- else
- {
- fputs ("offline\n", file);
- }
- }
-
- // close filestream
- fclose (file);
- }
-
- virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
- m_sPath = sArgs;
- PutModule("StatUpdate module successfully loaded with args: [" + sArgs + "]");
- return true;
- }
-
- virtual bool OnBoot() {
- return true;
- }
-
- virtual void OnUserAttached ()
- {
- UpdateStatFile();
- }
-
- virtual void OnUserDetached ()
- {
- UpdateStatFile();
- }
-
- virtual void OnModCommand(const CString& sCommand) {
- if (sCommand.CaseCmp("DEBUG") == 0) {
- PutModule("Current path is: " + m_sPath);
- }
-
- if ((sCommand.CaseCmp("UPDATE") == 0 || sCommand.CaseCmp("REFRESH") == 0) && m_pUser->IsAdmin()) {
- UpdateStatFile();
- PutModule("StatUpdate file successfully updated.");
- }
-
- if (sCommand.CaseCmp("VERSION") == 0) {
- PutModule("StatUpdate - v0.2b");
- PutModule("Autor: Daniel 'd4n13L' Schmitz (daniel at danielschmitz.de)");
- }
- }
-
- virtual EModRet OnStatusCommand(const CString& sCommand) {
- if (sCommand.CaseCmp("STATUPDATE") == 0) {
- PutModule("Hello! I am here ;-)");
- return HALT;
- }
-
- return CONTINUE;
- }
-};
-
-GLOBALMODULEDEFS(CStatUpdateMod, "StatUpdate writes users online status into a text file.")
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/znc.git/commitdiff/923a9da5c617827b225bc0b7b4cd72756939c444
More information about the pld-cvs-commit
mailing list