2023-02-15 19:07:12 +03:00
|
|
|
package reality
|
|
|
|
|
|
|
|
import (
|
2024-06-29 21:32:57 +03:00
|
|
|
"context"
|
2024-01-11 09:36:13 +03:00
|
|
|
"io"
|
2023-02-26 14:26:57 +03:00
|
|
|
"net"
|
2024-01-11 09:36:13 +03:00
|
|
|
"os"
|
2023-02-15 19:07:12 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/xtls/reality"
|
2024-06-29 21:32:57 +03:00
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2023-02-15 19:07:12 +03:00
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Config) GetREALITYConfig() *reality.Config {
|
2023-02-26 14:26:57 +03:00
|
|
|
var dialer net.Dialer
|
2023-02-15 19:07:12 +03:00
|
|
|
config := &reality.Config{
|
2023-02-26 14:26:57 +03:00
|
|
|
DialContext: dialer.DialContext,
|
|
|
|
|
2023-02-15 19:07:12 +03:00
|
|
|
Show: c.Show,
|
|
|
|
Type: c.Type,
|
|
|
|
Dest: c.Dest,
|
|
|
|
Xver: byte(c.Xver),
|
|
|
|
|
|
|
|
PrivateKey: c.PrivateKey,
|
|
|
|
MinClientVer: c.MinClientVer,
|
|
|
|
MaxClientVer: c.MaxClientVer,
|
|
|
|
MaxTimeDiff: time.Duration(c.MaxTimeDiff) * time.Millisecond,
|
|
|
|
|
|
|
|
NextProtos: nil, // should be nil
|
|
|
|
SessionTicketsDisabled: true,
|
2024-01-11 09:36:13 +03:00
|
|
|
|
|
|
|
KeyLogWriter: KeyLogWriterFromConfig(c),
|
2023-02-15 19:07:12 +03:00
|
|
|
}
|
|
|
|
config.ServerNames = make(map[string]bool)
|
|
|
|
for _, serverName := range c.ServerNames {
|
|
|
|
config.ServerNames[serverName] = true
|
|
|
|
}
|
|
|
|
config.ShortIds = make(map[[8]byte]bool)
|
|
|
|
for _, shortId := range c.ShortIds {
|
|
|
|
config.ShortIds[*(*[8]byte)(shortId)] = true
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2024-01-11 09:36:13 +03:00
|
|
|
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 {
|
2024-06-29 21:32:57 +03:00
|
|
|
errors.LogErrorInner(context.Background(), err, "failed to open ", c.MasterKeyLog, " as master key log")
|
2024-01-11 09:36:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return writer
|
|
|
|
}
|
|
|
|
|
2023-02-15 19:07:12 +03:00
|
|
|
func ConfigFromStreamSettings(settings *internet.MemoryStreamConfig) *Config {
|
|
|
|
if settings == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
config, ok := settings.SecuritySettings.(*Config)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|