本文介绍了gocql中的SSL选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Cassandra配置中,我启用了用户身份验证,并通过ssl与cqlsh连接.我在用gocql实现相同功能时遇到了麻烦,以下是我的代码:

In my Cassandra config I have enabled user authentication and connect with cqlsh over ssl.I'm having trouble implementing the same with gocql, following is my code:

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

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

When I try to connect I get following error:

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

在python中,我可以使用类似的方法做到这一点:

In python I can do this with something like:

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)

我在此处此处,但我不确定如何设置ssl选项.

I checked the gocql and TLS documentation here and here but I'm unsure about how to set ssl options.

推荐答案

您要添加的证书没有私钥,这是无此文件或目录"错误的出处.

You're adding a cert without a private key, which is where the "no such file or directory" error is coming from.

您的python代码正在添加CA;您应该对Go代码执行相同的操作:

Your python code is adding a CA; you should do the same with the Go code:

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

这篇关于gocql中的SSL选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:17