aiohttp 和基于证书的身份验证 (cba)
aiohttp and certificate based authentication (cba)
我正在尝试将基于证书的身份验证 (cba) 与证书文件和密钥文件结合使用,以在服务器上进行身份验证。如何使用 aiohttp 实现此目的?使用用户名和密码的 HTTP 身份验证工作正常,但我找不到 cba 的任何示例。
我试图扩展 aiohttp 文档中的示例 http://aiohttp.readthedocs.io/en/stable/client.html#ssl-control-for-tcp-sockets
async def main_ssl(loop):
sslcontext = ssl.create_default_context()
sslcontext.load_cert_chain(certfile=cert_file, keyfile=client_key)
conn = aiohttp.TCPConnector(ssl_context=sslcontext)
async with aiohttp.ClientSession(connector=conn) as session:
await post_ssl(session)
但这给了我以下错误:
aiohttp.errors.ClientOSError: [Errno 1] Cannot connect to host
10.202.200.10:443 ssl:True [Can not connect to 10.202.200.10:443 [[SSL:
CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f1dce7f5940>
您必须将上下文的用途设置为 CLIENT_AUTH
(默认=SERVER_AUTH
)。
sslcontext = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
我正在尝试将基于证书的身份验证 (cba) 与证书文件和密钥文件结合使用,以在服务器上进行身份验证。如何使用 aiohttp 实现此目的?使用用户名和密码的 HTTP 身份验证工作正常,但我找不到 cba 的任何示例。
我试图扩展 aiohttp 文档中的示例 http://aiohttp.readthedocs.io/en/stable/client.html#ssl-control-for-tcp-sockets
async def main_ssl(loop):
sslcontext = ssl.create_default_context()
sslcontext.load_cert_chain(certfile=cert_file, keyfile=client_key)
conn = aiohttp.TCPConnector(ssl_context=sslcontext)
async with aiohttp.ClientSession(connector=conn) as session:
await post_ssl(session)
但这给了我以下错误:
aiohttp.errors.ClientOSError: [Errno 1] Cannot connect to host
10.202.200.10:443 ssl:True [Can not connect to 10.202.200.10:443 [[SSL:
CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f1dce7f5940>
您必须将上下文的用途设置为 CLIENT_AUTH
(默认=SERVER_AUTH
)。
sslcontext = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)