-MC password links lock
-...
This commit is contained in:
tonikelope 2016-10-07 17:14:23 +02:00
parent a563690027
commit a4a38a60c9
9 changed files with 85 additions and 73 deletions

View File

@ -35,7 +35,7 @@ public final class ChunkWriter implements Runnable, SecureNotifiable {
_byte_file_key = CryptTools.initMEGALinkKey(_download.getFile_key()); _byte_file_key = CryptTools.initMEGALinkKey(_download.getFile_key());
_byte_iv = CryptTools.initMEGALinkKeyIV(_download.getFile_key()); _byte_iv = CryptTools.initMEGALinkKeyIV(_download.getFile_key());
_chunk_queue = new ConcurrentHashMap(); _chunk_queue = new ConcurrentHashMap();
_rejectedChunkIds = new ConcurrentLinkedQueue(); _rejectedChunkIds = new ConcurrentLinkedQueue<>();
if(_download.getProgress() == 0) if(_download.getProgress() == 0)
{ {

View File

@ -121,9 +121,9 @@ public final class Download implements Transference, Runnable, SecureNotifiable
_slots = slots; _slots = slots;
_restart= restart; _restart= restart;
_secure_notify_lock = new Object(); _secure_notify_lock = new Object();
_chunkworkers = new ArrayList(); _chunkworkers = new ArrayList<>();
_partialProgressQueue = new ConcurrentLinkedQueue(); _partialProgressQueue = new ConcurrentLinkedQueue<>();
_rejectedChunkIds = new ConcurrentLinkedQueue(); _rejectedChunkIds = new ConcurrentLinkedQueue<>();
_thread_pool = newCachedThreadPool(); _thread_pool = newCachedThreadPool();
} }
@ -1196,6 +1196,10 @@ public final class Download implements Transference, Runnable, SecureNotifiable
case 24: case 24:
emergencyStopDownloader("MegaCrypter link has expired!"); emergencyStopDownloader("MegaCrypter link has expired!");
break; break;
case 25:
emergencyStopDownloader("MegaCrypter bad password!");
break;
default: default:

View File

@ -212,7 +212,7 @@ public class GetMegaMasterPasswordDialog extends javax.swing.JDialog {
if(!pass_hash.equals(_current_pass_hash)) { if(!pass_hash.equals(_current_pass_hash)) {
JOptionPane.showMessageDialog(tthis, "Bad password!", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(tthis, "BAD PASSWORD!", "Error", JOptionPane.ERROR_MESSAGE);
swingReflectionInvoke("setText", status_label, ""); swingReflectionInvoke("setText", status_label, "");

View File

@ -61,7 +61,7 @@ import static megabasterd.Transference.MAX_TRANSFERENCE_SPEED_DEFAULT;
*/ */
public final class MainPanel { public final class MainPanel {
public static final String VERSION="1.17"; public static final String VERSION="1.18";
public static final int CONNECTION_TIMEOUT = 30000; public static final int CONNECTION_TIMEOUT = 30000;
public static final int THROTTLE_SLICE_SIZE=16*1024; public static final int THROTTLE_SLICE_SIZE=16*1024;
public static final int STREAMER_PORT = 1337; public static final int STREAMER_PORT = 1337;

View File

@ -9,6 +9,9 @@ import java.net.URL;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import static java.util.logging.Logger.getLogger; import static java.util.logging.Logger.getLogger;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@ -32,6 +35,8 @@ import org.codehaus.jackson.map.ObjectMapper;
public final class MegaCrypterAPI { public final class MegaCrypterAPI {
public static final String USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"; public static final String USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0";
public static final Set<String> PASS_CACHE = new HashSet<>();
public static final Object PASS_LOCK = new Object();
private static String _rawRequest(String request, URL url_api) throws IOException, MegaCrypterAPIException { private static String _rawRequest(String request, URL url_api) throws IOException, MegaCrypterAPIException {
@ -213,70 +218,73 @@ public final class MegaCrypterAPI {
Cipher decrypter; Cipher decrypter;
try { synchronized(PASS_LOCK) {
do
{ LinkedList<String> pass_list = new LinkedList(PASS_CACHE);
bad_pass = false;
do
password = JOptionPane.showInputDialog(panel, "Enter password:"); {
bad_pass = true;
if(password!=null) {
if((password = pass_list.poll()) == null) {
password = JOptionPane.showInputDialog(panel, "Enter password for MegaCrypter link:");
}
if(password != null) {
try {
info_key=CryptTools.PBKDF2HMACSHA256(password, salt, (int)Math.pow(2, iterations));
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
try { try {
info_key=CryptTools.PBKDF2HMACSHA256(password, salt, (int)Math.pow(2, iterations));
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
try { bad_pass = !Arrays.equals(info_key, decrypter.doFinal(key_check));
bad_pass = !Arrays.equals(info_key, decrypter.doFinal(key_check)); if(!bad_pass) {
} catch (IllegalBlockSizeException | BadPaddingException ex) { PASS_CACHE.add(password);
bad_pass=true;
} }
} catch (InvalidKeySpecException ex) {
bad_pass=true;
}
}
}while(password!=null && bad_pass);
if(password==null) } catch (IllegalBlockSizeException | BadPaddingException ex) {}
{
return null;
}
else
{
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
byte[] decrypted_key = decrypter.doFinal(BASE642Bin(fkey)); } catch (InvalidKeySpecException ex) {}
fkey = Bin2UrlBASE64(decrypted_key);
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
byte[] decrypted_name = decrypter.doFinal(BASE642Bin(fname));
fname = new String(decrypted_name);
if(fpath != null)
{
byte[] decrypted_fpath = decrypter.doFinal(BASE642Bin(fpath));
fpath = new String(decrypted_fpath);
}
pass=Bin2BASE64(info_key);
} }
} catch (Exception ex) { }while(password!=null && bad_pass);
getLogger(MegaCrypterAPI.class.getName()).log(Level.SEVERE, null, ex); }
}
if(bad_pass)
{
throw new MegaCrypterAPIException("25");
}
else
{
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
byte[] decrypted_key = decrypter.doFinal(BASE642Bin(fkey));
fkey = Bin2UrlBASE64(decrypted_key);
decrypter = CryptTools.genDecrypter("AES", "AES/CBC/PKCS5Padding", info_key, iv);
byte[] decrypted_name = decrypter.doFinal(BASE642Bin(fname));
fname = new String(decrypted_name);
if(fpath != null)
{
byte[] decrypted_fpath = decrypter.doFinal(BASE642Bin(fpath));
fpath = new String(decrypted_fpath);
}
pass=Bin2BASE64(info_key);
}
} }
if(fpath != null) if(fpath != null)

View File

@ -124,7 +124,7 @@ public final class MiscTools {
} }
else else
{ {
ArrayList<Integer> list = new ArrayList(); ArrayList<Integer> list = new ArrayList<>();
while(int_buffer.hasRemaining()) { while(int_buffer.hasRemaining()) {
list.add(int_buffer.get()); list.add(int_buffer.get());
@ -151,7 +151,7 @@ public final class MiscTools {
} }
else else
{ {
ArrayList<Byte> list = new ArrayList(); ArrayList<Byte> list = new ArrayList<>();
while(int_buffer.hasRemaining()) { while(int_buffer.hasRemaining()) {
list.add(bin_buffer.get()); list.add(bin_buffer.get());

View File

@ -1226,7 +1226,7 @@ public final class SettingsDialog extends javax.swing.JDialog {
private void delete_all_accounts_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delete_all_accounts_buttonActionPerformed private void delete_all_accounts_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delete_all_accounts_buttonActionPerformed
swingReflectionInvoke("setEnabled", delete_all_accounts_button, true); swingReflectionInvoke("setEnabled", delete_all_accounts_button, false);
final SettingsDialog tthis = this; final SettingsDialog tthis = this;

View File

@ -51,12 +51,12 @@ abstract public class TransferenceManager implements Runnable, SecureNotifiable
_pause_all_button = pause_all_button; _pause_all_button = pause_all_button;
_clean_all_menu = clean_all_menu; _clean_all_menu = clean_all_menu;
_secure_notify_lock = new Object(); _secure_notify_lock = new Object();
_transference_waitstart_queue = new ConcurrentLinkedQueue(); _transference_waitstart_queue = new ConcurrentLinkedQueue<>();
_transference_provision_queue = new ConcurrentLinkedQueue(); _transference_provision_queue = new ConcurrentLinkedQueue<>();
_transference_remove_queue = new ConcurrentLinkedQueue(); _transference_remove_queue = new ConcurrentLinkedQueue<>();
_transference_finished_queue = new ConcurrentLinkedQueue(); _transference_finished_queue = new ConcurrentLinkedQueue<>();
_transference_running_list = new ConcurrentLinkedQueue(); _transference_running_list = new ConcurrentLinkedQueue<>();
_transference_preprocess_queue = new ConcurrentLinkedQueue(); _transference_preprocess_queue = new ConcurrentLinkedQueue<>();
} }
abstract public void provision(Transference transference); abstract public void provision(Transference transference);

View File

@ -99,9 +99,9 @@ public final class Upload implements Transference, Runnable, SecureNotifiable {
_slots = slots; _slots = slots;
_restart = restart; _restart = restart;
_secure_notify_lock = new Object(); _secure_notify_lock = new Object();
_chunkworkers = new ArrayList(); _chunkworkers = new ArrayList<>();
_partialProgressQueue = new ConcurrentLinkedQueue(); _partialProgressQueue = new ConcurrentLinkedQueue<>();
_rejectedChunkIds = new ConcurrentLinkedQueue(); _rejectedChunkIds = new ConcurrentLinkedQueue<>();
_thread_pool = Executors.newCachedThreadPool(); _thread_pool = Executors.newCachedThreadPool();
} }