我不确定这是否真的是一个Wireshark,Go或Syncthing问题;我尝试了 wireshark dev list https://groups.google.com/g/golang-nuts/c/dp70565acra“ rel =” nofollow noreferrer'> go dev list ,但没有回复,所以我想在这里尝试:
我'm在
我阅读 wireshark tls tls documentation ;同步写在旅途中,因此,这样(这只是在上游代码与添加两行同步的代码):
// The TLS configuration is used for both the listening socket and outgoing
// connections.
var tlsCfg *tls.Config
if a.cfg.Options().InsecureAllowOldTLSVersions {
l.Infoln("TLS 1.2 is allowed on sync connections. This is less than optimally secure.")
tlsCfg = tlsutil.SecureDefaultWithTLS12()
} else {
tlsCfg = tlsutil.SecureDefaultTLS13()
}
tlsCfg.Certificates = []tls.Certificate{a.cert}
tlsCfg.NextProtos = []string{bepProtocolName}
tlsCfg.ClientAuth = tls.RequestClientCert
tlsCfg.SessionTicketsDisabled = true
tlsCfg.InsecureSkipVerify = true
// The following two lines open a file in the current directory and configure the application to dump its TLS secrets there
// See: https://pkg.go.dev/crypto/tls#example-Config-KeyLogWriter
w, err := os.OpenFile("tls-secrets.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
tlsCfg.KeyLogWriter = w
这项工作原理,并且将各种内容写入指定的文件,但是将该文件提供给Wireshark并不启用TLS解密。 I examined the file, and I see that it contains CLIENT_HANDSHAKE_TRAFFIC_SECRET
, SERVER_HANDSHAKE_TRAFFIC_SECRET
, CLIENT_TRAFFIC_SECRET_0
, and SERVER_TRAFFIC_SECRET_0
lines, but不是关键 client_random
行。我是做错事还是错过了什么?
I'm not totally sure whether this is really a Wireshark, Go, or Syncthing question; I tried the Wireshark dev list and the Go dev list but got no response, so I figured I'll try here:
I'm working on a Wireshark Syncthing dissector. Since most of the Syncthing protocols are encapsulated in TLS, I need to provide the TLS secrets to Wireshark.
I read the Wireshark TLS documentation; Syncthing is written in Go, so I patched it to export TLS secrets, like this (this is just Syncthing upstream code with the addition of the two final lines):
// The TLS configuration is used for both the listening socket and outgoing
// connections.
var tlsCfg *tls.Config
if a.cfg.Options().InsecureAllowOldTLSVersions {
l.Infoln("TLS 1.2 is allowed on sync connections. This is less than optimally secure.")
tlsCfg = tlsutil.SecureDefaultWithTLS12()
} else {
tlsCfg = tlsutil.SecureDefaultTLS13()
}
tlsCfg.Certificates = []tls.Certificate{a.cert}
tlsCfg.NextProtos = []string{bepProtocolName}
tlsCfg.ClientAuth = tls.RequestClientCert
tlsCfg.SessionTicketsDisabled = true
tlsCfg.InsecureSkipVerify = true
// The following two lines open a file in the current directory and configure the application to dump its TLS secrets there
// See: https://pkg.go.dev/crypto/tls#example-Config-KeyLogWriter
w, err := os.OpenFile("tls-secrets.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
tlsCfg.KeyLogWriter = w
This works, and various stuff is written to the specified file, but providing that file to Wireshark doesn't enable TLS decryption. I examined the file, and I see that it contains CLIENT_HANDSHAKE_TRAFFIC_SECRET
, SERVER_HANDSHAKE_TRAFFIC_SECRET
, CLIENT_TRAFFIC_SECRET_0
, and SERVER_TRAFFIC_SECRET_0
lines, but not the crucial CLIENT_RANDOM
lines. Am I doing something wrong or missing something?
发布评论
评论(2)
根本原因是
tls1.2
和tls1.3
之间的区别,可以找到差异在这里per per per per
tls1.3
, those parametersCLIENT_HANDSHAKE_TRAFFIC_SECRET
,SERVER_HANDSHAKE_TRAFFIC_SECRET
,CLIENT_TRAFFIC_SECRET_0
, andserver_traffic_secret_0
可以作为tls1.2
,client> client_random
的客户秘密导出,可以作为客户端秘密导出,所有这些>都可以在Wireshark中使用,以解密TLS1。 2和TLS 1.3。
这是一个测试示例
,然后启动一台HTTPS服务器
,然后通过
curl
使用tls1.3
curl -lv https:// localhost:4000- cacert/crtpath/ca.crt -tlsv1.3
我们可以在下面找到
https-key.txt
的内容,然后设置keyfile
/keypath/grpc-key。 txt
to首选项 - >协议 - > TLS - > (pre) - 船长销售日志文件名
在Wireshark中,现在Wireshark可以对TLS1.2测试进行TLS解密,您可以将服务器代码更改为
tlscfg.minversion = tls.versiontls12
然后通过curl
用tls1.2
curl -lv https:// localhost:4000 -cacert/crtpath/ca.crt -tlsv1对其进行测试。 2
。并再次检查https-key.txt
,您可以发现内容可以是client_random xxxxxx yyyyyyyyyyyyyyyy
。The root cause is the difference between

tls1.2
andtls1.3
, the difference could be found herePer golang tls code
tls1.3
, those parametersCLIENT_HANDSHAKE_TRAFFIC_SECRET
,SERVER_HANDSHAKE_TRAFFIC_SECRET
,CLIENT_TRAFFIC_SECRET_0
, andSERVER_TRAFFIC_SECRET_0
could be exported as client secretstls1.2
,CLIENT_RANDOM
could be exported as client secretsAll of them could be used in Wireshark to decrypt TLS1.2 and TLS 1.3.
Here is one test sample
First, start one HTTPS server
Then, test it through
curl
withtls1.3
curl -Lv https://localhost:4000 --cacert /crtpath/ca.crt --tlsv1.3
We could find the content of
https-key.txt
as belowThen set the keyFile
/keypath/grpc-key.txt
toPreferences -> Protocols -> TLS -> (Pre)-Master-Secret log filename
in WireShark, now the Wireshark could do TLS decryptionFor TLS1.2 test, you could change the server code to
tlsCfg.MinVersion = tls.VersionTLS12
and then test it throughcurl
withtls1.2
curl -Lv https://localhost:4000 --cacert /crtpath/ca.crt --tlsv1.2
. And check thehttps-key.txt
again, you could find the content could beCLIENT_RANDOM xxxxxx yyyyyyyy
.我在@zangw的大力帮助下弄清楚了。有两个问题:
client_random
,这仅适用于TLS 1.2;当前同步通常使用TLS 1.3,这涉及我看到的其他秘密(client_handshake_traffic_secret
,server_handshake_handshake_traffic_secret
,> code>>>>>> client_traffic_secret_0
code> code> code> code_secret_secret_secret_secret_secret_secret_secret_0 ) - 请参见日志格式。Wireshark现在成功地解密了TLS数据;可以通过选择“加密应用程序数据”,然后单击窗口底部的“解密TLS”选项卡来查看。
I figured it out, with a lot of help from @zangw. There were two problems:
CLIENT_RANDOM
, this is only for TLS 1.2; current Syncthing generally uses TLS 1.3, which involves the other secrets I was seeing (CLIENT_HANDSHAKE_TRAFFIC_SECRET
,SERVER_HANDSHAKE_TRAFFIC_SECRET
,CLIENT_TRAFFIC_SECRET_0
, andSERVER_TRAFFIC_SECRET_0
) - see the official documentation of the NSS Key Log Format.Wireshark now successfuly decrypts the TLS data; it can be viewed by selecting "Encrypted Application Data" and then clicking on the "Decrypted TLS" tab at the bottom of the window.