fixed password handling in deferred signature algorithm (in case of cancel, enter wrong passphrase, etc)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8423 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-06-12 21:04:11 +00:00
parent 46c5e08f31
commit f360e9d0ba
8 changed files with 201 additions and 172 deletions

View file

@ -2285,6 +2285,8 @@ void RsGenExchange::publishGrps()
{ {
create = CREATE_FAIL_TRY_LATER; create = CREATE_FAIL_TRY_LATER;
} }
else if(ret == SERVICE_CREATE_FAIL)
create = CREATE_FAIL;
} }
else else
{ {

View file

@ -1312,21 +1312,33 @@ bool PGPHandler::SignDataBin(const RsPgpId& id,const void *data, const uint32_t
PGPFingerprintType fp(f.fingerprint) ; PGPFingerprintType fp(f.fingerprint) ;
#endif #endif
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()) ; bool last_passwd_was_wrong = false ;
ops_secret_key_t *secret_key = NULL ;
if(!secret_key) for(int i=0;i<3;++i)
{ {
std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl; bool cancelled =false;
return false ; std::string passphrase = _passphrase_callback(NULL,uid_hint.c_str(),"Please enter passwd for encrypting your key : ",last_passwd_was_wrong,&cancelled) ;
}
secret_key = ops_decrypt_secret_key_from_data(key,passphrase.c_str()) ;
if(cancelled) if(cancelled)
{ {
std::cerr << "Key entering cancelled" << std::endl; std::cerr << "Key entering cancelled" << std::endl;
return false ; return false ;
} }
if(secret_key)
break ;
std::cerr << "Key decryption went wrong. Wrong passwd?" << std::endl;
last_passwd_was_wrong = true ;
}
if(!secret_key)
{
std::cerr << "Could not obtain secret key. Signature cancelled." << std::endl;
return false ;
}
// then do the signature. // then do the signature.

View file

@ -552,7 +552,6 @@ void p3NetMgrIMPL::netTick()
case RS_NET_LOOPBACK: case RS_NET_LOOPBACK:
//don't do a shutdown because a client in a computer without local network might be usefull for debug. //don't do a shutdown because a client in a computer without local network might be usefull for debug.
//shutdown(); //shutdown();
std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#endif #endif
@ -961,8 +960,10 @@ bool p3NetMgrIMPL::checkNetAddress()
if (mNetMode & RS_NET_MODE_TRY_LOOPBACK) if (mNetMode & RS_NET_MODE_TRY_LOOPBACK)
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgrIMPL::checkNetAddress() LOOPBACK ... forcing to 127.0.0.1"; std::cerr << "p3NetMgrIMPL::checkNetAddress() LOOPBACK ... forcing to 127.0.0.1";
std::cerr << std::endl; std::cerr << std::endl;
#endif
sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1"); sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1");
validAddr = true; validAddr = true;
} }

View file

@ -51,6 +51,11 @@ const uint32_t RS_TRUST_LVL_MARGINAL = 3;
const uint32_t RS_TRUST_LVL_FULL = 4; const uint32_t RS_TRUST_LVL_FULL = 4;
const uint32_t RS_TRUST_LVL_ULTIMATE = 5; const uint32_t RS_TRUST_LVL_ULTIMATE = 5;
const uint32_t SELF_SIGNATURE_RESULT_PENDING = 0x00;
const uint32_t SELF_SIGNATURE_RESULT_SUCCESS = 0x01;
const uint32_t SELF_SIGNATURE_RESULT_FAILED = 0x02;
/* Net Mode */ /* Net Mode */
const uint32_t RS_NETMODE_UDP = 0x0001; const uint32_t RS_NETMODE_UDP = 0x0001;
const uint32_t RS_NETMODE_UPNP = 0x0002; const uint32_t RS_NETMODE_UPNP = 0x0002;

View file

