Browse Source

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

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

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

@ -198,26 +198,8 @@ 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.setShortmsg("p≡p");
msg.setLongmsg("this message was encrypted with p≡p https://pEp-project.org");
msg.setEncFormat(encFormat);
// Attachments
Blob att0 = new Blob();
att0.mime_type = "application/pgp-encrypted";
att0.filename = null;
att0.data = "Version: 1".getBytes();
Blob att1 = new Blob();
att1.mime_type = "application/octet-stream";
att1.filename = "file://msg.asc";
att1.data = pgpText.getBytes();
Vector<Blob> attachments = new Vector<>();
attachments.add(att0);
attachments.add(att1);
msg.setAttachments(attachments);
// Opts
ArrayList<Pair<String, String>> opts = new ArrayList<>();
Pair<String, String> xpEp = new Pair<>();
@ -226,7 +208,41 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AutoClosea
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");
// Attachments
Blob att0 = new Blob();
att0.mime_type = "application/pgp-encrypted";
att0.filename = null;
att0.data = "Version: 1".getBytes();
Blob att1 = new Blob();
att1.mime_type = "application/octet-stream";
att1.filename = "file://msg.asc";
att1.data = pgpText.getBytes();
Vector<Blob> attachments = new Vector<>();
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
msg.setShortmsg("");
msg.setLongmsg(pgpText);
}
else {
throw new pEpCannotEncode("Message.Encformat not supported: " + encFormat.toString());
}
return msg;
}
}
}

11
src/pEp.yml2

@ -285,11 +285,12 @@ namespace pEp {
}
enum EncFormat {
none > 0
inline > 1
SMIME > 2
PGPMIME > 3
PEP > 4
none > 0
inline > 1
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