Browse Source

merge in JNI-117 - "key export"

pull/1/head
heck 5 years ago
parent
commit
b1d6b534a5
  1. 5
      Makefile.conf
  2. 4
      src/codegen/gen_java_Engine.ysl2
  3. 1
      src/codegen/pEp.yml2
  4. 27
      src/cxx/basic_api.cc
  5. 37
      test/java/foundation/pEp/jniadapter/test/jni117/Makefile
  6. 23
      test/java/foundation/pEp/jniadapter/test/jni117/TestAlice.java

5
Makefile.conf

@ -48,9 +48,9 @@ ifndef JAVA_HOME
endif
# Guessing USE_JAVAH
# cant be guessed earlier, because we depend on JAVA_HOME which can be set in the local.conf
# cant be guessed earlier, because it depends on JAVA_HOME which can be set in the local.conf
# Old versions of a Java distribution have a `javah` binary, new version do not and the replacement is "javac -h"
# TODO: dont check for presence of javah, but check if javac -h is supported, because some java (RHEL) has javah but supports javac -h
# TODO: dont check for presence of javah, but check if javac -h is supported, because some java (RHEL) has javah but supports javac -h (and javac -h is preferred)
ifndef USE_JAVAH
DUMMY:=$(shell which $(JAVA_HOME)/bin/javah)
ifeq ($(.SHELLSTATUS),0)
@ -84,6 +84,7 @@ export YML_PATH=$(YML2_PATH)
# BEGIN // kryptic hack to to replace a space with a newline
# $(subst ${ },${space}, whatever)
# maybe not well known: define/endef is custom makefile function definition
null :=
space := ${null} ${null}
${space} := ${space}

4
src/codegen/gen_java_Engine.ysl2

@ -70,7 +70,9 @@ tstylesheet {
}
return ret;
||
} otherwise
} when "@type = 'bytearray'"
|> return _«@name»(`apply "parm/*", mode=basic_parm_name`);
otherwise
|> return Utils.toUTF16(_«@name»(`apply "parm/*", mode=basic_parm_name`));
}
||

1
src/codegen/pEp.yml2

@ -272,6 +272,7 @@ namespace pEp {
basic string getMachineDirectory();
basic void config_passphrase(string passphrase);
basic void config_passphrase_for_new_keys(bool enable, string passphrase);
basic bytearray export_key(string fpr);
};
struct message {

27
src/cxx/basic_api.cc

@ -512,5 +512,32 @@ JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_Engine__1config_1passphras
}
}
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Engine__1export_1key (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);
char *buff = nullptr;
size_t size = 0;
PEP_STATUS status = passphraseWrap(::export_key, session(), _fpr, &buff, &size);
if (status != PEP_STATUS_OK) {
throw_pEp_Exception(env, status);
return NULL;
}
return from_string(env, buff);
}
} // extern "C"

37
test/java/foundation/pEp/jniadapter/test/jni117/Makefile

@ -0,0 +1,37 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=jni117
JAVA_CLASSES = \
TestAlice.class \
../utils/AdapterBaseTestContext.class \
../utils/AdapterTestUtils.class \
../utils/TestCallbacks.class
.PHONY: pitytest compile alice test clean
all: alice compile
pitytest:
$(MAKE) -C $(PITYTEST_DIR)
alice: compile clean-pep-home-alice
cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice
compile: $(JAVA_CLASSES) pitytest
%.class: %.java
cd $(JAVA_CWD);$(JAVAC_CMD) -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: clean-pep-home-alice
clean-pep-home-alice:
rm -rf $(PEP_HOME_DIR_ALICE)/.pEp

23
test/java/foundation/pEp/jniadapter/test/jni117/TestAlice.java

@ -0,0 +1,23 @@
package foundation.pEp.jniadapter.test.jni117;
import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext;
import foundation.pEp.pitytest.TestSuite;
import foundation.pEp.pitytest.TestUnit;
import foundation.pEp.pitytest.utils.TestUtils;
import static foundation.pEp.pitytest.TestLogger.log;
class TestAlice {
public static void main(String[] args) throws Exception {
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
new TestUnit<AdapterBaseTestContext>("Test Alice",new AdapterBaseTestContext() , ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
log(new String(ctx.engine.export_key(ctx.alice.fpr)));
});
TestSuite.getDefault().run();
}
}
Loading…
Cancel
Save