forked from zu1k/proxypool
/
convert.go
100 lines (93 loc) · 1.97 KB
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package proxy
import (
"errors"
"github.com/zxfsq/proxypool/pkg/tool"
)
var ErrorTypeCanNotConvert = errors.New("type not support")
// Convert2SS convert proxy to ShadowsocksR if possible
func Convert2SSR(p Proxy) (ssr *ShadowsocksR, err error) {
if p.TypeName() == "ss" {
ss := p.(*Shadowsocks)
if ss == nil {
return nil, errors.New("ss is nil")
}
if !tool.CheckInList(SSRCipherList, ss.Cipher) {
return nil, errors.New("cipher not support")
}
base := ss.Base
base.Type = "ssr"
return &ShadowsocksR{
Base: base,
Password: ss.Password,
Cipher: ss.Cipher,
Protocol: "origin",
Obfs: "plain",
Group: "",
}, nil
}
return nil, ErrorTypeCanNotConvert
}
// Convert2SS convert proxy to Shadowsocks if possible
func Convert2SS(p Proxy) (ss *Shadowsocks, err error) {
if p.TypeName() == "ss" {
ssr := p.(*ShadowsocksR)
if ssr == nil {
return nil, errors.New("ssr is nil")
}
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
}
return nil, ErrorTypeCanNotConvert
}
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",
}