Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions proxy/shadowsocks/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type MemoryAccount struct {
Key []byte

replayFilter antireplay.GeneralizedReplayFilter

ReducedIVEntropy bool
}

// Equals implements protocol.Account.Equals().
Expand Down Expand Up @@ -101,6 +103,7 @@ func (a *Account) AsAccount() (protocol.Account, error) {
}
return nil
}(),
ReducedIVEntropy: a.ExperimentReducedIvHeadEntropy,
}, nil
}

Expand Down
93 changes: 53 additions & 40 deletions proxy/shadowsocks/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proxy/shadowsocks/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ message Account {
CipherType cipher_type = 2;

bool iv_check = 3;
bool experiment_reduced_iv_head_entropy = 90001;
}

enum CipherType {
Expand Down
12 changes: 12 additions & 0 deletions proxy/shadowsocks/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/sha256"
"hash/crc32"
"io"
mrand "math/rand"
gonet "net"

"github.com/v2fly/v2ray-core/v5/common"
Expand Down Expand Up @@ -103,6 +104,9 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Wri
if account.Cipher.IVSize() > 0 {
iv = make([]byte, account.Cipher.IVSize())
common.Must2(rand.Read(iv))
if account.ReducedIVEntropy {
remapToPrintable(iv[:6])
}
if ivError := account.CheckIV(iv); ivError != nil {
return nil, newError("failed to mark outgoing iv").Base(ivError)
}
Expand Down Expand Up @@ -301,3 +305,11 @@ func (w *UDPWriter) WriteTo(payload []byte, addr gonet.Addr) (n int, err error)
packet.Release()
return len(payload), err
}

func remapToPrintable(input []byte) {
const charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~\\\""
seed := mrand.New(mrand.NewSource(int64(crc32.ChecksumIEEE(input))))
for i := range input {
input[i] = charSet[seed.Intn(len(charSet))]
}
}
5 changes: 3 additions & 2 deletions proxy/shadowsocks/simplified/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ func init() {
User: []*protocol.User{
{
Account: serial.ToTypedMessage(&shadowsocks.Account{
Password: simplifiedClient.Password,
CipherType: shadowsocks.CipherFromString(simplifiedClient.Method),
Password: simplifiedClient.Password,
CipherType: shadowsocks.CipherFromString(simplifiedClient.Method),
ExperimentReducedIvHeadEntropy: simplifiedClient.ExperimentReducedIvHeadEntropy,
}),
},
},
Expand Down
49 changes: 31 additions & 18 deletions proxy/shadowsocks/simplified/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proxy/shadowsocks/simplified/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ message ClientConfig {
uint32 port = 2;
string method = 3;
string password = 4;
bool experiment_reduced_iv_head_entropy = 90001;
}