Browse Source

config_passphrase() - implemented using cache.add()

JNI-111
heck 5 years ago
parent
commit
49d4ac3b0d
  1. 35
      src/basic_api.cc
  2. 2
      src/jniutils.hh
  3. 5
      src/pEp.yml2
  4. 12
      test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java

35
src/basic_api.cc

@ -454,6 +454,41 @@ JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getMachineD
return from_string(env, ::per_machine_directory());
}
void logPassphraseCache() {
try {
while(true) {
pEpLog("Cache: '" << cache.latest_passphrase() << "'");
}
} catch(pEp::PassphraseCache::Empty e) {
pEpLog(e.what());
} catch(pEp::PassphraseCache::Exhausted ex) {
pEpLog(ex.what());
}
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphrase
(JNIEnv * env,
jobject obj,
jbyteArray passphrase)
{
std::mutex *mutex_local = nullptr;
{
std::lock_guard<std::mutex> l(global_mutex);
pEpLog("called with lock_guard");
mutex_local = get_engine_java_object_mutex(env, obj);
}
std::lock_guard<std::mutex> l(*mutex_local);
logPassphraseCache();
char *_passphrase = to_string(env, passphrase);
PEP_STATUS status = ::config_passphrase(session(),cache.add(_passphrase));
if (status != 0) {
throw_pEp_Exception(env, status);
return;
}
logPassphraseCache();
}
} // extern "C"

2
src/jniutils.hh

@ -8,6 +8,7 @@
#include <pEp/bloblist.h>
#include <pEp/message.h>
#include <pEp/sync_api.h>
#include <pEp/passphrase_cache.hh>
#if 0 // Enable if log needed
#include <android/log.h>
@ -20,6 +21,7 @@
namespace pEp {
namespace JNIAdapter {
static pEp::PassphraseCache cache;
// Global mutex needs to be locked in all constructors which insert their own mutex object
// into the unordered_map (which is thread safe for read, but not for write)
extern std::mutex global_mutex;

5
src/pEp.yml2

@ -250,10 +250,6 @@ namespace pEp {
in CipherSuite suite
);
method config_passphrase(
in string passphrase
);
method config_passphrase_for_new_keys(
in bool enable,
in string passphrase
@ -279,6 +275,7 @@ namespace pEp {
basic string getCrashdumpLog(int maxlines);
basic string getUserDirectory();
basic string getMachineDirectory();
basic void config_passphrase(string passphrase);
};
struct message {

12
test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java

@ -1,5 +1,7 @@
package foundation.pEp.jniadapter.test.jni111;
import static foundation.pEp.pitytest.TestLogger.*;
import foundation.pEp.pitytest.*;
import foundation.pEp.pitytest.utils.TestUtils;
import foundation.pEp.jniadapter.test.utils.*;
@ -12,11 +14,15 @@ class TestAlice {
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
new TestUnit<AdapterBaseTestContext>("config_passphrase",new AdapterBaseTestContext() , ctx -> {
ctx.engine.config_passphrase("SUPERCOMPLICATEDPASSPHRASE");
AdapterBaseTestContext jni111Ctx = new AdapterBaseTestContext();
new TestUnit<AdapterBaseTestContext>("config_passphrase", jni111Ctx, ctx -> {
ctx.engine.config_passphrase("chocolate");
ctx.engine.config_passphrase("Bar");
ctx.engine.config_passphrase("Foo");
});
new TestUnit<AdapterBaseTestContext>("config_passphrase_for_new_keys",new AdapterBaseTestContext() , ctx -> {
new TestUnit<AdapterBaseTestContext>("config_passphrase_for_new_keys", jni111Ctx, ctx -> {
ctx.engine.config_passphrase_for_new_keys(true, "SUPERCOMPLICATEDPASSPHRASE");
});

Loading…
Cancel
Save