fix linux

This commit is contained in:
Silvan 2020-02-21 20:10:15 +08:00
parent 7ab46e6b5c
commit fdac2e25e0
4 changed files with 55 additions and 16 deletions

View File

@ -41,8 +41,9 @@ sudo ./UnblockNeteaseMusic
本应用获取music.163.com的IP是通过本机直接查询非nodejs版本请求music.httpdns.c.163.com获取
已知windows版本的网易云音乐需要在应用内设置代理 127.0.0.1 端口 80
咪咕源貌似部分宽带无法使用
已知:
1. windows版本的网易云音乐需要在应用内设置代理 127.0.0.1 端口 80
2. Linux 客户端 (1.2 版本以上需要在终端启动增加 --ignore-certificate-errors 参数)
3. 咪咕源貌似部分宽带无法使用
# 感谢
[NodeJs版本](https://github.com/nondanee/UnblockNeteaseMusic)以及为它贡献的所有coder

View File

@ -1,4 +1,4 @@
CurrentVersion=0.1.4
CurrentVersion=0.1.5
Project=github.com/cnsilvan/UnblockNeteaseMusic
Path="$Project/version"
ExecName="UnblockNeteaseMusic"

View File

@ -1,3 +1,20 @@
basepath=$(cd `dirname $0`; pwd)
echo $basepath
openssl req -new -nodes -x509 -out $basepath/server.crt -keyout $basepath/server.key -days 3650 -subj "/C=CN/ST=SH/L=SH/O=UnblockNeteaseMusic/OU=UnblockNeteaseMusic Software/CN=127.0.0.1/emailAddress=cnsilvan@gmail.com"
extFile="$basepath/extFile.txt"
serverCrt="$basepath/server.crt"
serverKey="$basepath/server.key"
serverCsr="$basepath/server.csr"
caCrt="$basepath/ca.crt"
caKey="$basepath/ca.key"
# 生成 CA 私钥
openssl genrsa -out "${caKey}" 2048
# 生成 CA 证书
openssl req -x509 -new -nodes -key "${caKey}" -sha256 -days 1825 -out "${caCrt}" -subj "/C=CN/CN=UnblockNeteaseMusic Root CA/O=UnblockNeteaseMusic"
# 生成服务器私钥
openssl genrsa -out "${serverKey}" 2048
# 生成证书签发请求
openssl req -new -sha256 -key "${serverKey}" -out "${serverCsr}" -subj "/C=CN/L=Hangzhou/O=NetEase (Hangzhou) Network Co., Ltd/OU=IT Dept./CN=*.music.163.com"
# 使用 CA 签发服务器证书
touch "${extFile}"
echo "subjectAltName=DNS:music.163.com,DNS:*.music.163.com" >"${extFile}"
openssl x509 -req -extfile "${extFile}" -days 1825 -in "${serverCsr}" -CA "${caCrt}" -CAkey "${caKey}" -CAcreateserial -out "${serverCrt}"

View File

@ -62,6 +62,7 @@ type Netease struct {
JsonBody map[string]interface{}
Web bool
Encrypted bool
Forward bool
}
func RequestBefore(request *http.Request) *Netease {
@ -78,17 +79,23 @@ func RequestBefore(request *http.Request) *Netease {
pad = requestBody
}
if netease.Path == "/api/linux/forward" {
netease.Forward = true
requestBodyH := make([]byte, len(requestBody))
length, _ := hex.Decode(requestBodyH, requestBody[8:len(requestBody)-len(pad)])
decryptECBBytes, _ := crypto.AesDecryptECB(requestBodyH[:length], []byte(linuxApiKey))
var result common.MapType
result = utils.ParseJson(decryptECBBytes)
urlM, ok := result["url"].(common.MapType)
if ok && utils.Exist("url", result) && utils.Exist("path", urlM) {
netease.Path = urlM["path"].(string)
//fmt.Println(utils.ToJson(result))
urlM, ok := result["url"].(string)
if ok {
netease.Path = urlM
}
netease.Params = utils.ParseJson(bytes.NewBufferString(result["params"].(string)).Bytes())
fmt.Println("forward")
params, ok := result["params"].(common.MapType)
if ok {
netease.Params = params
}
//fmt.Println("forward")
//fmt.Printf("path:%s \nparams:%s\n", netease.Path, netease.Params)
} else {
requestBodyH := make([]byte, len(requestBody))
@ -100,7 +107,9 @@ func RequestBefore(request *http.Request) *Netease {
netease.Params = utils.ParseJson(bytes.NewBufferString(data[1]).Bytes())
//fmt.Printf("path:%s \nparams:%s\n", netease.Path, netease.Params)
}
netease.Path = strings.ReplaceAll(netease.Path, "https://music.163.com", "")
netease.Path = strings.ReplaceAll(netease.Path, "http://music.163.com", "")
netease.Path = utils.ReplaceAll(netease.Path, `\/\d*$`, "")
} else if strings.Index(netease.Path, "/weapi/") == 0 || strings.Index(netease.Path, "/api/") == 0 {
request.Header.Set("X-Real-IP", "118.66.66.66")
netease.Web = true
@ -110,7 +119,7 @@ func RequestBefore(request *http.Request) *Netease {
} else if strings.Contains(netease.Path, "package") {
}
//fmt.Println(utils.ToJson(netease))
return netease
}
func Request(request *http.Request, remoteUrl string) (*http.Response, error) {
@ -145,17 +154,30 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
decryptECBBytes, _ = utils.UnGzip(decryptECBBytes)
}
//fmt.Println(string(decryptECBBytes), netease)
decryptECBBytes, encrypted := crypto.AesDecryptECB(decryptECBBytes, []byte(eApiKey))
aeskey := eApiKey
if netease.Forward {
aeskey = linuxApiKey
}
decryptECBBytes, encrypted := crypto.AesDecryptECB(decryptECBBytes, []byte(aeskey))
netease.Encrypted = encrypted
result := utils.ParseJson(decryptECBBytes)
netease.JsonBody = result
//fmt.Println(utils.ToJson(netease))
modified := false
code := netease.JsonBody["code"].(json.Number).String()
codeN, ok := netease.JsonBody["code"].(json.Number)
code := "200"
if ok {
code = codeN.String()
}
if !netease.Web && (code == "401" || code == "512") && strings.Contains(netease.Path, "manipulate") {
//fmt.Println("tryCollect")
modified = tryCollect(netease, request)
} else if !netease.Web && (code == "401" || code == "512") && strings.EqualFold(netease.Path, "/api/song/like") {
//fmt.Println("tryLike")
modified = tryLike(netease, request)
} else if strings.Contains(netease.Path, "url") {
//fmt.Println("tryMatch")
modified = tryMatch(netease)
}
if processMapJson(netease.JsonBody) || modified {
@ -168,7 +190,7 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
//fmt.Println(netease)
//fmt.Println(string(modifiedJson))
if netease.Encrypted {
modifiedJson = crypto.AesEncryptECB(modifiedJson, []byte(eApiKey))
modifiedJson = crypto.AesEncryptECB(modifiedJson, []byte(aeskey))
}
response.Body = ioutil.NopCloser(bytes.NewBuffer(modifiedJson))
} else {
@ -287,7 +309,6 @@ func tryLike(netease *Netease, request *http.Request) bool {
return modified
}
func tryMatch(netease *Netease) bool {
//fmt.Println(netease.Path)
modified := false
jsonBody := netease.JsonBody
if value, ok := jsonBody["data"]; ok {