From 774bb3dad5f08284515907d68b49aacc2b6b323b Mon Sep 17 00:00:00 2001 From: Hussein Kasem Date: Wed, 24 Jun 2020 22:20:05 +0200 Subject: [PATCH 01/16] JNI-111 Update Makefile.conf and build.gradle Makefile.conf: point to pep-engine sequoia branch instead of the fork. build.gradle: Upgrade to match with latest android gradle plugin. --- android/build.gradle | 14 +++++++------- android/external/Makefile.conf | 2 +- .../foundation/pEp/jniadapter/AndroidHelper.java | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 5a8e6e8..da8455a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,7 +2,7 @@ def pEpEngineSrc = hasProperty('pEpEngineSrc') ? pEpEngineSrc : "../../pEpEngine" def buildAutomatic = hasProperty('buildAutomatic') ? buildAutomatic : "true" -def threadsToUse = hasProperty('threadsToUse') ? threadsToUse : 2 +def threadsToUse = hasProperty('threadsToUse') ? threadsToUse : 1 def pEpEngineDB = new File(new File(pEpEngineSrc), 'db') @@ -12,7 +12,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:4.0.0' } } @@ -26,14 +26,13 @@ allprojects { apply plugin: 'com.android.library' android { - compileSdkVersion 27 - buildToolsVersion '28.0.3' + compileSdkVersion 30 defaultConfig { minSdkVersion 19 - targetSdkVersion 27 - versionCode 1 - versionName "1.0" + targetSdkVersion 30 + versionCode 2 + versionName "2.1.0-RC5" externalNativeBuild { ndkBuild { @@ -145,6 +144,7 @@ android { from file(new File(pEpEngineDB, 'system.db')) into 'assets' } + ndkVersion '21.0.6113669' if(buildAutomatic == "true") { buildpEpEngineSystemDB.dependsOn(buildExternal) diff --git a/android/external/Makefile.conf b/android/external/Makefile.conf index 9adca16..60890e5 100644 --- a/android/external/Makefile.conf +++ b/android/external/Makefile.conf @@ -20,7 +20,7 @@ NETTLE_VERSION=3.4.1 ### Git deps repos EXTERNAL_GIT_REPOS += libetpan|https://github.com/fdik/libetpan.git?HEAD -EXTERNAL_GIT_REPOS += sequoia|https://gitlab.com/husspEp/sequoia.git?80cffd395147bc76c3d763618545e66dfe977ac1 +EXTERNAL_GIT_REPOS += sequoia|https://gitlab.com/sequoia-pgp/sequoia.git?b5b783f58c9b6fdb26163cb7b236ee71cfef339e ### Common variables #### Source code targets diff --git a/android/src/foundation/pEp/jniadapter/AndroidHelper.java b/android/src/foundation/pEp/jniadapter/AndroidHelper.java index e82c5c9..f9e71b8 100644 --- a/android/src/foundation/pEp/jniadapter/AndroidHelper.java +++ b/android/src/foundation/pEp/jniadapter/AndroidHelper.java @@ -28,7 +28,7 @@ public class AndroidHelper { private static File tmpDir; // TODO : Increment when needed. - public static int ENGINE_VERSION_CODE = 3896; + public static int ENGINE_VERSION_CODE = 4768; private static File shareDir; From 9c0592624b9910e5a11b26488a7a90843833ac52 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 24 Jun 2020 22:38:11 +0200 Subject: [PATCH 02/16] test templateAliceBob typo --- test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile | 2 +- .../{transportMessage.java => TransportMessage.java} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/java/foundation/pEp/jniadapter/test/templateAliceBob/{transportMessage.java => TransportMessage.java} (100%) diff --git a/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile b/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile index e1e5748..5a4c801 100644 --- a/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile +++ b/test/java/foundation/pEp/jniadapter/test/templateAlice/Makefile @@ -1,7 +1,7 @@ include ../../../../../../../Makefile.conf include ../Makefile.conf -TEST_UNIT_NAME=templateAliceBob +TEST_UNIT_NAME=templateAlice JAVA_CLASSES = \ TestAlice.class \ diff --git a/test/java/foundation/pEp/jniadapter/test/templateAliceBob/transportMessage.java b/test/java/foundation/pEp/jniadapter/test/templateAliceBob/TransportMessage.java similarity index 100% rename from test/java/foundation/pEp/jniadapter/test/templateAliceBob/transportMessage.java rename to test/java/foundation/pEp/jniadapter/test/templateAliceBob/TransportMessage.java From 49d4ac3b0d33b07e80b440621f402d8d52ea8b50 Mon Sep 17 00:00:00 2001 From: heck Date: Mon, 29 Jun 2020 22:56:52 +0200 Subject: [PATCH 04/16] config_passphrase() - implemented using cache.add() --- src/basic_api.cc | 35 +++++++++++++++++++ src/jniutils.hh | 2 ++ src/pEp.yml2 | 5 +-- .../pEp/jniadapter/test/jni111/TestAlice.java | 14 +++++--- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/basic_api.cc b/src/basic_api.cc index 43273f9..3fe1e63 100644 --- a/src/basic_api.cc +++ b/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 l(global_mutex); + pEpLog("called with lock_guard"); + mutex_local = get_engine_java_object_mutex(env, obj); + } + std::lock_guard 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" diff --git a/src/jniutils.hh b/src/jniutils.hh index e8ee16b..4b620d6 100644 --- a/src/jniutils.hh +++ b/src/jniutils.hh @@ -8,6 +8,7 @@ #include #include #include +#include #if 0 // Enable if log needed #include @@ -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; diff --git a/src/pEp.yml2 b/src/pEp.yml2 index ca4533a..e9d0309 100644 --- a/src/pEp.yml2 +++ b/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 { diff --git a/test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java index 2bf50db..74bbf98 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java +++ b/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,12 +14,16 @@ class TestAlice { TestSuite.getDefault().setVerbose(true); TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); - new TestUnit("config_passphrase",new AdapterBaseTestContext() , ctx -> { - ctx.engine.config_passphrase("SUPERCOMPLICATEDPASSPHRASE"); + AdapterBaseTestContext jni111Ctx = new AdapterBaseTestContext(); + + new TestUnit("config_passphrase", jni111Ctx, ctx -> { + ctx.engine.config_passphrase("chocolate"); + ctx.engine.config_passphrase("Bar"); + ctx.engine.config_passphrase("Foo"); }); - new TestUnit("config_passphrase_for_new_keys",new AdapterBaseTestContext() , ctx -> { - ctx.engine.config_passphrase_for_new_keys(true, "SUPERCOMPLICATEDPASSPHRASE"); + new TestUnit("config_passphrase_for_new_keys", jni111Ctx, ctx -> { + ctx.engine.config_passphrase_for_new_keys(true, "SUPERCOMPLICATEDPASSPHRASE"); }); TestSuite.getDefault().run(); From e84feed11ec129a17b59a2c202049c0cd463318d Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 02:31:31 +0200 Subject: [PATCH 05/16] call API functions like encrypt_message() or decrypt_message() using cache.api() --- src/gen_cpp_Engine.ysl2 | 18 +++++++++++++++++- src/pEp.yml2 | 17 +++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/gen_cpp_Engine.ysl2 b/src/gen_cpp_Engine.ysl2 index eef8111..9f50823 100644 --- a/src/gen_cpp_Engine.ysl2 +++ b/src/gen_cpp_Engine.ysl2 @@ -17,6 +17,7 @@ tstylesheet { #include "foundation_pEp_jniadapter_«@name».h" #include "throw_pEp_exception.hh" #include "jniutils.hh" + #include using pEp::Adapter::session; using namespace pEp::JNIAdapter; @@ -62,7 +63,20 @@ tstylesheet { apply "parm[creates|returns]", mode=out; || - PEP_STATUS status = ::«@name»(session()`apply "parm", mode=call`); + || + choose { + when "@cached = 'true'" { + || + pEpLog("cached passphrase"); + PEP_STATUS status = cache.api(::«@name»,session()`apply "parm", mode=call`); + || + } otherwise { + || + PEP_STATUS status = ::«@name»(session()`apply "parm", mode=call`); + || + } + } + || if ((status > PEP_STATUS_OK && status < PEP_UNENCRYPTED) |`> |` status < PEP_STATUS_OK |`> |` status >= PEP_TRUSTWORD_NOT_FOUND) { @@ -237,6 +251,8 @@ tstylesheet { | bool _«$name» = (bool) «$name»; when "$type='int'" | int _«$name» = (int) «$name»; + when "$type='string'" + | const char *_«$name» = to_string(env, «$name»); otherwise | √$type *_«$name» = to_«$type»(env, «$name»); } diff --git a/src/pEp.yml2 b/src/pEp.yml2 index e9d0309..603f4fe 100644 --- a/src/pEp.yml2 +++ b/src/pEp.yml2 @@ -85,32 +85,32 @@ namespace pEp { }; interface Engine { - method encrypt_message( + method cached=true encrypt_message( in message src, in stringlist extra, creates message dst, in EncFormat format, - Cconst PEP_encrypt_flags flags "0" + Cconst PEP_encrypt_flags flags "(PEP_encrypt_flags_t)0" ); - method encrypt_message_and_add_priv_key( + method cached=true encrypt_message_and_add_priv_key( in message src, creates message dst, in string fpr, Cconst PEP_enc_format encformat "PEP_enc_PEP", - Cconst PEP_encrypt_flags flags "0" + Cconst PEP_encrypt_flags flags "(PEP_encrypt_flags_t)0" ); - method encrypt_message_for_self( + method cached=true encrypt_message_for_self( in identity target, in message src, in stringlist extra, creates message dst, Cconst PEP_enc_format encformat "PEP_enc_PEP", - Cconst PEP_encrypt_flags flags "0" + Cconst PEP_encrypt_flags flags "(PEP_encrypt_flags_t)0" ); - method decrypt_message( + method cached=true decrypt_message( inout message src, creates message dst, inout stringlist keylist, @@ -150,7 +150,8 @@ namespace pEp { returns stringlist blacklist ); - method own_message_private_key_details( + // TODO: WTF is... + method cached=true own_message_private_key_details( in message msg, returns identity ident ); From 6099e26bca99b9460134dd9ed5c792d8c317ee90 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 02:50:34 +0200 Subject: [PATCH 06/16] Passphrase support for messageToSend() --- src/foundation_pEp_jniadapter_AbstractEngine.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/foundation_pEp_jniadapter_AbstractEngine.cc b/src/foundation_pEp_jniadapter_AbstractEngine.cc index beb06ef..b4e038b 100644 --- a/src/foundation_pEp_jniadapter_AbstractEngine.cc +++ b/src/foundation_pEp_jniadapter_AbstractEngine.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include "throw_pEp_exception.hh" #include "jniutils.hh" @@ -95,8 +96,16 @@ PEP_STATUS messageToSend(message *msg) std::lock_guard l(mutex_obj); pEpLog("############### messageToSend() called"); - jobject msg_ = nullptr; + // Passphrase + // When a protocol implementation of the p≡p engine using messageToSend() cannot sign or encrypt with an + // empty passphrase and not with the configured passphrase it is calling messageToSend() with a NULL instead + // of a struct _message object. + if (Adapter::on_sync_thread() && !msg) { + return pEp::PassphraseCache::messageToSend(cache, Adapter::session()); + } + + jobject msg_ = nullptr; assert(messageClass && messageConstructorMethodID && objj && messageToSendMethodID); msg_ = o.env()->NewObject(messageClass, messageConstructorMethodID, (jlong) msg); From 195e240a2e6c957355d8e28c7df6979584685db2 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 10:56:30 +0200 Subject: [PATCH 08/16] Make import_key return identity list instead of void --- src/basic_api.cc | 17 +++++++++++++---- src/pEp.yml2 | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/basic_api.cc b/src/basic_api.cc index 3fe1e63..dd51d7e 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -252,7 +252,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustOwnKey( ::trust_own_key(session(), _ident); } -JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_importKey( +JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_importKey( JNIEnv *env, jobject obj, jbyteArray key @@ -271,18 +271,27 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine_importKey( if(_key == NULL){ throw_pEp_Exception(env, PEP_OUT_OF_MEMORY); - return; + return NULL; } - PEP_STATUS status = ::import_key(session(), _key, _size, NULL); + identity_list *_identities; + + PEP_STATUS status = ::import_key(session(), _key, _size, &_identities); if (status != PEP_STATUS_OK && status != PEP_KEY_IMPORTED) { throw_pEp_Exception(env, status); - return; + return NULL; + } + + jobject identities_ = NULL; + if (_identities) { + identities_ = from_identitylist(env, _identities); } env->ReleaseByteArrayElements(key, (jbyte *) _key, JNI_ABORT); + return identities_; } + JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passive_1mode( JNIEnv *env, jobject obj, diff --git a/src/pEp.yml2 b/src/pEp.yml2 index 603f4fe..5ac43bd 100644 --- a/src/pEp.yml2 +++ b/src/pEp.yml2 @@ -267,7 +267,7 @@ namespace pEp { basic void keyResetTrust(identity ident); basic void trustPersonalKey(identity ident); basic void trustOwnKey(identity ident); - basic void importKey(bytearray key); + basic identitylist importKey(bytearray key); basic void blacklist_add(string fpr); basic void blacklist_delete(string fpr); basic bool blacklist_is_listed(string fpr); From 2fdf5c2ed8f944d02a872753b0c24421c67adf0b Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 14:12:04 +0200 Subject: [PATCH 09/16] Code generation "basic" for java extended with return type identitylist --- src/basic_api.cc | 2 +- src/gen_java_Engine.ysl2 | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/basic_api.cc b/src/basic_api.cc index dd51d7e..08c46c7 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -252,7 +252,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1trustOwnKey( ::trust_own_key(session(), _ident); } -JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine_importKey( +JNIEXPORT jobject JNICALL Java_foundation_pEp_jniadapter_Engine__1importKey( JNIEnv *env, jobject obj, jbyteArray key diff --git a/src/gen_java_Engine.ysl2 b/src/gen_java_Engine.ysl2 index c1faee1..f625efa 100644 --- a/src/gen_java_Engine.ysl2 +++ b/src/gen_java_Engine.ysl2 @@ -30,7 +30,7 @@ tstylesheet { const "jtype" call "toJava" with "type", "@type"; choose { - when "name(parm/*[1])='bytearray'" + when "name(parm/*[1])='bytearray|identitylist'" || public native «$itype» «@name»(`apply "parm/*", mode=basic_iparm`); @@ -49,7 +49,18 @@ tstylesheet { |> return new Identity(_«@name»(`apply "parm/*", mode=basic_parm_name`)); when "@type = 'bool'" |> return new Boolean(_«@name»(`apply "parm/*", mode=basic_parm_name`)); - otherwise + when "@type = 'identitylist'" { + || + Vector<_Identity> glist = _«@name»(`apply "parm/*", mode=basic_parm_name`); + Vector ret = new Vector(); + if(glist != null) { + for (_Identity i : glist) { + ret.add(new Identity(i)); + } + } + return ret; + || + } otherwise |> return AbstractEngine.toUTF16(_«@name»(`apply "parm/*", mode=basic_parm_name`)); } || @@ -83,6 +94,8 @@ tstylesheet { > IdentityList when "name(.) = 'bool'" > Boolean + when "name(.) = 'bytearray'" + > byte[] otherwise > «name(.)» } @@ -115,6 +128,8 @@ tstylesheet { | «$pitype» _«$pname» = «$pname».getBytes(); when "$ptype = 'bool'" | «$pitype» _«$pname» = «$pname».booleanValue(); + when "$ptype = 'bytearray'" + | «$pitype» _«$pname» = «$pname».clone(); when "$ptype = 'int'" | «$pitype» _«$pname» = «$pname»; when "ancestor::namespace/child::enum[@name=$ptype]" From 8d97abea3d167acd93863ae1c41df715f3a86302 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 14:12:54 +0200 Subject: [PATCH 10/16] test for key_import() --- .../pEp/jniadapter/test/jni96/Makefile | 37 +++++++++++ .../pEp/jniadapter/test/jni96/TestAlice.java | 61 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 test/java/foundation/pEp/jniadapter/test/jni96/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java diff --git a/test/java/foundation/pEp/jniadapter/test/jni96/Makefile b/test/java/foundation/pEp/jniadapter/test/jni96/Makefile new file mode 100644 index 0000000..101e87d --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni96/Makefile @@ -0,0 +1,37 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=jni96 + +JAVA_CLASSES = \ + TestAlice.class \ + ../utils/AdapterBaseTestContext.class \ + ../utils/AdapterTestUtils.class \ + ../utils/TestCallbacks.class + +.PHONY: pitytest compile alice test clean + +all: alice compile + +pitytest: + $(MAKE) -C $(PITYTEST_DIR) + +alice: compile clean-pep-home-alice + cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice + +compile: $(JAVA_CLASSES) pitytest + +%.class: %.java + cd $(JAVA_CWD);javac -cp $(CLASSPATH) $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$< + +clean: + rm -f $(JAVA_CLASSES) + rm -f *.class + rm -f *.log + rm -Rf .gnupg + rm -Rf .lldb + +clean-pep-home: clean-pep-home-alice + +clean-pep-home-alice: + rm -rf $(PEP_HOME_DIR_ALICE)/.pEp diff --git a/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java new file mode 100644 index 0000000..084c0b6 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java @@ -0,0 +1,61 @@ +package foundation.pEp.jniadapter.test.jni96; +import static foundation.pEp.pitytest.TestLogger.*; + +import foundation.pEp.jniadapter.Identity; +import foundation.pEp.pitytest.*; +import foundation.pEp.pitytest.utils.TestUtils; +import foundation.pEp.jniadapter.test.utils.*; + +import static foundation.pEp.pitytest.TestLogger.log; + +import java.util.Vector; + +class TestAlice { + public static void main(String[] args) throws Exception { + TestSuite.getDefault().setVerbose(true); + TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); + + new TestUnit("import_key() with pub no return",new AdapterBaseTestContext() , ctx -> { + Vector privKeys = null; + privKeys = ctx.engine.importKey(ctx.keyAlicePub); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 0: "pub key should not be in return"; + }); + + new TestUnit("import_key() with priv key",new AdapterBaseTestContext() , ctx -> { + Vector privKeys = null; + privKeys = ctx.engine.importKey(ctx.keyAliceSec); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 1: "imported priv key should be returned"; + }); + + new TestUnit("import_key() 2 pub",new AdapterBaseTestContext() , ctx -> { + byte[] keys = concat(ctx.keyAlicePub, ctx.keyBobPub); + + Vector privKeys = null; + privKeys = ctx.engine.importKey(keys); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 0: "imported priv key should be returned"; + }); + + new TestUnit("import_key() with key array",new AdapterBaseTestContext() , ctx -> { + byte[] keys = concat(ctx.keyAlicePub, concat(ctx.keyAliceSec, concat(ctx.keyBobPub, ctx.keyBobSec))); + + Vector privKeys = null; + privKeys = ctx.engine.importKey(keys); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 3: "imported priv key should be returned"; + }); + + TestSuite.getDefault().run(); + } + + public static byte[] concat(byte[] a, byte[] b) { + byte[] c = new byte[a.length + b.length]; + System.arraycopy(a, 0, c, 0, a.length); + System.arraycopy(b, 0, c, a.length, b.length); + return c; + } +} + + From ad410354e8ebe0cc3a46c3881e31528ecc9ac22f Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 14:25:57 +0200 Subject: [PATCH 11/16] test for key_import() updated --- .../pEp/jniadapter/test/jni96/TestAlice.java | 23 +++++++++++++------ .../test/utils/AdapterBaseTestContext.java | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java index 084c0b6..f9ee818 100644 --- a/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java +++ b/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java @@ -15,36 +15,45 @@ class TestAlice { TestSuite.getDefault().setVerbose(true); TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); - new TestUnit("import_key() with pub no return",new AdapterBaseTestContext() , ctx -> { + new TestUnit("import_key() 1 pub key",new AdapterBaseTestContext() , ctx -> { Vector privKeys = null; privKeys = ctx.engine.importKey(ctx.keyAlicePub); log(AdapterTestUtils.identityListToString(privKeys, false)); assert privKeys.size() == 0: "pub key should not be in return"; }); - new TestUnit("import_key() with priv key",new AdapterBaseTestContext() , ctx -> { + new TestUnit("import_key() 1 sec key",new AdapterBaseTestContext() , ctx -> { Vector privKeys = null; privKeys = ctx.engine.importKey(ctx.keyAliceSec); log(AdapterTestUtils.identityListToString(privKeys, false)); - assert privKeys.size() == 1: "imported priv key should be returned"; + assert privKeys.size() == 1: "imported sec key should be returned"; }); - new TestUnit("import_key() 2 pub",new AdapterBaseTestContext() , ctx -> { + new TestUnit("import_key() 2 pub keys",new AdapterBaseTestContext() , ctx -> { byte[] keys = concat(ctx.keyAlicePub, ctx.keyBobPub); Vector privKeys = null; privKeys = ctx.engine.importKey(keys); log(AdapterTestUtils.identityListToString(privKeys, false)); - assert privKeys.size() == 0: "imported priv key should be returned"; + assert privKeys.size() == 0: "imported pub keys should not be returned"; }); - new TestUnit("import_key() with key array",new AdapterBaseTestContext() , ctx -> { + new TestUnit("import_key() 2 sec keys",new AdapterBaseTestContext() , ctx -> { + byte[] keys = concat(ctx.keyAliceSec, ctx.keyBobSec); + + Vector privKeys = null; + privKeys = ctx.engine.importKey(keys); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 2: "imported sec keys should be returned"; + }); + + new TestUnit("import_key() 4 keys pub/sec",new AdapterBaseTestContext() , ctx -> { byte[] keys = concat(ctx.keyAlicePub, concat(ctx.keyAliceSec, concat(ctx.keyBobPub, ctx.keyBobSec))); Vector privKeys = null; privKeys = ctx.engine.importKey(keys); log(AdapterTestUtils.identityListToString(privKeys, false)); - assert privKeys.size() == 3: "imported priv key should be returned"; + assert privKeys.size() == 2: "nr of imported keys doesnt match"; }); TestSuite.getDefault().run(); diff --git a/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java b/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java index 8bb1562..aa38878 100644 --- a/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java +++ b/test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java @@ -44,10 +44,10 @@ public class AdapterBaseTestContext extends AbstractTestContext { private String filenameBobPub = "../resources/test_keys/bob-pub.asc"; public byte[] keyAlicePub; - private String filenameAlicePub = "../resources/test_keys/alice-pub.asc"; + private String filenameAlicePub = "../resources/test_keys/alicenew-pub.asc"; public byte[] keyAliceSec; - private String filenameAliceSec = "../resources/test_keys/alice-sec.asc"; + private String filenameAliceSec = "../resources/test_keys/alicenew-sec.asc"; // Messages public Message msgToSelf; From 03a5831b35289fb6402f29e645b63460ac639485 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 14:28:10 +0200 Subject: [PATCH 12/16] new test-keys --- test/resources/test_keys/alicenew-pub.asc | 29 ++++++++++++ test/resources/test_keys/alicenew-sec.asc | 55 +++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/resources/test_keys/alicenew-pub.asc create mode 100644 test/resources/test_keys/alicenew-sec.asc diff --git a/test/resources/test_keys/alicenew-pub.asc b/test/resources/test_keys/alicenew-pub.asc new file mode 100644 index 0000000..e64a7d9 --- /dev/null +++ b/test/resources/test_keys/alicenew-pub.asc @@ -0,0 +1,29 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBF77LLsBEACxl2LCTG3LX0wPSO0N1xV7AZ2eaDWoN7OvtHLAfue97NN+Pgno +Y5hPIoDnj5IeV3wfmB7DSYGZcCDwxQB08jWYfQabCslb+Y3lvFoudI5Ju02vBJgD +UUCJKxTDB63OOd0ip+xZVCImqB3wk6XjzMNQHhWO7tm82kr/VavTu4s2eUQYYwJ7 +zDXvNubwNVEANaEgzvlSryALoc9rjSNa6c7RYOKKXKCgu3dBzMahI41XvLEA0SP9 +9IK83/1tJo/Vtx8e38m+/2Jok1DBR2umfum7cX296RueS6ZIZyDgJ4tLTbtJ/vOC +oxBPDnwKYakEGRHTi2ZJS/TCh21XWMeRap1UGgLPBkwyuU4+Rr8unEglrgUfHw5t +jPfoDb02jyFXlG+O+X7PQAxPU9dynDx2Be8UJsPU+5qyZsDH8yl11reWEOtkIa+s +XQ9kkK5MQ+v4Pa1OfGIccFq4ugsWscqEDVCLNfdxqaAU8WSZza7E3LR4poKHVe10 +wzctxDu+aJNqOKDePdMBkp3zej5rZkm97a3DJa5IsWGfluaV02kl0hg27/lP6yu1 +n8oS/GSnRh7O2gL9T7m0JO6Rfhsc/LOy+5/MAl5Jven/qtdRYPm9HEF3lj4zebPS +V1j1kkSuGjSnJWyouz5Zt8a520WN1i81iOZWYjC/Kdm3g9a6rKUvjXXmQwARAQAB +tBlhbGljZSA8YWxpY2VAcGVwdGVzdC5vcmc+iQJUBBMBCgA+FiEEpQcDf0hg4gMz +sPkzUANH/1pQNMUFAl77LLsCGwMFCQPCZwAFCwkIBwIGFQoJCAsCBBYCAwECHgEC +F4AACgkQUANH/1pQNMWs/hAApmKtGrgNcdvfecKjV+6tCApp6enFqMOZj/JxUV6R +3ihMD7bvQtlww+TyqL3OjCSJn/28t93QAjJvFPQRI9cq0p9F0WaxXqmUH8O+f6mz +rgpbnBDJzujBNOTFXJO8CygxD7r2g3ymxIycB3x9LNKg0id0uBKPyOaMFmaB9BrW +pn6TngljSHEjzmxDp1ERKxbHRhqhQishh3xIB0hPUdOIyy00nEknG7q/CIqqb8In +iLs+G7l4g/ARpjxTucZj0/h1svsY1uB52JgsfL88bgu/ir8lmg0AWkd/AEN9WSit +0ZgxEcVnqP3MxkJMaQipWXYtzGpKrmOnEh+D9Ni4Y1gw/4p6gCR+nlfY54JftSG5 +btniW+aqleTwqTqaJtOyAg5D4y2lulnMyrIkA2hnJjY5fin4LUBAW6IgsmqcdCUT +RJmwOJIa466AROUMDL/tdErYhVVTSTAeuQD/VE2rfwmYrVXRg3mGYZS++hG9rXEF +IN7L6SzgKNO84WSHjmQi9o1XMXGYPc4w7ICG/vwxwlpDeTEYNQknDTnZNS8mdqtU +x1zjgOVfs4bfotWxh3KV0ZbwQyZw+jhcbb/bU2VxUMEKyN3sRxMYuo5lGNLShVFx +mE9bF+17VxGQIQvcne1kfETNdGJPH15Zt1hLACSmwn5H5wy+yj9ZhtLpmNuHMO7V +qf8= +=40gV +-----END PGP PUBLIC KEY BLOCK----- diff --git a/test/resources/test_keys/alicenew-sec.asc b/test/resources/test_keys/alicenew-sec.asc new file mode 100644 index 0000000..0d73303 --- /dev/null +++ b/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xwlpDeTEYNQknDTnZNS8mdqtUx1zjgOVf +s4bfotWxh3KV0ZbwQyZw+jhcbb/bU2VxUMEKyN3sRxMYuo5lGNLShVFxmE9bF+17 +VxGQIQvcne1kfETNdGJPH15Zt1hLACSmwn5H5wy+yj9ZhtLpmNuHMO7Vqf8= +=4Oz/ +-----END PGP PRIVATE KEY BLOCK----- From e1bcc578df7b996291606104d3f91a6cb84a3d13 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 15:30:57 +0200 Subject: [PATCH 14/16] complete engine functions that have to be called with passphrase support - cache.api() --- src/pEp.yml2 | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/pEp.yml2 b/src/pEp.yml2 index 5ac43bd..dfa6cbe 100644 --- a/src/pEp.yml2 +++ b/src/pEp.yml2 @@ -191,7 +191,7 @@ namespace pEp { in bool full ); - method get_message_trustwords( + method cached=true get_message_trustwords( in message msg, in stringlist keylist, in identity receivedby, @@ -210,27 +210,17 @@ namespace pEp { in identity ident ); - // old key_reset function needs to be replaced -/* - method key_reset( - in string fpr, - in identity ident - ); -*/ - - // new key reset API - - method key_reset_identity( + method cached=true key_reset_identity( in identity ident, in string fpr ); - method key_reset_user( + method cached=true key_reset_user( in string userid, in string fpr ); - method key_reset_all_own_keys(); + method cached=true key_reset_all_own_keys(); method deliverHandshakeResult( in SyncHandshakeResult shr, @@ -243,7 +233,7 @@ namespace pEp { in identity ident ); - method disable_identity_for_sync( + method cached=true disable_identity_for_sync( in identity ident ); From 9858091cbcb834cc7ef27f48c24ed8e2d75b2e18 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 16:02:40 +0200 Subject: [PATCH 15/16] remove debuglog --- src/basic_api.cc | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/basic_api.cc b/src/basic_api.cc index 08c46c7..ff3be92 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -463,17 +463,17 @@ 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()); - } -} +//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, @@ -488,7 +488,6 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphras } std::lock_guard l(*mutex_local); - logPassphraseCache(); char *_passphrase = to_string(env, passphrase); PEP_STATUS status = ::config_passphrase(session(),cache.add(_passphrase)); @@ -496,7 +495,6 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphras throw_pEp_Exception(env, status); return; } - logPassphraseCache(); } } // extern "C"