Skip to content

Commit

Permalink
Add option realitySettings.masterKeyLog
Browse files Browse the repository at this point in the history
  • Loading branch information
atmospher3 authored and yuhan6665 committed Jan 11, 2024
1 parent 961cf9d commit 0ea2a50
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
2 changes: 2 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ func (c *TLSConfig) Build() (proto.Message, error) {

type REALITYConfig struct {
Show bool `json:"show"`
MasterKeyLog string `json:"masterKeyLog"`
Dest json.RawMessage `json:"dest"`
Type string `json:"type"`
Xver uint64 `json:"xver"`
Expand All @@ -440,6 +441,7 @@ type REALITYConfig struct {
func (c *REALITYConfig) Build() (proto.Message, error) {
config := new(reality.Config)
config.Show = c.Show
config.MasterKeyLog = c.MasterKeyLog
var err error
if c.Dest != nil {
var i uint16
Expand Down
17 changes: 17 additions & 0 deletions transport/internet/reality/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package reality

import (
"io"
"net"
"os"
"time"

"github.com/xtls/reality"
Expand All @@ -25,6 +27,8 @@ func (c *Config) GetREALITYConfig() *reality.Config {

NextProtos: nil, // should be nil
SessionTicketsDisabled: true,

KeyLogWriter: KeyLogWriterFromConfig(c),
}
config.ServerNames = make(map[string]bool)
for _, serverName := range c.ServerNames {
Expand All @@ -37,6 +41,19 @@ func (c *Config) GetREALITYConfig() *reality.Config {
return config
}

func KeyLogWriterFromConfig(c *Config) io.Writer {
if len(c.MasterKeyLog) <= 0 || c.MasterKeyLog == "none" {
return nil
}

writer, err := os.OpenFile(c.MasterKeyLog, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
if err != nil {
newError("failed to open ", c.MasterKeyLog, " as master key log").AtError().Base(err).WriteToLog()
}

return writer
}

func ConfigFromStreamSettings(settings *internet.MemoryStreamConfig) *Config {
if settings == nil {
return nil
Expand Down
36 changes: 23 additions & 13 deletions transport/internet/reality/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions transport/internet/reality/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ message Config {
bytes short_id = 24;
string spider_x = 25;
repeated int64 spider_y = 26;
string master_key_log = 27;
}
1 change: 1 addition & 0 deletions transport/internet/reality/reality.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati
ServerName: config.ServerName,
InsecureSkipVerify: true,
SessionTicketsDisabled: true,
KeyLogWriter: KeyLogWriterFromConfig(config),
}
if utlsConfig.ServerName == "" {
utlsConfig.ServerName = dest.Address.String()
Expand Down

0 comments on commit 0ea2a50

Please sign in to comment.