fixed -U option in rs-nogui. Removed debug output that would ruin the terminal interface

This commit is contained in:
csoler 2017-07-11 23:32:22 +02:00
parent 3e3ee1a34b
commit a5e0b1c336
5 changed files with 49 additions and 10 deletions

View File

@ -46,6 +46,8 @@
#define LIMIT_CERTIFICATE_SIZE 1 #define LIMIT_CERTIFICATE_SIZE 1
#define MAX_CERTIFICATE_SIZE 10000 #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 const time_t STORE_KEY_TIMEOUT = 1 * 60 * 60; //store key is call around every hour
AuthGPG *AuthGPG::_instance = NULL ; 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) 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 #ifdef GPG_DEBUG2
fprintf(stderr, "pgp_pwd_callback() called.\n"); fprintf(stderr, "pgp_pwd_callback() called.\n");
#endif #endif
@ -162,7 +163,9 @@ AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& pa
*/ */
int AuthGPG::GPGInit(const RsPgpId &ownId) int AuthGPG::GPGInit(const RsPgpId &ownId)
{ {
#ifdef DEBUG_AUTHGPG
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId.toStdString() << std::endl; std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId.toStdString() << std::endl;
#endif
mOwnGpgId = RsPgpId(ownId); mOwnGpgId = RsPgpId(ownId);
@ -170,7 +173,9 @@ int AuthGPG::GPGInit(const RsPgpId &ownId)
privateTrustCertificate(ownId, 5); privateTrustCertificate(ownId, 5);
updateOwnSignatureFlag(mOwnGpgId) ; updateOwnSignatureFlag(mOwnGpgId) ;
#ifdef DEBUG_AUTHGPG
std::cerr << "AuthGPG::GPGInit finished." << std::endl; std::cerr << "AuthGPG::GPGInit finished." << std::endl;
#endif
return 1; return 1;
} }

View File

@ -109,6 +109,8 @@ bool RsAccountsDetail::checkAccountDirectory()
return setupAccount(PathAccountDirectory()); 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) bool RsAccountsDetail::selectAccountByString(const std::string &prefUserString)
{ {
if (mAccountsLocked) if (mAccountsLocked)
@ -137,9 +139,14 @@ bool RsAccountsDetail::selectAccountByString(const std::string &prefUserString)
{ {
mPreferredId = it->second.mSslId; mPreferredId = it->second.mSslId;
pgpNameFound = true; 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)) if (0 < AuthGPG::getAuthGPG() -> GPGInit(pgpId))
{ {
retVal = true; retVal = true;
#ifdef DEBUG_ACCOUNTS
std::cerr << "PGP Auth Success!"; std::cerr << "PGP Auth Success!";
#endif
} }
else else
std::cerr << "PGP Auth Failed!"; std::cerr << "PGP Auth Failed!";
#ifdef DEBUG_ACCOUNTS
std::cerr << " ID: " << pgpId << std::endl; std::cerr << " ID: " << pgpId << std::endl;
#endif
return retVal; return retVal;
} }

View File

@ -466,21 +466,28 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
// load Accounts. // load Accounts.
if (!rsAccounts->loadAccounts()) if (!rsAccounts->loadAccounts())
{
return RS_INIT_NO_KEYRING ; return RS_INIT_NO_KEYRING ;
}
// choose alternative account. // choose alternative account.
if(prefUserString != "") 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 << "Invalid User location id: not found in list";
std::cerr << std::endl; std::cerr << std::endl;
return RS_INIT_AUTH_FAILED ; 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 */ /* check that we have selected someone */
RsPeerId preferredId; RsPeerId preferredId;
bool existingUser = rsAccounts->getPreferredAccountId(preferredId); bool existingUser = rsAccounts->getPreferredAccountId(preferredId);
@ -488,9 +495,6 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
if (existingUser) if (existingUser)
{ {
if (rsInitConfig->passwd != "") if (rsInitConfig->passwd != "")
{
return RS_INIT_HAVE_ACCOUNT;
}
if(RsLoginHandler::getSSLPassword(preferredId,false,rsInitConfig->passwd)) 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; return RS_INIT_HAVE_ACCOUNT;
} }
} }
#endif
return RS_INIT_OK; return RS_INIT_OK;
} }
/* /*
@ -638,7 +643,9 @@ int RsInit::LoadCertificates(bool autoLoginNT)
if(rsInitConfig->passwd == "") { if(rsInitConfig->passwd == "") {
if (RsLoginHandler::getSSLPassword(preferredId,true,rsInitConfig->passwd) == false) { if (RsLoginHandler::getSSLPassword(preferredId,true,rsInitConfig->passwd) == false) {
#ifdef DEBUG_RSINIT
std::cerr << "RsLoginHandler::getSSLPassword() Failed!"; std::cerr << "RsLoginHandler::getSSLPassword() Failed!";
#endif
return 0 ; return 0 ;
} }
} else { } else {

View File

@ -5,6 +5,8 @@
#include "util/rsdir.h" #include "util/rsdir.h"
#include "rsaccounts.h" #include "rsaccounts.h"
//#define DEBUG_RSLOGINHANDLER 1
bool RsLoginHandler::getSSLPassword( const RsPeerId& ssl_id, bool RsLoginHandler::getSSLPassword( const RsPeerId& ssl_id,
bool enable_gpg_ask_passwd, bool enable_gpg_ask_passwd,
std::string& ssl_passwd ) std::string& ssl_passwd )
@ -59,18 +61,21 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const RsPeerId& ssl_id,std::string&
fclose(sslPassphraseFile); fclose(sslPassphraseFile);
#ifdef DEBUG_RSLOGINHANDLER
std::cerr << "opening sslPassphraseFile : " std::cerr << "opening sslPassphraseFile : "
<< getSSLPasswdFileName(ssl_id).c_str() << std::endl; << getSSLPasswdFileName(ssl_id).c_str() << std::endl;
#endif
std::string plain; std::string plain;
if ( AuthGPG::getAuthGPG()->decryptTextFromFile( plain, getSSLPasswdFileName(ssl_id)) ) if ( AuthGPG::getAuthGPG()->decryptTextFromFile( plain, getSSLPasswdFileName(ssl_id)) )
{ {
sslPassword = plain; sslPassword = plain;
#ifdef DEBUG_RSLOGINHANDLER
if(sslPassword.length() > 0) if(sslPassword.length() > 0)
std::cerr << "Decrypting went ok !" << std::endl; std::cerr << "Decrypting went ok !" << std::endl;
else else
std::cerr << "Passphrase is empty!" << std::endl; std::cerr << "Passphrase is empty!" << std::endl;
#endif
return sslPassword.length() > 0 ; return sslPassword.length() > 0 ;
} }

View File

@ -266,6 +266,17 @@ void TerminalApiClient::data_tick()
sendPassword(passwd) ; sendPassword(passwd) ;
sendSelectedAccount(acc_ssl_id) ; 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) ;
}
} }
} }