Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option realitySettings.masterKeyLog #2912

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading