带有 STARTTLS 和身份验证的 Python Twisted TLS 连接 - 示例代码中的错误?

标签 python authentication ssl twisted

我一直在尝试基于 https://twistedmatrix.com/documents/14.0.0/core/howto/ssl.html#client-authentication 创建一个简单的 python 扭曲 TLS 客户端/服务器应用程序和 https://twistedmatrix.com/documents/14.0.0/core/howto/ssl.html#using-starttls .即,我想创建一个纯文本连接,然后在客户端发出 STARTTLS 命令时,切换到安全连接,并使用适当的证书身份验证。到目前为止,我没有什么快乐。

我首先担心的是上面 URL 中的客户端身份验证示例是错误的。这似乎表明客户端和服务器需要“server.pem”(私钥和自签名证书)和“public.pem”(服务器本身的公共(public)证书)。我对身份验证的理解是,如果客户端拥有服务器的私钥,那么这会导致身份验证/安全性在很大程度上是多余的吗?假设我是对的,这个示例应该看起来如何?

其次,尽管我已经尝试了很多 - 我仍在努力了解 Twisted 的一般工作方式。有人可以举例说明如何修改上面 URL 中的 starttls 示例以合并身份验证吗?

谢谢!

最佳答案

My first concern is the client auth example in the URL above is wrong. This seems to suggest the client and server both need "server.pem" (private key and self-signed certificate together) and "public.pem" (the server’s public certificate by itself). My understanding of authentication is that if the client has the server's private key, then this renders the authentication / security largely redundant? Assuming I'm right, how should this example look?

您链接到的 URL 是 TLS 文档的“客户端身份验证”部分。它演示了如何使用客户端证书向服务器验证客户端(请注意,TLS - HTTPS - 的共同点是向客户端验证服务器)。

在客户端身份验证的情况下,客户端确实需要私钥和证书(自签名或其他方式)。这与在“正常”TLS 中(只有服务器向客户端验证自身)服务器必须具有私钥和证书(自签名或其他方式)的要求类似。

虽然客户端不需要服务器的私钥。它需要自己的。 (实际上,如果双方具有相同的 key ,它会起作用,但这不是典型的情况。)

Secondly, as much as I've tried - I'm still struggling to get my head around the way Twisted works generally. Can someone give some illustration to how amend the starttls example in the URL above to incorporate authentication?

你想要什么样的身份验证?如果您正在进行 TLS 客户端身份验证,那么这是一种身份验证形式。如果这足够了,您只需要正确配置您的服务器。当您使用客户端证书时,客户端通常为所提供的服务器证书执行的相同证书验证逻辑已完成 - 但方向相反。服务器查找从证书到其信任根之一的有效签名链。

关于带有 STARTTLS 和身份验证的 Python Twisted TLS 连接 - 示例代码中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26098369/

相关文章:

python - 如何判断具有离散数量的重复元素的列表 A 是否包含在列表 B 中?

python - 如何配置 python cffi 库以使用 mingw?

spring - 我如何通过 Spring Security 创建 oauth 2 用户名密码流

python - 使用python登录网页并在浏览器中显示结果

ssl - 如何在 jndi 中启用 ldap over ssl

python - Selenium Firefox 驱动程序截取窗口屏幕截图(非全屏)

c++ - 将 c++ 异常传播到 cython - python 异常

ruby-on-rails - #<ProjectsController :0x007faead1853e0> 的未定义方法 `user_signed_in?'

Java 邮件 TLS 身份验证

ssl - - 发现 IOException AMC java.security.cert.CertificateException : No subject alternative DNS name matching api. mitel-amc.com