From 02605575dd7cd57214e31a288e99084abe71059a Mon Sep 17 00:00:00 2001 From: Doge Date: Sat, 12 Oct 2024 20:28:25 +0100 Subject: [PATCH] Restore default keys and salts --- .../burp/config/BurpKeysModelPersistence.java | 32 +++++---- .../d4d/signsaboteur/forms/WordlistView.form | 34 +++++++--- .../d4d/signsaboteur/forms/WordlistView.java | 4 ++ .../signsaboteur/presenter/KeyPresenter.java | 68 ++++++++++++++----- .../one/d4d/signsaboteur/utils/Utils.java | 4 +- 5 files changed, 101 insertions(+), 41 deletions(-) diff --git a/src/main/java/burp/config/BurpKeysModelPersistence.java b/src/main/java/burp/config/BurpKeysModelPersistence.java index a2023f0..951f9fc 100644 --- a/src/main/java/burp/config/BurpKeysModelPersistence.java +++ b/src/main/java/burp/config/BurpKeysModelPersistence.java @@ -31,21 +31,29 @@ public KeysModel loadOrCreateNew() { Gson gson = GsonHelper.customGson; KeysModel keysModel = gson.fromJson(json, KeysModel.class); - if (keysModel.getSaltsFilePath() != null) { - Set result = Utils.deserializeFile(new File(keysModel.getSaltsFilePath())); - if (result.isEmpty()) { - keysModel.setSalts(loadDefaultSalts()); - } else { - keysModel.setSalts(result); + try { + if (keysModel.getSaltsFilePath() != null) { + Set result = Utils.deserializeFile(new File(keysModel.getSaltsFilePath())); + if (result.isEmpty()) { + keysModel.setSalts(loadDefaultSalts()); + } else { + keysModel.setSalts(result); + } } + } catch (Exception e) { + keysModel.setSalts(loadDefaultSalts()); } - if (keysModel.getSecretsFilePath() != null) { - Set result = Utils.deserializeFile(new File(keysModel.getSecretsFilePath())); - if (result.isEmpty()) { - keysModel.setSecrets(loadDefaultSecrets()); - } else { - keysModel.setSecrets(result); + try { + if (keysModel.getSecretsFilePath() != null) { + Set result = Utils.deserializeFile(new File(keysModel.getSecretsFilePath())); + if (result.isEmpty()) { + keysModel.setSecrets(loadDefaultSecrets()); + } else { + keysModel.setSecrets(result); + } } + } catch (Exception e) { + keysModel.setSecrets(loadDefaultSecrets()); } return keysModel; } diff --git a/src/main/java/one/d4d/signsaboteur/forms/WordlistView.form b/src/main/java/one/d4d/signsaboteur/forms/WordlistView.form index 6decb62..36cb380 100644 --- a/src/main/java/one/d4d/signsaboteur/forms/WordlistView.form +++ b/src/main/java/one/d4d/signsaboteur/forms/WordlistView.form @@ -3,7 +3,7 @@ - + @@ -16,7 +16,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -50,12 +50,20 @@ - + + + + + + + + + @@ -120,7 +128,7 @@ - + @@ -138,7 +146,7 @@ - + @@ -146,7 +154,7 @@ - + @@ -154,12 +162,20 @@ - + + + + + + + + + diff --git a/src/main/java/one/d4d/signsaboteur/forms/WordlistView.java b/src/main/java/one/d4d/signsaboteur/forms/WordlistView.java index c8db7df..6adf103 100644 --- a/src/main/java/one/d4d/signsaboteur/forms/WordlistView.java +++ b/src/main/java/one/d4d/signsaboteur/forms/WordlistView.java @@ -42,6 +42,8 @@ public class WordlistView { private JButton secretsAddButton; private JButton saltsAddButton; private JButton buttonLoadDefaults; + private JButton secretsLoadDefaultsButton; + private JButton saltsLoadDefaultsButton; private JMenuItem menuItemDelete; private JMenuItem menuItemCopy; @@ -82,11 +84,13 @@ public WordlistView( modelSalts); secretsLoadButton.addActionListener(presenter::onButtonLoadSecretsClick); + secretsLoadDefaultsButton.addActionListener(presenter::onButtonLoadDefaultsSecretsClick); secretsAddButton.addActionListener(presenter::onButtonAddSecretsClick); secretsRemoveButton.addActionListener(presenter::onButtonRemoveSecretsClick); secretsCleanButton.addActionListener(presenter::onButtonCleanSecretsClick); saltsLoadButton.addActionListener(presenter::onButtonLoadSaltsClick); + saltsLoadDefaultsButton.addActionListener(presenter::onButtonLoadDefaultsSaltsClick); saltsAddButton.addActionListener(presenter::onButtonAddSaltsClick); saltsRemoveButton.addActionListener(presenter::onButtonRemoveSaltsClick); saltsCleanButton.addActionListener(presenter::onButtonCleanSaltsClick); diff --git a/src/main/java/one/d4d/signsaboteur/presenter/KeyPresenter.java b/src/main/java/one/d4d/signsaboteur/presenter/KeyPresenter.java index c6e9b40..b995ff7 100644 --- a/src/main/java/one/d4d/signsaboteur/presenter/KeyPresenter.java +++ b/src/main/java/one/d4d/signsaboteur/presenter/KeyPresenter.java @@ -53,6 +53,9 @@ public void notifyKeyDeleted(int rowIndex) { public void onButtonLoadSecretsClick(ActionEvent e) { readSecretsFromFile(e); } + public void onButtonLoadDefaultsSecretsClick(ActionEvent e) { + readDefaultSecrets(); + } public void onButtonAddSecretsClick(ActionEvent e) { NewWordDialog d = new NewWordDialog(view.getParent()); @@ -87,6 +90,9 @@ public void onButtonCleanSecretsClick(ActionEvent e) { public void onButtonLoadSaltsClick(ActionEvent e) { readSaltsFromFile(e); } + public void onButtonLoadDefaultsSaltsClick(ActionEvent e) { + readDefaultSalts(); + } public void onButtonAddSaltsClick(ActionEvent e) { @@ -175,37 +181,63 @@ public void onPopupCopy(int row) { Utils.copyToClipboard(prettyPrintJSON(key.toJSONString())); } + private void readDefaultSecrets() { + Set s = Utils.readResourceForClass("/secrets", this.getClass()); + if (!s.isEmpty()) { + model.setSecrets(s); + model.setSecretsFilePath(""); + modelSecrets.clear(); + modelSecrets.addAll(s); + view.getSecretsTextArea().setText(""); + keysModelPersistence.save(model); + } + } private void readSecretsFromFile(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(view.getUiComponent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); - Set s = Utils.deserializeFile(selectedFile); - if (!s.isEmpty()) { - model.setSecrets(s); - model.setSecretsFilePath(selectedFile.getAbsolutePath()); - modelSecrets.clear(); - modelSecrets.addAll(s); - view.getSecretsTextArea().setText(selectedFile.getAbsolutePath()); - keysModelPersistence.save(model); + try { + Set s = Utils.deserializeFile(selectedFile); + if (!s.isEmpty()) { + model.setSecrets(s); + model.setSecretsFilePath(selectedFile.getAbsolutePath()); + modelSecrets.clear(); + modelSecrets.addAll(s); + view.getSecretsTextArea().setText(selectedFile.getAbsolutePath()); + keysModelPersistence.save(model); + } + } catch (Exception ignored) { } } } - + private void readDefaultSalts() { + Set s = Utils.readResourceForClass("/salts", this.getClass()); + if (!s.isEmpty()) { + model.setSalts(s); + model.setSaltsFilePath(""); + modelSalts.clear(); + modelSalts.addAll(s); + view.getSaltsTextArea().setText(""); + keysModelPersistence.save(model); + } + } private void readSaltsFromFile(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(view.getUiComponent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); - Set s = Utils.deserializeFile(selectedFile); - if (!s.isEmpty()) { - model.setSalts(s); - model.setSaltsFilePath(selectedFile.getAbsolutePath()); - modelSalts.clear(); - modelSalts.addAll(s); - view.getSaltsTextArea().setText(selectedFile.getAbsolutePath()); - keysModelPersistence.save(model); - } + try { + Set s = Utils.deserializeFile(selectedFile); + if (!s.isEmpty()) { + model.setSalts(s); + model.setSaltsFilePath(selectedFile.getAbsolutePath()); + modelSalts.clear(); + modelSalts.addAll(s); + view.getSaltsTextArea().setText(selectedFile.getAbsolutePath()); + keysModelPersistence.save(model); + } + } catch (Exception ignored) {} } } diff --git a/src/main/java/one/d4d/signsaboteur/utils/Utils.java b/src/main/java/one/d4d/signsaboteur/utils/Utils.java index 77a56de..8cd7740 100644 --- a/src/main/java/one/d4d/signsaboteur/utils/Utils.java +++ b/src/main/java/one/d4d/signsaboteur/utils/Utils.java @@ -454,7 +454,7 @@ public static String compactJSON(String json) { } - public static Set deserializeFile(File f) { + public static Set deserializeFile(File f) throws Exception{ Set result = new HashSet<>(); Gson gson = new Gson(); try (Stream lines = Files.lines(f.toPath())) { @@ -466,7 +466,7 @@ public static Set deserializeFile(File f) { } }); } catch (IOException ex) { - return result; + throw new Exception(); } return result; }