Mongocxx无法使用SSL连接到mongoDB
Mongocxx fails to connect to mongoDB with SSL
我完成了以下教程(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
错误
当我尝试使用C++程序连接到数据库时,出现 seg 错误:
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++代码
我实例化了与以下方面的联系:
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 ()
在C++驱动程序版本 3.3.0 中将options::ssl_opts
传递给客户端构造函数会导致段错误,这是一个已知的严重错误。此问题已在 3.3.1 中修复。强烈建议您升级。
作为 3.3.0 的解决方法,您可以通过 URI 字符串传递 pem_file 选项。URI 选项"sslclientcertificatekeyfile"
对应于options::ssl::pem_file
选项。例如:
auto uri = mongocxx::uri{"mongodb://localhost/?ssl=true&sslclientcertificatekeyfile=/path/to/mongodb.pem"};
但如果可能,请升级到 3.3.1。
- Mongodb c++驱动程序:如何查询元素的数组
- 当套接字连接断开时检测C/C++Unix
- 无法在windows上使用mingw将sqlite3与c连接
- 到连接组件算法的问题(递归)
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- 无法在C++中建立与MySQL数据库的连接
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 使用 bfs 解决连接组件问题时得到错误的答案
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- MongoDB 阻止连接或更改连接超时的解决方法.[C++]
- MongoDB C++驱动程序中关于通过游标间接连接使用的线程安全性
- MongoDB C++驱动程序处理副本集连接故障
- 如何启用MongoDB C++驱动程序自动连接功能
- 在C ++ R3.0.2驱动程序中使用连接池连接到MongoDB副本集的正确方法是什么?
- 如何连接MongoDB与Qt c++
- 如何使用c++驱动程序连接两个客户端IP到相同的mongodb
- C ++驱动程序MongoDB连接选项