forked from XTLS/Xray-core
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from GFW-knocker/bring-quic-back
Bring quic back
- Loading branch information
Showing
15 changed files
with
1,460 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package quic | ||
|
||
import ( | ||
"crypto/aes" | ||
"crypto/cipher" | ||
"crypto/sha256" | ||
"errors" | ||
|
||
"github.com/GFW-knocker/Xray-core/common" | ||
"github.com/GFW-knocker/Xray-core/common/protocol" | ||
"github.com/GFW-knocker/Xray-core/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, errors.New("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) | ||
} |
Oops, something went wrong.