mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
add gpg password static store when gpg password callback is called
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2260 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a9029b26c1
commit
fba2a3afae
@ -71,24 +71,37 @@ gpgcert::~gpgcert()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string gpg_password_static;
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
static std::string sp = "" ;
|
#ifdef GPG_DEBUG
|
||||||
|
fprintf(stderr, "pgp_pwd_callback() called.\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string text ;
|
std::string text;
|
||||||
|
if (is_set_gpg_password_static) {
|
||||||
if(sp == "" || prev_was_bad)
|
#ifdef GPG_DEBUG
|
||||||
{
|
fprintf(stderr, "pgp_pwd_callback() using already setted password.\n");
|
||||||
if(prev_was_bad)
|
#endif
|
||||||
text = rsicontrol->getNotify().askForPassword("GPG key passphrase",std::string("Wrong password !\n\nPlease enter the password to unlock the following GPG key:\n\n ")+uid_hint+"\n") ;
|
text = gpg_password_static;
|
||||||
else
|
} else {
|
||||||
text = rsicontrol->getNotify().askForPassword("GPG key passphrase",std::string("Please enter the password to unlock the following GPG key:\n\n")+uid_hint+"\n") ;
|
if(prev_was_bad) {
|
||||||
sp = text ;
|
#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);
|
||||||
|
#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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
text = sp ;
|
|
||||||
|
|
||||||
fprintf(stderr, "pgp_pwd_callback() Set Password\n");
|
|
||||||
|
|
||||||
#ifndef WINDOWS_SYS
|
#ifndef WINDOWS_SYS
|
||||||
write(fd, text.c_str(), text.size());
|
write(fd, text.c_str(), text.size());
|
||||||
@ -100,6 +113,10 @@ gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passp
|
|||||||
WriteFile(winFd, "\n", 1, &written, NULL);
|
WriteFile(winFd, "\n", 1, &written, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef GPG_DEBUG
|
||||||
|
fprintf(stderr, "pgp_pwd_callback() password setted\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +269,8 @@ bool AuthGPG::availableGPGCertificatesWithPrivateKeys(std::list<std::string> &id
|
|||||||
*/
|
*/
|
||||||
int AuthGPG::GPGInit(std::string ownId)
|
int AuthGPG::GPGInit(std::string ownId)
|
||||||
{
|
{
|
||||||
|
is_set_gpg_password_static= false;
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
|
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
|
||||||
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl;
|
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId << std::endl;
|
||||||
|
@ -208,7 +208,7 @@ class NotifyBase
|
|||||||
virtual void notifyOwnAvatarChanged() {}
|
virtual void notifyOwnAvatarChanged() {}
|
||||||
virtual void notifyOwnStatusMessageChanged() {}
|
virtual void notifyOwnStatusMessageChanged() {}
|
||||||
|
|
||||||
virtual std::string askForPassword(const std::string& window_title,const std::string& text) { return "" ;}
|
virtual std::string askForPassword(const std::string& key_details) { return "" ;}
|
||||||
};
|
};
|
||||||
|
|
||||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||||
|
@ -42,10 +42,12 @@ void NotifyQt::notifyOwnAvatarChanged()
|
|||||||
emit ownAvatarChanged() ;
|
emit ownAvatarChanged() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NotifyQt::askForPassword(const std::string& window_title,const std::string& text)
|
std::string NotifyQt::askForPassword(const std::string& key_details)
|
||||||
{
|
{
|
||||||
return QInputDialog::getText(NULL, QString::fromStdString(window_title),
|
|
||||||
QString::fromStdString(text), QLineEdit::Password,
|
return QInputDialog::getText(NULL, tr("GPG key passphrase"),
|
||||||
|
tr("Please enter the password to unlock the following GPG key:\n") + QString::fromStdString(key_details),
|
||||||
|
QLineEdit::Password,
|
||||||
NULL, NULL).toStdString();
|
NULL, NULL).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class NotifyQt: public QObject, public NotifyBase
|
|||||||
virtual void notifyOwnAvatarChanged() ;
|
virtual void notifyOwnAvatarChanged() ;
|
||||||
virtual void notifyOwnStatusMessageChanged() ;
|
virtual void notifyOwnStatusMessageChanged() ;
|
||||||
|
|
||||||
virtual std::string askForPassword(const std::string& window_title,const std::string& text) ;
|
virtual std::string askForPassword(const std::string& key_details) ;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// It's beneficial to send info to the GUI using signals, because signals are thread-safe
|
// It's beneficial to send info to the GUI using signals, because signals are thread-safe
|
||||||
|
Loading…
Reference in New Issue
Block a user