gpt4 book ai didi

gocql 中的 SSL 选项

转载 作者:IT王子 更新时间:2023-10-29 01:45:24 26 4
gpt4 key购买 nike

在我的 Cassandra 配置中,我启用了用户身份验证并通过 ssl 连接到 cqlsh。我在使用 gocql 实现相同时遇到了问题,以下是我的代码:

cluster := gocql.NewCluster("127.0.0.1")
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: "myuser",
Password: "mypassword",
}
cluster.SslOpts = &gocql.SslOptions {
CertPath: "/path/to/cert.pem",
}

当我尝试连接时出现以下错误:

 gocql: unable to create session: connectionpool: unable to load X509 key pair: open : no such file or directory

在 python 中,我可以用类似的东西来做到这一点:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
USER = 'username'
PASS = 'password'
ssl_opts = {'ca_certs': '/path/to/cert.pem',
'ssl_version': PROTOCOL_TLSv1
}
credentials = PlainTextAuthProvider(username = USER, password = PASS)
# define host, port, cqlsh protocaol version
cluster = Cluster(contact_points= HOST, protocol_version= CQLSH_PROTOCOL_VERSION, auth_provider = credentials, port = CASSANDRA_PORT)

我检查了 gocql 和 TLS 文档 herehere但我不确定如何设置 ssl 选项。

最佳答案

您正在添加没有私钥的证书,这是“没有这样的文件或目录”错误的来源。

您的 Python 代码正在添加一个 CA;你应该对 Go 代码做同样的事情:

gocql.SslOptions {
CaPath: "/path/to/cert.pem",
}

关于gocql 中的 SSL 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35970581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com