forgot to commit this one! Sorry.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2739 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-04-20 12:08:25 +00:00
parent f2a3486e4b
commit 7c6ad47bcf

View File

@ -34,7 +34,7 @@
//#define GPG_DEBUG 1 //#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();
/* Turn a set of parameters into a string */ /* Turn a set of parameters into a string */
@ -71,58 +71,38 @@ gpgcert::~gpgcert()
} }
} }
static std::string gpg_password_static; #define GPG_DEBUG2
static bool is_set_gpg_password_static = false;
gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd) gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd)
{ {
#ifdef GPG_DEBUG #ifdef GPG_DEBUG2
fprintf(stderr, "pgp_pwd_callback() called.\n"); fprintf(stderr, "pgp_pwd_callback() called.\n");
#endif #endif
std::string text = rsicontrol->getNotify().askForPassword(uid_hint,prev_was_bad);
std::string text; #ifdef GPG_DEBUG2
if (is_set_gpg_password_static) { std::cerr << "pgp_pwd_callback() got GPG passwd from gui." << std::endl;
#ifdef GPG_DEBUG
fprintf(stderr, "pgp_pwd_callback() using already setted password.\n");
#endif
text = gpg_password_static;
} else {
if(prev_was_bad || !AuthGPG::getAuthGPG()->getAutorisePasswordCallbackNotify()) {
#ifdef GPG_DEBUG
fprintf(stderr, "pgp_pwd_callback() allow only one try to be consistent with gpg agent.\n");
#endif
text = "";
} else {
text = rsicontrol->getNotify().askForPassword(uid_hint, prev_was_bad);
#ifdef GPG_DEBUG
std::cerr << "pgp_pwd_callback() got GPG passwd from gui." << std::endl;
#endif
gpg_password_static = text;
is_set_gpg_password_static = true;
}
}
#ifndef WINDOWS_SYS
write(fd, text.c_str(), text.size());
write(fd, "\n", 1); /* needs a new line? */
#else
DWORD written = 0;
HANDLE winFd = (HANDLE) fd;
WriteFile(winFd, text.c_str(), text.size(), &written, NULL);
WriteFile(winFd, "\n", 1, &written, NULL);
#endif #endif
#ifdef GPG_DEBUG if((void*)fd != NULL)
fprintf(stderr, "pgp_pwd_callback() password setted\n"); {
#endif #ifndef WINDOWS_SYS
write(fd, text.c_str(), text.size());
write(fd, "\n", 1); /* needs a new line? */
#else
DWORD written = 0;
HANDLE winFd = (HANDLE) fd;
WriteFile(winFd, text.c_str(), text.size(), &written, NULL);
WriteFile(winFd, "\n", 1, &written, NULL);
#endif
}
#ifdef GPG_DEBUG2
fprintf(stderr, "pgp_pwd_callback() password setted\n");
#endif
return 0; return 0;
} }
static char *PgpPassword = NULL;
AuthGPG::AuthGPG() AuthGPG::AuthGPG()
:gpgmeInit(false),gpgmeKeySelected(false),autorisePasswordCallbackNotify(true),p3Config(CONFIG_TYPE_AUTHGPG) :gpgmeInit(false),gpgmeKeySelected(false),autorisePasswordCallbackNotify(true),p3Config(CONFIG_TYPE_AUTHGPG)
{ {
@ -275,7 +255,7 @@ int AuthGPG::GPGInit(std::string ownId)
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/
is_set_gpg_password_static= false;
if (!gpgmeInit) { if (!gpgmeInit) {
return 0; return 0;
} }
@ -523,7 +503,6 @@ bool AuthGPG::updateTrustAllKeys_locked()
/* have to do this the hard way! */ /* have to do this the hard way! */
gpgme_trust_item_t ti = NULL;
std::map<std::string, gpgcert>::iterator it; std::map<std::string, gpgcert>::iterator it;
for(it = mKeyList.begin(); it != mKeyList.end(); it++) for(it = mKeyList.begin(); it != mKeyList.end(); it++)
@ -545,6 +524,8 @@ bool AuthGPG::updateTrustAllKeys_locked()
/* Loop until end of key */ /* Loop until end of key */
#ifdef GPG_DEBUG #ifdef GPG_DEBUG
gpgme_trust_item_t ti = NULL;
for(int i = 0;(GPG_ERR_NO_ERROR == (ERR = 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;
@ -742,7 +723,6 @@ bool AuthGPG::DoOwnSignature_locked(const void *data, unsigned int datalen, void
/* now extract the data from gpgmeSig */ /* now extract the data from gpgmeSig */
size_t len = 0; size_t len = 0;
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 #ifdef GPG_DEBUG
@ -1234,7 +1214,6 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id)
#ifdef GPG_DEBUG #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 #endif
imported = res->imported; imported = res->imported;
#ifdef GPG_DEBUG #ifdef GPG_DEBUG
@ -1388,21 +1367,22 @@ int AuthGPG::privateSignCertificate(std::string id)
* Once the key is signed, it moves from Others to Peers list ??? * Once the key is signed, it moves from Others to Peers list ???
*/ */
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() == (it = mKeyList.find(id))) if (mKeyList.end() == (it = mKeyList.find(id)))
{ {
return false; return false;
} }
gpgme_key_t signKey = it->second.key; gpgme_key_t signKey = it->second.key;
gpgme_key_t ownKey = mOwnGpgCert.key; gpgme_key_t ownKey = mOwnGpgCert.key;
class SignParams sparams("0"); class SignParams sparams("0");
class EditParams params(SIGN_START, &sparams); class EditParams params(SIGN_START, &sparams);
gpgme_data_t out; gpgme_data_t out;
gpg_error_t ERR; gpg_error_t ERR;
if(GPG_ERR_NO_ERROR != (ERR = gpgme_data_new(&out))) { if(GPG_ERR_NO_ERROR != (ERR = gpgme_data_new(&out))) {
return 0; return 0;
} }
@ -1413,6 +1393,7 @@ int AuthGPG::privateSignCertificate(std::string id)
} }
if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, signKey, keySignCallback, &params, out))) { if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, signKey, keySignCallback, &params, out))) {
return 0; return 0;
} }