feat: 广电加密参数改为按脚本内容读取
This commit is contained in:
+45
-14
@@ -17,7 +17,7 @@ const siteCacheTTL = 6 * time.Hour
|
||||
var (
|
||||
keyRE = regexp.MustCompile(`MII[A-Za-z0-9+/]{200,}={0,2}`)
|
||||
versionRE = regexp.MustCompile(`\d+\.\d+\.\d+\.\d+_[A-Za-z0-9]+`)
|
||||
channelRE = regexp.MustCompile(`channelId:"(cd_[0-9_]+)"`)
|
||||
channelRE = regexp.MustCompile(`channelId\s*:\s*"([^"]+)"`)
|
||||
scriptRE = regexp.MustCompile(`(?i)src=["']([^"']+\.js)["']`)
|
||||
)
|
||||
|
||||
@@ -29,6 +29,7 @@ type siteProfile struct {
|
||||
Public *rsa.PublicKey
|
||||
Private *rsa.PrivateKey
|
||||
FetchedAt time.Time
|
||||
useNative bool
|
||||
}
|
||||
|
||||
type siteFile struct {
|
||||
@@ -75,38 +76,68 @@ func parseSiteJS(src string) (*siteProfile, error) {
|
||||
return nil, errors.New("页面脚本里没有找到加密密钥")
|
||||
}
|
||||
ver := versionRE.FindString(src)
|
||||
ch := channelRE.FindStringSubmatch(src)
|
||||
if ver == "" || ch == nil {
|
||||
ch := chooseChannel(channelRE.FindAllStringSubmatch(src, -1))
|
||||
if ver == "" || ch == "" {
|
||||
return nil, errors.New("页面脚本里没有找到渠道或版本号")
|
||||
}
|
||||
return &siteProfile{
|
||||
ChannelID: ch[1],
|
||||
p := &siteProfile{
|
||||
ChannelID: ch,
|
||||
Version: ver,
|
||||
PublicB64: pubB64,
|
||||
PrivateB64: privB64,
|
||||
Public: pub,
|
||||
Private: priv,
|
||||
FetchedAt: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
p.useNative = p.roundtrip()
|
||||
if !p.useNative {
|
||||
return nil, errors.New("页面脚本里的密钥无法对应")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func chooseChannel(matches [][]string) string {
|
||||
first := ""
|
||||
for _, m := range matches {
|
||||
if len(m) < 2 || m[1] == "" {
|
||||
continue
|
||||
}
|
||||
if first == "" {
|
||||
first = m[1]
|
||||
}
|
||||
if strings.HasPrefix(m[1], "cd_") {
|
||||
return m[1]
|
||||
}
|
||||
}
|
||||
return first
|
||||
}
|
||||
|
||||
func (p *siteProfile) roundtrip() bool {
|
||||
if p == nil || p.Public == nil || p.Private == nil {
|
||||
return false
|
||||
}
|
||||
const probe = "probe"
|
||||
enc, err := encryptLong(p.Public, probe)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
back, err := decryptLong(p.Private, enc)
|
||||
return err == nil && back == probe
|
||||
}
|
||||
|
||||
func scriptURLs(html string) []string {
|
||||
matches := scriptRE.FindAllStringSubmatch(html, -1)
|
||||
var common, rest []string
|
||||
var out []string
|
||||
seen := map[string]bool{}
|
||||
for _, m := range matches {
|
||||
u := m[1]
|
||||
if seen[u] {
|
||||
if u == "" || seen[u] {
|
||||
continue
|
||||
}
|
||||
seen[u] = true
|
||||
if strings.Contains(u, "common-") {
|
||||
common = append(common, u)
|
||||
continue
|
||||
}
|
||||
rest = append(rest, u)
|
||||
out = append(out, u)
|
||||
}
|
||||
return append(common, rest...)
|
||||
return out
|
||||
}
|
||||
|
||||
func resolveURL(ref string) string {
|
||||
|
||||
Reference in New Issue
Block a user