mongodb - 无法使用 SSL 连接到 Mongodb
问题描述
- Windows 10 专业版 x64
- MongoDB 4.4
- 指南针图形用户界面
我正常设置了 Mongodb(没有安全性)并验证一切正常。现在尝试添加 TLS/SSL。我按照以下说明操作:
https://docs.mongodb.com/manual/appendix/security/appendixA-openssl-ca/ https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/
没有错误。一切都成功了。通过以下方式验证了 pem:
openssl verify -CAfile mongodb.pem mongodb01.pem
mongodb01.pem: OK
更新了我的配置文件:
net:
port: 27017
bindIp: mongodb01.xxx.com
tls:
mode: requireTLS
certificateKeyFile: C:\Program Files\MongoDB\Server\4.4\bin\mongodb01.pem
CAFile: C:\Program Files\MongoDB\Server\4.4\bin\mongodb.pem
CA 证书是为 *.xxx.com 创建的,服务器证书是为 mongodb01.xxx.com 创建的。注意:mongodb01.xxx.com 在我的主机文件中被伪造为 127.0.0.1。我之前已经做过很多次了,当假的 dns 名称技巧都在同一台机器上时,它确实有效。
然后我运行 mongodb:
mongod --config "C:\Program Files\MongoDB\Server\4.4\bin\mongod.cfg"
但是当我尝试时:
openssl s_client -connect mongodb01.xxx.com:27017
verify error:num=20:unable to get local issuer certificate
verify error:num=21:unable to verify the first certificate
编辑:
所以我取得了一些进展。我不认为 MongoDB 正在接受 CAFile。当我将根证书和中间证书添加到 mongodb01.pem (以及所有 3 个使用相同密钥签名的证书)中时,证书链通过,但它返回一个自签名证书错误(如预期的那样)。
我还没有尝试从 Java 调用它,我试图让它首先在 Compass 中工作。但是,Compass 抱怨自签名证书。我尝试将证书放在我信任的商店中,但 Compass 仍然拒绝连接。
解决方案
您需要向 s_client 提供 CA 证书,除非该证书是由知名 CA 颁发的,并且其 CA 证书位于 openssl 附带的捆绑包中(假设甚至存在这样的捆绑包)。
使用-CApath
或-CAfile
选项指定 CA 证书。
推荐阅读
- java - 无法插入sqlite
- html - 悬停时填充文本颜色动画,使用动画颜色
- emacs - 如何使用 Projectile grep 非项目目录中的所有文件?
- batch-file - 将命令输出分配给变量不起作用
- python - 根据 __init__.py 中的位置,Python 导入语句不起作用
- java - 以多种语言维护对象模型
- react-native - Jest mock onPress 反应原生
- c# - 如何在 SQL Server 2014 中为 SQL CLR 注册 PdfSharp?
- c - AT&T 汇编器中的 extrn 模拟是什么?
- c# - GetManifestResourceNames 返回空数组