c++ - 使用Botan访问违规阅读位置

标签 c++ botan

我已经为 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/

相关文章:

c++ - 如何从另一个命名空间而不是全局命名空间定义函数和数据?

c++ - 使用MSVC在Windows上编译报错Botan库

mingw - 在 Windows 7 64 位中使用 MinGW 编译 Botan 时出现问题

c++ - 我如何使用 Botan::MemoryRegion?

c++ - 此错误会导致什么 C++ 模板问题?

c++ - 移动构造函数是否使 shared_from_this 无效

c++ - 删除后重建列表迭代器

c++ - Qt5 QuickView 无法创建窗口 : no screens are available

c++ - 使用 AES_256_CBC 解密文件返回 "bad decrypt"错误

aes - 参数无效 : AES-128/XTS cannot accept a key of length 16