Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 48852 Details for
Bug 78540
licq-1.2.7.ebuild (pacth for gpg)
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
the patch use to enable gpg in licq-1.2.7
licq-gpg-patch-1.2.7-r1 (text/plain), 8.40 KB, created by
Benjamin
on 2005-01-18 10:25:55 UTC
(
hide
)
Description:
the patch use to enable gpg in licq-1.2.7
Filename:
MIME Type:
Creator:
Benjamin
Created:
2005-01-18 10:25:55 UTC
Size:
8.40 KB
patch
obsolete
>diff -Naur licq-1.2.7/configure.in licq-1.2.7-gpg/configure.in >--- licq-1.2.7/configure.in 2003-06-25 18:07:33.000000000 +0200 >+++ licq-1.2.7-gpg/configure.in 2003-09-16 21:58:05.000000000 +0200 >@@ -145,6 +145,9 @@ > AC_CHECK_SOCKS5 > LICQ_CHECK_OPENSSL > >+dnl Check for gpgme >+AC_CHECK_LIB(gpgme,gpgme_check_version) >+ > dnl Switch to C++ mode and check for needed C++ headers > AC_LANG_SAVE > AC_LANG_CPLUSPLUS >diff -Naur licq-1.2.7/include/licq_gpg.h licq-1.2.7-gpg/include/licq_gpg.h >--- licq-1.2.7/include/licq_gpg.h 1970-01-01 01:00:00.000000000 +0100 >+++ licq-1.2.7-gpg/include/licq_gpg.h 2003-09-16 21:58:05.000000000 +0200 >@@ -0,0 +1,42 @@ >+ >+#ifndef _LICQ_GPG_H_INCLUDED_ >+#define _LICQ_GPG_H_INCLUDED_ >+ >+#include <gpgme.h> >+#include <pthread.h> >+ >+class CGPGHelper >+{ >+public: >+ static const char pgpSig[]; >+ CGPGHelper(); >+ ~CGPGHelper(); >+ char *Decrypt(const char *); >+ char *Encrypt(const char *, unsigned long); >+ void Start(); >+ >+protected: >+ CIniFile mKeysIni; >+ GpgmeCtx mCtx; >+ char *mGPGPassphrase; >+ >+ void gpgmeLock(); >+ void gpgmeUnlock(); >+ static const char *PassphraseCallback(void *, const char *, void **); >+}; >+ >+class CGPGMEMutex >+{ >+public: >+ ~CGPGMEMutex(); >+ CGPGMEMutex(); >+ bool Lock(); >+ >+protected: >+ static pthread_mutex_t mutex; >+}; >+ >+ >+extern CGPGHelper gGPGHelper; >+ >+#endif //_LICQ_GPG_H_INCLUDED_ >diff -Naur licq-1.2.7/src/gpg.cpp licq-1.2.7-gpg/src/gpg.cpp >--- licq-1.2.7/src/gpg.cpp 1970-01-01 01:00:00.000000000 +0100 >+++ licq-1.2.7-gpg/src/gpg.cpp 2003-09-16 21:58:05.000000000 +0200 >@@ -0,0 +1,154 @@ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <stdio.h> >+#include <string.h> >+ >+#include "licq_file.h" >+#include "licq_gpg.h" >+#include "licq_log.h" >+ >+CGPGHelper gGPGHelper; >+ >+const char CGPGHelper::pgpSig[] = "-----BEGIN PGP MESSAGE-----"; >+ >+ >+CGPGHelper::CGPGHelper() >+ : mKeysIni(INI_FxALLOWxCREATE) >+{ >+ mCtx = 0; >+ mGPGPassphrase = 0; >+} >+ >+ >+CGPGHelper::~CGPGHelper() >+{ >+ if (mCtx) gpgme_release(mCtx); >+ if (mGPGPassphrase) free(mGPGPassphrase); >+ mKeysIni.CloseFile(); >+} >+ >+ >+char *CGPGHelper::Decrypt(const char *szCipher) >+{ >+ if (!mCtx) return 0; >+ >+ size_t nRead = 0; >+ GpgmeData cipher, plain; >+ >+ CGPGMEMutex mutex; >+ if (!mutex.Lock()) return 0; >+ if (gpgme_data_new(&cipher) != GPGME_No_Error) return 0; >+ char *buf = strdup(szCipher); >+ GpgmeError err; >+ gpgme_data_write(cipher, buf, strlen(buf)); >+ free(buf); >+ if (gpgme_data_new(&plain) != GPGME_No_Error) { >+ gpgme_data_release(cipher); >+ return 0; >+ } >+ if ((err = gpgme_op_decrypt(mCtx, cipher, plain)) != GPGME_No_Error) >+ gLog.Warn("%sgpgme message decryption failed: %s\n", L_WARNxSTR, gpgme_strerror(err)); >+ gpgme_data_release(cipher); >+ buf = gpgme_data_release_and_get_mem(plain, &nRead); >+ if (!buf) return 0; >+ buf = (char *)realloc(buf, nRead+1); >+ buf[nRead] = 0; >+ return buf; >+} >+ >+ >+char *CGPGHelper::Encrypt(const char *szPlain, unsigned long uin) >+{ >+ if (!mCtx) return 0; >+ if (!szPlain) return 0; >+ >+ gLog.Info("gpgme: Encrypting message to %lu\n", uin); >+ >+ char szUIN[20], buf[MAX_LINE_LEN]; >+ mKeysIni.SetSection("keys"); >+ snprintf(szUIN, 20, "%lu", uin); >+ if (!mKeysIni.ReadStr(szUIN, buf)) return 0; >+ >+ CGPGMEMutex mutex; >+ if (!mutex.Lock()) return 0; >+ GpgmeRecipients rcps; >+ GpgmeData plain = 0, cipher = 0; >+ GpgmeError err; >+ char *szCipher = 0; >+ >+ if (gpgme_recipients_new(&rcps) != GPGME_No_Error) return 0; >+ if (gpgme_recipients_add_name_with_validity(rcps, buf, GPGME_VALIDITY_FULL) != GPGME_No_Error) >+ gLog.Error("%sCouldn't use gpgme recipient: %s\n", L_ERRORxSTR, buf); >+ else { >+ if (gpgme_data_new_from_mem(&plain, szPlain, strlen(szPlain), 1) == GPGME_No_Error && >+ gpgme_data_new(&cipher) == GPGME_No_Error) >+ { >+ if ((err = gpgme_op_encrypt(mCtx, rcps, plain, cipher)) == GPGME_No_Error) { >+ size_t nRead; >+ if (gpgme_data_read(cipher, 0, 0, &nRead) == GPGME_No_Error) { >+ szCipher = (char *)malloc(nRead+1); >+ memset(szCipher, 0, nRead+1); >+ gpgme_data_read(cipher, szCipher, nRead, &nRead); >+ } >+ } else >+ gLog.Error("%sEncryption failed: %s\n", L_ERRORxSTR, gpgme_strerror(err)); >+ } >+ if (cipher) gpgme_data_release(cipher); >+ if (plain) gpgme_data_release(plain); >+ } >+ gpgme_recipients_release(rcps); >+ return szCipher; >+} >+ >+ >+void CGPGHelper::Start() >+{ >+ char buf[MAX_LINE_LEN]; >+ snprintf(buf, MAX_LINE_LEN, "%s/licq_gpg.conf", BASE_DIR); >+ mKeysIni.LoadFile(buf); >+ >+ mKeysIni.SetSection("gpg"); >+ mKeysIni.ReadStr("passphrase", buf); mGPGPassphrase = strdup(buf); >+ >+ const char *gpgme_ver = gpgme_check_version(0); >+ gLog.Info("%sgpgme library found: %s\n", L_INITxSTR, gpgme_ver); >+ >+ if (gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP) != GPGME_No_Error) >+ gLog.Error("%sgpgme engine OpenPGP not found!\n", L_ERRORxSTR); >+ >+ gpgme_new(&mCtx); >+ gpgme_set_protocol(mCtx, GPGME_PROTOCOL_OpenPGP); >+ gpgme_set_armor(mCtx, 1); >+ gpgme_set_passphrase_cb(mCtx, PassphraseCallback, 0); >+} >+ >+ >+const char *CGPGHelper::PassphraseCallback(void *, const char *, void **) >+{ >+ return gGPGHelper.mGPGPassphrase; >+} >+ >+ >+ >+/*** GPGME lock for thread safety ***/ >+ >+pthread_mutex_t CGPGMEMutex::mutex; >+ >+CGPGMEMutex::~CGPGMEMutex() >+{ >+ pthread_mutex_unlock(&mutex); >+} >+ >+CGPGMEMutex::CGPGMEMutex() >+{ >+ pthread_mutex_init(&mutex, 0); >+} >+ >+bool CGPGMEMutex::Lock() >+{ >+ return pthread_mutex_lock(&mutex) == 0; >+} >+ >diff -Naur licq-1.2.7/src/icqd.cpp licq-1.2.7-gpg/src/icqd.cpp >--- licq-1.2.7/src/icqd.cpp 2003-06-16 19:09:46.000000000 +0200 >+++ licq-1.2.7-gpg/src/icqd.cpp 2003-09-16 21:58:05.000000000 +0200 >@@ -35,6 +35,7 @@ > #include "licq_translate.h" > #include "licq_packets.h" > #include "licq_plugind.h" >+#include "licq_gpg.h" // ## > #include "licq.h" > #include "support.h" > >@@ -252,6 +253,9 @@ > // Initialize the random number generator > srand(time(NULL)); > >+ // start GPG helper >+ gGPGHelper.Start(); >+ > // Start up our threads > pthread_mutex_init(&mutex_runningevents, NULL); > pthread_mutex_init(&mutex_extendedevents, NULL); >diff -Naur licq-1.2.7/src/icqd-tcp.cpp licq-1.2.7-gpg/src/icqd-tcp.cpp >--- licq-1.2.7/src/icqd-tcp.cpp 2003-06-16 19:09:46.000000000 +0200 >+++ licq-1.2.7-gpg/src/icqd-tcp.cpp 2003-09-16 21:58:05.000000000 +0200 >@@ -27,6 +27,7 @@ > #include "licq_log.h" > #include "licq_chat.h" > #include "licq_filetransfer.h" >+#include "licq_gpg.h" > #include "support.h" > > //-----ICQ::sendMessage-------------------------------------------------------- >@@ -86,16 +87,22 @@ > } > else // send direct > { >+ /* get GPG key */ >+ char *cipher = gGPGHelper.Encrypt(mDos, _nUin); >+ if (cipher) f |= E_ENCRYPTED; >+ > u = gUserManager.FetchUser(_nUin, LOCK_W); > if (u == NULL) return 0; > if (u->Secure()) f |= E_ENCRYPTED; > e = new CEventMsg(m, ICQ_CMDxTCP_START, TIME_NOW, f); > if (pColor != NULL) e->SetColor(pColor); >- CPT_Message *p = new CPT_Message(mDos, nLevel, bMultipleRecipients, pColor, u); >+ CPT_Message *p = new CPT_Message(cipher?cipher:mDos, nLevel, bMultipleRecipients, pColor, u); > gLog.Info("%sSending %smessage to %s (#%ld).\n", L_TCPxSTR, > nLevel == ICQ_TCPxMSG_URGENT ? "urgent " : "", > u->GetAlias(), -p->Sequence()); > result = SendExpectEvent_Client(u, p, e); >+ >+ if (cipher) free(cipher); > } > > if (u != NULL) >diff -Naur licq-1.2.7/src/Makefile.am licq-1.2.7-gpg/src/Makefile.am >--- licq-1.2.7/src/Makefile.am 2003-04-08 08:54:57.000000000 +0200 >+++ licq-1.2.7-gpg/src/Makefile.am 2003-09-16 21:58:05.000000000 +0200 >@@ -15,7 +15,7 @@ > file.cpp message.cpp support.c pthread_rdwr.c \ > onevent.cpp plugind.cpp sar.cpp languagecodes.c \ > icqd-chat.cpp sighandler.c icqd-filetransfer.cpp \ >- hebrev.c icqcolor.cpp fifo.cpp >+ hebrev.c icqcolor.cpp fifo.cpp gpg.cpp > > #licq_LDADD = $(top_builddir)/src/daemon/liblicq-daemon.la @SOCKS_LIBS@ > licq_LDADD = @SOCKS_LIBS@ >diff -Naur licq-1.2.7/src/message.cpp licq-1.2.7-gpg/src/message.cpp >--- licq-1.2.7/src/message.cpp 2003-06-16 19:09:46.000000000 +0200 >+++ licq-1.2.7-gpg/src/message.cpp 2003-09-16 21:58:05.000000000 +0200 >@@ -18,6 +18,7 @@ > #include "licq_user.h" > #include "licq_translate.h" > #include "licq_icqd.h" >+#include "licq_gpg.h" > #include "support.h" > > #ifdef USE_HEBREW >@@ -153,6 +154,13 @@ > : CUserEvent(ICQ_CMDxSUB_MSG, _nCommand, 0, _tTime, _nFlags) > { > m_szMessage = strdup(_szMessage == NULL ? "" : _szMessage); >+ >+ if (strstr(m_szMessage, CGPGHelper::pgpSig) == m_szMessage) >+ if (char *plaintext = gGPGHelper.Decrypt(m_szMessage)) { >+ m_nFlags |= E_ENCRYPTED; >+ free(m_szMessage); >+ m_szMessage = plaintext; >+ } > } > >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 78540
:
48851
| 48852