- Ported trunk commit 2780: Set the trust lvl to 3 when accepting a friend and the trust lvl is unknown.

- Removed some potentially harmful (deadlock) code.
- Put some printf into debugging #ifdef



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2783 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-04-25 19:00:33 +00:00
parent df7c8dacb3
commit c7db07c37b
2 changed files with 230 additions and 192 deletions

View File

@ -104,7 +104,7 @@ gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passp
}
AuthGPG::AuthGPG()
:gpgmeInit(false),gpgmeKeySelected(false),autorisePasswordCallbackNotify(true),p3Config(CONFIG_TYPE_AUTHGPG)
:gpgmeInit(false),gpgmeKeySelected(false),p3Config(CONFIG_TYPE_AUTHGPG)
{
{
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/
@ -279,11 +279,8 @@ int AuthGPG::GPGInit(std::string ownId)
lvl = mOwnGpgCert.validLvl;
}
//check the validity of the private key. When set to unknown, it caused signature and text encryptions bugs
if (lvl < 2) {
std::cerr << "AuthGPG::GPGInit() abnormal validity set to private key. Switch it to none by default." << std::endl;
privateTrustCertificate(mOwnGpgId, 4);
}
//force the validity of the private key. When set to unknown, it caused signature and text encryptions bugs
privateTrustCertificate(mOwnGpgId, 5);
//printAllKeys_locked();
@ -313,7 +310,9 @@ bool AuthGPG::storeAllKeys_locked()
std::cerr << "AuthGPG::storeAllKeys_locked()" << std::endl;
#endif
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/
std::list<std::string> gpg_change_trust_list;
{
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK);
gpg_error_t ERR;
if (!gpgmeInit)
@ -339,9 +338,9 @@ bool AuthGPG::storeAllKeys_locked()
if (GPG_ERR_NO_ERROR != gpgme_op_keylist_start (CTX, "", 0))
{
std::cerr << "AuthGPG::storeAllKeys_locked() Error iterating through KeyList" << std::endl;
// if (rsicontrol != NULL) {
// rsicontrol->getNotify().notifyErrorMsg(0,0,"Error reading gpg keyring, cannot acess key list.");
// }
// if (rsicontrol != NULL) {
// rsicontrol->getNotify().notifyErrorMsg(0,0,"Error reading gpg keyring, cannot acess key list.");
// }
gpgme_set_keylist_mode(CTX, origmode);
return false;
}
@ -351,14 +350,15 @@ bool AuthGPG::storeAllKeys_locked()
ERR = gpgme_op_keylist_next (CTX, &KEY);
if (GPG_ERR_NO_ERROR != ERR) {
std::cerr << "AuthGPG::storeAllKeys_locked() didn't find any gpg key in the keyring" << std::endl;
// if (rsicontrol != NULL) {
// rsicontrol->getNotify().notifyErrorMsg(0,0,"Error reading gpg keyring, cannot find any key in the list.");
// }
// if (rsicontrol != NULL) {
// rsicontrol->getNotify().notifyErrorMsg(0,0,"Error reading gpg keyring, cannot find any key in the list.");
// }
return false;
} else {
//let's start a new list
mKeyList.clear();
}
for(int i = 0;GPG_ERR_NO_ERROR == ERR; i++)
{
/* store in pqiAuthDetails */
@ -470,6 +470,15 @@ bool AuthGPG::storeAllKeys_locked()
/* store in map */
mKeyList[nu.id] = nu;
#ifdef GPG_DEBUG
std::cerr << "nu.name" << nu.name << std::endl;
std::cerr << "nu.trustLvl" << nu.trustLvl << std::endl;
std::cerr << "nu.accept_connection" << nu.accept_connection << std::endl;
#endif
if (nu.trustLvl < 2 && nu.accept_connection) {
//add it to the list of key that we will force the trust to 2
gpg_change_trust_list.push_back(nu.id);
}
//store own key
if (nu.id == mOwnGpgId) {
@ -487,6 +496,14 @@ bool AuthGPG::storeAllKeys_locked()
}
gpgme_set_keylist_mode(CTX, origmode);
}
std::list<std::string>::iterator it;
for(it = gpg_change_trust_list.begin(); it != gpg_change_trust_list.end(); it++)
{
privateTrustCertificate(*it, 3);
}
return true;
}
@ -1274,13 +1291,17 @@ bool AuthGPG::setAcceptToConnectGPGCertificate(std::string gpg_id, bool acceptan
/* reload stuff now ... */
storeAllKeys_locked();
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/
{
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK);
certmap::iterator it;
if (mKeyList.end() == (it = mKeyList.find(gpg_id))) {
return false;
}
it->second.accept_connection = acceptance;
mAcceptToConnectMap[gpg_id] = acceptance;
}
storeAllKeys_locked();
IndicateConfigChanged();
@ -1410,12 +1431,14 @@ int AuthGPG::privateRevokeCertificate(std::string id)
int AuthGPG::privateTrustCertificate(std::string id, int trustlvl)
{
/* The certificate should be in Peers list ??? */
if(!isGPGSigned(id)) {
if(!isGPGAccepted(id)) {
std::cerr << "Invalid Certificate" << std::endl;
return 0;
}
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/
{
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK);
gpgcert trustCert = mKeyList.find(id)->second;
gpgme_key_t trustKey = trustCert.key;
std::string trustString;
@ -1436,6 +1459,9 @@ int AuthGPG::privateTrustCertificate(std::string id, int trustlvl)
//the key ref has changed, we got to get rid of the old reference.
trustCert.key = NULL;
}
storeAllKeys_locked();
return 1;
}
@ -1582,6 +1608,7 @@ static std::string setKeyPairParams(bool useRsa, unsigned int blen,
* from the keyring
*/
#ifdef UNUSED_CODE
static gpgme_key_t getKey(gpgme_ctx_t CTX, std::string name, std::string comment, std::string email) {
gpgme_key_t key;
@ -1625,6 +1652,7 @@ static gpgme_key_t getKey(gpgme_ctx_t CTX, std::string name, std::string comment
}
return NULL;
}
#endif
/* Callback function for key signing */
@ -1635,7 +1663,7 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
class EditParams *params = (class EditParams *)opaque;
class SignParams *sparams = (class SignParams *)params->oParams;
const char *result = NULL;
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback status: %d args: %s, params->state: %d\n", status, args, params->state);
/* printf stuff out */
@ -1677,6 +1705,7 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
fprintf(stderr,"keySignCallback params->state SIGN_ENTER_PASSPHRASE\n");
if (params->state == SIGN_ERROR)
fprintf(stderr,"keySignCallback params->state SIGN_ERROR");
#endif
if(status == GPGME_STATUS_EOF ||
@ -1696,7 +1725,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
switch (params->state)
{
case SIGN_START:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_START\n");
#endif
if (status == GPGME_STATUS_GET_LINE &&
(!std::string("keyedit.prompt").compare(args)))
@ -1711,7 +1742,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_COMMAND:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_COMMAND\n");
#endif
if (status == GPGME_STATUS_GET_BOOL &&
(!std::string("keyedit.sign_all.okay").compare(args)))
@ -1757,7 +1790,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_UIDS:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_UIDS\n");
#endif
if (status == GPGME_STATUS_GET_LINE &&
(!std::string("sign_uid.expire").compare(args)))
@ -1791,7 +1826,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_SET_EXPIRE:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_SET_EXPIRE\n");
#endif
if (status == GPGME_STATUS_GET_LINE &&
(!std::string("sign_uid.class").compare(args)))
@ -1806,7 +1843,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_SET_CHECK_LEVEL:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_SET_CHECK_LEVEL\n");
#endif
if (status == GPGME_STATUS_GET_BOOL &&
(!std::string("sign_uid.okay").compare(args)))
@ -1821,7 +1860,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_ENTER_PASSPHRASE:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_ENTER_PASSPHRASE\n");
#endif
if (status == GPGME_STATUS_GOOD_PASSPHRASE)
{
@ -1834,7 +1875,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_CONFIRM:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_CONFIRM\n");
#endif
if (status == GPGME_STATUS_GET_LINE &&
(!std::string("keyedit.prompt").compare(args)))
@ -1849,7 +1892,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_QUIT:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_QUIT\n");
#endif
if (status == GPGME_STATUS_GET_BOOL &&
(!std::string("keyedit.save.okay").compare(args)))
@ -1864,7 +1909,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
}
break;
case SIGN_ERROR:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_ERROR\n");
#endif
if (status == GPGME_STATUS_GET_LINE &&
(!std::string("keyedit.prompt").compare(args)))
@ -1886,7 +1933,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
if (result)
{
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback result:%s\n", result);
#endif
#ifndef WINDOWS_SYS
if (*result)
{
@ -1923,6 +1972,7 @@ static gpgme_error_t trustCallback(void *opaque, gpgme_status_code_t status, \
const char *result = NULL;
/* printf stuff out */
#ifdef GPG_DEBUG
if (status == GPGME_STATUS_EOF)
fprintf(stderr,"keySignCallback GPGME_STATUS_EOF\n");
if (status == GPGME_STATUS_GOT_IT)
@ -1955,6 +2005,7 @@ static gpgme_error_t trustCallback(void *opaque, gpgme_status_code_t status, \
fprintf(stderr,"keySignCallback params->state TRUST_QUIT\n");
if (params->state == TRUST_ERROR)
fprintf(stderr,"keySignCallback params->state TRUST_ERROR\n");
#endif
if(status == GPGME_STATUS_EOF ||
@ -2141,11 +2192,3 @@ bool AuthGPG::loadList(std::list<RsItem*> load)
return true;
}
void AuthGPG::setAutorisePasswordCallbackNotify(bool autorise) {
autorisePasswordCallbackNotify = autorise;
return;
}
bool AuthGPG::getAutorisePasswordCallbackNotify() {
return autorisePasswordCallbackNotify;
}

View File

@ -120,9 +120,6 @@ class AuthGPG : public p3Config
bool printKeys();
void setAutorisePasswordCallbackNotify(bool);
bool getAutorisePasswordCallbackNotify();
/*********************************************************************************/
/************************* STAGE 1 ***********************************************/
/*********************************************************************************/
@ -243,8 +240,6 @@ private:
bool gpgmeKeySelected;
bool autorisePasswordCallbackNotify;
gpgme_engine_info_t INFO;
gpgme_ctx_t CTX;