added a debug ifdef to GPG stuff to remove printfs

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2110 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-01-21 23:01:48 +00:00
parent 633300c5cc
commit 09acb717a0

View file

@ -32,6 +32,7 @@
#include "serialiser/rsconfigitems.h" #include "serialiser/rsconfigitems.h"
#include "cleanupxpgp.h" #include "cleanupxpgp.h"
//#define GPG_DEBUG 1
// initialisation du pointeur de singleton à zéro // initialisation du pointeur de singleton à zéro
AuthGPG *AuthGPG::instance_gpg = new AuthGPG(); AuthGPG *AuthGPG::instance_gpg = new AuthGPG();
@ -222,13 +223,15 @@ bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &id
if (KEY->subkeys) if (KEY->subkeys)
{ {
ids.push_back(KEY->subkeys->keyid); ids.push_back(KEY->subkeys->keyid);
std::cerr << "AuthGPG::availablePGPCertificates() Added: " #ifdef GPG_DEBUG
<< KEY->subkeys->keyid << std::endl; std::cerr << "AuthGPG::availablePGPCertificates() Added: " << KEY->subkeys->keyid << std::endl;
#endif
} }
else else
{ {
std::cerr << "AuthGPG::availablePGPCertificates() Missing subkey" #ifdef GPG_DEBUG
<< std::endl; std::cerr << "AuthGPG::availablePGPCertificates() Missing subkey" << std::endl;
#endif
} }
} }
@ -283,7 +286,9 @@ int AuthGPG::GPGInit(std::string ownId)
} }
bool AuthGPG::storeAllKeys_timed() { bool AuthGPG::storeAllKeys_timed() {
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::storeAllKeys_timed() called." << std::endl; std::cerr << "AuthGPG::storeAllKeys_timed() called." << std::endl;
#endif
if ((time(NULL) - mStoreKeyTime) > STORE_KEY_TIMEOUT) { if ((time(NULL) - mStoreKeyTime) > STORE_KEY_TIMEOUT) {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/ RsStackMutex stack(pgpMtx); /******* LOCKED ******/
storeAllKeys_locked(); storeAllKeys_locked();
@ -293,7 +298,9 @@ bool AuthGPG::storeAllKeys_timed() {
// store all keys in map mKeyList to avoid callin gpgme exe repeatedly // store all keys in map mKeyList to avoid callin gpgme exe repeatedly
bool AuthGPG::storeAllKeys_locked() bool AuthGPG::storeAllKeys_locked()
{ {
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::storeAllKeys_locked()" << std::endl; std::cerr << "AuthGPG::storeAllKeys_locked()" << std::endl;
#endif
mStoreKeyTime = time(NULL); mStoreKeyTime = time(NULL);
gpg_error_t ERR; gpg_error_t ERR;
@ -304,8 +311,10 @@ bool AuthGPG::storeAllKeys_locked()
return false; return false;
} }
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::storeAllKeys_locked() clearing existing ones"; std::cerr << "AuthGPG::storeAllKeys_locked() clearing existing ones";
std::cerr << std::endl; std::cerr << std::endl;
#endif
mKeyList.clear(); mKeyList.clear();
/* enable SIG mode */ /* enable SIG mode */
@ -350,11 +359,11 @@ bool AuthGPG::storeAllKeys_locked()
nu.id = mainsubkey->keyid; nu.id = mainsubkey->keyid;
nu.fpr = mainsubkey->fpr; nu.fpr = mainsubkey->fpr;
#ifdef GPG_DEBUG
std::cerr << "MAIN KEYID: " << nu.id; std::cerr << "MAIN KEYID: " << nu.id;
std::cerr << " FPR: " << nu.fpr; std::cerr << " FPR: " << nu.fpr;
std::cerr << std::endl; std::cerr << std::endl;
gpgme_subkey_t subkeylist = KEY->subkeys; gpgme_subkey_t subkeylist = KEY->subkeys;
while(subkeylist != NULL) while(subkeylist != NULL)
{ {
@ -364,6 +373,7 @@ bool AuthGPG::storeAllKeys_locked()
subkeylist = subkeylist->next; subkeylist = subkeylist->next;
} }
#endif
/* NB uids is a linked list and can contain multiple ids. /* NB uids is a linked list and can contain multiple ids.
@ -404,6 +414,7 @@ bool AuthGPG::storeAllKeys_locked()
mainsiglist = mainsiglist->next; mainsiglist = mainsiglist->next;
} }
#ifdef GPG_DEBUG
gpgme_user_id_t uidlist = KEY->uids; gpgme_user_id_t uidlist = KEY->uids;
while(uidlist != NULL) while(uidlist != NULL)
{ {
@ -427,6 +438,7 @@ bool AuthGPG::storeAllKeys_locked()
uidlist = uidlist->next; uidlist = uidlist->next;
} }
#endif
/* signatures are attached to uids... but only supplied /* signatures are attached to uids... but only supplied
* if GPGME_KEYLIST_MODE_SIGS is on. * if GPGME_KEYLIST_MODE_SIGS is on.
@ -481,8 +493,10 @@ bool AuthGPG::updateTrustAllKeys_locked()
{ {
/* check for trust items associated with key */ /* check for trust items associated with key */
std::string peerid = it->second.email; std::string peerid = it->second.email;
#ifdef GPG_DEBUG
std::cerr << "Searching GPGme for TrustInfo on: " << peerid; std::cerr << "Searching GPGme for TrustInfo on: " << peerid;
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* Initiates a key listing. NB: maxlevel is ignored!*/ /* Initiates a key listing. NB: maxlevel is ignored!*/
if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_trustlist_start (CTX, peerid.c_str(), 0))) if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_trustlist_start (CTX, peerid.c_str(), 0)))
@ -495,8 +509,8 @@ bool AuthGPG::updateTrustAllKeys_locked()
/* Loop until end of key */ /* Loop until end of key */
for(int i = 0;(GPG_ERR_NO_ERROR == (ERR = #ifdef GPG_DEBUG
gpgme_op_trustlist_next (CTX, &ti))); i++) for(int i = 0;(GPG_ERR_NO_ERROR == (ERR = gpgme_op_trustlist_next (CTX, &ti))); i++)
{ {
std::string keyid = ti->keyid; std::string keyid = ti->keyid;
int type = ti->type; int type = ti->type;
@ -514,11 +528,10 @@ bool AuthGPG::updateTrustAllKeys_locked()
std::cerr << " Validity: " << ti->validity; std::cerr << " Validity: " << ti->validity;
std::cerr << " Name: " << ti->name; std::cerr << " Name: " << ti->name;
std::cerr << std::endl; std::cerr << std::endl;
} }
std::cerr << "End of TrustList Iteration."; std::cerr << "End of TrustList Iteration.";
std::cerr << std::endl; std::cerr << std::endl;
#endif
ProcessPGPmeError(ERR); ProcessPGPmeError(ERR);
if (GPG_ERR_NO_ERROR != gpgme_op_trustlist_end(CTX)) if (GPG_ERR_NO_ERROR != gpgme_op_trustlist_end(CTX))
@ -578,7 +591,6 @@ bool AuthGPG::printAllKeys_locked()
bool AuthGPG::printOwnKeys_locked() bool AuthGPG::printOwnKeys_locked()
{ {
certmap::iterator it; certmap::iterator it;
for(it = mKeyList.begin(); it != mKeyList.end(); it++) for(it = mKeyList.begin(); it != mKeyList.end(); it++)
{ {
@ -623,9 +635,11 @@ void ProcessPGPmeError(gpgme_error_t ERR)
gpgme_err_code_t code = gpgme_err_code(ERR); gpgme_err_code_t code = gpgme_err_code(ERR);
gpgme_err_source_t src = gpgme_err_source(ERR); gpgme_err_source_t src = gpgme_err_source(ERR);
std::cerr << "GPGme ERROR: Code: " << code << " Source: " << src << std::endl; if(code > 0)
std::cerr << "GPGme ERROR: " << gpgme_strerror(ERR) << std::endl; {
std::cerr << "GPGme ERROR: Code: " << code << " Source: " << src << std::endl;
std::cerr << "GPGme ERROR: " << gpgme_strerror(ERR) << std::endl;
}
} }
void print_pgpme_verify_summary(unsigned int summary) void print_pgpme_verify_summary(unsigned int summary)
@ -695,7 +709,7 @@ bool AuthGPG::DoOwnSignature_locked(const void *data, unsigned int datalen, void
} }
gpgme_sign_result_t res = gpgme_op_sign_result(CTX); gpgme_sign_result_t res = gpgme_op_sign_result(CTX);
#ifdef GPG_DEBUG
if (res) if (res)
{ {
fprintf(stderr, "Sign Got Result\n"); fprintf(stderr, "Sign Got Result\n");
@ -707,6 +721,7 @@ bool AuthGPG::DoOwnSignature_locked(const void *data, unsigned int datalen, void
gpgme_invalid_key_t ik = res->invalid_signers; gpgme_invalid_key_t ik = res->invalid_signers;
gpgme_new_signature_t sg = res->signatures; gpgme_new_signature_t sg = res->signatures;
while(ik != NULL) while(ik != NULL)
{ {
fprintf(stderr, "AuthGPG::Sign, Invalid by: %s\n", ik->fpr); fprintf(stderr, "AuthGPG::Sign, Invalid by: %s\n", ik->fpr);
@ -718,13 +733,16 @@ bool AuthGPG::DoOwnSignature_locked(const void *data, unsigned int datalen, void
fprintf(stderr, "AuthGPG::Signed by: %s\n", sg->fpr); fprintf(stderr, "AuthGPG::Signed by: %s\n", sg->fpr);
sg = sg->next; sg = sg->next;
} }
#endif
/* now extract the data from gpgmeSig */ /* now extract the data from gpgmeSig */
size_t len = 0; size_t len = 0;
int len2 = len; int len2 = len;
// gpgme_data_write (gpgmeSig, "", 1); // to be able to convert it into a string // gpgme_data_write (gpgmeSig, "", 1); // to be able to convert it into a string
char *export_sig = gpgme_data_release_and_get_mem(gpgmeSig, &len); char *export_sig = gpgme_data_release_and_get_mem(gpgmeSig, &len);
#ifdef GPG_DEBUG
fprintf(stderr, "AuthGPG::Signature len: %d \n", len); fprintf(stderr, "AuthGPG::Signature len: %d \n", len);
#endif
if (len < *outl) // -1 because we added a 0 at the end. if (len < *outl) // -1 because we added a 0 at the end.
{ {
@ -745,8 +763,10 @@ bool AuthGPG::VerifySignature_locked(const void *data, int datalen, const void *
gpgme_data_t gpgmeSig; gpgme_data_t gpgmeSig;
gpgme_data_t gpgmeData; gpgme_data_t gpgmeData;
#ifdef GPG_DEBUG
std::cerr << "VerifySignature: datalen: " << datalen << " siglen: " << siglen; std::cerr << "VerifySignature: datalen: " << datalen << " siglen: " << siglen;
std::cerr << std::endl; std::cerr << std::endl;
#endif
if(siglen==73) if(siglen==73)
{ {
@ -782,11 +802,15 @@ bool AuthGPG::VerifySignature_locked(const void *data, int datalen, const void *
if (res) if (res)
{ {
#ifdef GPG_DEBUG
fprintf(stderr, "VerifySignature Got Result\n"); fprintf(stderr, "VerifySignature Got Result\n");
#endif
} }
else else
{ {
#ifdef GPG_DEBUG
fprintf(stderr, "VerifySignature Failed to get Result\n"); fprintf(stderr, "VerifySignature Failed to get Result\n");
#endif
return false ; return false ;
} }
@ -795,18 +819,24 @@ bool AuthGPG::VerifySignature_locked(const void *data, int datalen, const void *
while(sg != NULL) while(sg != NULL)
{ {
fprintf(stderr, "AuthGPG::Verify Sig by: %s, Result: %d\n", sg->fpr, sg->summary); #ifdef GPG_DEBUG
fprintf(stderr, "AuthGPG::Verify Sig by: %s, Result: %d\n", sg->fpr, sg->summary);
print_pgpme_verify_summary(sg->summary); print_pgpme_verify_summary(sg->summary);
#endif
if (sg->summary & GPGME_SIGSUM_VALID) if (sg->summary & GPGME_SIGSUM_VALID)
{ {
fprintf(stderr, "AuthGPG::VerifySignature() OK\n"); #ifdef GPG_DEBUG
if (withfingerprint != "" && withfingerprint == std::string(sg->fpr)) { fprintf(stderr, "AuthGPG::VerifySignature() OK\n");
fprintf(stderr, "AuthGPG::VerifySignature() for the fingerprint key : "); #endif
std::cerr << withfingerprint; if (withfingerprint != "" && withfingerprint == std::string(sg->fpr)) {
fprintf(stderr, "\n"); #ifdef GPG_DEBUG
valid = true; fprintf(stderr, "AuthGPG::VerifySignature() for the fingerprint key : ");
} std::cerr << withfingerprint;
fprintf(stderr, "\n");
#endif
valid = true;
}
} }
sg = sg->next; sg = sg->next;
@ -828,7 +858,10 @@ bool AuthGPG::VerifySignature_locked(const void *data, int datalen, const void *
bool AuthGPG::active() { bool AuthGPG::active()
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
return ((gpgmeInit) && (gpgmeKeySelected)); return ((gpgmeInit) && (gpgmeKeySelected));
} }
@ -901,11 +934,13 @@ std::string AuthGPG::getGPGEmail(GPG_id id)
std::string AuthGPG::getGPGOwnId() std::string AuthGPG::getGPGOwnId()
{ {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
return mOwnGpgId; return mOwnGpgId;
} }
std::string AuthGPG::getGPGOwnName() std::string AuthGPG::getGPGOwnName()
{ {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
return mOwnGpgCert.name; return mOwnGpgCert.name;
} }
@ -925,7 +960,9 @@ bool AuthGPG::getGPGAllList(std::list<std::string> &ids)
bool AuthGPG::getGPGDetails(std::string id, RsPeerDetails &d) bool AuthGPG::getGPGDetails(std::string id, RsPeerDetails &d)
{ {
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::getPGPDetails() called for : " << id << std::endl; std::cerr << "AuthGPG::getPGPDetails() called for : " << id << std::endl;
#endif
storeAllKeys_timed(); storeAllKeys_timed();
RsStackMutex stack(pgpMtx); /******* LOCKED ******/ RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -955,7 +992,9 @@ bool AuthGPG::getGPGDetails(std::string id, RsPeerDetails &d)
} }
} }
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::getPGPDetails() Name : " << it->second.name << std::endl; std::cerr << "AuthGPG::getPGPDetails() Name : " << it->second.name << std::endl;
#endif
return true; return true;
} else { } else {
return false; return false;
@ -1137,10 +1176,12 @@ std::string AuthGPG::SaveCertificateToString(std::string id)
char *export_txt = gpgme_data_release_and_get_mem(gpgmeData, &len); char *export_txt = gpgme_data_release_and_get_mem(gpgmeData, &len);
tmp = std::string(export_txt); tmp = std::string(export_txt);
#ifdef GPG_DEBUG
std::cerr << "Exported Certificate: "; std::cerr << "Exported Certificate: ";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << tmp; std::cerr << tmp;
std::cerr << std::endl; std::cerr << std::endl;
#endif
gpgme_free(export_txt); gpgme_free(export_txt);
@ -1156,7 +1197,9 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id)
//std::string cleancert = cleanUpCertificate(str); disable for p3disc message on windows system. Move the clean cert in p3peers //std::string cleancert = cleanUpCertificate(str); disable for p3disc message on windows system. Move the clean cert in p3peers
std::string cleancert = str; std::string cleancert = str;
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::LoadCertificateFromString() cleancert : " << cleancert; std::cerr << "AuthGPG::LoadCertificateFromString() cleancert : " << cleancert;
#endif
gpgme_data_t gpgmeData; gpgme_data_t gpgmeData;
if (GPG_ERR_NO_ERROR != gpgme_data_new_from_mem(&gpgmeData, cleancert.c_str(), cleancert.length(), 1)) if (GPG_ERR_NO_ERROR != gpgme_data_new_from_mem(&gpgmeData, cleancert.c_str(), cleancert.length(), 1))
@ -1179,12 +1222,16 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id)
gpgme_import_result_t res = gpgme_op_import_result(CTX); gpgme_import_result_t res = gpgme_op_import_result(CTX);
std::string fingerprint = std::string(res->imports->fpr); std::string fingerprint = std::string(res->imports->fpr);
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::LoadCertificateFromString() Importing considered folowing fpr : " << fingerprint << std::endl; std::cerr << "AuthGPG::LoadCertificateFromString() Importing considered folowing fpr : " << fingerprint << std::endl;
#endif
int imported = res->imported; int imported = res->imported;
#ifdef GPG_DEBUG
fprintf(stderr, "ImportCertificate(Considered: %d Imported: %d)\n", fprintf(stderr, "ImportCertificate(Considered: %d Imported: %d)\n",
res->considered, res->imported); res->considered, res->imported);
#endif
/* do we need to delete res??? */ /* do we need to delete res??? */
gpgme_data_release (gpgmeData); gpgme_data_release (gpgmeData);
@ -1203,7 +1250,9 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id)
break; break;
} }
} }
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::LoadCertificateFromString() returning with gpg_id : " << gpg_id << std::endl; std::cerr << "AuthGPG::LoadCertificateFromString() returning with gpg_id : " << gpg_id << std::endl;
#endif
return true; return true;
} }
@ -1225,8 +1274,10 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id)
bool AuthGPG::setAcceptToConnectGPGCertificate(std::string gpg_id, bool acceptance) bool AuthGPG::setAcceptToConnectGPGCertificate(std::string gpg_id, bool acceptance)
{ {
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::markGPGCertificateAsFriends(" << gpg_id << ")"; std::cerr << "AuthGPG::markGPGCertificateAsFriends(" << gpg_id << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
RsStackMutex stack(pgpMtx); /******* LOCKED ******/ RsStackMutex stack(pgpMtx); /******* LOCKED ******/
@ -1248,8 +1299,10 @@ bool AuthGPG::setAcceptToConnectGPGCertificate(std::string gpg_id, bool acceptan
bool AuthGPG::SignCertificateLevel0(GPG_id id) bool AuthGPG::SignCertificateLevel0(GPG_id id)
{ {
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::SignCertificat(" << id << ")"; std::cerr << "AuthGPG::SignCertificat(" << id << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
if (1 != privateSignCertificate(id)) if (1 != privateSignCertificate(id))
@ -1268,15 +1321,19 @@ bool AuthGPG::RevokeCertificate(std::string id)
{ {
RsStackMutex stack(pgpMtx); /******* LOCKED ******/ RsStackMutex stack(pgpMtx); /******* LOCKED ******/
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::RevokeCertificate(" << id << ") not implemented yet"; std::cerr << "AuthGPG::RevokeCertificate(" << id << ") not implemented yet";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
bool AuthGPG::TrustCertificate(std::string id, int trustlvl) bool AuthGPG::TrustCertificate(std::string id, int trustlvl)
{ {
#ifdef GPG_DEBUG
std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl; std::cerr << "AuthGPG::TrustCertificate(" << id << ", " << trustlvl << ")" << std::endl;
#endif
return this->privateTrustCertificate(id, trustlvl); return this->privateTrustCertificate(id, trustlvl);
} }
@ -1471,7 +1528,9 @@ static std::string setKeyPairParams(bool useRsa, unsigned int blen,
params << "Key-Type: RSA"<< std::endl; params << "Key-Type: RSA"<< std::endl;
if (blen < 1024) if (blen < 1024)
{ {
#ifdef GPG_DEBUG
std::cerr << "Weak Key... strengthing..."<< std::endl; std::cerr << "Weak Key... strengthing..."<< std::endl;
#endif
blen = 1024; blen = 1024;
} }
blen = ((blen / 512) * 512); /* make multiple of 512 */ blen = ((blen / 512) * 512); /* make multiple of 512 */
@ -1504,7 +1563,9 @@ static std::string setKeyPairParams(bool useRsa, unsigned int blen,
params << "Key-Type: RSA"<< std::endl; params << "Key-Type: RSA"<< std::endl;
if (blen < 1024) if (blen < 1024)
{ {
#ifdef GPG_DEBUG
std::cerr << "Weak Key... strengthing..."<< std::endl; std::cerr << "Weak Key... strengthing..."<< std::endl;
#endif
blen = 1024; blen = 1024;
} }
blen = ((blen / 512) * 512); /* make multiple of 512 */ blen = ((blen / 512) * 512); /* make multiple of 512 */
@ -1995,7 +2056,9 @@ static gpgme_error_t trustCallback(void *opaque, gpgme_status_code_t status, \
WriteFile(winFd, result, strlen (result), &written, NULL); WriteFile(winFd, result, strlen (result), &written, NULL);
WriteFile(winFd, "\n", 1, &written, NULL); WriteFile(winFd, "\n", 1, &written, NULL);
#endif #endif
#ifdef GPG_DEBUG
std::cerr << "trustCallback() result : " << result << std::endl; std::cerr << "trustCallback() result : " << result << std::endl;
#endif
} }
return params->err; return params->err;
@ -2026,7 +2089,7 @@ std::list<RsItem*> AuthGPG::saveList(bool& cleanup)
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
std::map<std::string, bool>::iterator mapIt; std::map<std::string, bool>::iterator mapIt;
for (mapIt = mAcceptToConnectMap.begin(); mapIt != mAcceptToConnectMap.end(); mapIt++) { for (mapIt = mAcceptToConnectMap.begin(); mapIt != mAcceptToConnectMap.end(); mapIt++) {
if (mapIt->first == getGPGOwnId()) { if (mapIt->first == mOwnGpgId) {
continue; continue;
} }
RsTlvKeyValue kv; RsTlvKeyValue kv;
@ -2060,7 +2123,7 @@ bool AuthGPG::loadList(std::list<RsItem*> load)
std::list<RsTlvKeyValue>::iterator kit; std::list<RsTlvKeyValue>::iterator kit;
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) { for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
if (kit->key == getGPGOwnId()) { if (kit->key == mOwnGpgId) {
continue; continue;
} }
mAcceptToConnectMap[kit->key] = (kit->value == "TRUE"); mAcceptToConnectMap[kit->key] = (kit->value == "TRUE");