Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialogs #79

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/main/java/burp/JWTEditorExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.blackberry.jwteditor.view.editor.WebSocketEditorView;
import com.blackberry.jwteditor.view.hexcodearea.HexCodeAreaFactory;
import com.blackberry.jwteditor.view.rsta.RstaFactory;
import com.blackberry.jwteditor.view.utils.ErrorLoggingActionListenerFactory;

import java.awt.*;

Expand Down Expand Up @@ -69,7 +68,6 @@ public void initialize(MontoyaApi api) {
userInterface.registerSuiteTab(suiteView.getTabCaption(), suiteView.getUiComponent());

HexCodeAreaFactory hexAreaCodeFactory = new HexCodeAreaFactory(api.logging(), api.userInterface());
ErrorLoggingActionListenerFactory actionListenerFactory = new ErrorLoggingActionListenerFactory(api.logging());
InformationPanelFactory informationPanelFactory = new InformationPanelFactory(api.userInterface(), api.logging());

userInterface.registerHttpRequestEditorProvider(editorCreationContext ->
Expand All @@ -78,7 +76,7 @@ public void initialize(MontoyaApi api) {
rstaFactory,
api.collaborator().defaultPayloadGenerator(),
hexAreaCodeFactory,
actionListenerFactory,
api.logging(),
informationPanelFactory,
editorCreationContext.editorMode() != READ_ONLY,
isProVersion
Expand All @@ -91,7 +89,7 @@ public void initialize(MontoyaApi api) {
rstaFactory,
api.collaborator().defaultPayloadGenerator(),
hexAreaCodeFactory,
actionListenerFactory,
api.logging(),
informationPanelFactory,
editorCreationContext.editorMode() != READ_ONLY,
isProVersion
Expand All @@ -104,7 +102,7 @@ public void initialize(MontoyaApi api) {
rstaFactory,
api.collaborator().defaultPayloadGenerator(),
hexAreaCodeFactory,
actionListenerFactory,
api.logging(),
informationPanelFactory,
editorCreationContext.editorMode() != READ_ONLY,
isProVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.blackberry.jwteditor.presenter;

import burp.api.montoya.collaborator.CollaboratorPayloadGenerator;
import burp.api.montoya.logging.Logging;
import com.blackberry.jwteditor.model.jose.*;
import com.blackberry.jwteditor.model.keys.Key;
import com.blackberry.jwteditor.model.keys.KeyRing;
Expand All @@ -28,7 +29,6 @@
import com.blackberry.jwteditor.view.dialog.operations.*;
import com.blackberry.jwteditor.view.editor.EditorMode;
import com.blackberry.jwteditor.view.editor.EditorView;
import com.blackberry.jwteditor.view.utils.ErrorLoggingActionListenerFactory;
import com.nimbusds.jose.util.Base64URL;
import org.json.JSONException;

Expand All @@ -45,6 +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.SignDialog.Mode.EMBED_JWK;

/**
* Presenter class for the Editor tab
Expand All @@ -54,7 +55,7 @@ public class EditorPresenter {
private final KeysRepository keysRepository;
private final EditorView view;
private final CollaboratorPayloadGenerator collaboratorPayloadGenerator;
private final ErrorLoggingActionListenerFactory actionListenerFactory;
private final Logging logging;
private final MessageDialogFactory messageDialogFactory;
private final EditorModel model;

Expand All @@ -63,11 +64,11 @@ public class EditorPresenter {
public EditorPresenter(
EditorView view,
CollaboratorPayloadGenerator collaboratorPayloadGenerator,
ErrorLoggingActionListenerFactory actionListenerFactory,
Logging logging,
KeysRepository keysRepository) {
this.view = view;
this.collaboratorPayloadGenerator = collaboratorPayloadGenerator;
this.actionListenerFactory = actionListenerFactory;
this.logging = logging;
this.keysRepository = keysRepository;
this.model = new EditorModel();
this.messageDialogFactory = new MessageDialogFactory(view.uiComponent());
Expand Down Expand Up @@ -188,7 +189,7 @@ private JWE getJWE() {
* Handle clicks events from the Embedded JWK Attack button
*/
public void onAttackEmbedJWKClicked() {
signingDialog(SignDialog.Mode.EMBED_JWK);
signingDialog(EMBED_JWK);
}

/**
Expand All @@ -210,78 +211,45 @@ public void onAttackKeyConfusionClicked() {
return;
}

// Create the key confusion attack dialog with the JWS currently in the editor fields
KeyConfusionAttackDialog keyConfusionAttackDialog = new KeyConfusionAttackDialog(
OperationDialog<JWS> dialog = new KeyConfusionAttackDialog(
view.window(),
actionListenerFactory,
logging,
verificationKeys,
getJWS()
);
keyConfusionAttackDialog.display();

// Set the result as the JWS in the editor if the attack succeeds
JWS signedJWS = keyConfusionAttackDialog.getJWS();
if (signedJWS != null) {
setJWS(signedJWS);
}
showDialogAndUpdateJWS(dialog);
}

/**
* Handle clicks events from the none Signing algorithm button
*/
public void onAttackSignNoneClicked() {
// Get the JWS from the editor, strip the signature and set the editor to the new JWS
NoneDialog noneDialog = new NoneDialog(view.window(), getJWS());
noneDialog.display();
OperationDialog<JWS> dialog = new NoneDialog(view.window(), logging, getJWS());

JWS unsignedJWS = noneDialog.getJWS();

if (unsignedJWS != null) {
setJWS(unsignedJWS);
}
showDialogAndUpdateJWS(dialog);
}

public void onAttackSignEmptyKeyClicked() {
EmptyKeySigningDialog signingDialog = new EmptyKeySigningDialog(view.window(), actionListenerFactory, getJWS());
signingDialog.display();

JWS signedJWS = signingDialog.getJWS();
OperationDialog<JWS> dialog = new EmptyKeySigningDialog(view.window(), logging, getJWS());

if (signedJWS != null) {
setJWS(signedJWS);
}
showDialogAndUpdateJWS(dialog);
}

public void onAttackPsychicSignatureClicked() {
PsychicSignatureDialog signingDialog = new PsychicSignatureDialog(view.window(), getJWS());
signingDialog.display();

JWS signedJWS = signingDialog.getJWS();
OperationDialog<JWS> dialog = new PsychicSignatureDialog(view.window(), logging, getJWS());

if (signedJWS != null) {
setJWS(signedJWS);
}
showDialogAndUpdateJWS(dialog);
}

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

collaboratorPayloadDialog.display();

JWS updatedJWS = collaboratorPayloadDialog.getJWS();

if (updatedJWS != null) {
setJWS(updatedJWS);
}
showDialogAndUpdateJWS(dialog);
}

/**
* Handle click events from the Sign button
*/
public void onSignClicked() {
signingDialog(SignDialog.Mode.NORMAL);
}
Expand All @@ -298,19 +266,24 @@ private void signingDialog(SignDialog.Mode mode) {
return;
}

SignDialog signDialog = new SignDialog(
OperationDialog<JWS> signDialog = new SignDialog(
view.window(),
actionListenerFactory,
logging,
keysRepository.getSigningKeys(),
getJWS(),
mode
);
signDialog.display();

// If a JWS was created by the dialog, replace the contents of the editor
JWS signedJWS = signDialog.getJWS();
if (signedJWS != null) {
setJWS(signedJWS);
showDialogAndUpdateJWS(signDialog);
}

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

JWS updatedJWS = dialog.getJWT();

if (updatedJWS != null) {
setJWS(updatedJWS);
}
}

Expand Down Expand Up @@ -342,16 +315,16 @@ public void onEncryptClicked() {
return;
}

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

// If a JWE was created by the dialog, replace the contents of the editor and change to JWE mode
JWE jwe = encryptDialog.getJWE();
JWE jwe = encryptDialog.getJWT();

if (jwe != null) {
view.setMode(EditorMode.JWE);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
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 com.blackberry.jwteditor.view.dialog.AbstractDialog;

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

import static com.nimbusds.jose.HeaderParameterNames.JWK_SET_URL;
import static com.nimbusds.jose.HeaderParameterNames.X_509_CERT_URL;

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

private final CollaboratorPayloadGenerator collaboratorPayloadGenerator;
Expand All @@ -39,43 +38,25 @@ public class EmbedCollaboratorPayloadDialog extends AbstractDialog {
private JButton buttonOK;
private JButton buttonCancel;
private JComboBox<String> comboBoxAlgorithm;
private JWS jws;

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

setContentPane(contentPane);
getRootPane().setDefaultButton(buttonOK);

buttonOK.addActionListener(e -> onOK());
buttonCancel.addActionListener(e -> onCancel());

// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(
e -> onCancel(),
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
);
configureUI(contentPane, buttonOK, buttonCancel);

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

public JWS getJWS() {
return jws;
}

private void onOK() {
@Override
JWS performOperation() {
String selectedLocation = (String) comboBoxAlgorithm.getSelectedItem();

jws = Attacks.embedCollaboratorPayload(
jws,
return Attacks.embedCollaboratorPayload(
jwt,
selectedLocation,
collaboratorPayloadGenerator.generatePayload().toString()
);

dispose();
}
}
Loading
Loading