improved login system: do not re-ask for passphrase when user clicks cancel. Removed warning stating that maybe passphrase is wrong

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8415 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-06-11 20:31:52 +00:00
parent 3bec1f4f69
commit 74c01423f0
14 changed files with 87 additions and 45 deletions

View File

@ -26,7 +26,7 @@ GUI
[ ] "Wrong IP" security items shouldn't show up when the IP reported by friend is whitelisted. [ ] "Wrong IP" security items shouldn't show up when the IP reported by friend is whitelisted.
[ ] at login, when cancel is pressed, the system keeps asking for the passwd. It shouldn't, and directly go back to the list of locations. [X] at login, when cancel is pressed, the system keeps asking for the passwd. It shouldn't, and directly go back to the list of locations.
0000 [ ] merge the various help systems. there's 3 of them: (1) help buttons on most tabs that pop a flat panel with some 0000 [ ] merge the various help systems. there's 3 of them: (1) help buttons on most tabs that pop a flat panel with some
info; (2) help wizard accessible from the "!" button in friends details->Trust; (3) 'getting started tab' info; (2) help wizard accessible from the "!" button in friends details->Trust; (3) 'getting started tab'

View File

@ -64,7 +64,12 @@ ops_parse_cb_return_t cb_get_passphrase(const ops_parser_content_t *content_,ops
uid_hint = std::string((const char *)cbinfo->cryptinfo.keydata->uids[0].user_id) ; uid_hint = std::string((const char *)cbinfo->cryptinfo.keydata->uids[0].user_id) ;
uid_hint += "(" + RsPgpId(cbinfo->cryptinfo.keydata->key_id).toStdString()+")" ; uid_hint += "(" + RsPgpId(cbinfo->cryptinfo.keydata->key_id).toStdString()+")" ;
passwd = PGPHandler::passphraseCallback()(NULL,uid_hint.c_str(),NULL,prev_was_bad) ; bool cancelled = false ;
passwd = PGPHandler::passphraseCallback()(NULL,uid_hint.c_str(),NULL,prev_was_bad,&cancelled) ;
if(cancelled)
*(unsigned char *)cbinfo->arg = 1;
*(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ; *(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ;
memcpy(*(content->secret_key_passphrase.passphrase),passwd.c_str(),passwd.length()) ; memcpy(*(content->secret_key_passphrase.passphrase),passwd.c_str(),passwd.length()) ;
return OPS_KEEP_MEMORY; return OPS_KEEP_MEMORY;
@ -1307,7 +1312,8 @@ bool PGPHandler::SignDataBin(const RsPgpId& id,const void *data, const uint32_t
PGPFingerprintType fp(f.fingerprint) ; PGPFingerprintType fp(f.fingerprint) ;
#endif #endif
std::string passphrase = _passphrase_callback(NULL,uid_hint.c_str(),"Please enter passwd for encrypting your key : ",false) ; bool cancelled =false;
std::string passphrase = _passphrase_callback(NULL,uid_hint.c_str(),"Please enter passwd for encrypting your key : ",false,&cancelled) ;
ops_secret_key_t *secret_key = ops_decrypt_secret_key_from_data(key,passphrase.c_str()) ; ops_secret_key_t *secret_key = ops_decrypt_secret_key_from_data(key,passphrase.c_str()) ;
@ -1316,6 +1322,11 @@ bool PGPHandler::SignDataBin(const RsPgpId& id,const void *data, const uint32_t
std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl; std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl;
return false ; return false ;
} }
if(cancelled)
{
std::cerr << "Key entering cancelled" << std::endl;
return false ;
}
// then do the signature. // then do the signature.
@ -1387,10 +1398,16 @@ bool PGPHandler::privateSignCertificate(const RsPgpId& ownId,const RsPgpId& id_o
return false ; return false ;
} }
std::string passphrase = _passphrase_callback(NULL,RsPgpId(skey->key_id).toStdString().c_str(),"Please enter passwd for encrypting your key : ",false) ; bool cancelled = false;
std::string passphrase = _passphrase_callback(NULL,RsPgpId(skey->key_id).toStdString().c_str(),"Please enter passwd for encrypting your key : ",false,&cancelled) ;
ops_secret_key_t *secret_key = ops_decrypt_secret_key_from_data(skey,passphrase.c_str()) ; ops_secret_key_t *secret_key = ops_decrypt_secret_key_from_data(skey,passphrase.c_str()) ;
if(cancelled)
{
std::cerr << "Key cancelled by used." << std::endl;
return false ;
}
if(!secret_key) if(!secret_key)
{ {
std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl; std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl;

View File

@ -16,7 +16,7 @@ extern "C" {
#include <openpgpsdk/keyring_local.h> #include <openpgpsdk/keyring_local.h>
} }
typedef std::string (*PassphraseCallback)(void *data, const char *uid_hint, const char *passphrase_info, int prev_was_bad) ; typedef std::string (*PassphraseCallback)(void *data, const char *uid_hint, const char *passphrase_info, int prev_was_bad,bool *cancelled) ;
class PGPCertificateInfo class PGPCertificateInfo
{ {

View File

@ -86,14 +86,14 @@ bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfi
// return PGPHandler::encryptTextToString(RsPgpId(pgp_id),text,outstr) ; // return PGPHandler::encryptTextToString(RsPgpId(pgp_id),text,outstr) ;
// } // }
std::string pgp_pwd_callback(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad) std::string pgp_pwd_callback(void * /*hook*/, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad,bool *cancelled)
{ {
#define GPG_DEBUG2 #define GPG_DEBUG2
#ifdef GPG_DEBUG2 #ifdef GPG_DEBUG2
fprintf(stderr, "pgp_pwd_callback() called.\n"); fprintf(stderr, "pgp_pwd_callback() called.\n");
#endif #endif
std::string password; std::string password;
RsServer::notify()->askForPassword(uid_hint, prev_was_bad, password) ; RsServer::notify()->askForPassword(uid_hint, prev_was_bad, password,cancelled) ;
return password ; return password ;
} }

View File

@ -247,10 +247,10 @@ void p3Notify::notifyDownloadComplete (const std::string& fileHash )
void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; } void p3Notify::notifyDownloadCompleteCount (uint32_t count ) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyDownloadCompleteCount (count) ; }
void p3Notify::notifyHistoryChanged (uint32_t msgId , int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHistoryChanged (msgId,type) ; } void p3Notify::notifyHistoryChanged (uint32_t msgId , int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyHistoryChanged (msgId,type) ; }
bool p3Notify::askForPassword (const std::string& key_details , bool prev_is_bad , std::string& password) bool p3Notify::askForPassword (const std::string& key_details , bool prev_is_bad , std::string& password,bool *cancelled)
{ {
FOR_ALL_NOTIFY_CLIENTS FOR_ALL_NOTIFY_CLIENTS
if( (*it)->askForPassword(key_details,prev_is_bad,password)) if( (*it)->askForPassword(key_details,prev_is_bad,password,*cancelled))
return true ; return true ;
return false ; return false ;

View File

@ -123,7 +123,7 @@ class p3Notify: public RsNotify
void notifyDownloadCompleteCount (uint32_t /* count */) ; void notifyDownloadCompleteCount (uint32_t /* count */) ;
void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) ; void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) ;
bool askForPassword (const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */ ) ; bool askForPassword (const std::string& /* key_details */, bool /* prev_is_bad */, std::string&, bool *cancelled /* password */ ) ;
bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */) ; bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */) ;
private: private:

View File

@ -234,7 +234,7 @@ class NotifyClient
virtual void notifyDownloadCompleteCount (uint32_t /* count */) {} virtual void notifyDownloadCompleteCount (uint32_t /* count */) {}
virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {} virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {}
virtual bool askForPassword (const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */ ) { return false ;} virtual bool askForPassword (const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */,bool& /* cancelled */ ) { return false ;}
virtual bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */) { return false ;} virtual bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */) { return false ;}
}; };

