Skip to content

Commit

Permalink
Merge pull request #97 from DolphFlynn/dialogs
Browse files Browse the repository at this point in the history
Convert operation dialogs to panels and use generic dialog.
  • Loading branch information
DolphFlynn authored Jan 11, 2025
2 parents 8c57c37 + ac2d7c9 commit 19bf5a9
Show file tree
Hide file tree
Showing 23 changed files with 496 additions and 775 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import static com.blackberry.jwteditor.utils.Base64URLUtils.base64UrlEncodeJson;
import static com.blackberry.jwteditor.utils.JSONUtils.isJsonCompact;
import static com.blackberry.jwteditor.utils.JSONUtils.prettyPrintJSON;
import static com.blackberry.jwteditor.view.dialog.operations.SigningDialog.Mode.EMBED_JWK;
import static com.blackberry.jwteditor.view.dialog.operations.SigningPanel.Mode.EMBED_JWK;

/**
* Presenter class for the Editor tab
Expand Down Expand Up @@ -208,44 +208,23 @@ public void onAttackKeyConfusionClicked() {
return;
}

OperationDialog<JWS> dialog = new KeyConfusionAttackDialog(
view.window(),
logging,
attackKeys,
lastSigningKeys,
getJWS()
);

showDialogAndUpdateJWS(dialog);
showDialogAndUpdateJWS(new KeyConfusionAttackPanel(attackKeys, lastSigningKeys));
}

public void onAttackSignNoneClicked() {
OperationDialog<JWS> dialog = new NoneDialog(view.window(), logging, getJWS());

showDialogAndUpdateJWS(dialog);
showDialogAndUpdateJWS(new NoneOperation());
}

public void onAttackSignEmptyKeyClicked() {
OperationDialog<JWS> dialog = new EmptyKeySigningDialog(view.window(), logging, getJWS());

showDialogAndUpdateJWS(dialog);
showDialogAndUpdateJWS(new EmptyKeySigningPanel());
}

public void onAttackPsychicSignatureClicked() {
OperationDialog<JWS> dialog = new PsychicSignatureDialog(view.window(), logging, getJWS());

showDialogAndUpdateJWS(dialog);
showDialogAndUpdateJWS(new PsychicSignaturePanel());
}

public void onAttackEmbedCollaboratorPayloadClicked() {
OperationDialog<JWS> dialog = new EmbedCollaboratorPayloadDialog(
view.window(),
logging,
getJWS(),
collaboratorPayloadGenerator
);

showDialogAndUpdateJWS(dialog);
showDialogAndUpdateJWS(new EmbedCollaboratorPayloadPanel(collaboratorPayloadGenerator));
}

public void onAttackWeakHMACSecret() {
Expand All @@ -261,34 +240,32 @@ public void onAttackWeakHMACSecret() {
}

public void onSignClicked() {
signingDialog(SigningDialog.Mode.NORMAL);
signingDialog(SigningPanel.Mode.NORMAL);
}

/**
* Create a signing dialog based on the provided mode
*
* @param mode mode of the signing dialog to display
*/
private void signingDialog(SigningDialog.Mode mode) {
private void signingDialog(SigningPanel.Mode mode) {
// Check there are signing keys in the keystore
if (keysRepository.getSigningKeys().isEmpty()) {
messageDialogFactory.showWarningDialog("error_title_no_signing_keys", "error_no_signing_keys");
return;
}

OperationDialog<JWS> signDialog = new SigningDialog(
showDialogAndUpdateJWS(new SigningPanel(keysRepository.getSigningKeys(), mode, lastSigningKeys));
}

private void showDialogAndUpdateJWS(Operation<JWS, JWS> operation) {
OperationDialog<JWS, JWS> dialog = new OperationDialog<>(
view.window(),
logging,
keysRepository.getSigningKeys(),
getJWS(),
mode,
lastSigningKeys
operation,
getJWS()
);

showDialogAndUpdateJWS(signDialog);
}

private void showDialogAndUpdateJWS(OperationDialog<JWS> dialog) {
dialog.display();

JWS updatedJWS = dialog.getJWT();
Expand All @@ -298,9 +275,6 @@ private void showDialogAndUpdateJWS(OperationDialog<JWS> dialog) {
}
}

/**
* Handle click events from the Verify button
*/
public void onVerifyClicked() {
List<Key> keys = keysRepository.getVerificationKeys();

Expand All @@ -326,11 +300,11 @@ public void onEncryptClicked() {
return;
}

OperationDialog<JWE> encryptDialog = new EncryptDialog(
OperationDialog<JWE, JWS> encryptDialog = new OperationDialog<>(
view.window(),
logging,
getJWS(),
keysRepository.getEncryptionKeys()
new EncryptPanel(keysRepository.getEncryptionKeys()),
getJWS()
);
encryptDialog.display();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.blackberry.jwteditor.view.dialog.operations.EmbedCollaboratorPayloadPanel">
<grid id="cbd77" binding="panel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="129" width="427" height="104"/>
</constraints>
<properties/>
<border type="none">
<title-color color="-4473925"/>
</border>
<children>
<grid id="55a21" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="2" left="5" bottom="5" right="5"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="line" title-resource-bundle="strings" title-key="embed_collaborator_payload_location">
<color color="-4473925"/>
</border>
<children>
<component id="f7fed" class="javax.swing.JComboBox" binding="comboBoxAlgorithm">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,39 @@
package com.blackberry.jwteditor.view.dialog.operations;

import burp.api.montoya.collaborator.CollaboratorPayloadGenerator;
import burp.api.montoya.logging.Logging;
import com.blackberry.jwteditor.model.jose.JWS;
import com.blackberry.jwteditor.operations.Attacks;

import javax.swing.*;
import java.awt.*;

import static com.nimbusds.jose.HeaderParameterNames.JWK_SET_URL;
import static com.nimbusds.jose.HeaderParameterNames.X_509_CERT_URL;
import static java.awt.BorderLayout.CENTER;

public class EmbedCollaboratorPayloadDialog extends OperationDialog<JWS> {
public class EmbedCollaboratorPayloadPanel extends OperationPanel<JWS, JWS> {
private static final String[] HEADER_LOCATION_VALUES = {JWK_SET_URL, X_509_CERT_URL};

private final CollaboratorPayloadGenerator collaboratorPayloadGenerator;

private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JPanel panel;
private JComboBox<String> comboBoxAlgorithm;

public EmbedCollaboratorPayloadDialog(Window parent, Logging logging, JWS jws, CollaboratorPayloadGenerator collaboratorPayloadGenerator) {
super(parent, logging, "embed_collaborator_payload_attack_dialog_title", jws);
public EmbedCollaboratorPayloadPanel(CollaboratorPayloadGenerator collaboratorPayloadGenerator) {
super("embed_collaborator_payload_attack_dialog_title");
this.collaboratorPayloadGenerator = collaboratorPayloadGenerator;

configureUI(contentPane, buttonOK, buttonCancel);

comboBoxAlgorithm.setModel(new DefaultComboBoxModel<>(HEADER_LOCATION_VALUES));
comboBoxAlgorithm.setSelectedIndex(0);

add(panel, CENTER);
}

@Override
JWS performOperation() {
public JWS performOperation(JWS originalJwt) {
String selectedLocation = (String) comboBoxAlgorithm.getSelectedItem();

return Attacks.embedCollaboratorPayload(
jwt,
originalJwt,
selectedLocation,
collaboratorPayloadGenerator.generatePayload().toString()
);
Expand Down
Loading

0 comments on commit 19bf5a9

Please sign in to comment.