diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index 32b42461a..b437fb855 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -46,6 +46,8 @@ #define LIMIT_CERTIFICATE_SIZE 1 #define MAX_CERTIFICATE_SIZE 10000 +//#define DEBUG_AUTHGPG 1 + const time_t STORE_KEY_TIMEOUT = 1 * 60 * 60; //store key is call around every hour AuthGPG *AuthGPG::_instance = NULL ; @@ -88,7 +90,6 @@ bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfi std::string pgp_pwd_callback(void * /*hook*/, const char *uid_title, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad,bool *cancelled) { -#define GPG_DEBUG2 #ifdef GPG_DEBUG2 fprintf(stderr, "pgp_pwd_callback() called.\n"); #endif @@ -162,7 +163,9 @@ AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& pa */ int AuthGPG::GPGInit(const RsPgpId &ownId) { +#ifdef DEBUG_AUTHGPG std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId.toStdString() << std::endl; +#endif mOwnGpgId = RsPgpId(ownId); @@ -170,7 +173,9 @@ int AuthGPG::GPGInit(const RsPgpId &ownId) privateTrustCertificate(ownId, 5); updateOwnSignatureFlag(mOwnGpgId) ; +#ifdef DEBUG_AUTHGPG std::cerr << "AuthGPG::GPGInit finished." << std::endl; +#endif return 1; } diff --git a/libretroshare/src/rsserver/rsaccounts.cc b/libretroshare/src/rsserver/rsaccounts.cc index 27b6816c2..236c2af4d 100644 --- a/libretroshare/src/rsserver/rsaccounts.cc +++ b/libretroshare/src/rsserver/rsaccounts.cc @@ -109,6 +109,8 @@ bool RsAccountsDetail::checkAccountDirectory() return setupAccount(PathAccountDirectory()); } +#warning we need to clean that up. Login should only ask for a SSL id, instead of a std::string. + bool RsAccountsDetail::selectAccountByString(const std::string &prefUserString) { if (mAccountsLocked) @@ -137,9 +139,14 @@ bool RsAccountsDetail::selectAccountByString(const std::string &prefUserString) { mPreferredId = it->second.mSslId; pgpNameFound = true; + + std::cerr << "Account selected: " << ssl_id << std::endl; + + return true; } } - return pgpNameFound; + std::cerr << "No suitable candidate found." << std::endl; + return false; } @@ -872,12 +879,16 @@ bool RsAccountsDetail::SelectPGPAccount(const RsPgpId& pgpId) if (0 < AuthGPG::getAuthGPG() -> GPGInit(pgpId)) { retVal = true; +#ifdef DEBUG_ACCOUNTS std::cerr << "PGP Auth Success!"; +#endif } else std::cerr << "PGP Auth Failed!"; +#ifdef DEBUG_ACCOUNTS std::cerr << " ID: " << pgpId << std::endl; +#endif return retVal; } diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 51f82a275..5085d7fe6 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -466,21 +466,28 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */) // load Accounts. if (!rsAccounts->loadAccounts()) - { return RS_INIT_NO_KEYRING ; - } // choose alternative account. if(prefUserString != "") { - if (!rsAccounts->selectAccountByString(prefUserString)) + RsPeerId ssl_id(prefUserString); + + if(ssl_id.isNull()) { std::cerr << "Invalid User location id: not found in list"; std::cerr << std::endl; return RS_INIT_AUTH_FAILED ; } + + if(rsAccounts->selectId(ssl_id)) + { + std::cerr << "Auto-selectng account ID " << ssl_id << std::endl; + return RS_INIT_HAVE_ACCOUNT; + } } +#ifdef TO_REMOVE /* check that we have selected someone */ RsPeerId preferredId; bool existingUser = rsAccounts->getPreferredAccountId(preferredId); @@ -488,9 +495,6 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */) if (existingUser) { if (rsInitConfig->passwd != "") - { - return RS_INIT_HAVE_ACCOUNT; - } if(RsLoginHandler::getSSLPassword(preferredId,false,rsInitConfig->passwd)) { @@ -499,8 +503,9 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */) return RS_INIT_HAVE_ACCOUNT; } } +#endif return RS_INIT_OK; - } +} /* @@ -638,7 +643,9 @@ int RsInit::LoadCertificates(bool autoLoginNT) if(rsInitConfig->passwd == "") { if (RsLoginHandler::getSSLPassword(preferredId,true,rsInitConfig->passwd) == false) { +#ifdef DEBUG_RSINIT std::cerr << "RsLoginHandler::getSSLPassword() Failed!"; +#endif return 0 ; } } else { diff --git a/libretroshare/src/rsserver/rsloginhandler.cc b/libretroshare/src/rsserver/rsloginhandler.cc index b6558c991..7c031ef45 100644 --- a/libretroshare/src/rsserver/rsloginhandler.cc +++ b/libretroshare/src/rsserver/rsloginhandler.cc @@ -5,6 +5,8 @@ #include "util/rsdir.h" #include "rsaccounts.h" +//#define DEBUG_RSLOGINHANDLER 1 + bool RsLoginHandler::getSSLPassword( const RsPeerId& ssl_id, bool enable_gpg_ask_passwd, std::string& ssl_passwd ) @@ -59,18 +61,21 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const RsPeerId& ssl_id,std::string& fclose(sslPassphraseFile); +#ifdef DEBUG_RSLOGINHANDLER std::cerr << "opening sslPassphraseFile : " << getSSLPasswdFileName(ssl_id).c_str() << std::endl; +#endif std::string plain; if ( AuthGPG::getAuthGPG()->decryptTextFromFile( plain, getSSLPasswdFileName(ssl_id)) ) { sslPassword = plain; - +#ifdef DEBUG_RSLOGINHANDLER if(sslPassword.length() > 0) std::cerr << "Decrypting went ok !" << std::endl; else std::cerr << "Passphrase is empty!" << std::endl; +#endif return sslPassword.length() > 0 ; } diff --git a/retroshare-nogui/src/TerminalApiClient.cpp b/retroshare-nogui/src/TerminalApiClient.cpp index 3c5e55703..cdd23cb48 100644 --- a/retroshare-nogui/src/TerminalApiClient.cpp +++ b/retroshare-nogui/src/TerminalApiClient.cpp @@ -266,6 +266,17 @@ void TerminalApiClient::data_tick() sendPassword(passwd) ; sendSelectedAccount(acc_ssl_id) ; } + else if(ask_for_password) + { + std::string prompt = "Enter the password for key " + key_name + " : " ; + std::cout << prompt ; + std::cout.flush(); + std::string passwd = readStringFromKeyboard(true); + + // now we have passwd and account number, so send it to the core. + + sendPassword(passwd) ; + } } }