【发布时间】:2015-03-06 13:49:24
【问题描述】:
我们为 Cryptopp 实现了一个小型包装器,用于在 iOS 和 Android (JNI) 之间交换密钥。共享代码适用于 iOS 和 pre-ART android 设备。据说 ART 和它的垃圾收集器现在更严格了。
指出设置私钥功能在 Dalvik 和 ART 运行时都成功可能很重要。
代码: --> 设置公钥:
jboolean *isCopy;
//get bytes from jbytearray
jbyte* ba = (jbyte *)env->GetByteArrayElements( byteArray, isCopy);
//load bytearray to crypto bytequeue
ByteQueue queue2;
queue2.Put2((byte*)ba, 1000, 0, true);
//build public key
AutoSeededRandomPool rnd;
RSA::PublicKey publicKey;
publicKey.Load(*queue2); //<-------- CRASH
--> 设置私钥
jboolean *isCopy;
jbyte* ba = (jbyte *)env->GetByteArrayElements( byteArray, isCopy);
//load bytearray to bytequeue
ByteQueue queue2;
queue2.Put2((byte*)ba, 3072, 0, true);
//fill up the key
RSA::PrivateKey privateKey;
privateKey.Load(queue2);
堆栈跟踪:
backtrace:
#00 pc 00027e6c <project_name>/lib/arm/libstlport_shared.so
#01 pc 00027e79 <project_name>/lib/arm/libstlport_shared.so
#02 pc 00027efb <project_name>/lib/arm/libstlport_shared.so (std::terminate()+6)
#03 pc 000273d3 <project_name>/lib/arm/libstlport_shared.so
#04 pc 000268c9 <project_name>/lib/arm/libstlport_shared.so
#05 pc 0002698b <project_name>/lib/arm/libstlport_shared.so (__cxa_throw+34)
#06 pc 001b3ce4 <project_name>/lib/arm/libcryptopp.so (CryptoPP::BERDecodeError()+128)
#07 pc 001b1598 <project_name>/lib/arm/libcryptopp.so (CryptoPP::BERGeneralDecoder::Init(unsigned char)+56)
#08 pc 001b1638 <project_name>/lib/arm/libcryptopp.so (CryptoPP::BERGeneralDecoder::BERGeneralDecoder(CryptoPP::BufferedTransformation&, unsigned char)+104)
#09 pc 0027697c <project_name>/lib/arm/libcryptopp.so (CryptoPP::Integer::BERDecode(CryptoPP::BufferedTransformation&)+20)
#10 pc 002aec7c <project_name>/lib/arm/libcryptopp.so (CryptoPP::RSAFunction::BERDecodePublicKey(CryptoPP::BufferedTransformation&, bool, unsigned int)+64)
#11 pc 001b20e0 <project_name>/lib/arm/libcryptopp.so (CryptoPP::X509PublicKey::BERDecode(CryptoPP::BufferedTransformation&)+264)
#12 pc 00014a0b <project_name>/lib/arm/libsecurity.so (CryptoPP::ASN1CryptoMaterial<CryptoPP::PublicKey>::Load(CryptoPP::BufferedTransformation&)+6)
值得一提的是,新的(大部分)Google 设备(Nexus 4、5、7)现在默认使用 ART。
请指教!
【问题讨论】:
-
你是怎么看出来的?
标签: android android-ndk segmentation-fault android-5.0-lollipop crypto++