Browse Source

Add EncFormat PEPEncInlineEA. BUT a lot of question marks. see TODO:

JNI-98
heck 5 years ago
parent
commit
a1555e720f
  1. 34
      src/foundation/pEp/jniadapter/AbstractEngine.java
  2. 1
      src/pEp.yml2
  3. 50
      test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java

34
src/foundation/pEp/jniadapter/AbstractEngine.java

@ -198,9 +198,21 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AutoClosea
public static Message incomingMessageFromPGPText(String pgpText, Message.EncFormat encFormat) {
Message msg = new Message();
msg.setDir(Message.Direction.Incoming);
msg.setEncFormat(encFormat);
// Opts
ArrayList<Pair<String, String>> opts = new ArrayList<>();
Pair<String, String> xpEp = new Pair<>();
xpEp.first = "X-pEp-Version";
xpEp.second = "2.1";
opts.add(xpEp);
msg.setOptFields(opts);
if(encFormat == Message.EncFormat.PEP) {
// For EncFormat.PEP
// The pgpText goes into the attachment index 1
msg.setShortmsg("p≡p");
msg.setLongmsg("this message was encrypted with p≡p https://pEp-project.org");
msg.setEncFormat(encFormat);
// Attachments
Blob att0 = new Blob();
@ -217,16 +229,20 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AutoClosea
attachments.add(att0);
attachments.add(att1);
msg.setAttachments(attachments);
}
else if (encFormat == Message.EncFormat.PEPEncInlineEA) {
// For EncFormat.PEPEncInlineEA
// The pgpText goes into the longMessage
// TODO: Attachment index 0 should contain, i guess, the pubkey of the sender
// TODO: BUT why is there an attachemnt ElevatedAttachments are for non attachment transports
// Opts
ArrayList<Pair<String, String>> opts = new ArrayList<>();
Pair<String, String> xpEp = new Pair<>();
xpEp.first = "X-pEp-Version";
xpEp.second = "2.1";
opts.add(xpEp);
msg.setOptFields(opts);
msg.setShortmsg("");
msg.setLongmsg(pgpText);
}
else {
throw new pEpCannotEncode("Message.Encformat not supported: " + encFormat.toString());
}
return msg;
}
}

1
src/pEp.yml2

@ -290,6 +290,7 @@ namespace pEp {
SMIME > 2
PGPMIME > 3
PEP > 4
PEP_enc_inline_EA > 6
}
direction dir;

50
test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java

@ -1,6 +1,6 @@
package foundation.pEp.jniadapter.test.jni98;
import foundation.pEp.jniadapter.test.utils.TestUtils;
import static foundation.pEp.jniadapter.test.utils.TestUtils.*;
import foundation.pEp.jniadapter.*;
import java.nio.file.Files;
@ -54,7 +54,7 @@ class TestEnv {
Path path = Paths.get(fileNameKeyBobPub);
keyBobPub = Files.readAllBytes(path);
} catch (Exception e) {
TestUtils.log("Could not open key file:" + fileNameKeyBobPub);
log("Could not open key file:" + fileNameKeyBobPub);
throw e;
}
engine.importKey(keyBobPub);
@ -93,14 +93,14 @@ class TestUnit {
}
public void run() {
TestUtils.logH1(testUnitName);
logH1(testUnitName);
try {
lambda.accept(env);
} catch (Throwable e) {
TestUtils.logH1("TestUnit FAILED: " + e.toString());
logH1("TestUnit FAILED: " + e.toString());
return;
}
TestUtils.logH2("SUCCESS!");
logH2("SUCCESS!");
}
}
@ -111,27 +111,49 @@ class TestMain {
}
public static void testRunNew() throws Exception {
new TestUnit("JNI-98 - Factory function for generating incoming message from PGP text", env -> {
new TestUnit("JNI-98 - Message.EncFormat.PEP", env -> {
// Make msg1 by encrypting msgToBob
TestUtils.logH2("Create target Message");
logH2("Create target Message");
Message msg1 = env.engine.encrypt_message(env.msgToBob, null, Message.EncFormat.PEP);
TestUtils.log(TestUtils.msgToString(msg1));
TestUtils.log("msg returned from encrypt_message is null");
log(msgToString(msg1));
log("EncPep:" + Message.EncFormat.PEP.value);
// Lets get the pgpText of the msg1, and the EncFormat
String pgpText = Engine.toUTF16(msg1.getAttachments().elementAt(1).data);
Message.EncFormat ef = msg1.getEncFormat();
log("EncPepReturn:" + ef.value);
//TODO: setting encformat to 4 (PEP) getting back 3 (PGPMIME)
// Create msg2 by using incomingMessageFromPGPText with the pgpText and EncFormat from msg1
TestUtils.logH2("incomingMessageFromPGPText()");
logH2("incomingMessageFromPGPText()");
Message msg2 = Engine.incomingMessageFromPGPText(pgpText, Message.EncFormat.PEP);
log(msgToString(msg2));
logH2("Verify msg2");
Engine.decrypt_message_Return result = null;
result = env.engine.decrypt_message(msg2, env.vStr, 0);
log(msgToString(result.dst));
}).run();
new TestUnit("JNI-98 - Message.EncFormat.PEP_enc_inline_EA", env -> {
// Make msg1 by encrypting msgToBob
logH2("Create target Message");
Message msg1 = env.engine.encrypt_message(env.msgToBob, null, Message.EncFormat.PEPEncInlineEA);
log(msgToString(msg1));
// Lets get the pgpText of the msg1, and the EncFormat
String pgpText = msg1.getLongmsg();
Message.EncFormat ef = msg1.getEncFormat();
// Create msg2 by using incomingMessageFromPGPText with the pgpText and EncFormat from msg1
logH2("incomingMessageFromPGPText()");
Message msg2 = Engine.incomingMessageFromPGPText(pgpText, ef);
TestUtils.log(TestUtils.msgToString(msg2));
TestUtils.log("msg returned from incomingMessageFromPGPText() is null");
log(msgToString(msg2));
TestUtils.logH2("Verify msg2");
logH2("Verify msg2");
Engine.decrypt_message_Return result = null;
result = env.engine.decrypt_message(msg2, env.vStr, 0);
TestUtils.log(TestUtils.msgToString(result.dst));
log(msgToString(result.dst));
}).run();
}
}

Loading…
Cancel
Save