refactor: move vendor app credentials and signing keys into config

The provider apps' own identifiers and protocol keys were scattered as
constants across six packages. They are not user secrets and stay baked in so
the tool still works out of the box, but they are now mirrored into the config
so that when a provider rotates one, a user can fix their install with a config
edit instead of waiting for a release.

Moved, each with the current value as the default in internal/config:
  qobuz     mobile_app_id, mobile_app_secret
  tidal     app_client_id, app_client_secret
  deezer    api_key, gateway_key, blowfish_secret
  yandex    sign_key, legacy_mp3_sign_salt
  beatport  app_client_id

applyVendorDefaults backfills any empty value, so configs written before these
keys existed keep working and the clients never have to nil-check them. Each
client reads through a small accessor; the package-level signing helpers
(mobileSignRequest, yandexDownloadSign, legacyDirectURL, deriveGatewayAuthToken
and friends, deriveDeezerBlowfishKey) now take the key as a parameter instead
of closing over a constant. The blowfish secret reaches internal/download
through a field on Downloader set by app.New.

The blowfish key derivation XORs 16 bytes of the secret, so a mistyped override
would have panicked; a wrong-length value is now rejected with a warning and
the built-in value is used. Tests pin the length and that the qobuz mobile
secret is valid hex, since the HKDF step requires it.

Also drops soundcloud.client_id and soundcloud.app_version: soundcloud goes
through yt-dlp, which supplies its own, so nothing read them.

config.toml.example documents each new key as "leave empty unless the vendor
rotates theirs".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
JorenandClaude Opus 5 committed 2026-10-03 17:11:41 +02:00
1 parent b3b6a2eb1d
commit 384f32cd67
13 files changed
+323 -61

No files matched your search

+31 -15
View File
@@ -33,8 +33,6 @@ var (
mediaURL = "https://media.deezer.com/v1/get_url"
pipeURL = "https://pipe.deezer.com/api"
authURL = "https://auth.deezer.com/login/renew"
apiKey = "4VCYIJUCDLOUELGD1V8WBVYBNVDYOXEWSLLZDONGBBDFVXTZJRXPR29JRLQFO6ZE"
gatewayDec = "VBK1FSUEXHTSDBJJ"
deezerUAPool = []string{
"Deezer/9.0.11.4 (Android; 14; Mobile; us) Xiaomi Redmi Note 7",
"Deezer/9.0.11.4 (Android; 14; Mobile; us) Samsung SM-G991B",
@@ -499,7 +497,7 @@ func (c *Client) loginWithCredentials(ctx context.Context, email, password strin
if err != nil {
return err
}
authToken, err := deriveGatewayAuthToken(mobileToken)
authToken, err := deriveGatewayAuthToken(c.gatewayKey(), mobileToken)
if err != nil {
return err
}
@@ -509,7 +507,7 @@ func (c *Client) loginWithCredentials(ctx context.Context, email, password strin
}
c.sid = jsonutil.FirstNonEmpty(c.sid, sid)
encryptedPassword, err := encryptPassword(mobileToken, password)
encryptedPassword, err := encryptPassword(c.gatewayKey(), mobileToken, password)
if err != nil {
return err
}
@@ -528,7 +526,7 @@ func (c *Client) loginWithCredentials(ctx context.Context, email, password strin
"password": encryptedPassword,
}
params := url.Values{}
params.Set("api_key", apiKey)
params.Set("api_key", c.apiKey())
params.Set("sid", c.sid)
params.Set("method", "mobile_userAuth")
params.Set("output", "3")
@@ -737,7 +735,7 @@ func (c *Client) bootstrapSID(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
authToken, err := deriveGatewayAuthToken(mobileToken)
authToken, err := deriveGatewayAuthToken(c.gatewayKey(), mobileToken)
if err != nil {
return "", err
}
@@ -749,7 +747,7 @@ func (c *Client) mobileAuth(ctx context.Context) (string, error) {
return "", err
}
params := url.Values{}
params.Set("api_key", apiKey)
params.Set("api_key", c.apiKey())
params.Set("output", "3")
params.Set("method", "mobile_auth")
params.Set("network", randomHexN(32))
@@ -802,7 +800,7 @@ func (c *Client) apiCheckToken(ctx context.Context, authToken string) (string, e
return "", err
}
params := url.Values{}
params.Set("api_key", apiKey)
params.Set("api_key", c.apiKey())
params.Set("method", "api_checkToken")
params.Set("auth_token", authToken)
params.Set("output", "3")
@@ -865,7 +863,7 @@ func (c *Client) mobileUserAutolog(ctx context.Context) error {
payload["refresh_token"] = strings.TrimSpace(c.refresh)
}
params := url.Values{}
params.Set("api_key", apiKey)
params.Set("api_key", c.apiKey())
params.Set("sid", c.sid)
params.Set("output", "3")
params.Set("input", "3")
@@ -1075,8 +1073,10 @@ func (c *Client) refreshLicenseFromPipe(ctx context.Context) error {
return nil
}
func deriveGatewayAuthToken(mobileToken string) (string, error) {
dec, err := decryptMobileToken(mobileToken)
// deriveGatewayAuthToken and friends take gatewayKey explicitly so the key
// comes from config rather than a package constant.
func deriveGatewayAuthToken(gatewayKey, mobileToken string) (string, error) {
dec, err := decryptMobileToken(gatewayKey, mobileToken)
if err != nil {
return "", err
}
@@ -1092,19 +1092,19 @@ func deriveGatewayAuthToken(mobileToken string) (string, error) {
return hex.EncodeToString(enc), nil
}
func decryptMobileToken(mobileToken string) ([]byte, error) {
func decryptMobileToken(gatewayKey, mobileToken string) ([]byte, error) {
b, err := hex.DecodeString(strings.TrimSpace(mobileToken))
if err != nil {
return nil, err
}
return aesECBDecrypt([]byte(gatewayDec), b)
return aesECBDecrypt([]byte(gatewayKey), b)
}
func encryptPassword(mobileToken, password string) (string, error) {
func encryptPassword(gatewayKey, mobileToken, password string) (string, error) {
if strings.TrimSpace(password) == "" {
return "", errors.New("missing deezer password")
}
dec, err := decryptMobileToken(mobileToken)
dec, err := decryptMobileToken(gatewayKey, mobileToken)
if err != nil {
return "", err
}
@@ -1513,3 +1513,19 @@ func enrichAlbumImage(meta map[string]any) {
"original": cover,
}
}
// apiKey and gatewayKey read the vendor protocol keys from config, falling
// back to the built-in defaults.
func (c *Client) apiKey() string {
if v := strings.TrimSpace(c.cfg.Session.Deezer.APIKey); v != "" {
return v
}
return config.DefaultDeezerAPIKey
}
func (c *Client) gatewayKey() string {
if v := strings.TrimSpace(c.cfg.Session.Deezer.GatewayKey); v != "" {
return v
}
return config.DefaultDeezerGatewayKey
}
+1 -1
View File
@@ -728,7 +728,7 @@ func TestMobileUserAutologIncludesRefreshToken(t *testing.T) {
func testMobileToken(t *testing.T) string {
t.Helper()
plain := []byte(strings.Repeat("A", 64) + strings.Repeat("B", 16) + strings.Repeat("C", 16))
enc, err := aesECBEncrypt([]byte(gatewayDec), plain)
enc, err := aesECBEncrypt([]byte(config.DefaultDeezerGatewayKey), plain)
if err != nil {
t.Fatalf("aesECBEncrypt() error = %v", err)
}