View File

@ -411,20 +411,36 @@ callback_cmd_get_secret_key(const ops_parser_content_t *content_,ops_parse_cb_in
{ {
if (!cbinfo->cryptinfo.passphrase) if (!cbinfo->cryptinfo.passphrase)
{ {
cbinfo->arg = malloc(sizeof(unsigned char)) ;
*(unsigned char *)cbinfo->arg = 0 ;
memset(&pc,'\0',sizeof pc); memset(&pc,'\0',sizeof pc);
pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase; pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
CB(cbinfo,tag_to_use,&pc); CB(cbinfo,tag_to_use,&pc);
if(*(unsigned char*)(cbinfo->arg) == 1)
{
fprintf(stderr,"passphrase cancelled\n");
free(cbinfo->arg) ;
cbinfo->arg=NULL ;
return 0 ; // ASSERT(0);
}
if (!cbinfo->cryptinfo.passphrase) if (!cbinfo->cryptinfo.passphrase)
{ {
free(cbinfo->arg) ;
cbinfo->arg=NULL ;
fprintf(stderr,"can't get passphrase\n"); fprintf(stderr,"can't get passphrase\n");
return 0 ; // ASSERT(0); return 0 ; // ASSERT(0);
} }
free(cbinfo->arg) ;
cbinfo->arg=NULL ;
} }
/* then it must be encrypted */ /* then it must be encrypted */
secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase); secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase);
free(cbinfo->cryptinfo.passphrase) ; free(cbinfo->cryptinfo.passphrase) ;
cbinfo->cryptinfo.passphrase = NULL ; cbinfo->cryptinfo.passphrase = NULL ;
tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD ; tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD ;
} }

View File

