Wireshark无法检测到TLS连接。

3

我想进行TLS通信,但当我尝试用WireShark检查时,它显示这只是普通的TCP连接,没有使用TLS。这不应该发生,因为有证书存在。

客户端:

import socket
import ssl

hostname = 'localhost'
# PROTOCOL_TLS_CLIENT requires valid cert chain and hostname
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_verify_locations('certificates/ca.pem')

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

ssock = context.wrap_socket(sock, server_hostname=hostname)
ssock.connect((hostname, 8080))

print(ssock.version())
ssock.send("TLSnotWorking".encode("UTF-8"))

ssock.close()

服务器:

import ssl
import socket

context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain('certificates/server.pem', 'certificates/server.key')

with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as sock:
    sock.bind(('127.0.0.1', 8080))
    sock.listen(5)
    with context.wrap_socket(sock, server_side=True) as ssock:
        try:
            while True:
                conn, addr = ssock.accept()
                
                try:
                    while True:
                        msg = conn.recv(4096)
                        if not len(msg):
                            conn.close()
                            break

                        print(msg.decode("UTF-8"))

                except Exception as e:
                    print(e)
        except KeyboardInterrupt:
                conn.close()
                ssock.shutdown(socket.SHUT_RDWR)
                ssock.close()

在我看来很好。因为wrap_socket()默认设置为do_handshake_on_connect=True,所以在ssock.connect()ssock.accept()中应自动执行TLS握手。你确定你在Wireshark中查看了正确的TCP连接吗?默认情况下未启用捕获“localhost”流量 - Remy Lebeau
2
“...它说这是一个普通的TCP连接,不使用TLS” - Wireshark并没有像“不使用TLS”这样的说法。也许您实际上没有将其解释为在此非标准端口上使用TLS的流量,因此即使它是TLS(在TCP之上),您也只能看到TCP。” - Steffen Ullrich
1
https://osqa-ask.wireshark.org/questions/51310/does-wireshark-recognize-non-standard-https-ports - President James K. Polk
嗨,我刚开始使用wireshark,想知道如何使用它来验证连接到Aurora RDS数据库的TLS版本? - wawawa
1个回答

0

Wireshark可以检测到是否使用了TLS,但如果我使用了错误的端口,例如“8443”,在端口处就无法看到是否有TLS通信。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接