事件:'keylog'


【Event: 'keylog'

  • line <Buffer> ASCII 文本行,采用 NSS SSLKEYLOGFILE 格式。

keylog 事件会在 tls.TLSSocket 上触发,当套接字生成或接收到密钥材料时。该密钥材料可以被存储用于调试,因为它允许解密捕获的 TLS 流量。它可能会在握手完成前或完成后多次触发。

【The keylog event is emitted on a tls.TLSSocket when key material is generated or received by the socket. This keying material can be stored for debugging, as it allows captured TLS traffic to be decrypted. It may be emitted multiple times, before or after the handshake completes.】

一个典型的使用案例是将接收到的行追加到一个通用的文本文件中,该文件随后被软件(例如 Wireshark)用来解密流量:

【A typical use case is to append received lines to a common text file, which is later used by software (such as Wireshark) to decrypt the traffic:】

const logFile = fs.createWriteStream('/tmp/ssl-keys.log', { flags: 'a' });
// ...
tlsSocket.on('keylog', (line) => logFile.write(line));