Browse Source

implementing ENGINE-781

ENGINE-781
Volker Birk 5 years ago
parent
commit
f210495d67
  1. 8
      Adapter.cc
  2. 1
      Adapter.hh
  3. 16
      passphrase_cache.cc
  4. 1
      passphrase_cache.hh

8
Adapter.cc

@ -7,6 +7,7 @@
#include <assert.h> #include <assert.h>
#include "status_to_string.hh" #include "status_to_string.hh"
#include "pEpLog.hh" #include "pEpLog.hh"
#include "passphrase_cache.hh"
using namespace std; using namespace std;
@ -82,6 +83,11 @@ namespace pEp {
return 0; return 0;
} }
PEP_STATUS _ensure_passphrase(PEP_SESSION session, const char *fpr)
{
return passphrase_cache.ensure_passphrase(session, fpr);
}
// threshold: max waiting time in seconds // threshold: max waiting time in seconds
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold) SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold)
{ {
@ -120,7 +126,7 @@ namespace pEp {
case init: case init:
if (!_session) if (!_session)
status = ::init(&_session, _messageToSend, _inject_sync_event); status = ::init(&_session, _messageToSend, _inject_sync_event, _ensure_passphrase);
break; break;
default: default:

1
Adapter.hh

@ -24,6 +24,7 @@ namespace pEp {
namespace Adapter { namespace Adapter {
int _inject_sync_event(SYNC_EVENT ev, void *management); int _inject_sync_event(SYNC_EVENT ev, void *management);
PEP_STATUS _ensure_passphrase(PEP_SESSION session, const char *fpr);
template<class T = void> template<class T = void>
void startup( void startup(

16
passphrase_cache.cc

@ -153,5 +153,21 @@ namespace pEp {
return PEP_WRONG_PASSPHRASE; return PEP_WRONG_PASSPHRASE;
} }
} }
PEP_STATUS PassphraseCache::ensure_passphrase(PEP_SESSION session, std::string fpr)
{
PEP_STATUS status = PEP_STATUS_OK;
for_each_passphrase([&](std::string passphrase) {
status = ::config_passphrase(session, passphrase.c_str());
if (status)
return true;
status = ::probe_encrypt(session, fpr.c_str());
return status == PEP_STATUS_OK;
});
return status;
}
}; };

1
passphrase_cache.hh

@ -73,6 +73,7 @@ namespace pEp {
static const char *latest_passphrase(PassphraseCache& _cache); static const char *latest_passphrase(PassphraseCache& _cache);
using passphrase_callee = std::function<bool(std::string)>; using passphrase_callee = std::function<bool(std::string)>;
bool for_each_passphrase(const passphrase_callee& callee); bool for_each_passphrase(const passphrase_callee& callee);
PEP_STATUS ensure_passphrase(PEP_SESSION session, std::string fpr);
protected: protected:
void cleanup(); void cleanup();

Loading…
Cancel
Save