mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 17:07:17 -05:00
Changed: Simplified asking for deferred self signature
This commit is contained in:
parent
569458a1c1
commit
efd6ce3ed5
@ -458,120 +458,17 @@ void RsControlModule::handleCreateLocation(Request &req, Response &resp)
|
|||||||
resp.setFail("could not create a new location. Error: "+err_string);
|
resp.setFail("could not create a new location. Error: "+err_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SignatureEventData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SignatureEventData(const void *_data,int32_t _len,unsigned int _signlen, std::string _reason)
|
|
||||||
{
|
|
||||||
// We need a new memory chnk because there's no guarranty _sign nor _signlen are not in the stack
|
|
||||||
|
|
||||||
sign = (unsigned char *)rs_malloc(_signlen);
|
|
||||||
|
|
||||||
if(!sign)
|
|
||||||
{
|
|
||||||
signlen = NULL;
|
|
||||||
signature_result = SELF_SIGNATURE_RESULT_FAILED;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
signlen = new unsigned int;
|
|
||||||
*signlen = _signlen;
|
|
||||||
signature_result = SELF_SIGNATURE_RESULT_PENDING;
|
|
||||||
data = rs_malloc(_len);
|
|
||||||
|
|
||||||
if(!data)
|
|
||||||
{
|
|
||||||
len = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
len = _len;
|
|
||||||
memcpy(data,_data,len);
|
|
||||||
reason = _reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
~SignatureEventData()
|
|
||||||
{
|
|
||||||
free(sign);
|
|
||||||
delete signlen;
|
|
||||||
free(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void performSignature()
|
|
||||||
{
|
|
||||||
if(rsPeers->gpgSignData(data,len,sign,signlen,reason))
|
|
||||||
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/cancelled.
|
|
||||||
std::string reason;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool RsControlModule::askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason /*=""*/)
|
bool RsControlModule::askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason /*=""*/)
|
||||||
{
|
{
|
||||||
|
if(rsPeers->gpgSignData(data,len,sign,signlen,reason))
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDataMtx);
|
signature_result = SELF_SIGNATURE_RESULT_SUCCESS;
|
||||||
std::cerr << "NotifyTxt:: deferred signature event requeted. " << std::endl;
|
return true;
|
||||||
|
|
||||||
// Look into the queue
|
|
||||||
|
|
||||||
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())
|
|
||||||
{
|
|
||||||
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.
|
|
||||||
//
|
|
||||||
std::cerr << "Found into queue: returning it" << std::endl;
|
|
||||||
|
|
||||||
memcpy(sign,it->second->sign,*it->second->signlen);
|
|
||||||
*signlen = *(it->second->signlen);
|
|
||||||
|
|
||||||
delete it->second;
|
|
||||||
_deferred_signature_queue.erase(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true; // already registered, but not done yet.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not found. Store in the queue and emit a signal.
|
|
||||||
//
|
|
||||||
std::cerr << "NotifyTxt:: deferred signature event requeted. Pushing into queue" << std::endl;
|
|
||||||
|
|
||||||
SignatureEventData *edta = new SignatureEventData(data,len,*signlen, reason);
|
|
||||||
|
|
||||||
_deferred_signature_queue[chksum.toStdString()] = edta;
|
|
||||||
}
|
}
|
||||||
handleSignatureEvent();
|
else
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RsControlModule::handleSignatureEvent()
|
|
||||||
{
|
|
||||||
std::cerr << "NotifyTxt:: performing a deferred signature in the main GUI thread." << std::endl;
|
|
||||||
|
|
||||||
static bool working = false ;
|
|
||||||
|
|
||||||
if(!working)
|
|
||||||
{
|
{
|
||||||
working = true ;
|
signature_result = SELF_SIGNATURE_RESULT_FAILED;
|
||||||
|
return false;
|
||||||
for(std::map<std::string,SignatureEventData*>::const_iterator it(_deferred_signature_queue.begin());it!=_deferred_signature_queue.end();++it)
|
|
||||||
it->second->performSignature() ;
|
|
||||||
|
|
||||||
working = false ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@ namespace resource_api{
|
|||||||
class StateTokenServer;
|
class StateTokenServer;
|
||||||
class ApiServer;
|
class ApiServer;
|
||||||
|
|
||||||
class SignatureEventData;
|
|
||||||
|
|
||||||
// resource api module to control accounts, startup and shutdown of retroshare
|
// resource api module to control accounts, startup and shutdown of retroshare
|
||||||
// - this module handles everything, no things are required from outside
|
// - this module handles everything, no things are required from outside
|
||||||
// - exception: users of this module have to create an api server and register this module
|
// - exception: users of this module have to create an api server and register this module
|
||||||
@ -87,9 +85,6 @@ private:
|
|||||||
// we store the password in this variable, it has higher priority than the normal password variable
|
// we store the password in this variable, it has higher priority than the normal password variable
|
||||||
// it is also to avoid a lock, when we make a synchronous call into librs, like in ssl cert generation
|
// it is also to avoid a lock, when we make a synchronous call into librs, like in ssl cert generation
|
||||||
std::string mFixedPassword;
|
std::string mFixedPassword;
|
||||||
|
|
||||||
void handleSignatureEvent();
|
|
||||||
std::map<std::string, SignatureEventData*> _deferred_signature_queue ;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace resource_api
|
} // namespace resource_api
|
||||||
|
Loading…
Reference in New Issue
Block a user