Skip to content

Commit 0cf077e

Browse files
authored
Validate master decryption key using hash. (#305)
1 parent 7a7da12 commit 0cf077e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

main/src/main/java/com/github/topi314/lavasrc/deezer/DeezerAudioSourceManager.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@
3030
import java.io.IOException;
3131
import java.net.URLEncoder;
3232
import java.nio.charset.StandardCharsets;
33+
import java.security.MessageDigest;
34+
import java.security.NoSuchAlgorithmException;
3335
import java.time.Duration;
34-
import java.util.ArrayList;
35-
import java.util.Collections;
36-
import java.util.List;
37-
import java.util.Set;
36+
import java.util.*;
3837
import java.util.function.Consumer;
3938
import java.util.function.Function;
4039
import java.util.regex.Pattern;
4140
import java.util.stream.Collectors;
4241

4342
public class DeezerAudioSourceManager extends ExtendedAudioSourceManager implements HttpConfigurable, AudioSearchManager, AudioLyricsManager {
43+
private static final byte[] decryptionKeyHash = new byte[] {
44+
52, 76, 41, -118, 120, -123, 48, 72, -58, 74, 16, 75, 82, 101, -70, -33, 15, -66, 111, -38, -80, 71, 103, 11, -75, -120, -101, -9, 66, -53, -38, -16
45+
};
4446

4547
public static final Pattern URL_PATTERN = Pattern.compile("(https?://)?(www\\.)?deezer\\.com/(?<countrycode>[a-zA-Z]{2}/)?(?<type>track|album|playlist|artist)/(?<identifier>[0-9]+)");
4648
public static final String SEARCH_PREFIX = "dzsearch:";
@@ -75,12 +77,26 @@ public DeezerAudioSourceManager(String masterDecryptionKey, @Nullable String arl
7577
throw new IllegalArgumentException("Deezer master key must be set");
7678
}
7779

80+
if (!validateDecryptionKey(masterDecryptionKey)) {
81+
log.warn("Deezer master decryption key is possibly invalid, playback may not work!");
82+
}
83+
7884
this.masterDecryptionKey = masterDecryptionKey;
7985
this.tokenTracker = new DeezerTokenTracker(this, arl);
8086
this.formats = formats != null && formats.length > 0 ? formats : DeezerAudioTrack.TrackFormat.DEFAULT_FORMATS;
8187
this.httpInterfaceManager = HttpClientTools.createCookielessThreadLocalManager();
8288
}
8389

90+
public boolean validateDecryptionKey(String masterDecryptionKey) {
91+
try {
92+
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
93+
messageDigest.update(masterDecryptionKey.getBytes(StandardCharsets.UTF_8));
94+
return Arrays.equals(messageDigest.digest(), decryptionKeyHash);
95+
} catch (NoSuchAlgorithmException e) {
96+
return false;
97+
}
98+
}
99+
84100
static void checkResponse(JsonBrowser json, String message) throws IllegalStateException {
85101
if (json == null) {
86102
throw new IllegalStateException(message + "No response");

0 commit comments

Comments
 (0)