
6 changed files with 343 additions and 90 deletions
@ -0,0 +1,34 @@ |
|||||
|
include ../../../../../../../Makefile.conf |
||||
|
include ../Makefile.conf |
||||
|
|
||||
|
TEST_UNIT_NAME=jni98 |
||||
|
|
||||
|
JAVA_CLASSES = \
|
||||
|
TestMain.class \
|
||||
|
../utils/AdapterTestUtils.class |
||||
|
|
||||
|
JAVA_CLASSES += $(JAVA_CLASSES_FRAMEWORK) |
||||
|
|
||||
|
.PHONY: compile run test clean |
||||
|
|
||||
|
all: compile |
||||
|
$(MAKE) run |
||||
|
|
||||
|
run: compile |
||||
|
cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestMain |
||||
|
|
||||
|
compile: $(JAVA_CLASSES) |
||||
|
|
||||
|
%.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: |
||||
|
rm -rf $(PEP_HOME_DIR)/* |
||||
|
rm -rf $(PEP_HOME_DIR)/.pEp |
@ -0,0 +1,84 @@ |
|||||
|
package foundation.pEp.jniadapter.test.jni98; |
||||
|
|
||||
|
import foundation.pEp.jniadapter.Engine; |
||||
|
import foundation.pEp.jniadapter.Message; |
||||
|
import foundation.pEp.jniadapter.test.framework.TestUnit; |
||||
|
import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext; |
||||
|
|
||||
|
import static foundation.pEp.jniadapter.test.framework.TestLogger.log; |
||||
|
import static foundation.pEp.jniadapter.test.framework.TestLogger.logH2; |
||||
|
import static foundation.pEp.jniadapter.test.utils.AdapterTestUtils.msgToString; |
||||
|
|
||||
|
/* |
||||
|
JNI-98 - "Factory function for generating incoming message from PGP text" |
||||
|
|
||||
|
Problem: |
||||
|
There must be a static function in class Engine, which is generating an encrypted |
||||
|
version of a Message, which is structured like messages coming out from encrypt_message() |
||||
|
when being used with Message.EncFormat.PEP. Additionally, it should work with inline format, too. |
||||
|
The signature is expected to be: |
||||
|
|
||||
|
public static Message incomingMessageFromPGPText(String pgpText, Message.EncFormat encFormat) |
||||
|
|
||||
|
Please see https://pep.foundation/jira/browse/JNI-98 for further discussion
|
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
class TestMain { |
||||
|
public static void main(String[] args) throws Exception { |
||||
|
new TestUnit<AdapterBaseTestContext>("JNI-98 - Message.EncFormat.PEP", new AdapterBaseTestContext(), env -> { |
||||
|
// Make msg1 by encrypting msgToBob
|
||||
|
logH2("Create target Message"); |
||||
|
Message msg1 = env.engine.encrypt_message(env.msgToBob, null, Message.EncFormat.PEP); |
||||
|
log("\n" + msgToString(msg1, false)); |
||||
|
|
||||
|
// Lets get the pgpText of the msg1, and the EncFormat
|
||||
|
String pgpText = Engine.toUTF16(msg1.getAttachments().elementAt(1).data); |
||||
|
Message.EncFormat ef = msg1.getEncFormat(); |
||||
|
//TODO: setting encformat to 4 (PEP) but getting back 3 (PGPMIME)
|
||||
|
|
||||
|
// Create msg2 by using incomingMessageFromPGPText with the pgpText and EncFormat from msg1
|
||||
|
logH2("incomingMessageFromPGPText()"); |
||||
|
Message msg2 = env.engine.incomingMessageFromPGPText(pgpText, Message.EncFormat.PEP); |
||||
|
log("\n" + msgToString(msg2, false)); |
||||
|
|
||||
|
logH2("Verify msg2"); |
||||
|
Engine.decrypt_message_Return result = null; |
||||
|
result = env.engine.decrypt_message(msg2, env.vStr, 0); |
||||
|
log("\n" + msgToString(result.dst, false)); |
||||
|
}).run(); |
||||
|
|
||||
|
new TestUnit<AdapterBaseTestContext>("JNI-98 - Message.EncFormat.PEP_enc_inline_EA", new AdapterBaseTestContext(), env -> { |
||||
|
// Make msg1 by encrypting msgToBob
|
||||
|
logH2("Create target Message"); |
||||
|
Message msg1 = env.engine.encrypt_message(env.msgToBob, null, Message.EncFormat.PEPEncInlineEA); |
||||
|
log("\n" + msgToString(msg1, false)); |
||||
|
|
||||
|
// 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 = env.engine.incomingMessageFromPGPText(pgpText, ef); |
||||
|
log("\n" + msgToString(msg2, false)); |
||||
|
|
||||
|
// Cant be just simply decrypted again
|
||||
|
// And thats correct according to fdik
|
||||
|
//[21:29] < heck> | Assertion failed: (value && size && mime_type && code && !code[0] && code_size), function decode_internal, file internal_format.c, line 113.
|
||||
|
//[21:31] < fdik> | ja
|
||||
|
//[21:31] < fdik> | auch das ist korrekt
|
||||
|
//[21:31] < fdik> | wenn Du EA verwendest, dann geht es nicht, dass man die Nachricht so wie sie ist wieder decrypted
|
||||
|
//[21:31] < fdik> | sondern das geht nur, wenn man sie zerlegt
|
||||
|
//[21:32] < fdik> | dafür ist das Verfahren da
|
||||
|
//[21:34] < fdik> | ich hab einen Test dafür geschrieben
|
||||
|
//[21:34] < fdik> | pEpEngine/test/src/ElevatedAttachmentsTest.cc
|
||||
|
//[21:34] < fdik> | in default
|
||||
|
//[21:35] < fdik> | Doku hier https://dev.pep.foundation/Engine/ElevatedAttachments
|
||||
|
//[21:35] < fdik> | siehe hier:
|
||||
|
//[21:35] < fdik> | https://dev.pep.foundation/Engine/ElevatedAttachments#support-in-message-api
|
||||
|
}).run(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
Loading…
Reference in new issue