From 3222a7d206dadeb42422b796389768ac21f976be Mon Sep 17 00:00:00 2001 From: J08nY Date: Fri, 29 Mar 2024 19:24:46 +0100 Subject: Catch Botan exceptions on decoding. --- .../cz/crcs/ectester/standalone/libs/jni/botan.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'standalone/src') diff --git a/standalone/src/main/resources/cz/crcs/ectester/standalone/libs/jni/botan.cpp b/standalone/src/main/resources/cz/crcs/ectester/standalone/libs/jni/botan.cpp index 3e266f6..b26d11a 100644 --- a/standalone/src/main/resources/cz/crcs/ectester/standalone/libs/jni/botan.cpp +++ b/standalone/src/main/resources/cz/crcs/ectester/standalone/libs/jni/botan.cpp @@ -368,7 +368,14 @@ jbyteArray generate_secret(JNIEnv *env, jobject self, jbyteArray pubkey, jbyteAr jsize pubkey_length = env->GetArrayLength(pubkey); jbyte *pubkey_data = env->GetByteArrayElements(pubkey, nullptr); - Botan::PointGFp public_point = curve_group.OS2ECP((uint8_t*) pubkey_data, pubkey_length); + Botan::PointGFp public_point; + try { + public_point = curve_group.OS2ECP((uint8_t*) pubkey_data, pubkey_length); + } catch (Botan::Exception & ex) { + throw_new(env, "java/security/GeneralSecurityException", ex.what()); + return nullptr; + } + env->ReleaseByteArrayElements(pubkey, pubkey_data, JNI_ABORT); Botan::ECDH_PublicKey pkey(curve_group, public_point); @@ -499,7 +506,13 @@ JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSigna jsize pubkey_length = env->GetArrayLength(pubkey); jbyte *pubkey_data = env->GetByteArrayElements(pubkey, nullptr); - Botan::PointGFp public_point = curve_group.OS2ECP((uint8_t*) pubkey_data, pubkey_length); + Botan::PointGFp public_point; + try { + public_point = curve_group.OS2ECP((uint8_t*) pubkey_data, pubkey_length); + } catch (Botan::Exception & ex) { + throw_new(env, "java/security/GeneralSecurityException", ex.what()); + return JNI_FALSE; + } env->ReleaseByteArrayElements(pubkey, pubkey_data, JNI_ABORT); std::unique_ptr pkey; -- cgit v1.3.1