change how the encrypted parameters are handled.

based on 7a56a46864
This commit is contained in:
Fijxu 2025-03-27 22:06:20 -03:00
parent 235a2c48a6
commit cb370138b8
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
2 changed files with 15 additions and 19 deletions

View file

@ -2,6 +2,7 @@ package paths
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
@ -57,33 +58,28 @@ func checkRequest(w http.ResponseWriter, req *http.Request, params url.Values) {
func Videoplayback(w http.ResponseWriter, req *http.Request) {
q := req.URL.Query()
if q.Get("enc") == "yes" {
deencryptedQueryParams, err := utils.DecryptQueryParams(req.URL.Query().Get("data"), config.Cfg.Companion.Secret_key)
if q.Get("enc") == "true" {
decryptedQueryParams, err := utils.DecryptQueryParams(req.URL.Query().Get("data"), config.Cfg.Companion.Secret_key)
if err != nil {
http.Error(w, "Internal Server Error:\nFailed to decrypt query parameters", http.StatusInternalServerError)
return
}
q, err = url.ParseQuery(deencryptedQueryParams)
var structuredDecryptedQueryParams [][]string
err = json.Unmarshal([]byte(decryptedQueryParams), &structuredDecryptedQueryParams)
if err != nil {
http.Error(w, "Internal Server Error:\nFailed to parse query parameters from the decrypted query parameters", http.StatusInternalServerError)
return
}
pot := structuredDecryptedQueryParams[1][1]
ip := structuredDecryptedQueryParams[0][1]
q.Del("enc")
q.Del("data")
q.Set("pot", pot)
q.Set("ip", ip)
}
checkRequest(w, req, q)
expire, err := strconv.ParseInt(q.Get("expire"), 10, 64)
if err != nil {
w.WriteHeader(500)
io.WriteString(w, "Expire query string undefined")
return
}
// Prevent the process of already expired playbacks
// since they will return 403 from googlevideo server
if (expire - time.Now().Unix()) <= 0 {
w.WriteHeader(403)
io.WriteString(w, "Videoplayback URL has expired.")
return
}

View file

@ -79,7 +79,7 @@ func PanicHandler(w http.ResponseWriter) {
// https://stackoverflow.com/a/41652605
func DecryptQueryParams(encryptedQuery string, key string) (string, error) {
se, err := base64.URLEncoding.DecodeString(encryptedQuery)
se, err := base64.StdEncoding.DecodeString(encryptedQuery)
if err != nil {
log.Println("[ERROR] Error when decoding base64 string:", err)
return "", err