首页 > 解决方案 > 使用 aiogremlin 连接到 Neptune

问题描述

我正在尝试使用aiogremlin连接到 AWS Neptune,但不断收到 SSL 证书错误。我尝试使用从Amazon Trust Repository下载的 3 个不同的证书,但它们都不起作用。随着AmazonRootCA1.pemSFSRootCAG2.pem我不断得到File Not Found errorSFSRootCAG2.cer我得到ssl_context.load_cert_chain(ssl.SSLError: [SSL] PEM lib (_ssl.c:4046)

这是我用来与 Neptune 交互的片段。

import asyncio
from aiogremlin import DriverRemoteConnection, Graph
from .constants import NEPTUNE_ENDPOINT, CERT_DIR


async def go():
    remote_connection = await DriverRemoteConnection.open(f'https://{NEPTUNE_ENDPOINT}:8182/gremlin', 'g',
                                                          ssl_certfile=CERT_DIR+'SFSRootCAG2.cer')
    g = Graph().traversal().withRemote(remote_connection)
    vertices = await g.V().toList()
    await remote_connection.close()
    return vertices

print(asyncio.get_event_loop().run_until_complete(go()))

无法确定我是否使用了错误的证书文件或做其他错误的事情。

标签: python-3.xsslgremlinamazon-neptunegoblin

解决方案


当我将密钥库转换为没有证书部分的 pem 文件时,我得到了完全相同的错误(直到 ssl.c 中的第 4046 行)。

我在没有'-nocerts'标志的情况下再次转换它,并且我在文件中得到了两个部分,如下所示:

Bag Attributes
    friendlyName: mykey
    localKeyID: ...
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
... [magic key details] ...
-----END PRIVATE KEY-----
Bag Attributes
    friendlyName: mykey
    localKeyID: ...
subject=C = NO, O = ..., CN = Server Administrator

issuer=C = NO, O = ..., CN = Server Administrator

-----BEGIN CERTIFICATE-----
... [magic key details] ...
-----END CERTIFICATE-----

我还创建了一个这样的新证书,它可以毫无问题地工作:

# openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem

推荐阅读