mirror of
https://github.com/corda/corda.git
synced 2024-12-27 08:22:35 +00:00
Register Kryo serializer for use inside the SGX enclave. (#23)
This commit is contained in:
parent
aa82c55c87
commit
3ae53683ea
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user