Skip to content

Commit

Permalink
Merge pull request #7 from d0ge/6-reload-the-built-in-lists
Browse files Browse the repository at this point in the history
Restore default keys and salts
  • Loading branch information
d0ge authored Oct 12, 2024
2 parents baf4c3f + 0260557 commit c19dee3
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 41 deletions.
32 changes: 20 additions & 12 deletions src/main/java/burp/config/BurpKeysModelPersistence.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,29 @@ public KeysModel loadOrCreateNew() {

Gson gson = GsonHelper.customGson;
KeysModel keysModel = gson.fromJson(json, KeysModel.class);
if (keysModel.getSaltsFilePath() != null) {
Set<String> result = Utils.deserializeFile(new File(keysModel.getSaltsFilePath()));
if (result.isEmpty()) {
keysModel.setSalts(loadDefaultSalts());
} else {
keysModel.setSalts(result);
try {
if (keysModel.getSaltsFilePath() != null) {
Set<String> 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<String> result = Utils.deserializeFile(new File(keysModel.getSecretsFilePath()));
if (result.isEmpty()) {
keysModel.setSecrets(loadDefaultSecrets());
} else {
keysModel.setSecrets(result);
try {
if (keysModel.getSecretsFilePath() != null) {
Set<String> 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;
}
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/one/d4d/signsaboteur/forms/WordlistView.form
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="601"/>
<xy x="20" y="20" width="500" height="671"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -16,7 +16,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="14ed4" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="14ed4" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -26,7 +26,7 @@
<children>
<component id="19c2b" class="javax.swing.JButton" binding="secretsCleanButton">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_clean"/>
Expand All @@ -42,20 +42,28 @@
</component>
<component id="4034f" class="javax.swing.JButton" binding="secretsRemoveButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_remove"/>
</properties>
</component>
<component id="c0cf9" class="javax.swing.JButton" binding="secretsAddButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_add_label"/>
</properties>
</component>
<component id="739e1" class="javax.swing.JButton" binding="secretsLoadDefaultsButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_load_defaults"/>
</properties>
</component>
</children>
</grid>
<scrollpane id="64d96">
Expand Down Expand Up @@ -120,7 +128,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="ed6f3" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="ed6f3" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -138,28 +146,36 @@
</component>
<component id="96db8" class="javax.swing.JButton" binding="saltsRemoveButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_remove"/>
</properties>
</component>
<component id="856e7" class="javax.swing.JButton" binding="saltsCleanButton">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_clean"/>
</properties>
</component>
<component id="b72e9" class="javax.swing.JButton" binding="saltsAddButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_add_label"/>
</properties>
</component>
<component id="5555b" class="javax.swing.JButton" binding="saltsLoadDefaultsButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="strings" key="button_load_defaults"/>
</properties>
</component>
</children>
</grid>
<scrollpane id="b7e21">
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/one/d4d/signsaboteur/forms/WordlistView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
68 changes: 50 additions & 18 deletions src/main/java/one/d4d/signsaboteur/presenter/KeyPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -175,37 +181,63 @@ public void onPopupCopy(int row) {
Utils.copyToClipboard(prettyPrintJSON(key.toJSONString()));
}

private void readDefaultSecrets() {
Set<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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) {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/one/d4d/signsaboteur/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public static String compactJSON(String json) {
}


public static Set<String> deserializeFile(File f) {
public static Set<String> deserializeFile(File f) throws Exception{
Set<String> result = new HashSet<>();
Gson gson = new Gson();
try (Stream<String> lines = Files.lines(f.toPath())) {
Expand All @@ -466,7 +466,7 @@ public static Set<String> deserializeFile(File f) {
}
});
} catch (IOException ex) {
return result;
throw new Exception();
}
return result;
}
Expand Down

0 comments on commit c19dee3

Please sign in to comment.