我完成了以下教程(https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89 https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89)设置自签名 SSL 证书以保护设备和托管 mongoDB 数据库的服务器之间的通信。
我可以使用以下命令从服务器和设备访问数据库:
mongo --ssl --sslCAFile /path/to/CA.pem --sslPEMKeyFile /path/to/mongodb.pem --host IP:port
Error
当我尝试使用 C++ 程序连接到数据库时,出现段错误:
Segmentation fault (core dumped)
GDB 的输出是
Program received signal SIGSEGV, Segmentation fault.
0x0000007fb7f6d6a8 in mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&, mongocxx::v_noabi::options::client const&) () from /usr/local/lib/libmongocxx.so._noabi
C++ code
我实例化连接:
mongocxx::instance instance{};
mongocxx::options::ssl ssl_opts;
ssl_opts.pem_file("/path/to/mongodb.pem");
// ssl_opts.allow_invalid_certificates(false); // I have tried this
mongocxx::options::client client_opts;
client_opts.ssl_opts(ssl_opts);
auto client = mongocxx::client{mongocxx::uri{"mongodb://user:pwd@IP:port/?authMechanism=MONGODB-X509&ssl=true"}, client_opts};
并使用以下命令进行编译:
c++ --std=c++11 main.cpp $(pkg-config --cflags --libs libmongocxx) -Wl,-rpath,/usr/local/lib
我无法修复此错误或在线找到解决方案,任何帮助将不胜感激。
附加信息
版本:
蒙戈c-1.10.1
蒙戈 cxx - 3.3.0
回溯:
(gdb) thread apply all bt
Thread 1 (Thread 0x7fb7ff4000 (LWP 17800)):
#0 0x0000007fb7f6d6a8 in
mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&,
mongocxx::v_noabi::options::client const&) () from
/usr/local/lib/libmongocxx.so._noabi
#1 0x00000000004027d0 in main ()