mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
fix: panic under some stupid input config
This commit is contained in:
@@ -20,16 +20,19 @@ func (o RealityOptions) Parse() (*tlsC.RealityConfig, error) {
|
||||
config := new(tlsC.RealityConfig)
|
||||
|
||||
const x25519ScalarSize = 32
|
||||
var publicKey [x25519ScalarSize]byte
|
||||
n, err := base64.RawURLEncoding.Decode(publicKey[:], []byte(o.PublicKey))
|
||||
if err != nil || n != x25519ScalarSize {
|
||||
publicKey, err := base64.RawURLEncoding.DecodeString(o.PublicKey)
|
||||
if err != nil || len(publicKey) != x25519ScalarSize {
|
||||
return nil, errors.New("invalid REALITY public key")
|
||||
}
|
||||
config.PublicKey, err = ecdh.X25519().NewPublicKey(publicKey[:])
|
||||
config.PublicKey, err = ecdh.X25519().NewPublicKey(publicKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fail to create REALITY public key: %w", err)
|
||||
}
|
||||
|
||||
n := hex.DecodedLen(len(o.ShortID))
|
||||
if n > tlsC.RealityMaxShortIDLen {
|
||||
return nil, errors.New("invalid REALITY short id")
|
||||
}
|
||||
n, err = hex.Decode(config.ShortID[:], []byte(o.ShortID))
|
||||
if err != nil || n > tlsC.RealityMaxShortIDLen {
|
||||
return nil, errors.New("invalid REALITY short ID")
|
||||
|
||||
Reference in New Issue
Block a user