From 5e2a04219799b0667cdd0c416431842b82517b8a Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 1 Jul 2021 14:13:58 +0200 Subject: [PATCH 1/3] JNI-158 - JNI-159 - Remove all keyserver functions --- ...oundation_pEp_jniadapter_AbstractEngine.cc | 114 ------------------ .../pEp/jniadapter/AbstractEngine.java | 17 --- .../interfaces/AbstractEngineInterface.java | 4 - .../jniadapter/test/regression/TestMain.java | 4 - 4 files changed, 139 deletions(-) diff --git a/src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc b/src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc index ca179eb..80bcdf0 100644 --- a/src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc +++ b/src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc @@ -1,5 +1,4 @@ #include "foundation_pEp_jniadapter_AbstractEngine.h" -#include #include #include #include @@ -326,119 +325,6 @@ int examine_identity(pEp_identity *ident, return 0; } -pEp_identity *retrieve_next_identity(void *arg) -{ - pEpLog("called"); - locked_queue < pEp_identity * > *queue = static_cast * > (arg); - - while (!queue->size()) { - usleep(100000); - } - - pEp_identity *ident = queue->front(); - queue->pop_front(); - return ident; -} - -static void *keyserver_thread_routine(void *arg) -{ - PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg); - locked_queue < pEp_identity * > *queue = static_cast * > (arg); - - while (queue->size()) { - pEp_identity *ident = queue->front(); - queue->pop_front(); - free_identity(ident); - } - - delete queue; - return reinterpret_cast(status); -} - -JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeyserverLookup(JNIEnv *env, - jobject obj) -{ - 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); - - pthread_t *thread = nullptr; - locked_queue< pEp_identity * > *queue = nullptr; - - jfieldID thread_handle; - jfieldID queue_handle; - - try { - thread_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverThread", "J"); - queue_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverQueue", "J"); - } - catch (std::exception& ex) { - assert(0); - return; - } - - thread = reinterpret_cast(env->GetLongField(obj, thread_handle)); - if (thread) - return; - - thread = static_cast(calloc(1, sizeof(pthread_t))); - assert(thread); - env->SetLongField(obj, thread_handle, reinterpret_cast(thread)); - - queue = new locked_queue< pEp_identity * >(); - env->SetLongField(obj, queue_handle, reinterpret_cast(queue)); - - register_examine_function(Adapter::session(), examine_identity,static_cast(queue)); - - pthread_create(thread, nullptr, keyserver_thread_routine, static_cast(queue)); -} - -JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyserverLookup(JNIEnv *env, - jobject obj) -{ - 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); - - pthread_t *thread = nullptr; - locked_queue< pEp_identity * > *queue = nullptr; - - jfieldID thread_handle; - jfieldID queue_handle; - - try { - thread_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverThread", "J"); - queue_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverQueue", "J"); - } - catch (std::exception& ex) { - assert(0); - return; - } - - thread = reinterpret_cast(env->GetLongField(obj, thread_handle)); - if (!thread) - return; - - queue = reinterpret_cast*>(env->GetLongField(obj, queue_handle)); - - env->SetLongField(obj, queue_handle, 0); - env->SetLongField(obj, thread_handle, 0); - - register_examine_function(Adapter::session(), nullptr, nullptr); - - queue->push_front(nullptr); - pthread_join(*thread, nullptr); - free(thread); -} - JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync(JNIEnv *env, jobject obj) { diff --git a/src/java/foundation/pEp/jniadapter/AbstractEngine.java b/src/java/foundation/pEp/jniadapter/AbstractEngine.java index f16e302..7d160d8 100644 --- a/src/java/foundation/pEp/jniadapter/AbstractEngine.java +++ b/src/java/foundation/pEp/jniadapter/AbstractEngine.java @@ -23,9 +23,6 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AbstractEn private native void init(); private native void release(); - private long keyserverThread; - private long keyserverQueue; - public AbstractEngine() throws pEpException { synchronized (AbstractEngine.class) { init(); @@ -67,20 +64,6 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AbstractEn private native String _getProtocolVersion(); - public void startKeyserverLookup() { - _startKeyserverLookup(); - } - - private native void _startKeyserverLookup(); - - - public void stopKeyserverLookup() { - _startKeyserverLookup(); - } - - private native void _stopKeyserverLookup(); - - public void startSync() { _startSync(); } diff --git a/src/java/foundation/pEp/jniadapter/interfaces/AbstractEngineInterface.java b/src/java/foundation/pEp/jniadapter/interfaces/AbstractEngineInterface.java index 63fb399..17d6f53 100644 --- a/src/java/foundation/pEp/jniadapter/interfaces/AbstractEngineInterface.java +++ b/src/java/foundation/pEp/jniadapter/interfaces/AbstractEngineInterface.java @@ -8,10 +8,6 @@ public interface AbstractEngineInterface extends AutoCloseable { public String getProtocolVersion(); - public void startKeyserverLookup(); - - public void stopKeyserverLookup(); - public void startSync(); public void stopSync(); diff --git a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java index acf87a0..3add3e1 100644 --- a/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java +++ b/test/java/foundation/pEp/jniadapter/test/regression/TestMain.java @@ -276,10 +276,6 @@ class TestMain { ctx.engine.getProtocolVersion(); }); - new TestUnit("Engine.startKeyserverLookup", new CTXBase(), ctx -> { - ctx.engine.startKeyserverLookup(); - }); - new TestUnit("Engine.startSync", new CTXBase(), ctx -> { ctx.engine.startSync(); }); From bc035e291022987c56bae4bad623e376e9563b5c Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 1 Jul 2021 14:15:19 +0200 Subject: [PATCH 2/3] JNI-158 - remove __LP64__ related stuff --- src/cxx/jniutils.cc | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/cxx/jniutils.cc b/src/cxx/jniutils.cc index 27f2438..3d3b2ad 100644 --- a/src/cxx/jniutils.cc +++ b/src/cxx/jniutils.cc @@ -1,17 +1,7 @@ -#include #include "jniutils.hh" #include - -#ifndef __LP64__ - -#include - -#define time_t time64_t -#define timegm timegm64 -#define gmtime_r gmtime64_r -#else -#include -#endif +#include +#include namespace pEp { namespace JNIAdapter { From 3b9b7c74ae65d0acdcf03b2ad57bc362a3faf1fc Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 1 Jul 2021 14:16:11 +0200 Subject: [PATCH 3/3] JNI-158: Android activity - remove keyserver stuff --- .../main/java/com/pep/k9/MainActivity.java | 59 +------------------ .../app/src/main/res/layout/activity_main.xml | 21 ------- 2 files changed, 3 insertions(+), 77 deletions(-) diff --git a/androidTests/app/src/main/java/com/pep/k9/MainActivity.java b/androidTests/app/src/main/java/com/pep/k9/MainActivity.java index 435a4f7..37fa1a3 100644 --- a/androidTests/app/src/main/java/com/pep/k9/MainActivity.java +++ b/androidTests/app/src/main/java/com/pep/k9/MainActivity.java @@ -260,7 +260,6 @@ public class MainActivity extends AppCompatActivity { @BindView(R.id.bRunTypes) Button runTypes; @BindView(R.id.bRunAliceBob) Button runIntegration; - @BindView(R.id.bRunServerLookup) Button runLookup; @BindView(R.id.bRunGenKey) Button runGenKey; @BindView(R.id.encrypt_and_decrypt) Button runEncryptAndDecrypt; @BindView(R.id.encrypt_and_decrypt_without_key) Button runEncryptAndDecryptWithoutKey; @@ -287,11 +286,6 @@ public class MainActivity extends AppCompatActivity { runIntegration.setText(TESTING); new RunTestTask().execute(6); } - @OnClick(R.id.bRunServerLookup) - public void runLookup() { - runLookup.setText(TESTING); - new RunTestTask().execute(2); - } @OnClick(R.id.bRunGenKey) public void runGenKey() { runGenKey.setText(TESTING); @@ -390,10 +384,6 @@ public class MainActivity extends AppCompatActivity { testPEpTypes(); } - private void runTestKeyserverLookup() throws pEpException, InterruptedException, IOException { - testKeyserverLookup(); - } - private void runTestKeyGen() throws pEpException, InterruptedException, IOException { testKeyGen(); } @@ -1494,46 +1484,6 @@ public class MainActivity extends AppCompatActivity { msg.setAttachments(attachments); } - /* - tests its possible to find the fingerprint on server - */ - public void testKeyserverLookup() throws pEpException, IOException, AssertionError, InterruptedException { - log("TEST: ", "Test keyserver lookup loaded"); - Engine e; - - e = new Engine(); - - long lastTime = System.currentTimeMillis(); - e.startKeyserverLookup(); - log("engine.startLookup", String.valueOf(System.currentTimeMillis() - lastTime)); - - Identity vb = new Identity(); - vb.username = "pEpDontAssert"; - vb.address = "vb@ulm.ccc.de"; - vb.user_id = "SsI6H9"; - updateIdentityOnEngine(e, vb); - - int count = 0; - while (count++ < 5000) { - Thread.sleep(1); - } - - String fpr = e.updateIdentity(vb).fpr; - - log("PEPTEST", "keyserver test fpr"); - log("PEPTEST", fpr != null ? fpr : "NULL"); - if (fpr == null) throw new AssertionError(); - - lastTime = System.currentTimeMillis(); - e.stopKeyserverLookup(); - log("engine.stopLookup", String.valueOf(System.currentTimeMillis() - lastTime)); - - lastTime = System.currentTimeMillis(); - e.close(); - log("engine.close", String.valueOf(System.currentTimeMillis() - lastTime)); - log("TEST: ", "Test keyserver lookup finished"); - } - /* tests I can get my own fingerprint */ @@ -1927,18 +1877,15 @@ public class MainActivity extends AppCompatActivity { runTestPEpTypes(); return 1; case 2: - runTestKeyserverLookup(); - return 2; - case 3: runEncryptAndDecryptTest(); return 3; - case 4: + case 3: runEncryptAndDecryptWithoutKeyTest(); return 4; - case 5: + case 4: runColorRatingsTest(); return 5; - case 6: + case 5: runIntegrationTest(); return 6; case 16: diff --git a/androidTests/app/src/main/res/layout/activity_main.xml b/androidTests/app/src/main/res/layout/activity_main.xml index 25726c4..344b55e 100644 --- a/androidTests/app/src/main/res/layout/activity_main.xml +++ b/androidTests/app/src/main/res/layout/activity_main.xml @@ -57,27 +57,6 @@ android:text="Run" /> - - - - -