Thomas 2 months ago
parent
commit
9c6f5de489
11 changed files with 86 additions and 556 deletions
  1. +5
    -5
      androidTests/app/build.gradle
  2. +54
    -337
      androidTests/app/src/main/java/com/pep/k9/MainActivity.java
  3. +5
    -4
      androidTests/app/src/main/java/com/pep/k9/PEpUnitaryStuff.java
  4. +15
    -14
      androidTests/app/src/main/java/com/pep/k9/UnitActivity.java
  5. +0
    -84
      androidTests/app/src/main/res/layout/activity_main.xml
  6. +1
    -1
      androidTests/build.gradle
  7. +1
    -1
      src/codegen/gen_cpp_Engine.ysl2
  8. +0
    -7
      src/codegen/pEp.yml2
  9. +0
    -82
      src/cxx/basic_api.cc
  10. +5
    -5
      src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc
  11. +0
    -16
      test/java/foundation/pEp/jniadapter/test/regression/TestMain.java

+ 5
- 5
androidTests/app/build.gradle View File

@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
compileSdkVersion 30
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "security.pEp"
applicationId "security.pEp.test"
minSdkVersion 19
targetSdkVersion 25
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
@ -26,9 +26,9 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation project(':pEpJNIAdapter')
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
implementation 'com.jakewharton:butterknife:8.0.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'
implementation 'com.karumi:dexter:5.0.0'


+ 54
- 337
androidTests/app/src/main/java/com/pep/k9/MainActivity.java View File