@ -34,6 +34,7 @@
#include "util/rsstring.h" #include "util/rsstring.h"
#include "util/radix64.h" #include "util/radix64.h"
#include "gxs/gxssecurity.h" #include "gxs/gxssecurity.h"
#include "retroshare/rspeers.h"
//#include "pqi/authgpg.h" //#include "pqi/authgpg.h"
@ -2582,14 +2583,20 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
memset(signarray,0,MAX_SIGN_SIZE) ; // just in case. memset(signarray,0,MAX_SIGN_SIZE) ; // just in case.
if (!mPgpUtils->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result)) mPgpUtils->askForDeferredSelfSignature((void *) hash.toByteArray(), hash.SIZE_IN_BYTES, signarray, &sign_size,result) ;
{
/* error */ /* error */
std::cerr << "p3IdService::service_CreateGroup() ERROR Signing stuff"; switch(result)
std::cerr << std::endl; {
createStatus = SERVICE_CREATE_FAIL_TRY_LATER; case SELF_SIGNATURE_RESULT_PENDING : createStatus = SERVICE_CREATE_FAIL_TRY_LATER;
} std::cerr << "p3IdService::service_CreateGroup() signature still pending" << std::endl;
else break ;
default:
case SELF_SIGNATURE_RESULT_FAILED: return SERVICE_CREATE_FAIL ;
std::cerr << "p3IdService::service_CreateGroup() signature failed" << std::endl;
break ;
case SELF_SIGNATURE_RESULT_SUCCESS:
{ {
// Additional consistency checks. // Additional consistency checks.
@ -2617,6 +2624,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
std::cerr << strout; std::cerr << strout;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
}
} }
/* done! */ /* done! */
} }

View file

@ -153,7 +153,7 @@ class SignatureEventData
sign = (unsigned char *)malloc(_signlen) ; sign = (unsigned char *)malloc(_signlen) ;
signlen = new unsigned int ; signlen = new unsigned int ;
*signlen = _signlen ; *signlen = _signlen ;
signature_result = 0 ; signature_result = SELF_SIGNATURE_RESULT_PENDING ;
data = malloc(_len) ; data = malloc(_len) ;
len = _len ; len = _len ;
memcpy(data,_data,len) ; memcpy(data,_data,len) ;
@ -169,14 +169,16 @@ class SignatureEventData
void performSignature() void performSignature()
{ {
if(rsPeers->gpgSignData(data,len,sign,signlen)) if(rsPeers->gpgSignData(data,len,sign,signlen))
signature_result = 1 ; signature_result = SELF_SIGNATURE_RESULT_SUCCESS ;
else
signature_result = SELF_SIGNATURE_RESULT_FAILED ;
} }
void *data ; void *data ;
uint32_t len ; uint32_t len ;
unsigned char *sign ; unsigned char *sign ;
unsigned int *signlen ; unsigned int *signlen ;
int signature_result ; // 0=pending, 1=done, 2=failed. int signature_result ; // 0=pending, 1=done, 2=failed/cancelled.
}; };
bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result) bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result)
@ -191,10 +193,13 @@ bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len,
Sha1CheckSum chksum = RsDirUtil::sha1sum((uint8_t*)data,len) ; Sha1CheckSum chksum = RsDirUtil::sha1sum((uint8_t*)data,len) ;
std::map<std::string,SignatureEventData*>::iterator it = _deferred_signature_queue.find(chksum.toStdString()) ; std::map<std::string,SignatureEventData*>::iterator it = _deferred_signature_queue.find(chksum.toStdString()) ;
signature_result = SELF_SIGNATURE_RESULT_PENDING ;
if(it != _deferred_signature_queue.end()) if(it != _deferred_signature_queue.end())
{ {
if(it->second->signature_result != 0) // found it. Copy the result, and remove from the queue. signature_result = it->second->signature_result ;
if(it->second->signature_result != SELF_SIGNATURE_RESULT_PENDING) // found it. Copy the result, and remove from the queue.
{ {
// We should check for the exact data match, for the sake of being totally secure. // We should check for the exact data match, for the sake of being totally secure.
// //
@ -202,15 +207,11 @@ bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len,
memcpy(sign,it->second->sign,*it->second->signlen) ; memcpy(sign,it->second->sign,*it->second->signlen) ;
*signlen = *(it->second->signlen) ; *signlen = *(it->second->signlen) ;
signature_result = it->second->signature_result ;
delete it->second ; delete it->second ;
_deferred_signature_queue.erase(it) ; _deferred_signature_queue.erase(it) ;
return true ;
} }
else return true ; // already registered, but not done yet.
return false ; // already registered, but not done yet.
} }
// Not found. Store in the queue and emit a signal. // Not found. Store in the queue and emit a signal.
@ -222,7 +223,7 @@ bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len,
_deferred_signature_queue[chksum.toStdString()] = edta ; _deferred_signature_queue[chksum.toStdString()] = edta ;
} }
emit deferredSignatureHandlingRequested() ; emit deferredSignatureHandlingRequested() ;
return false; return true;
} }
void NotifyQt::handleSignatureEvent() void NotifyQt::handleSignatureEvent()