implementing ENGINE-781

ENGINE-781
Volker Birk 2020-08-04 16:09:20 +02:00
parent dcd8224e50
commit f210495d67
4 changed files with 25 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include <assert.h>
#include "status_to_string.hh"
#include "pEpLog.hh"
#include "passphrase_cache.hh"
using namespace std;
@ -82,6 +83,11 @@ namespace pEp {
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
SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold)
{
@ -120,7 +126,7 @@ namespace pEp {
case init:
if (!_session)
status = ::init(&_session, _messageToSend, _inject_sync_event);
status = ::init(&_session, _messageToSend, _inject_sync_event, _ensure_passphrase);
break;
default:

View File

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

View File

@ -153,5 +153,21 @@ namespace pEp {
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;
}
};

View File

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