1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-20 10:56:07 -04:00
v2fly/proxy/shadowsocks2022/ss2022.go

89 lines
2.2 KiB
Go
Raw Normal View History

2023-11-03 16:10:11 -04:00
package shadowsocks2022
import (
"crypto/cipher"
"github.com/lunixbochs/struc"
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/protocol"
"io"
)
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
type KeyDerivation interface {
GetSessionSubKey(effectivePsk, Salt []byte, OutKey []byte) error
GetIdentitySubKey(effectivePsk, Salt []byte, OutKey []byte) error
}
type Method interface {
GetSessionSubKeyAndSaltLength() int
GetStreamAEAD(SessionSubKey []byte) (cipher.AEAD, error)
GenerateEIH(CurrentIdentitySubKey []byte, nextPskHash []byte, out []byte) error
}
type ExtensibleIdentityHeaders interface {
struc.Custom
}
type DestinationAddress interface {
net.Address
}
type RequestSalt interface {
struc.Custom
isRequestSalt()
Bytes() []byte
FillAllFrom(reader io.Reader) error
}
type TCPRequestHeader1PreSessionKey struct {
Salt RequestSalt
EIH ExtensibleIdentityHeaders
}
type TCPRequestHeader2FixedLength struct {
Type byte
Timestamp uint64
HeaderLength uint16
}
type TCPRequestHeader3VariableLength struct {
DestinationAddress DestinationAddress
Contents struct {
PaddingLength uint16 `struc:"sizeof=Padding"`
Padding []byte
}
}
type TCPRequestHeader struct {
PreSessionKeyHeader TCPRequestHeader1PreSessionKey
FixedLengthHeader TCPRequestHeader2FixedLength
Header TCPRequestHeader3VariableLength
}
type TCPResponseHeader1PreSessionKey struct {
Salt RequestSalt
}
type TCPResponseHeader2FixedLength struct {
Type byte
Timestamp uint64
RequestSalt RequestSalt
InitialPayloadLength uint16
}
type TCPResponseHeader struct {
PreSessionKeyHeader TCPResponseHeader1PreSessionKey
Header TCPResponseHeader2FixedLength
}
const TCPHeaderTypeClientToServerStream = byte(0x00)
const TCPHeaderTypeServerToClientStream = byte(0x01)
const TCPMinPaddingLength = 0
const TCPMaxPaddingLength = 900
var addrParser = protocol.NewAddressParser(
protocol.AddressFamilyByte(0x01, net.AddressFamilyIPv4),
protocol.AddressFamilyByte(0x04, net.AddressFamilyIPv6),
protocol.AddressFamilyByte(0x03, net.AddressFamilyDomain),
)