From efd6ce3ed518af7462689ed467fda66cdf6c0831 Mon Sep 17 00:00:00 2001 From: Konrad Date: Tue, 28 Mar 2017 11:19:50 +0200 Subject: [PATCH] Changed: Simplified asking for deferred self signature --- libresapi/src/api/RsControlModule.cpp | 115 ++------------------------ libresapi/src/api/RsControlModule.h | 5 -- 2 files changed, 6 insertions(+), 114 deletions(-) diff --git a/libresapi/src/api/RsControlModule.cpp b/libresapi/src/api/RsControlModule.cpp index 228bb691a..595509f09 100644 --- a/libresapi/src/api/RsControlModule.cpp +++ b/libresapi/src/api/RsControlModule.cpp @@ -458,120 +458,17 @@ void RsControlModule::handleCreateLocation(Request &req, Response &resp) 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 /*=""*/) { - + if(rsPeers->gpgSignData(data,len,sign,signlen,reason)) { - RsStackMutex stack(mDataMtx); - std::cerr << "NotifyTxt:: deferred signature event requeted. " << std::endl; - - // Look into the queue - - Sha1CheckSum chksum = RsDirUtil::sha1sum((uint8_t*)data,len); - - std::map::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; + signature_result = SELF_SIGNATURE_RESULT_SUCCESS; + return true; } - handleSignatureEvent(); - 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) + else { - working = true ; - - for(std::map::const_iterator it(_deferred_signature_queue.begin());it!=_deferred_signature_queue.end();++it) - it->second->performSignature() ; - - working = false ; + signature_result = SELF_SIGNATURE_RESULT_FAILED; + return false; } } diff --git a/libresapi/src/api/RsControlModule.h b/libresapi/src/api/RsControlModule.h index 338027e15..1323651fc 100644 --- a/libresapi/src/api/RsControlModule.h +++ b/libresapi/src/api/RsControlModule.h @@ -9,8 +9,6 @@ namespace resource_api{ class StateTokenServer; class ApiServer; -class SignatureEventData; - // resource api module to control accounts, startup and shutdown of retroshare // - 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 @@ -87,9 +85,6 @@ private: // 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 std::string mFixedPassword; - - void handleSignatureEvent(); - std::map _deferred_signature_queue ; }; } // namespace resource_api