|
|
|
@@ -51,9 +51,14 @@ import javax.crypto.SecretKeyFactory;
|
|
|
|
import javax.crypto.spec.PBEKeySpec;
|
|
|
|
import javax.crypto.spec.PBEKeySpec;
|
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.swing.*;
|
|
|
|
import javax.swing.JButton;
|
|
|
|
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
import javax.swing.JPasswordField;
|
|
|
|
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import net.runelite.api.Client;
|
|
|
|
import net.runelite.api.Client;
|
|
|
|
import net.runelite.client.ui.ColorScheme;
|
|
|
|
import net.runelite.client.ui.ColorScheme;
|
|
|
|
@@ -81,12 +86,10 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
private static ProfilesConfig profilesConfig;
|
|
|
|
private static ProfilesConfig profilesConfig;
|
|
|
|
|
|
|
|
|
|
|
|
private final JPasswordField txtDecryptPassword = new JPasswordField(UNLOCK_PASSWORD);
|
|
|
|
private final JPasswordField txtDecryptPassword = new JPasswordField(UNLOCK_PASSWORD);
|
|
|
|
private final JButton btnLoadAccounts = new JButton(LOAD_ACCOUNTS);
|
|
|
|
|
|
|
|
private final JTextField txtAccountLabel = new JTextField(ACCOUNT_LABEL);
|
|
|
|
private final JTextField txtAccountLabel = new JTextField(ACCOUNT_LABEL);
|
|
|
|
private final JPasswordField txtAccountLogin = new JPasswordField(ACCOUNT_USERNAME);
|
|
|
|
private final JPasswordField txtAccountLogin = new JPasswordField(ACCOUNT_USERNAME);
|
|
|
|
private final JPasswordField txtPasswordLogin = new JPasswordField(PASSWORD_LABEL);
|
|
|
|
private final JPasswordField txtPasswordLogin = new JPasswordField(PASSWORD_LABEL);
|
|
|
|
private final JPanel profilesPanel = new JPanel();
|
|
|
|
private final JPanel profilesPanel = new JPanel();
|
|
|
|
private final JPanel helpPanel = new JPanel(new BorderLayout());
|
|
|
|
|
|
|
|
private GridBagConstraints c;
|
|
|
|
private GridBagConstraints c;
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
@@ -108,6 +111,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
c.weighty = 0;
|
|
|
|
c.weighty = 0;
|
|
|
|
c.insets = new Insets(0, 0, 4, 0);
|
|
|
|
c.insets = new Insets(0, 0, 4, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JPanel helpPanel = new JPanel(new BorderLayout());
|
|
|
|
helpPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
|
|
|
helpPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
|
|
|
JLabel helpLabel = new JLabel("<html> <p>" + HELP + "</p></html>");
|
|
|
|
JLabel helpLabel = new JLabel("<html> <p>" + HELP + "</p></html>");
|
|
|
|
helpLabel.setFont(FontManager.getRunescapeSmallFont());
|
|
|
|
helpLabel.setFont(FontManager.getRunescapeSmallFont());
|
|
|
|
@@ -119,7 +123,6 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
c.gridy = c.gridy + 3;
|
|
|
|
c.gridy = c.gridy + 3;
|
|
|
|
c.gridy++;
|
|
|
|
c.gridy++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
txtDecryptPassword.setEchoChar((char) 0);
|
|
|
|
txtDecryptPassword.setEchoChar((char) 0);
|
|
|
|
txtDecryptPassword.setPreferredSize(PREFERRED_SIZE);
|
|
|
|
txtDecryptPassword.setPreferredSize(PREFERRED_SIZE);
|
|
|
|
txtDecryptPassword.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
|
|
|
|
txtDecryptPassword.setForeground(ColorScheme.MEDIUM_GRAY_COLOR);
|
|
|
|
@@ -154,6 +157,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
add(txtDecryptPassword, c);
|
|
|
|
add(txtDecryptPassword, c);
|
|
|
|
c.gridy++;
|
|
|
|
c.gridy++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JButton btnLoadAccounts = new JButton(LOAD_ACCOUNTS);
|
|
|
|
btnLoadAccounts.setPreferredSize(PREFERRED_SIZE);
|
|
|
|
btnLoadAccounts.setPreferredSize(PREFERRED_SIZE);
|
|
|
|
btnLoadAccounts.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
|
|
|
btnLoadAccounts.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
|
|
|
btnLoadAccounts.setMinimumSize(MINIMUM_SIZE);
|
|
|
|
btnLoadAccounts.setMinimumSize(MINIMUM_SIZE);
|
|
|
|
@@ -413,7 +417,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
// addAccounts(config.profilesData());
|
|
|
|
// addAccounts(config.profilesData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void redrawProfiles() throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
private void redrawProfiles() throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
profilesPanel.removeAll();
|
|
|
|
profilesPanel.removeAll();
|
|
|
|
c.gridy = 0;
|
|
|
|
c.gridy = 0;
|
|
|
|
@@ -433,7 +437,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
repaint();
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addAccounts(String data)
|
|
|
|
private void addAccounts(String data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// log.info("Data: " + data);
|
|
|
|
// log.info("Data: " + data);
|
|
|
|
data = data.trim();
|
|
|
|
data = data.trim();
|
|
|
|
@@ -444,7 +448,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
Arrays.stream(data.split("\\n")).forEach(this::addAccount);
|
|
|
|
Arrays.stream(data.split("\\n")).forEach(this::addAccount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean addProfile(String data) throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
private boolean addProfile(String data) throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return setProfileData(
|
|
|
|
return setProfileData(
|
|
|
|
getProfileData() + data + "\n");
|
|
|
|
getProfileData() + data + "\n");
|
|
|
|
@@ -459,12 +463,12 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setSalt(byte[] bytes)
|
|
|
|
private void setSalt(byte[] bytes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
profilesConfig.salt(base64Encode(bytes));
|
|
|
|
profilesConfig.salt(base64Encode(bytes));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
byte[] getSalt()
|
|
|
|
private byte[] getSalt()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (profilesConfig.salt().length() == 0)
|
|
|
|
if (profilesConfig.salt().length() == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -473,7 +477,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
return base64Decode(profilesConfig.salt());
|
|
|
|
return base64Decode(profilesConfig.salt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SecretKey getAesKey() throws NoSuchAlgorithmException, InvalidKeySpecException
|
|
|
|
private SecretKey getAesKey() throws NoSuchAlgorithmException, InvalidKeySpecException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (getSalt().length == 0)
|
|
|
|
if (getSalt().length == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -483,11 +487,10 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
|
|
|
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
|
|
|
KeySpec spec = new PBEKeySpec(txtDecryptPassword.getPassword(), getSalt(), iterations, 128);
|
|
|
|
KeySpec spec = new PBEKeySpec(txtDecryptPassword.getPassword(), getSalt(), iterations, 128);
|
|
|
|
SecretKey key = factory.generateSecret(spec);
|
|
|
|
return factory.generateSecret(spec);
|
|
|
|
return key;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String getProfileData() throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
private String getProfileData() throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String tmp = profilesConfig.profilesData();
|
|
|
|
String tmp = profilesConfig.profilesData();
|
|
|
|
if (tmp.startsWith("¬"))
|
|
|
|
if (tmp.startsWith("¬"))
|
|
|
|
@@ -503,7 +506,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
return tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean setProfileData(String data) throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
private boolean setProfileData(String data) throws InvalidKeySpecException, NoSuchAlgorithmException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (txtDecryptPassword.getPassword().length == 0 || String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD))
|
|
|
|
if (txtDecryptPassword.getPassword().length == 0 || String.valueOf(txtDecryptPassword.getPassword()).equals(UNLOCK_PASSWORD))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -512,18 +515,20 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
byte[] enc = encryptText(data, getAesKey());
|
|
|
|
byte[] enc = encryptText(data, getAesKey());
|
|
|
|
if (enc.length == 0)
|
|
|
|
if (enc.length == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
String s = "¬" + base64Encode(enc);
|
|
|
|
String s = "¬" + base64Encode(enc);
|
|
|
|
profilesConfig.profilesData(s);
|
|
|
|
profilesConfig.profilesData(s);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] base64Decode(String data)
|
|
|
|
private byte[] base64Decode(String data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Base64.getDecoder().decode(data);
|
|
|
|
return Base64.getDecoder().decode(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String base64Encode(byte[] data)
|
|
|
|
private String base64Encode(byte[] data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Base64.getEncoder().encodeToString(data);
|
|
|
|
return Base64.getEncoder().encodeToString(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -534,7 +539,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
* @param text text to encrypt
|
|
|
|
* @param text text to encrypt
|
|
|
|
* @return encrypted string
|
|
|
|
* @return encrypted string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static byte[] encryptText(String text, SecretKey aesKey)
|
|
|
|
private static byte[] encryptText(String text, SecretKey aesKey)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -550,7 +555,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
return new byte[0];
|
|
|
|
return new byte[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String decryptText(byte[] enc, SecretKey aesKey)
|
|
|
|
private static String decryptText(byte[] enc, SecretKey aesKey)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -566,7 +571,7 @@ class ProfilesPanel extends PluginPanel
|
|
|
|
return "";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void showErrorMessage(String title, String text)
|
|
|
|
private static void showErrorMessage(String title, String text)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(null,
|
|
|
|
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(null,
|
|
|
|
text,
|
|
|
|
text,
|
|
|
|
|