mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2024-04-21 12:21:34 +00:00
add tls key logging
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
[](http://hits.dwyl.io/p4gefau1t/trojan-go)
|
||||
[](https://img.shields.io/github/v/release/p4gefau1t/trojan-go?include_prereleases)
|
||||
[](https://img.shields.io/github/release-date-pre/p4gefau1t/trojan-go)
|
||||
[](https://microbadger.com/images/p4gefau1t/trojan-go)
|
||||
[](https://hub.docker.com/r/p4gefau1t/trojan-go)
|
||||
|
||||
[](https://img.shields.io/github/last-commit/p4gefau1t/trojan-go)
|
||||
[](https://img.shields.io/github/commit-activity/m/p4gefau1t/trojan-go)
|
||||
|
||||
@@ -3,6 +3,7 @@ package conf
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"io"
|
||||
|
||||
"github.com/p4gefau1t/trojan-go/common"
|
||||
utls "github.com/refraction-networking/utls"
|
||||
@@ -45,6 +46,7 @@ type TLSConfig struct {
|
||||
Curves string `json:"curves"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
ServePlainText bool `json:"serve_plain_text"`
|
||||
KeyLogPath string `json:"key_log"`
|
||||
|
||||
ClientHelloID *utls.ClientHelloID
|
||||
FallbackAddress *common.Address
|
||||
@@ -56,6 +58,7 @@ type TLSConfig struct {
|
||||
CipherSuiteTLS13 []uint16
|
||||
SessionTicket bool
|
||||
CurvePreferences []tls.CurveID
|
||||
KeyLogger io.Writer
|
||||
}
|
||||
|
||||
type TCPConfig struct {
|
||||
|
||||
@@ -18,7 +18,23 @@ import (
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
)
|
||||
|
||||
func setKeyLogger(tlsConfig *TLSConfig) error {
|
||||
if tlsConfig.KeyLogPath != "" {
|
||||
log.Warn("TLS key logging activated. USE OF KEY LOGGING COMPROMISES SECURITY. IT SHOULD ONLY BE USED FOR DEBUGGING.")
|
||||
file, err := os.OpenFile(tlsConfig.KeyLogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
return common.NewError("Failed to open key log file").Base(err)
|
||||
}
|
||||
tlsConfig.KeyLogger = file
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadCert(tlsConfig *TLSConfig) error {
|
||||
err := setKeyLogger(tlsConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tlsConfig.CertPath == "" {
|
||||
log.Info("Cert of the remote server is unspecified. Using default CA list")
|
||||
} else {
|
||||
@@ -55,6 +71,10 @@ func loadCert(tlsConfig *TLSConfig) error {
|
||||
}
|
||||
|
||||
func loadCertAndKey(tlsConfig *TLSConfig) error {
|
||||
err := setKeyLogger(tlsConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tlsConfig.KeyPassword != "" {
|
||||
keyFile, err := ioutil.ReadFile(tlsConfig.KeyPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -326,6 +326,7 @@ func (m *TLSManager) dialTLSWithFakeFingerprint() (*utls.UConn, error) {
|
||||
RootCAs: m.config.TLS.CertPool,
|
||||
ServerName: m.config.TLS.SNI,
|
||||
InsecureSkipVerify: !m.config.TLS.Verify,
|
||||
KeyLogWriter: m.config.TLS.KeyLogger,
|
||||
}
|
||||
if workingFingerprint != "" {
|
||||
spec, err := m.genClientSpec(workingFingerprint)
|
||||
@@ -414,6 +415,7 @@ func (m *TLSManager) DialToServer() (io.ReadWriteCloser, error) {
|
||||
CurvePreferences: m.config.TLS.CurvePreferences,
|
||||
NextProtos: m.config.TLS.ALPN,
|
||||
ClientSessionCache: m.sessionCache,
|
||||
KeyLogWriter: m.config.TLS.KeyLogger,
|
||||
}
|
||||
tlsConn := tls.Client(tcpConn, tlsConfig)
|
||||
err = tlsConn.Handshake()
|
||||
|
||||
Reference in New Issue
Block a user