mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-17 04:53:59 +00:00
https://github.com/XTLS/REALITY/commit/83f621788ca88b83179810b12baa7ae518aacb83 https://github.com/XTLS/REALITY/commit/14cefac9bd7a724a811b02759fa97aa86a1ec894 https://github.com/XTLS/REALITY/commit/3c98159dee388c2914a2b9e73ea57bc10023f9d3
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package reality
|
|
|
|
import (
|
|
"context"
|
|
"crypto/ecdh"
|
|
"crypto/mldsa"
|
|
"io"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/xtls/reality"
|
|
"github.com/xtls/xray-core/common/errors"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
)
|
|
|
|
func (c *Config) GetREALITYConfig() *reality.Config {
|
|
var dialer net.Dialer
|
|
config := &reality.Config{
|
|
DialContext: dialer.DialContext,
|
|
|
|
Show: c.Show,
|
|
Type: c.Type,
|
|
Dest: c.Dest,
|
|
Xver: byte(c.Xver),
|
|
|
|
MinClientVer: c.MinClientVer,
|
|
MaxClientVer: c.MaxClientVer,
|
|
MaxTimeDiff: time.Duration(c.MaxTimeDiff) * time.Millisecond,
|
|
|
|
NextProtos: nil, // should be nil
|
|
SessionTicketsDisabled: true,
|
|
|
|
KeyLogWriter: KeyLogWriterFromConfig(c),
|
|
}
|
|
var err error
|
|
if config.PrivateKey, err = ecdh.X25519().NewPrivateKey(c.PrivateKey); err != nil {
|
|
panic(err)
|
|
}
|
|
if c.Mldsa65Seed != nil {
|
|
if config.Mldsa65Key, err = mldsa.NewPrivateKey(mldsa.MLDSA65(), c.Mldsa65Seed); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
if c.LimitFallbackUpload != nil {
|
|
config.LimitFallbackUpload.AfterBytes = c.LimitFallbackUpload.AfterBytes
|
|
config.LimitFallbackUpload.BytesPerSec = c.LimitFallbackUpload.BytesPerSec
|
|
config.LimitFallbackUpload.BurstBytesPerSec = c.LimitFallbackUpload.BurstBytesPerSec
|
|
}
|
|
if c.LimitFallbackDownload != nil {
|
|
config.LimitFallbackDownload.AfterBytes = c.LimitFallbackDownload.AfterBytes
|
|
config.LimitFallbackDownload.BytesPerSec = c.LimitFallbackDownload.BytesPerSec
|
|
config.LimitFallbackDownload.BurstBytesPerSec = c.LimitFallbackDownload.BurstBytesPerSec
|
|
}
|
|
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
|
|
}
|
|
|
|
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, 0o644)
|
|
if err != nil {
|
|
errors.LogErrorInner(context.Background(), err, "failed to open ", c.MasterKeyLog, " as master key log")
|
|
}
|
|
|
|
return writer
|
|
}
|
|
|
|
func ConfigFromStreamSettings(settings *internet.MemoryStreamConfig) *Config {
|
|
if settings == nil {
|
|
return nil
|
|
}
|
|
config, ok := settings.SecuritySettings.(*Config)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return config
|
|
}
|