mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 15:39:27 -05:00
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:
parent
3bec1f4f69
commit
74c01423f0
2
TODO.txt
2
TODO.txt
@ -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'
|
||||||
|
@ -64,8 +64,13 @@ 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 ;
|
||||||
*(content->secret_key_passphrase.passphrase)= (char *)ops_mallocz(passwd.length()+1) ;
|
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) ;
|
||||||
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,11 +1398,17 @@ 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(!secret_key)
|
if(cancelled)
|
||||||
|
{
|
||||||
|
std::cerr << "Key cancelled by used." << std::endl;
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
if(!secret_key)
|
||||||
{
|
{
|
||||||
std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl;
|
std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl;
|
||||||
return false ;
|
return false ;
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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 ;
|
||||||
}
|
}
|
||||||
|
@ -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 ;
|
||||||
|
@ -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:
|
||||||
|
@ -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 ;}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -405,28 +405,44 @@ callback_cmd_get_secret_key(const ops_parser_content_t *content_,ops_parse_cb_in
|
|||||||
/* now get the key from the data */
|
/* now get the key from the data */
|
||||||
secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
|
secret=ops_get_secret_key_from_data(cbinfo->cryptinfo.keydata);
|
||||||
int tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE ;
|
int tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE ;
|
||||||
int nbtries = 0 ;
|
int nbtries = 0 ;
|
||||||
|
|
||||||
while( (!secret) && nbtries++ < 3)
|
while( (!secret) && nbtries++ < 3)
|
||||||
{
|
{
|
||||||
if (!cbinfo->cryptinfo.passphrase)
|
if (!cbinfo->cryptinfo.passphrase)
|
||||||
{
|
{
|
||||||
memset(&pc,'\0',sizeof pc);
|
cbinfo->arg = malloc(sizeof(unsigned char)) ;
|
||||||
pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
|
*(unsigned char *)cbinfo->arg = 0 ;
|
||||||
CB(cbinfo,tag_to_use,&pc);
|
|
||||||
if (!cbinfo->cryptinfo.passphrase)
|
|
||||||
{
|
|
||||||
fprintf(stderr,"can't get passphrase\n");
|
|
||||||
return 0 ; // ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* then it must be encrypted */
|
|
||||||
secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase);
|
|
||||||
|
|
||||||
free(cbinfo->cryptinfo.passphrase) ;
|
memset(&pc,'\0',sizeof pc);
|
||||||
cbinfo->cryptinfo.passphrase = NULL ;
|
pc.content.secret_key_passphrase.passphrase=&cbinfo->cryptinfo.passphrase;
|
||||||
tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD ;
|
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)
|
||||||
|
{
|
||||||
|
free(cbinfo->arg) ;
|
||||||
|
cbinfo->arg=NULL ;
|
||||||
|
fprintf(stderr,"can't get passphrase\n");
|
||||||
|
return 0 ; // ASSERT(0);
|
||||||
|
}
|
||||||
|
free(cbinfo->arg) ;
|
||||||
|
cbinfo->arg=NULL ;
|
||||||
|
}
|
||||||
|
/* then it must be encrypted */
|
||||||
|
secret=ops_decrypt_secret_key_from_data(cbinfo->cryptinfo.keydata,cbinfo->cryptinfo.passphrase);
|
||||||
|
|
||||||
|
free(cbinfo->cryptinfo.passphrase) ;
|
||||||
|
cbinfo->cryptinfo.passphrase = NULL ;
|
||||||
|
|
||||||
|
tag_to_use = OPS_PARSER_CMD_GET_SK_PASSPHRASE_PREV_WAS_BAD ;
|
||||||
|
}
|
||||||
|
|
||||||
if(!secret)
|
if(!secret)
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
@ -150,11 +150,10 @@ enum ops_content_tag_t
|
|||||||
OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY=0x300+15,
|
OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY=0x300+15,
|
||||||
|
|
||||||
/* commands to the callback */
|
/* commands to the callback */
|
||||||
OPS_PARSER_CMD_GET_SK_PASSPHRASE =0x400,
|
OPS_PARSER_CMD_GET_SK_PASSPHRASE =0x400,
|
||||||
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 */
|
||||||
|
@ -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,12 +256,20 @@ 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::Accepted) {
|
if (ret == QDialog::Rejected) {
|
||||||
|
password.clear() ;
|
||||||
|
cancelled = true ;
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == QDialog::Accepted) {
|
||||||
password = dialog.textValue().toUtf8().constData();
|
password = dialog.textValue().toUtf8().constData();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -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).
|
||||||
|
@ -650,10 +650,11 @@ bool Rshare::loadCertificate(const RsPeerId &accountId, bool autoLogin)
|
|||||||
QObject::tr("An unexpected error occurred when Retroshare "
|
QObject::tr("An unexpected error occurred when Retroshare "
|
||||||
"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;
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user