Skip to content

Commit

Permalink
Merge pull request #101 from DolphFlynn/op
Browse files Browse the repository at this point in the history
Op
  • Loading branch information
DolphFlynn authored Jan 12, 2025
2 parents 0fbbdb6 + 337f7f9 commit a985b3d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
<text resource-bundle="strings" key="encrypt"/>
</properties>
</component>
<component id="6588e" class="javax.swing.JButton" binding="buttonAttack" custom-create="true">
<component id="6588e" class="javax.swing.JButton" binding="buttonAttack">
<constraints>
<grid row="0" 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>
Expand Down
44 changes: 7 additions & 37 deletions src/main/java/com/blackberry/jwteditor/view/editor/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public abstract class EditorView {
private final boolean editable;
private final HexCodeAreaFactory hexCodeAreaFactory;
private final InformationPanel informationPanel;
private final boolean isProVersion;

private EditorMode mode;
private JTabbedPane tabbedPane;
Expand Down Expand Up @@ -114,10 +113,15 @@ public abstract class EditorView {
this.rstaFactory = rstaFactory;
this.editable = editable;
this.hexCodeAreaFactory = hexAreaCodeFactory;
this.isProVersion = isProVersion;

// IntelliJ generated code inserted here

this.presenter = new EditorPresenter(this, collaboratorPayloadGenerator, logging, keysRepository);
this.informationPanel = informationPanelFactory.build();

EditorViewAttackMenuFactory attackMenuFactory = new EditorViewAttackMenuFactory(presenter, isProVersion);
buttonAttack.setComponentPopupMenu(attackMenuFactory.buildAttackPopupMenu());

informationScrollPane.setViewportView(informationPanel);

panel.addHierarchyListener(new RunEDTActionOnFirstRenderHierarchyListener(
Expand Down Expand Up @@ -159,6 +163,7 @@ public abstract class EditorView {
buttonEncrypt.addActionListener(e -> presenter.onEncryptClicked());
buttonDecrypt.addActionListener(e -> presenter.onDecryptClicked());
buttonCopy.addActionListener(e -> presenter.onCopyClicked());
buttonAttack.addActionListener(e -> onAttackClicked());
}

/**
Expand Down Expand Up @@ -511,41 +516,6 @@ private void createUIComponents() {
codeAreaTag = hexCodeAreaFactory.build();
panelTag.add(codeAreaTag, BorderLayout.CENTER);

// Create the Attack popup menu
JPopupMenu popupMenuAttack = new JPopupMenu();
JMenuItem menuItemAttackEmbedJWK = new JMenuItem(Utils.getResourceString("editor_view_button_attack_embed_jwk"));
JMenuItem menuItemAttackSignNone = new JMenuItem(Utils.getResourceString("editor_view_button_attack_sign_none"));
JMenuItem menuItemAttackKeyConfusion = new JMenuItem(Utils.getResourceString("editor_view_button_attack_key_confusion"));
JMenuItem menuItemAttackSignEmptyKey = new JMenuItem(Utils.getResourceString("editor_view_button_attack_sign_empty_key"));
JMenuItem menuItemAttackSignPsychicSignature = new JMenuItem(Utils.getResourceString("editor_view_button_attack_sign_psychic_signature"));
JMenuItem menuItemAttackEmbedCollaboratorPayload = new JMenuItem(Utils.getResourceString("editor_view_button_attack_embed_collaborator_payload"));
JMenuItem menuItemAttackWeakSymmetricKey = new JMenuItem(Utils.getResourceString("editor_view_button_attack_weak_symmetric_key"));

// Attach the event handlers to the popup menu click events
menuItemAttackEmbedJWK.addActionListener(e -> presenter.onAttackEmbedJWKClicked());
menuItemAttackKeyConfusion.addActionListener(e -> presenter.onAttackKeyConfusionClicked());
menuItemAttackSignNone.addActionListener(e -> presenter.onAttackSignNoneClicked());
menuItemAttackSignEmptyKey.addActionListener(e -> presenter.onAttackSignEmptyKeyClicked());
menuItemAttackSignPsychicSignature.addActionListener(e -> presenter.onAttackPsychicSignatureClicked());
menuItemAttackEmbedCollaboratorPayload.addActionListener(e -> presenter.onAttackEmbedCollaboratorPayloadClicked());
menuItemAttackWeakSymmetricKey.addActionListener(e -> presenter.onAttackWeakHMACSecret());

menuItemAttackEmbedCollaboratorPayload.setEnabled(isProVersion);

// Add the buttons to the popup menu
popupMenuAttack.add(menuItemAttackEmbedJWK);
popupMenuAttack.add(menuItemAttackSignNone);
popupMenuAttack.add(menuItemAttackKeyConfusion);
popupMenuAttack.add(menuItemAttackSignEmptyKey);
popupMenuAttack.add(menuItemAttackSignPsychicSignature);
popupMenuAttack.add(menuItemAttackEmbedCollaboratorPayload);
popupMenuAttack.add(menuItemAttackWeakSymmetricKey);

// Associate the popup menu to the Attack button
buttonAttack = new JButton();
buttonAttack.setComponentPopupMenu(popupMenuAttack);
buttonAttack.addActionListener(e -> onAttackClicked());

textAreaSerialized = rstaFactory.buildSerializedJWTTextArea();
textAreaJWEHeader = rstaFactory.buildDefaultTextArea();
textAreaJWSHeader = rstaFactory.buildDefaultTextArea();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Author : Dolph Flynn
Copyright 2025 Dolph Flynn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.blackberry.jwteditor.view.editor;

import com.blackberry.jwteditor.presenter.EditorPresenter;
import com.blackberry.jwteditor.utils.Utils;

import javax.swing.*;

class EditorViewAttackMenuFactory {
private final EditorPresenter presenter;
private final boolean isProVersion;

EditorViewAttackMenuFactory(EditorPresenter presenter, boolean isProVersion) {
this.presenter = presenter;
this.isProVersion = isProVersion;
}

JPopupMenu buildAttackPopupMenu() {

JPopupMenu popupMenuAttack = new JPopupMenu();
JMenuItem menuItemAttackEmbedJWK = new JMenuItem(Utils.getResourceString("editor_view_button_attack_embed_jwk"));
JMenuItem menuItemAttackSignNone = new JMenuItem(Utils.getResourceString("editor_view_button_attack_sign_none"));
JMenuItem menuItemAttackKeyConfusion = new JMenuItem(Utils.getResourceString("editor_view_button_attack_key_confusion"));
JMenuItem menuItemAttackSignEmptyKey = new JMenuItem(Utils.getResourceString("editor_view_button_attack_sign_empty_key"));
JMenuItem menuItemAttackSignPsychicSignature = new JMenuItem(Utils.getResourceString("editor_view_button_attack_sign_psychic_signature"));
JMenuItem menuItemAttackEmbedCollaboratorPayload = new JMenuItem(Utils.getResourceString("editor_view_button_attack_embed_collaborator_payload"));
JMenuItem menuItemAttackWeakSymmetricKey = new JMenuItem(Utils.getResourceString("editor_view_button_attack_weak_symmetric_key"));

menuItemAttackEmbedJWK.addActionListener(e -> presenter.onAttackEmbedJWKClicked());
menuItemAttackKeyConfusion.addActionListener(e -> presenter.onAttackKeyConfusionClicked());
menuItemAttackSignNone.addActionListener(e -> presenter.onAttackSignNoneClicked());
menuItemAttackSignEmptyKey.addActionListener(e -> presenter.onAttackSignEmptyKeyClicked());
menuItemAttackSignPsychicSignature.addActionListener(e -> presenter.onAttackPsychicSignatureClicked());
menuItemAttackEmbedCollaboratorPayload.addActionListener(e -> presenter.onAttackEmbedCollaboratorPayloadClicked());
menuItemAttackWeakSymmetricKey.addActionListener(e -> presenter.onAttackWeakHMACSecret());

menuItemAttackEmbedCollaboratorPayload.setEnabled(isProVersion);

popupMenuAttack.add(menuItemAttackEmbedJWK);
popupMenuAttack.add(menuItemAttackSignNone);
popupMenuAttack.add(menuItemAttackKeyConfusion);
popupMenuAttack.add(menuItemAttackSignEmptyKey);
popupMenuAttack.add(menuItemAttackSignPsychicSignature);
popupMenuAttack.add(menuItemAttackEmbedCollaboratorPayload);
popupMenuAttack.add(menuItemAttackWeakSymmetricKey);

return popupMenuAttack;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ encryption = Encryption
decryption = Decryption
delete=Delete
generate = Generate
ok = OK
cancel = Cancel
ok = &OK
cancel = &Cancel
copy=Copy
key = Key
keys = Keys
Expand Down

0 comments on commit a985b3d

Please sign in to comment.