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;
}
else if(ret == SERVICE_CREATE_FAIL)
create = CREATE_FAIL;
}
else
{

View file

@ -1312,21 +1312,33 @@ bool PGPHandler::SignDataBin(const RsPgpId& id,const void *data, const uint32_t
PGPFingerprintType fp(f.fingerprint) ;
#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;
return false ;
}
bool cancelled =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)
{
std::cerr << "Key entering cancelled" << std::endl;
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.

View file

@ -552,7 +552,6 @@ void p3NetMgrIMPL::netTick()
case RS_NET_LOOPBACK:
//don't do a shutdown because a client in a computer without local network might be usefull for debug.
//shutdown();
std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#endif
@ -961,8 +960,10 @@ bool p3NetMgrIMPL::checkNetAddress()
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 << std::endl;
#endif
sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1");
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_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 */
const uint32_t RS_NETMODE_UDP = 0x0001;
const uint32_t RS_NETMODE_UPNP = 0x0002;

View file

@ -34,6 +34,7 @@
#include "util/rsstring.h"
#include "util/radix64.h"
#include "gxs/gxssecurity.h"
#include "retroshare/rspeers.h"
//#include "pqi/authgpg.h"
@ -2492,33 +2493,33 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
/********************* TEMP HACK UNTIL GXS FILLS IN GROUP_ID *****************/
// SANITY CHECK.
// if (item->mMeta.mAuthorId != item->meta.mAuthorId)
// {
// std::cerr << "p3IdService::service_CreateGroup() AuthorId mismatch(";
// std::cerr << item->mMeta.mAuthorId;
// std::cerr << " vs ";
// std::cerr << item->meta.mAuthorId;
// std::cerr << std::endl;
// }
//
// if (item->group.mMeta.mGroupId != item->meta.mGroupId)
// {
// std::cerr << "p3IdService::service_CreateGroup() GroupId mismatch(";
// std::cerr << item->mMeta.mGroupId;
// std::cerr << " vs ";
// std::cerr << item->meta.mGroupId;
// std::cerr << std::endl;
// }
//
//
// if (item->group.mMeta.mGroupFlags != item->meta.mGroupFlags)
// {
// std::cerr << "p3IdService::service_CreateGroup() GroupFlags mismatch(";
// std::cerr << item->mMeta.mGroupFlags;
// std::cerr << " vs ";
// std::cerr << item->meta.mGroupFlags;
// std::cerr << std::endl;
// }
// if (item->mMeta.mAuthorId != item->meta.mAuthorId)
// {
// std::cerr << "p3IdService::service_CreateGroup() AuthorId mismatch(";
// std::cerr << item->mMeta.mAuthorId;
// std::cerr << " vs ";
// std::cerr << item->meta.mAuthorId;
// std::cerr << std::endl;
// }
//
// if (item->group.mMeta.mGroupId != item->meta.mGroupId)
// {
// std::cerr << "p3IdService::service_CreateGroup() GroupId mismatch(";
// std::cerr << item->mMeta.mGroupId;
// std::cerr << " vs ";
// std::cerr << item->meta.mGroupId;
// std::cerr << std::endl;
// }
//
//
// if (item->group.mMeta.mGroupFlags != item->meta.mGroupFlags)
// {
// std::cerr << "p3IdService::service_CreateGroup() GroupFlags mismatch(";
// std::cerr << item->mMeta.mGroupFlags;
// std::cerr << " vs ";
// std::cerr << item->meta.mGroupFlags;
// std::cerr << std::endl;
// }
#ifdef DEBUG_IDS
std::cerr << "p3IdService::service_CreateGroup() for : " << item->mMeta.mGroupId;
@ -2544,10 +2545,10 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
#endif
#ifdef GXSID_GEN_DUMMY_DATA
// if (item->group.mMeta.mAuthorId != "")
// {
// ownId = RsPgpId(item->group.mMeta.mAuthorId);
// }
// if (item->group.mMeta.mAuthorId != "")
// {
// ownId = RsPgpId(item->group.mMeta.mAuthorId);
// }
#endif
if (!mPgpUtils->getKeyFingerprint(ownId,ownFinger))
@ -2582,14 +2583,20 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
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 */
std::cerr << "p3IdService::service_CreateGroup() ERROR Signing stuff";
std::cerr << std::endl;
createStatus = SERVICE_CREATE_FAIL_TRY_LATER;
}
else
switch(result)
{
case SELF_SIGNATURE_RESULT_PENDING : createStatus = SERVICE_CREATE_FAIL_TRY_LATER;
std::cerr << "p3IdService::service_CreateGroup() signature still pending" << std::endl;
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.
@ -2617,6 +2624,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
std::cerr << strout;
std::cerr << std::endl;
#endif
}
}
/* done! */
}

View file

@ -153,7 +153,7 @@ class SignatureEventData
sign = (unsigned char *)malloc(_signlen) ;
signlen = new unsigned int ;
*signlen = _signlen ;
signature_result = 0 ;
signature_result = SELF_SIGNATURE_RESULT_PENDING ;
data = malloc(_len) ;
len = _len ;
memcpy(data,_data,len) ;
@ -169,14 +169,16 @@ class SignatureEventData
void performSignature()
{
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 ;
uint32_t len ;
unsigned char *sign ;
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)
@ -191,10 +193,13 @@ bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len,
Sha1CheckSum chksum = RsDirUtil::sha1sum((uint8_t*)data,len) ;
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->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.
//
@ -202,15 +207,11 @@ bool NotifyQt::askForDeferredSelfSignature(const void *data, const uint32_t len,
memcpy(sign,it->second->sign,*it->second->signlen) ;
*signlen = *(it->second->signlen) ;
signature_result = it->second->signature_result ;
delete it->second ;
_deferred_signature_queue.erase(it) ;
return true ;
}
else
return false ; // already registered, but not done yet.
return true ; // already registered, but not done yet.
}
// 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 ;
}
emit deferredSignatureHandlingRequested() ;
return false;
return true;
}
void NotifyQt::handleSignatureEvent()