Register Kryo serializer for use inside the SGX enclave. (#23)

This commit is contained in:
Chris Rankin 2017-08-14 13:51:25 +01:00 committed by Michal Kit
parent aa82c55c87
commit 3ae53683ea
3 changed files with 37 additions and 5 deletions

View File

@ -46,6 +46,7 @@ clean:
$(MAKE) -C linux-sgx clean
$(MAKE) -C linux-sgx-driver clean
[ ! -d jdk8u ] || $(MAKE) -C jdk8u clean
../gradlew -p .. verify-enclave:clean
$(MAKE) -C avian clean
.PHONY: distclean

View File

@ -53,13 +53,16 @@ void check_transaction(void *reqbuf, size_t buflen, char *error) {
JNI_CreateJavaVM(&vm, &env_void, &vmArgs);
JNIEnv* env = static_cast<JNIEnv*>(env_void);
jclass c = env->FindClass("com/r3/enclaves/txverify/Enclavelet");
env->FindClass("com/r3/enclaves/txverify/KryoVerifierSerializationScheme");
if (!env->ExceptionCheck()) {
jmethodID m = env->GetStaticMethodID(c, "verifyInEnclave", "([B)V");
jclass c = env->FindClass("com/r3/enclaves/txverify/Enclavelet");
if (!env->ExceptionCheck()) {
jbyteArray reqbits = env->NewByteArray((jsize) buflen);
env->SetByteArrayRegion(reqbits, 0, buflen, (const jbyte *)reqbuf);
jobject result = env->CallStaticObjectMethod(c, m, reqbits);
jmethodID m = env->GetStaticMethodID(c, "verifyInEnclave", "([B)V");
if (!env->ExceptionCheck()) {
jbyteArray reqbits = env->NewByteArray((jsize) buflen);
env->SetByteArrayRegion(reqbits, 0, buflen, (const jbyte *)reqbuf);
jobject result = env->CallStaticObjectMethod(c, m, reqbits);
}
}
}

View File

@ -0,0 +1,28 @@
package com.r3.enclaves.txverify
import net.corda.core.serialization.SerializationContext
import net.corda.core.serialization.SerializationDefaults
import net.corda.core.utilities.ByteSequence
import net.corda.nodeapi.internal.serialization.AbstractKryoSerializationScheme
import net.corda.nodeapi.internal.serialization.KRYO_P2P_CONTEXT
import net.corda.nodeapi.internal.serialization.KryoHeaderV0_1
import net.corda.nodeapi.internal.serialization.SerializationFactoryImpl
@Suppress("UNUSED")
private class KryoVerifierSerializationScheme : AbstractKryoSerializationScheme() {
override fun canDeserializeVersion(byteSequence: ByteSequence, target: SerializationContext.UseCase): Boolean {
return byteSequence == KryoHeaderV0_1 && target == SerializationContext.UseCase.P2P
}
override fun rpcClientKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
override fun rpcServerKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
private companion object {
init {
SerializationDefaults.SERIALIZATION_FACTORY = SerializationFactoryImpl().apply {
registerScheme(KryoVerifierSerializationScheme())
}
SerializationDefaults.P2P_CONTEXT = KRYO_P2P_CONTEXT
}
}
}