mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-06 20:28:40 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
49
transport/internet/quic/config.go
Normal file
49
transport/internet/quic/config.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
// +build !confonly
|
||||
|
||||
package quic
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/sha256"
|
||||
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
"github.com/xtls/xray-core/v1/common/protocol"
|
||||
"github.com/xtls/xray-core/v1/transport/internet"
|
||||
"golang.org/x/crypto/chacha20poly1305"
|
||||
)
|
||||
|
||||
func getAuth(config *Config) (cipher.AEAD, error) {
|
||||
security := config.Security.GetSecurityType()
|
||||
if security == protocol.SecurityType_NONE {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
salted := []byte(config.Key + "xray-quic-salt")
|
||||
key := sha256.Sum256(salted)
|
||||
|
||||
if security == protocol.SecurityType_AES128_GCM {
|
||||
block, err := aes.NewCipher(key[:16])
|
||||
common.Must(err)
|
||||
return cipher.NewGCM(block)
|
||||
}
|
||||
|
||||
if security == protocol.SecurityType_CHACHA20_POLY1305 {
|
||||
return chacha20poly1305.New(key[:])
|
||||
}
|
||||
|
||||
return nil, newError("unsupported security type")
|
||||
}
|
||||
|
||||
func getHeader(config *Config) (internet.PacketHeader, error) {
|
||||
if config.Header == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
msg, err := config.Header.GetInstance()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return internet.CreatePacketHeader(msg)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue