From c7925f9b508b2afaecb95bbc83539a079e5f1276 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 8 May 2015 08:20:20 +0000 Subject: [PATCH] * login and store only the MD5 password --- source/net/filebot/util/FileUtilities.java | 17 +++++++++++++++++ .../net/filebot/web/OpenSubtitlesClient.java | 19 ++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/source/net/filebot/util/FileUtilities.java b/source/net/filebot/util/FileUtilities.java index 11343c11..b0f8db43 100644 --- a/source/net/filebot/util/FileUtilities.java +++ b/source/net/filebot/util/FileUtilities.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.math.BigInteger; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; @@ -24,6 +25,8 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributes; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; @@ -627,6 +630,20 @@ public final class FileUtilities { return Pattern.compile("\\s*[\\\\/]+\\s*").matcher(path).replaceAll(replacement); } + public static String md5(byte[] data) { + return md5(ByteBuffer.wrap(data)); + } + + public static String md5(ByteBuffer data) { + try { + MessageDigest hash = MessageDigest.getInstance("MD5"); + hash.update(data); + return String.format("%032x", new BigInteger(1, hash.digest())); // as hex string + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + public static List asFileList(Object... paths) { List files = new ArrayList(paths.length); for (Object it : paths) { diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index 14d0906d..25ed8bbd 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -8,10 +8,8 @@ import static net.filebot.web.OpenSubtitlesHasher.*; import java.io.File; import java.io.IOException; -import java.math.BigInteger; import java.net.URI; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -64,7 +62,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS this.logout(); this.username = username; - this.password = password; + this.password = md5(StandardCharsets.UTF_8.encode(password)); } public boolean isAnonymous() { @@ -348,19 +346,6 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS xmlrpc.uploadSubtitles(info, sub); } - /** - * Calculate MD5 hash. - */ - private String md5(byte[] data) throws IOException { - try { - MessageDigest hash = MessageDigest.getInstance("MD5"); - hash.update(data); - return String.format("%032x", new BigInteger(1, hash.digest())); // as hex string - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); // won't happen - } - } - @Override public List searchMovie(String query, Locale locale) throws Exception { throw new UnsupportedOperationException();