我已经为 TLS 安全集成了 botan 库。 我收到以下错误:
jsonrpctest.exe 中 0x6DBFD1CE (vcruntime140.dll) 的第一次机会异常:0xC0000005:访问冲突读取位置 0x00962000。 如果有这个异常的处理程序,程序可以安全地继续执行
下面是我调用的代码
int main(int argc, char *argv[])
{
// prepare all the parameters
Callbacks callbacks;
Botan::AutoSeeded_RNG rng;
Botan::TLS::Session_Manager_In_Memory session_mgr(rng);
Client_Credentials creds;
Botan::TLS::Strict_Policy policy;
// open the tls connection : Error comes here
Botan::TLS::Client client(callbacks,
session_mgr,
creds,
policy,
rng,
Botan::TLS::Server_Information("10.193.252.14", 43733),
Botan::TLS::Protocol_Version::TLS_V12);
while (!client.is_closed())
{
//cout << client.is_active;
// read data received from the tls server, e.g., using BSD sockets or
boost asio
// ...
// send data to the tls server using client.send_data()
} }
最佳答案
此错误的确切原因未知。我认为它可能是 visual studio 的一些构建标志。我在我制作的发布版本中遇到了类似的错误,但它在调试版本中工作正常。然后我将它构建为库 (DLL) 而不是应用程序 (.exe),我没有看到任何问题。我认为使用 Botan 的最佳方式是进行合并构建(即不使用 Botan DLL 库,而是将 Botan 代码导入您的应用程序然后使用它)。这是对我有用的构建命令(从 Botan 源文件夹运行):
configure.py --cpu=i386 --amalgamation --single-amalgamation-file --minimized-build --enable-modules=tls,x509,seed,rdseed,rdrand,rdrand_rng,auto_rng --disable-shared
在运行上述命令之前,您需要安装 Python 并在路径中。 上述命令将在 Botan 源代码目录(即您运行上述命令的同一路径)中生成以下文件:
botan_all.h、botan_all_internal.h 和 botan_all.cpp
您需要将这些文件包含在您的应用程序代码中,使用并构建它。
有关 Botan 合并构建的更多信息:https://botan.randombit.net/manual/building.html#amalgamation
关于c++ - 使用Botan访问违规阅读位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46903283/