如何通过将所有选项放入 mongodb 的 Node.js 驱动程序的连接字符串中来连接 X509?

2024-01-21

我正在使用可用的密钥mongodb 文档 http://mongodb.github.io/node-mongodb-native/3.6/api/MongoClient.html使用带有 Node.js 驱动程序的 X509 身份验证的自签名证书。

当尝试连接到数据库时,我收到以下错误:

MongoNetworkError: failed to connect to server [pedro.com:57040] on first connect [MongoNetworkError: unable to verify the first certificate]

尽管存在该错误,但我确信连接可以正常工作,因为我使用的是 Studio 3T,并且所有内容都通过使用相同的证书启动并运行。

所以我的问题是...如何通过在连接字符串中写入所有选项来使用 x509 证书以编程方式连接到数据库?也许我提供的密钥是错误的?或者有些缺失了?

db: `mongodb://CN=pedro.com,OU=IT,O=Polygon,L=Setubal,ST=Setubal,[email protected] /cdn-cgi/l/email-protection:57040,pedro.com:57041
,pedro.com:57042/testBO?
ssl=true&authMechanism=MONGODB-X509
&sslPEMKeyFile=${fs.readFileSync(
        `${Helpers.appRoot(Env.get('DB_SSL_CERT'))}`
      )}
&sslCAFile=${fs.readFileSync(
        `${Helpers.appRoot(Env.get('DB_SSL_CA'))}`
      )}&replicaSet=testReplica`

您需要确保服务器和客户端都可以验证彼此的证书。这两个验证是独立的并且使用不同的选项。

对于服务器端,请参阅https://github.com/mongodb/mongo-ruby-driver/blob/master/.evergreen/run-tests.sh#L74 https://github.com/mongodb/mongo-ruby-driver/blob/master/.evergreen/run-tests.sh#L74,客户端见https://github.com/mongodb/mongo-ruby-driver/blob/master/.evergreen/run-tests.sh#L91 https://github.com/mongodb/mongo-ruby-driver/blob/master/.evergreen/run-tests.sh#L91。 URI 选项是跨驱动程序标准化的。

另请参阅https://github.com/mongodb/mongo-ruby-driver/blob/master/spec/README.md#x509-authentication https://github.com/mongodb/mongo-ruby-driver/blob/master/spec/README.md#x509-authentication.

sslPEMKeyFile是旧节点驱动程序选项(假设它有效),tls* 选项采用文件路径而不是文件内容。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过将所有选项放入 mongodb 的 Node.js 驱动程序的连接字符串中来连接 X509? 的相关文章

随机推荐