Skip to content

Commit

Permalink
try to convert between ssr and ss
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Sep 6, 2020
1 parent 679c6fa commit 49b1c69
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 58 deletions.
9 changes: 0 additions & 9 deletions pkg/provider/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ type Provider interface {
Provide() string
}

func checkInList(list []string, item string) bool {
for _, i := range list {
if item == i {
return true
}
}
return false
}

type Base struct {
Proxies *proxy.ProxyList `yaml:"proxies"`
Types string `yaml:"type"`
Expand Down
49 changes: 5 additions & 44 deletions pkg/provider/clash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package provider
import (
"strings"

"github.com/zu1k/proxypool/pkg/tool"

"github.com/zu1k/proxypool/pkg/proxy"
)

Expand Down Expand Up @@ -37,17 +39,17 @@ func checkClashSupport(p proxy.Proxy) bool {
switch p.TypeName() {
case "ssr":
ssr := p.(*proxy.ShadowsocksR)
if checkInList(ssrCipherList, ssr.Cipher) && checkInList(ssrProtocolList, ssr.Protocol) && checkInList(ssrObfsList, ssr.Obfs) {
if tool.CheckInList(proxy.SSRCipherList, ssr.Cipher) && tool.CheckInList(ssrProtocolList, ssr.Protocol) && tool.CheckInList(ssrObfsList, ssr.Obfs) {
return true
}
case "vmess":
vmess := p.(*proxy.Vmess)
if checkInList(vmessCipherList, vmess.Cipher) {
if tool.CheckInList(vmessCipherList, vmess.Cipher) {
return true
}
case "ss":
ss := p.(*proxy.Shadowsocks)
if checkInList(ssCipherList, ss.Cipher) {
if tool.CheckInList(proxy.SSCipherList, ss.Cipher) {
return true
}
case "trojan":
Expand All @@ -58,30 +60,6 @@ func checkClashSupport(p proxy.Proxy) bool {
return false
}

var ssrCipherList = []string{
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"aes-128-ofb",
"aes-192-ofb",
"aes-256-ofb",
"des-cfb",
"bf-cfb",
"cast5-cfb",
"rc4-md5",
"chacha20-ietf",
"salsa20",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"idea-cfb",
"rc2-cfb",
"seed-cfb",
}

var ssrObfsList = []string{
"plain",
"http_simple",
Expand Down Expand Up @@ -110,20 +88,3 @@ var vmessCipherList = []string{
"chacha20-poly1305",
"none",
}

var ssCipherList = []string{
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"rc4-md5",
"chacha20-ietf",
"xchacha20",
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305",
}
13 changes: 11 additions & 2 deletions pkg/provider/ssrsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package provider
import (
"strings"

"github.com/zu1k/proxypool/pkg/proxy"

"github.com/zu1k/proxypool/pkg/tool"
)

Expand All @@ -11,11 +13,18 @@ type SSRSub struct {
}

func (sub SSRSub) Provide() string {
sub.Types = "ssr"
sub.Types = "ssr,ss"
sub.preFilter()
var resultBuilder strings.Builder
for _, p := range *sub.Proxies {
resultBuilder.WriteString(p.Link() + "\n")
if p.TypeName() == "ssr" {
resultBuilder.WriteString(p.Link() + "\n")
} else if p.TypeName() == "ss" {
ssr, err := proxy.SS2SSR(p.(*proxy.Shadowsocks))
if err == nil {
resultBuilder.WriteString(ssr.Link() + "\n")
}
}
}
return tool.Base64EncodeString(resultBuilder.String(), false)
}
15 changes: 13 additions & 2 deletions pkg/provider/sssub.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ type ssJson struct {
}

func (sub SSSub) Provide() string {
sub.Types = "ss"
sub.Types = "ss,ssr"
sub.preFilter()
proxies := make([]ssJson, 0, sub.Proxies.Len())
for _, p := range *sub.Proxies {
pp := p.(*proxy.Shadowsocks)
var pp *proxy.Shadowsocks

if p.TypeName() == "ssr" {
var err error
pp, err = proxy.SSR2SS(p.(*proxy.ShadowsocksR))
if err != nil {
continue
}
} else if p.TypeName() == "ss" {
pp = p.(*proxy.Shadowsocks)
}

proxies = append(proxies, ssJson{
Remarks: pp.Name,
Server: pp.Server,
Expand Down
4 changes: 3 additions & 1 deletion pkg/provider/surge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package provider
import (
"strings"

"github.com/zu1k/proxypool/pkg/tool"

"github.com/zu1k/proxypool/pkg/proxy"
)

Expand Down Expand Up @@ -30,7 +32,7 @@ func checkSurgeSupport(p proxy.Proxy) bool {
return true
case *proxy.Shadowsocks:
ss := p.(*proxy.Shadowsocks)
if checkInList(ssCipherList, ss.Cipher) {
if tool.CheckInList(proxy.SSCipherList, ss.Cipher) {
return true
}
default:
Expand Down
82 changes: 82 additions & 0 deletions pkg/proxy/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package proxy

import (
"errors"

"github.com/zu1k/proxypool/pkg/tool"
)

func SS2SSR(ss *Shadowsocks) (ssr *ShadowsocksR, err error) {
if !tool.CheckInList(SSRCipherList, ss.Cipher) {
return nil, errors.New("cipher not support")
}
base := ssr.Base
base.Type = "ssr"
return &ShadowsocksR{
Base: base,
Password: ss.Password,
Cipher: ss.Cipher,
Protocol: "origin",
Obfs: "plain",
Group: "proxy.tgbot.co",
}, nil
}

func SSR2SS(ssr *ShadowsocksR) (ss *Shadowsocks, err error) {
if !tool.CheckInList(SSCipherList, ssr.Cipher) {
return nil, errors.New("cipher not support")
}
if ssr.Protocol != "origin" || ssr.Obfs != "plain" {
return nil, errors.New("protocol or obfs not allowed")
}
base := ssr.Base
base.Type = "ss"
return &Shadowsocks{
Base: base,
Password: ssr.Password,
Cipher: ssr.Cipher,
Plugin: "",
PluginOpts: nil,
}, nil
}

var SSRCipherList = []string{
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"aes-128-ofb",
"aes-192-ofb",
"aes-256-ofb",
"des-cfb",
"bf-cfb",
"cast5-cfb",
"rc4-md5",
"chacha20-ietf",
"salsa20",
"camellia-128-cfb",
"camellia-192-cfb",
"camellia-256-cfb",
"idea-cfb",
"rc2-cfb",
"seed-cfb",
}

var SSCipherList = []string{
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
"aes-128-cfb",
"aes-192-cfb",
"aes-256-cfb",
"aes-128-ctr",
"aes-192-ctr",
"aes-256-ctr",
"rc4-md5",
"chacha20-ietf",
"xchacha20",
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305",
}
10 changes: 10 additions & 0 deletions pkg/tool/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tool

func CheckInList(list []string, item string) bool {
for _, i := range list {
if item == i {
return true
}
}
return false
}

0 comments on commit 49b1c69

Please sign in to comment.