Skip to content

Commit

Permalink
Add password support for shadowsocks 2022 ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed May 12, 2022
1 parent 2b40871 commit 0d3435b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 59 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/miekg/dns v1.1.49
github.com/mustafaturan/bus v1.0.2
github.com/pires/go-proxyproto v0.6.2
github.com/sagernet/sing v0.0.0-20220512055044-f1a5f8aaa3c6
github.com/sagernet/sing v0.0.0-20220512091719-2aae93c5b8a5
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb
github.com/stretchr/testify v1.7.1
github.com/v2fly/BrowserBridge v0.0.0-20210430233438-0570fc1d7d08
Expand All @@ -44,14 +44,11 @@ require (
lukechampine.com/blake3 v1.1.7
)

require github.com/marten-seemann/qtls-go1-17 v0.1.1 // indirect

// https://github.com/google/gvisor/releases/tag/release-20220314.0
replace gvisor.dev/gvisor => github.com/sagernet/gvisor v0.0.0-20220402114650-763d12dc953e

//replace github.com/sagernet/sing => ../sing

//
require (
github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 // indirect
github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d // indirect
Expand All @@ -71,6 +68,7 @@ require (
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.1 // indirect
github.com/mustafaturan/monoton v1.0.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sagernet/gvisor v0.0.0-20220402114650-763d12dc953e h1:Y4avBAtZ59OWvLl6zP9sF62jtMEVRPIH78IQctq9aXQ=
github.com/sagernet/gvisor v0.0.0-20220402114650-763d12dc953e/go.mod h1:tWwEcFvJavs154OdjFCw78axNrsDlz4Zh8jvPqwcpGI=
github.com/sagernet/sing v0.0.0-20220512055044-f1a5f8aaa3c6 h1:5xDtCbrv5ZBErp/A+3iEfpHllTLrDQFGTf0PKoyDW/s=
github.com/sagernet/sing v0.0.0-20220512055044-f1a5f8aaa3c6/go.mod h1:VwWKzsa5GIx/hqqPbbbcpb33g82m6UTXz1nsPwxE4J0=
github.com/sagernet/sing v0.0.0-20220512091719-2aae93c5b8a5 h1:ssOV7zutm1ulWE2ZMbuHBlXHbevnPIGsofvHl+Gl1AI=
github.com/sagernet/sing v0.0.0-20220512091719-2aae93c5b8a5/go.mod h1:VwWKzsa5GIx/hqqPbbbcpb33g82m6UTXz1nsPwxE4J0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4 h1:zOjq+1/uLzn/Xo40stbvjIY/yehG0+mfmlsiEmc0xmQ=
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4/go.mod h1:aI+8yClBW+1uovkHw6HM01YXnYB8vohtB9C83wzx34E=
Expand Down
63 changes: 10 additions & 53 deletions proxy/shadowsocks_sing/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package shadowsocks_sing

import (
"context"
"encoding/base64"
"io"
"runtime"
"strings"
"time"

C "github.com/sagernet/sing/common"
Expand All @@ -16,8 +14,7 @@ import (
"github.com/sagernet/sing/common/random"
"github.com/sagernet/sing/common/rw"
"github.com/sagernet/sing/protocol/shadowsocks"
"github.com/sagernet/sing/protocol/shadowsocks/shadowaead"
"github.com/sagernet/sing/protocol/shadowsocks/shadowaead_2022"
"github.com/sagernet/sing/protocol/shadowsocks/shadowimpl"
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/net"
Expand Down Expand Up @@ -48,57 +45,17 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
Network: net.Network_TCP,
},
}
if config.Method == shadowsocks.MethodNone {
o.method = shadowsocks.NewNone()
} else if common.Contains(shadowaead.List, config.Method) {
var key []byte
if config.Key != "" {
bKdy, err := base64.StdEncoding.DecodeString(config.Key)
if err != nil {
return nil, newError("shadowsocks: decode key ", config.Key).Base(err)
}
key = bKdy
}
var rng io.Reader = random.Default
if config.ReducedIvHeadEntropy {
rng = &shadowsocks.ReducedEntropyReader{
Reader: rng,
}
}
method, err := shadowaead.New(config.Method, key, []byte(config.Password), rng)
if err != nil {
return nil, newError("create method").Base(err)
}
o.method = method
} else if common.Contains(shadowaead_2022.List, config.Method) {
if config.Password != "" {
return nil, newError("use psk instead of password")
}
if config.Key == "" {
return nil, newError("missing psk")
}
var pskList [][]byte
for _, ks := range strings.Split(config.Key, ":") {
psk, err := base64.StdEncoding.DecodeString(ks)
if err != nil {
return nil, newError("decode key ", ks).Base(err)
}
pskList = append(pskList, psk)
var rng io.Reader = random.Default
if config.ReducedIvHeadEntropy {
rng = &shadowsocks.ReducedEntropyReader{
Reader: rng,
}
var rng io.Reader = random.Default
if config.ReducedIvHeadEntropy {
rng = &shadowsocks.ReducedEntropyReader{
Reader: rng,
}
}
method, err := shadowaead_2022.New(config.Method, pskList, rng)
if err != nil {
return nil, newError("create method").Base(err)
}
o.method = method
} else {
return nil, newError("unknown method ", config.Method)
}
method, err := shadowimpl.FetchMethod(config.Method, config.Key, config.Password, rng)
if err != nil {
return nil, err
}
o.method = method
return o, nil
}

Expand Down

0 comments on commit 0d3435b

Please # to comment.