@ -8,8 +8,8 @@ import android.content.res.AssetManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@ -31,14 +31,16 @@ import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;
import org.pEp.jniadapter.AndroidHelper;
import org.pEp.jniadapter.Blob;
import org.pEp.jniadapter.Engine;
import org.pEp.jniadapter.Identity;
import org.pEp.jniadapter.Message;
import org.pEp.jniadapter.Pair;
import org.pEp.jniadapter.Rating;
import org.pEp.jniadapter.pEpException;
import foundation.pEp.jniadapter.AndroidHelper;
import foundation.pEp.jniadapter.Blob;
import foundation.pEp.jniadapter.Engine;
import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.Message;
import foundation.pEp.jniadapter.Pair;
import foundation.pEp.jniadapter.Rating;
import foundation.pEp.jniadapter.Utils;
import foundation.pEp.jniadapter.decrypt_message_Return;
import foundation.pEp.jniadapter.exceptions.pEpException;
import java.io.File;
import java.io.FileInputStream;
@ -83,7 +85,6 @@ public class MainActivity extends AppCompatActivity {
ButterKnife.bind(this);
Context c = getApplicationContext();
Dexter.initialize(getApplication());
PermissionListener feedbackViewPermissionListener = new PermissionListener() {
@Override
public void onPermissionGranted(PermissionGrantedResponse response) {
@ -105,7 +106,12 @@ public class MainActivity extends AppCompatActivity {
SnackbarOnDeniedPermissionListener.Builder.with(rootView, R.string.hello_world)
.withOpenSettingsButton("SETTINGS")
.build());
Dexter.checkPermission(storagePermissionListener, Manifest.permission.WRITE_EXTERNAL_STORAGE);
Dexter.withActivity(this)
.withPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.withListener(storagePermissionListener)
.onSameThread()
.check();
generatedIdentities = new ArrayList<>();
text = new StringBuilder();
@ -264,9 +270,6 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.encrypt_and_decrypt) Button runEncryptAndDecrypt;
@BindView(R.id.encrypt_and_decrypt_without_key) Button runEncryptAndDecryptWithoutKey;
@BindView(R.id.ratings) Button runRatings;
@BindView(R.id.black_list) Button runBlackList;
@BindView(R.id.black_list_and_send) Button runBlackListAndSendMessage;
@BindView(R.id.black_list_and_delete) Button runBlackListAndDelete;
@BindView(R.id.unencrypted_subject) Button runUnencryptedSubject;
@BindView(R.id.passive_mode) Button runPassiveMode;
@BindView(R.id.message_from_me_green) Button runMessageFromMeIsGreen;
@ -274,7 +277,6 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.times_to_test) EditText timesToTest;
@BindView(R.id.outgoing_color) Button runOutgoingColor;
@BindView(R.id.identity_rating) Button runIdentityRating;
@BindView(R.id.deblacklist) Button runDeblacklist;
@OnClick(R.id.bRunTypes)
public void runTypes() {
@ -307,12 +309,6 @@ public class MainActivity extends AppCompatActivity {
new RunTestTask().execute(5);
}
@OnClick(R.id.deblacklist)
public void runDeblack() {
runDeblacklist.setText(TESTING);
new RunTestTask().execute(16);
}
@OnClick(R.id.test_everything)
public void runAllTests() {
Toast.makeText(this, "Testing started. Please, don't touch anything ò.ó", Toast.LENGTH_LONG).show();
@ -356,10 +352,6 @@ public class MainActivity extends AppCompatActivity {
encryptAndDecryptAMessage();
}
private void runDeblacklistRatingTest() throws IOException, pEpException {
deblacklistRating();
}
private void runEncryptAndDecryptAMessageFromMyselft() throws IOException, pEpException {
encryptAndDecryptAMessageFromMyselfTest();
}
@ -388,18 +380,6 @@ public class MainActivity extends AppCompatActivity {
testKeyGen();
}
private void runAddToBlacklistTest() throws pEpException, InterruptedException, IOException {
addToBlacklistTest();
}
private void runAddToBlacklistAndSendMessageTest() throws pEpException, InterruptedException, IOException {
addToBlacklistAndSendMessageTest();
}
private void runAddAndRemoveFromBlacklistTest() throws pEpException, InterruptedException, IOException {
addAndRemoveFromBlacklistTest();
}
private void runPassiveModeTest() throws pEpException, InterruptedException, IOException {
passiveModeTest();
}
@ -775,32 +755,6 @@ public class MainActivity extends AppCompatActivity {
log("TEST: ", "integration test finished");
}
public void addToBlacklistTest() throws pEpException, IOException, AssertionError {
log("TEST: ", "blacklist test started");
long lastTime = System.currentTimeMillis();
Engine engine;
engine = new Engine();
log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
// trustwords
testTrustwords(engine);
Identity alice = loadFromAliceFromEngine(engine);
String fingerprint = alice.fpr;
addToBlacklistInEngine(engine, fingerprint);
alice = myselfInEngine(engine, alice);
//if (!fingerprint.equals(PEP_OWN_USER_ID)) {
// throw new AssertionError("fingerprint was " + fingerprint + " instead of PEP_OWN_USER_ID");
//}
removeFromBlacklistOnEngine(engine, alice.fpr);
engine.close();
log("TEST: ", "blacklist test finished");
}
public void testOutgoingColor() throws pEpException, IOException, AssertionError {
log("TEST: ", "testOutgoingColor start");
long lastTime = System.currentTimeMillis();
@ -858,105 +812,6 @@ public class MainActivity extends AppCompatActivity {
log("TEST: ", "testIdetntityRating finished");
}
public void addToBlacklistAndSendMessageTest() throws pEpException, IOException, AssertionError {
log("TEST: ", "blacklist + send message test started");
long lastTime = System.currentTimeMillis();
Engine engine;
engine = new Engine();
log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
// trustwords
testTrustwords(engine);
Identity aliceFrom = loadFromAliceFromEngine(engine);
Identity bobTo = loadToBobFromEngine(engine);
String fingerprint = bobTo.fpr;
addToBlacklistInEngine(engine, fingerprint);
// myselfInEngine(engine, aliceFrom);
// updateIdentityOnEngine(engine, bobTo);
// message
Message msg = setupMessage(aliceFrom, bobTo);
ArrayList<Pair<String, String>> pairs = new ArrayList<>();
pairs.add(new Pair<>("Received", "in time"));
pairs.add(new Pair<>("X-Foobaz", "of course"));
msg.setOptFields(pairs);
byte[] gif = LoadAssetAsBuffer("spinner.gif");
byte[] png = LoadAssetAsBuffer("pep.png");
byte[] tbz = LoadAssetAsBuffer("yml2.tar.bz2");
attachToMessage(msg, gif, png, tbz);
Message encriptedMessage;
encriptedMessage = encryptMessageOnEngine(engine, msg);
if (encriptedMessage != null) throw new AssertionError();
//if (!(encriptedMessage.getShortmsg().equals("pEp"))) throw new AssertionError();
//if (!(encriptedMessage.getLongmsg().contains("pEp-project.org")))
// throw new AssertionError();
removeFromBlacklistOnEngine(engine, fingerprint);
engine.close();
log("TEST: ", "blacklist + send message test finished");
}
public void addAndRemoveFromBlacklistTest() throws pEpException, IOException, AssertionError {
log("TEST: ", "blacklist + delete from blacklist test started");
long lastTime = System.currentTimeMillis();
Engine engine;
engine = new Engine();
log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
// trustwords
testTrustwords(engine);
Identity bob = loadToBobFromEngine(engine);
String fingerprint = bob.fpr;
addToBlacklistInEngine(engine, fingerprint);
removeFromBlacklistOnEngine(engine, fingerprint);
Boolean isBlacklisted = isBlacklistedOnEngine(engine, bob);
if (isBlacklisted) {
throw new AssertionError();
}
// message
getBlackList(engine);
engine.close();
log("TEST: ", "blacklist + delete from blacklist finished");
}
private Vector<String> getBlackList(Engine engine) throws pEpException {
long lastTime = System.currentTimeMillis();
logStart("blacklist_retrieve", String.valueOf(lastTime));
Vector<String> blacklist = engine.blacklist_retrieve();
logEnd("blacklist_retrieve", String.valueOf(System.currentTimeMillis() - lastTime));
return blacklist;
}
private Boolean isBlacklistedOnEngine(Engine engine, Identity bob) {
long lastTime = System.currentTimeMillis();
logStart("blacklist_is_listed", String.valueOf(lastTime));
Boolean isBlacklisted = engine.blacklist_is_listed(bob.fpr);
logEnd("blacklist_is_listed", String.valueOf(System.currentTimeMillis() - lastTime));
return isBlacklisted;
}
private void removeFromBlacklistOnEngine(Engine engine, String fingerprint) {
long lastTime = System.currentTimeMillis();
logStart("blacklist_delete", String.valueOf(lastTime));
engine.blacklist_delete(fingerprint);
logEnd("backlist_delete", String.valueOf(System.currentTimeMillis() - lastTime));
}
private Identity myselfInEngine(Engine engine, Identity identity) {
long lastTime = System.currentTimeMillis();
logStart("engine.addToBlacklist", String.valueOf(lastTime));
@ -965,13 +820,6 @@ public class MainActivity extends AppCompatActivity {
return myself;
}
private void addToBlacklistInEngine(Engine engine, String fingerprint) {
long lastTime = System.currentTimeMillis();
logStart("engine.addToBlacklist", String.valueOf(lastTime));
engine.blacklist_add(fingerprint);
logEnd("engine.addToBlacklist", String.valueOf(System.currentTimeMillis() - lastTime));
}
private void ratingsTest() throws pEpException, IOException, AssertionError {
log("TEST: ", "Test ratings loaded");
long lastTime = System.currentTimeMillis();
@ -1022,50 +870,6 @@ public class MainActivity extends AppCompatActivity {
log("TEST: ", "Test encrypt and decrypt finished");
}
public void deblacklistRating() throws pEpException, IOException, AssertionError {
log("TEST: ", "Test deblacklistRating loaded");
long lastTime = System.currentTimeMillis();
Engine engine;
engine = new Engine();
log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
Identity alice = loadFromAliceFromEngine(engine);
Identity bob = loadToBobFromEngine(engine);
removeFromBlacklistOnEngine(engine, bob.fpr);
// message
Message msg = setupMessage(alice, bob);
log("Test deblacklistRating after remove blacklist", getOutgoingMessageRatingFromEngine(engine, msg).name());
if (!(getOutgoingMessageRatingFromEngine(engine, msg).value >= Rating.pEpRatingReliable.value)) {
throw new AssertionError();
}
String fingerprint = bob.fpr;
addToBlacklistInEngine(engine, fingerprint);
Message msgBlacklisted = setupMessage(alice, bob);
log("Test deblacklistRating after blacklist", getOutgoingMessageRatingFromEngine(engine, msgBlacklisted).name());
if (getOutgoingMessageRatingFromEngine(engine, msgBlacklisted).value > 4) {
throw new AssertionError();
}
removeFromBlacklistOnEngine(engine, fingerprint);
Message msgDeBlacklisted = setupMessage(alice, bob);
log("Test deblacklistRating after remove blacklist", getOutgoingMessageRatingFromEngine(engine, msg).name());
if (!(getOutgoingMessageRatingFromEngine(engine, msgDeBlacklisted).equals(Rating.pEpRatingReliable))) {
throw new AssertionError();
}
engine.close();
log("TEST: ", "Test deblacklistRating finished");
}
public void encryptAndDecryptAMessageFromMyselfTest() throws pEpException, IOException, AssertionError {
log("TEST: ", "Test encrypt and decrypt from myself loaded");
@ -1094,10 +898,10 @@ public class MainActivity extends AppCompatActivity {
throw new AssertionError();
Vector<Blob> attachments = encryptedMessage.getAttachments();
if (!(Engine.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----")))
if (!(Utils.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----")))
throw new AssertionError();
Engine.decrypt_message_Return result = null;
decrypt_message_Return result = null;
decryptMessageOnEngine(engine, encryptedMessage);
engine.close();
@ -1121,7 +925,7 @@ public class MainActivity extends AppCompatActivity {
pairs.add(new Pair<>("X-Foobaz", "of course"));
msg.setOptFields(pairs);
Engine.decrypt_message_Return decrypt_message_return = encrypAndDecryptMessage(engine, msg);
decrypt_message_Return decrypt_message_return = encrypAndDecryptMessage(engine, msg);
if(decrypt_message_return.rating.value < 6) {
throw new AssertionError();
@ -1294,7 +1098,7 @@ public class MainActivity extends AppCompatActivity {
private void importKeyFromEngine(Engine engine, String filename) throws IOException {
long lastTime = System.currentTimeMillis();
logStart("engine.importKey", String.valueOf(lastTime));
engine.importKey(LoadAssetAsString(filename));
engine.importKey(LoadAssetAsBuffer(filename));
logEnd("engine.importKey", String.valueOf(System.currentTimeMillis() - lastTime));
}
@ -1394,7 +1198,7 @@ public class MainActivity extends AppCompatActivity {
}
@NonNull
private Engine.decrypt_message_Return encrypAndDecryptMessage(Engine engine, Message msg) throws pEpException {
private decrypt_message_Return encrypAndDecryptMessage(Engine engine, Message msg) throws pEpException {
Message encryptedMessage;
encryptedMessage = encryptMessageOnEngine(engine, msg);
@ -1405,10 +1209,10 @@ public class MainActivity extends AppCompatActivity {
throw new AssertionError();
Vector<Blob> attachments = encryptedMessage.getAttachments();
if (!(Engine.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----")))
if (!(Utils.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----")))
throw new AssertionError();
Engine.decrypt_message_Return result;
decrypt_message_Return result;
result = decryptMessageOnEngine(engine, encryptedMessage);
if (!(result.dst.getShortmsg().equals("hello, world"))) throw new AssertionError();
@ -1416,10 +1220,10 @@ public class MainActivity extends AppCompatActivity {
return result;
}
private Engine.decrypt_message_Return decryptMessageOnEngine(Engine engine, Message encriptedMessage) throws pEpException {
private decrypt_message_Return decryptMessageOnEngine(Engine engine, Message encriptedMessage) throws pEpException {
long lastTime = System.currentTimeMillis();
logStart("engine.decrypt_message", String.valueOf(lastTime));
Engine.decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage, 0);
decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage, new Vector<>(), 0);
logEnd("engine.decrypt_message", String.valueOf(System.currentTimeMillis() - lastTime));
return decrypt_message_return;
}
@ -1593,7 +1397,7 @@ public class MainActivity extends AppCompatActivity {
case 7:
if (!executedTasks.contains(7)) {
for (int i = 0; i< testingTimes; i++) {
runAddToBlacklistTest();
runUnencryptedSubjectTest();
}
executedTasks.add(7);
return 7;
@ -1602,7 +1406,7 @@ public class MainActivity extends AppCompatActivity {
case 8:
if (!executedTasks.contains(8)) {
for (int i = 0; i< testingTimes; i++) {
runAddToBlacklistAndSendMessageTest();
runPassiveModeTest();
}
executedTasks.add(8);
return 8;
@ -1611,7 +1415,7 @@ public class MainActivity extends AppCompatActivity {
case 9:
if (!executedTasks.contains(9)) {
for (int i = 0; i< testingTimes; i++) {
runAddAndRemoveFromBlacklistTest();
runEncryptAndDecryptAMessageFromMyselft();
}
executedTasks.add(9);
return 9;
@ -1620,7 +1424,7 @@ public class MainActivity extends AppCompatActivity {
case 10:
if (!executedTasks.contains(10)) {
for (int i = 0; i< testingTimes; i++) {
runUnencryptedSubjectTest();
runMessageForMeIsAlwaysGreenTest();
}
executedTasks.add(10);
return 10;
@ -1629,8 +1433,9 @@ public class MainActivity extends AppCompatActivity {
case 11:
if (!executedTasks.contains(11)) {
for (int i = 0; i< testingTimes; i++) {
runPassiveModeTest();
runOutgoingColorTest();
}
log("outgoing average", String.valueOf(outgoingColorAccumulative /testingTimes));
executedTasks.add(11);
return 11;
}
@ -1638,49 +1443,12 @@ public class MainActivity extends AppCompatActivity {
case 12:
if (!executedTasks.contains(12)) {
for (int i = 0; i< testingTimes; i++) {
runEncryptAndDecryptAMessageFromMyselft();
runIdetntityRatingTest();
}
executedTasks.add(12);
return 12;
}
break;
case 13:
if (!executedTasks.contains(13)) {
for (int i = 0; i< testingTimes; i++) {
runMessageForMeIsAlwaysGreenTest();
}
executedTasks.add(13);
return 13;
}
break;
case 14:
if (!executedTasks.contains(14)) {
for (int i = 0; i< testingTimes; i++) {
runOutgoingColorTest();
}
log("outgoing average", String.valueOf(outgoingColorAccumulative /testingTimes));
executedTasks.add(14);
return 14;
}
break;
case 15:
if (!executedTasks.contains(15)) {
for (int i = 0; i< testingTimes; i++) {
runIdetntityRatingTest();
}
executedTasks.add(15);
return 15;
}
break;
case 16:
if (!executedTasks.contains(16)) {
for (int i = 0; i< testingTimes; i++) {
runDeblacklistRatingTest();
}
executedTasks.add(16);
return 16;
}
break;
}
} catch (AssertionError | Exception ex) {
Log.e("PEPTEST", "##################### TEST Exception ####################", ex);
@ -1730,58 +1498,29 @@ public class MainActivity extends AppCompatActivity {
new RunAllTestsTask().execute(6);
break;
case 6:
runIntegration.setText(PASSED);
runBlackList.setText(TESTING);
new RunAllTestsTask().execute(7);
break;
case 7:
runBlackList.setText(PASSED);
runBlackListAndSendMessage.setText(TESTING);
new RunAllTestsTask().execute(8);
break;
case 8:
runBlackListAndSendMessage.setText(PASSED);
runBlackListAndDelete.setText(TESTING);
new RunAllTestsTask().execute(9);
break;
case 9:
runBlackListAndDelete.setText(PASSED);
runUnencryptedSubject.setText(TESTING);
new RunAllTestsTask().execute(10);
break;
case 10:
runUnencryptedSubject.setText(PASSED);
runPassiveMode.setText(TESTING);
new RunAllTestsTask().execute(11);
new RunAllTestsTask().execute(7);
break;
case 11:
case 7:
runPassiveMode.setText(PASSED);
runMessageMe.setText(TESTING);
new RunAllTestsTask().execute(12);
new RunAllTestsTask().execute(8);
break;
case 12:
case 8:
runMessageMe.setText(PASSED);
runMessageFromMeIsGreen.setText(TESTING);
new RunAllTestsTask().execute(13);
new RunAllTestsTask().execute(9);
break;
case 13:
case 9:
runMessageFromMeIsGreen.setText(PASSED);
runOutgoingColor.setText(TESTING);
new RunAllTestsTask().execute(14);
new RunAllTestsTask().execute(10);
break;
case 14:
case 10:
runOutgoingColor.setText(PASSED);
runIdentityRating.setText(TESTING);
new RunAllTestsTask().execute(15);
break;
case 15:
runIdentityRating.setText(PASSED);
runDeblacklist.setText(TESTING);
new RunAllTestsTask().execute(16);
break;
case 16:
runDeblacklist.setText(PASSED);
generateNoteOnSD("dump_test_engine");
new RunAllTestsTask().execute(11);
break;
}
Log.i("RunAllTestsTask", "onPostExecute " + "Ended test");
@ -1819,44 +1558,28 @@ public class MainActivity extends AppCompatActivity {
new RunAllTestsTask().execute(7);
break;
case 7:
runBlackList.setText(FAILED);
new RunAllTestsTask().execute(8);
break;
case 8:
runBlackListAndSendMessage.setText(FAILED);
new RunAllTestsTask().execute(9);
break;
case 9:
runBlackListAndDelete.setText(FAILED);
new RunAllTestsTask().execute(10);
break;
case 10:
runUnencryptedSubject.setText(FAILED);
new RunAllTestsTask().execute(11);
new RunAllTestsTask().execute(7);
break;
case 11:
case 8:
runMessageMe.setText(FAILED);
new RunAllTestsTask().execute(12);
new RunAllTestsTask().execute(8);
break;
case 12:
case 9:
runMessageMe.setText(FAILED);
new RunAllTestsTask().execute(13);
new RunAllTestsTask().execute(9);
break;
case 13:
case 10:
runMessageFromMeIsGreen.setText(FAILED);
new RunAllTestsTask().execute(14);
new RunAllTestsTask().execute(10);
break;
case 14:
case 11:
runMessageFromMeIsGreen.setText(FAILED);
new RunAllTestsTask().execute(14);
new RunAllTestsTask().execute(11);
break;
case 15:
case 12:
runIdentityRating.setText(FAILED);
new RunAllTestsTask().execute(15);
break;
case 16:
runDeblacklist.setText(FAILED);
generateNoteOnSD("dump_test_engine");
new RunAllTestsTask().execute(12);
break;
}
}
@ -1888,9 +1611,6 @@ public class MainActivity extends AppCompatActivity {
case 5:
runIntegrationTest();
return 6;
case 16:
runDeblacklistRatingTest();
return 6;
}
} catch (Exception e) {
e.printStackTrace();
@ -1929,9 +1649,6 @@ public class MainActivity extends AppCompatActivity {
case 6:
runIntegration.setText(TESTED);
break;
case 16:
runDeblacklist.setText(TESTED);
break;
}
Log.i("RunAllTestsTask", "onPostExecute " + "Ended test");
}


+ 5
- 4
androidTests/app/src/main/java/com/pep/k9/PEpUnitaryStuff.java View File

@ -1,8 +1,9 @@
package com.pep.k9;
import org.pEp.jniadapter.Engine;
import org.pEp.jniadapter.Identity;
import org.pEp.jniadapter.Message;
import foundation.pEp.jniadapter.Engine;
import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.Message;
import foundation.pEp.jniadapter.decrypt_message_Return;
import java.util.Vector;
@ -37,7 +38,7 @@ public class PEpUnitaryStuff {
msg.setCc(cc);
Message encriptedMessage = engine.encrypt_message(msg, null, Message.EncFormat.PEP);
Engine.decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage, 0);
decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage, new Vector<>(), 0);
if (!decrypt_message_return.dst.getLongmsg().equals(message)) {
throw new RuntimeException("FAILED");


+ 15
- 14
androidTests/app/src/main/java/com/pep/k9/UnitActivity.java View File

@ -1,17 +1,18 @@
package com.pep.k9;
import android.content.res.AssetManager;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import org.pEp.jniadapter.Blob;
import org.pEp.jniadapter.Engine;
import org.pEp.jniadapter.Identity;
import org.pEp.jniadapter.Message;
import org.pEp.jniadapter.Pair;
import org.pEp.jniadapter.pEpException;
import foundation.pEp.jniadapter.Blob;
import foundation.pEp.jniadapter.Engine;
import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.Message;
import foundation.pEp.jniadapter.Pair;
import foundation.pEp.jniadapter.decrypt_message_Return;
import foundation.pEp.jniadapter.exceptions.pEpException;
import java.io.IOException;
import java.io.InputStream;
@ -69,7 +70,7 @@ public class UnitActivity extends AppCompatActivity {
Vector<Blob> attachments = encryptedMessage.getAttachments();
Engine.decrypt_message_Return result;
decrypt_message_Return result;
result = decryptMessageOnEngine(engine, encryptedMessage);
engine.close();
@ -107,7 +108,7 @@ public class UnitActivity extends AppCompatActivity {
Vector<Blob> attachments = encryptedMessage.getAttachments();
Engine.decrypt_message_Return result;
decrypt_message_Return result;
result = decryptMessageOnEngine(engine, encryptedMessage);
engine.close();
@ -145,7 +146,7 @@ public class UnitActivity extends AppCompatActivity {
Vector<Blob> attachments = encryptedMessage.getAttachments();
Engine.decrypt_message_Return result;
decrypt_message_Return result;
result = decryptMessageOnEngine(engine, encryptedMessage);
engine.close();
@ -175,9 +176,9 @@ public class UnitActivity extends AppCompatActivity {
return msg;
}
private Engine.decrypt_message_Return decryptMessageOnEngine(Engine engine, Message encriptedMessage) throws pEpException {
private decrypt_message_Return decryptMessageOnEngine(Engine engine, Message encriptedMessage) throws pEpException {
long lastTime = System.currentTimeMillis();
Engine.decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage, 0);
decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage, new Vector<>(), 0x0);
long time = System.currentTimeMillis() - lastTime;
Log.d("time", " " + time);
return decrypt_message_return;
@ -256,7 +257,7 @@ public class UnitActivity extends AppCompatActivity {
private void importKeyFromEngine(Engine engine, String filename) throws IOException {
long lastTime = System.currentTimeMillis();
engine.importKey(LoadAssetAsString(filename));
engine.importKey(LoadAssetAsBuffer(filename));
long time = System.currentTimeMillis() - lastTime;
Log.d("time", " " + time);
}


+ 0
- 84
androidTests/app/src/main/res/layout/activity_main.xml View File

@ -141,69 +141,6 @@
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Add to blacklist + new key"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/black_list"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Blacklist + send"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/black_list_and_send"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Blacklist + delete"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/black_list_and_delete"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -330,27 +267,6 @@
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Deblacklist rating"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/deblacklist"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"


+ 1
- 1
androidTests/build.gradle View File

@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:4.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files


+ 1
- 1
src/codegen/gen_cpp_Engine.ysl2 View File

@ -13,7 +13,7 @@ tstylesheet {
template "interface" document("../cxx/foundation_pEp_jniadapter_{@name}.cc", "text")
||
#include <cassert>
#include <pEp/blacklist.h>
#include <pEp/pEpEngine.h>
#include <pEp/openpgp_compat.h>
#include <pEp/key_reset.h>
#include <pEp/Adapter.hh>


+ 0
- 7
src/codegen/pEp.yml2 View File

@ -149,10 +149,6 @@ namespace pEp {
returns Rating rating
);
method cached=true blacklist_retrieve(
returns stringlist blacklist
);
// TODO: WTF is...
method cached=true own_message_private_key_details(
in message msg,
@ -264,9 +260,6 @@ namespace pEp {
basic void trustPersonalKey(identity ident);
basic void trustOwnKey(identity ident);
basic identitylist importKey(bytearray key);
basic void blacklist_add(string fpr);
basic void blacklist_delete(string fpr);
basic bool blacklist_is_listed(string fpr);
basic void config_passive_mode(bool enable);
basic void config_unencrypted_subject(bool enable);
basic string getCrashdumpLog(int maxlines);


+ 0
- 82
src/cxx/basic_api.cc View File

@ -1,5 +1,4 @@
#include <pEp/keymanagement.h>
#include <pEp/blacklist.h>
#include <pEp/Adapter.hh>
#include <pEp/pEpLog.hh>
@ -340,88 +339,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1unencrypt
::config_unencrypted_subject(session(), static_cast<bool>(enable));
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1add(JNIEnv *env,
jobject obj,
jbyteArray fpr
)
{
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);
const char *_fpr = to_string(env, fpr);
if(_fpr == NULL){
throw_pEp_Exception(env, PEP_OUT_OF_MEMORY);
return;
}
PEP_STATUS status = passphraseWrap(::blacklist_add, session(), _fpr);
if (status != PEP_STATUS_OK) {
throw_pEp_Exception(env, status);
return;
}
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1delete(JNIEnv *env,
jobject obj,
jbyteArray fpr)
{
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);
const char *_fpr = to_string(env, fpr);
if(_fpr == NULL){
throw_pEp_Exception(env, PEP_OUT_OF_MEMORY);
return;
}
PEP_STATUS status = passphraseWrap(::blacklist_delete, session(), _fpr);
if (status != PEP_STATUS_OK) {
throw_pEp_Exception(env, status);
return;
}
}
JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_Engine__1blacklist_1is_1listed(JNIEnv *env,
jobject obj,
jbyteArray fpr)
{
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);
const char *_fpr = to_string(env, fpr);
bool _listed = 0;
if(_fpr == NULL){
throw_pEp_Exception(env, PEP_OUT_OF_MEMORY);
return 0;
}
PEP_STATUS status = passphraseWrap(::blacklist_is_listed, session(), _fpr, &_listed);
if (status != PEP_STATUS_OK) {
throw_pEp_Exception(env, status);
return 0;
}
return (jboolean)_listed;
}
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1getCrashdumpLog(JNIEnv *env,
jobject obj,


+ 5
- 5
src/cxx/foundation_pEp_jniadapter_AbstractEngine.cc View File

@ -5,6 +5,7 @@
#include <pEp/pEpLog.hh>
#include <pEp/passphrase_cache.hh>
#include <pEp/callback_dispatcher.hh>
#include <pEp/Adapter.hh>
#include "throw_pEp_exception.hh"
#include "jniutils.hh"
#include "passphrase_callback.hh"
@ -257,11 +258,10 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_init(JNIEnv
jni_init();
objj = env->NewGlobalRef(obj);
callback_dispatcher.add(messageToSend, notifyHandshake, JNISync::onSyncStartup, JNISync::onSyncShutdown);
Adapter::_messageToSend = CallbackDispatcher::messageToSend;
}
create_engine_java_object_mutex(env, obj); // Create a mutex per java object
Adapter::session();
Adapter::session.initialize(Adapter::SyncModes::Async, false);
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release(JNIEnv *env,
@ -270,7 +270,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine_release(JNI
std::lock_guard<std::mutex> l(global_mutex); // global mutex for write access to <unordered_map>
pEpLog("called");
release_engine_java_object_mutex(env, obj);
Adapter::session(pEp::Adapter::release);
Adapter::session.release();
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1setDebugLogEnabled(
@ -337,7 +337,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync
std::lock_guard<std::mutex> l(*mutex_local);
try {
CallbackDispatcher::start_sync();
Adapter::start_sync();
} catch (RuntimeError& ex) {
throw_pEp_Exception(env, ex.status);
return;
@ -355,7 +355,7 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopSync(
}
std::lock_guard<std::mutex> l(*mutex_local);
CallbackDispatcher::stop_sync();
Adapter::stop_sync();
}
JNIEXPORT jboolean JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1isSyncRunning(JNIEnv *env,


+ 0
- 16
test/java/foundation/pEp/jniadapter/test/regression/TestMain.java View File

@ -113,10 +113,6 @@ class TestMain {
ctx.engine.identity_rating(ctx.alice);
});
new TestUnit<CTXBase>("Engine.blacklist_retrieve", new CTXBase(), ctx -> {
ctx.engine.blacklist_retrieve();
});
// TODO: FAILS
// new TestUnit<CTXAlice2>("Engine.own_message_private_key_details", new CTXAlice2(), ctx -> {
// ctx.engine.own_message_private_key_details(ctx.msgToSelf);
@ -231,18 +227,6 @@ class TestMain {
ctx.engine.importKey(ctx.keyBobPub);
});
new TestUnit<CTXBase>("Engine.blacklist_add", new CTXBase(), ctx -> {
ctx.engine.blacklist_add("43");
});
new TestUnit<CTXBase>("Engine.blacklist_delete", new CTXBase(), ctx -> {
ctx.engine.blacklist_delete("43");
});
new TestUnit<CTXBase>("Engine.blacklist_is_listed", new CTXBase(), ctx -> {
ctx.engine.blacklist_is_listed("43");
});
new TestUnit<CTXBase>("Engine.config_passive_mode", new CTXBase(), ctx -> {
ctx.engine.config_passive_mode(false);
});


Loading…
Cancel
Save