@ -154,7 +154,6 @@ enum ops_content_tag_t
OPS_PARSER_CMD_GET_SECRET_KEY =0x400+1, OPS_PARSER_CMD_GET_SECRET_KEY =0x400+1,
OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD =0x400+2, OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD =0x400+2,
/* Errors */ /* Errors */
OPS_PARSER_ERROR =0x500, /*!< Internal Use: Parser Error */ OPS_PARSER_ERROR =0x500, /*!< Internal Use: Parser Error */
OPS_PARSER_ERRCODE =0x500+1, /*! < Internal Use: Parser Error with errcode returned */ OPS_PARSER_ERRCODE =0x500+1, /*! < Internal Use: Parser Error with errcode returned */

View File

@ -244,7 +244,7 @@ void NotifyQt::handleSignatureEvent()
bool NotifyQt::askForPassword(const std::string& key_details, bool prev_is_bad, std::string& password) bool NotifyQt::askForPassword(const std::string& key_details, bool prev_is_bad, std::string& password,bool& cancelled)
{ {
RsAutoUpdatePage::lockAllEvents() ; RsAutoUpdatePage::lockAllEvents() ;
@ -256,8 +256,16 @@ bool NotifyQt::askForPassword(const std::string& key_details, bool prev_is_bad,
int ret = dialog.exec(); int ret = dialog.exec();
cancelled = false ;
RsAutoUpdatePage::unlockAllEvents() ; RsAutoUpdatePage::unlockAllEvents() ;
if (ret == QDialog::Rejected) {
password.clear() ;
cancelled = true ;
return true ;
}
if (ret == QDialog::Accepted) { if (ret == QDialog::Accepted) {
password = dialog.textValue().toUtf8().constData(); password = dialog.textValue().toUtf8().constData();
return true; return true;

View File

@ -70,7 +70,7 @@ class NotifyQt: public QObject, public NotifyClient
virtual void notifyDiscInfoChanged() ; virtual void notifyDiscInfoChanged() ;
virtual void notifyDownloadComplete(const std::string& fileHash); virtual void notifyDownloadComplete(const std::string& fileHash);
virtual void notifyDownloadCompleteCount(uint32_t count); virtual void notifyDownloadCompleteCount(uint32_t count);
virtual bool askForPassword(const std::string& key_details, bool prev_is_bad, std::string& password); virtual bool askForPassword(const std::string& key_details, bool prev_is_bad, std::string& password, bool &cancelled);
virtual bool askForPluginConfirmation(const std::string& plugin_filename, const std::string& plugin_file_hash); virtual bool askForPluginConfirmation(const std::string& plugin_filename, const std::string& plugin_file_hash);
// Queues the signature event so that it canhappen in the main GUI thread (to ask for passwd). // Queues the signature event so that it canhappen in the main GUI thread (to ask for passwd).

View File

@ -651,9 +651,10 @@ bool Rshare::loadCertificate(const RsPeerId &accountId, bool autoLogin)
"tried to acquire the single instance lock\n Lock file:\n") + "tried to acquire the single instance lock\n Lock file:\n") +
QString::fromUtf8(lockFile.c_str())); QString::fromUtf8(lockFile.c_str()));
return false; return false;
case 3: QMessageBox::critical( 0, case 3:
QObject::tr("Login Failure"), // case 3: QMessageBox::critical( 0,
QObject::tr("Maybe password is wrong") ); // QObject::tr("Login Failure"),
// QObject::tr("Maybe password is wrong") );
return false; return false;
default: std::cerr << "Rshare::loadCertificate() unexpected switch value " << retVal << std::endl; default: std::cerr << "Rshare::loadCertificate() unexpected switch value " << retVal << std::endl;
return false; return false;

View File

@ -101,11 +101,12 @@ bool NotifyTxt::askForPluginConfirmation(const std::string& plugin_file_name, co
return a == 'y' ; return a == 'y' ;
} }
bool NotifyTxt::askForPassword(const std::string& question, bool prev_is_bad, std::string& password) bool NotifyTxt::askForPassword(const std::string& question, bool prev_is_bad, std::string& password,bool& cancel)
{ {
std::string question1="Please enter your PGP password for key:\n " + question + " :"; std::string question1="Please enter your PGP password for key:\n " + question + " :";
char *passwd = getpass(question1.c_str()) ; char *passwd = getpass(question1.c_str()) ;
password = passwd; password = passwd;
cancel = false ;
return !password.empty(); return !password.empty();
} }

View File

@ -41,7 +41,7 @@ class NotifyTxt: public NotifyClient
virtual void notifyListChange(int list, int type); virtual void notifyListChange(int list, int type);
virtual void notifyErrorMsg(int list, int sev, std::string msg); virtual void notifyErrorMsg(int list, int sev, std::string msg);
virtual void notifyChat(); virtual void notifyChat();
virtual bool askForPassword(const std::string& question, bool prev_is_bad, std::string& password); virtual bool askForPassword(const std::string& question, bool prev_is_bad, std::string& password,bool& cancel);
virtual bool askForPluginConfirmation(const std::string& plugin_file, const std::string& plugin_hash); virtual bool askForPluginConfirmation(const std::string& plugin_file, const std::string& plugin_hash);
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files); virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files);