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

Plan b #55

Merged
merged 4 commits into from
Aug 4, 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
12 changes: 0 additions & 12 deletions src/main/java/com/blackberry/jwteditor/model/jose/JOSEObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

import java.util.List;

import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.joining;

/**
* Abstract class representing common elements of JWE/JWT
*/
Expand Down Expand Up @@ -58,13 +55,4 @@ public Base64URL getEncodedHeader(){
public abstract String serialize();

public abstract List<TimeClaim> timeClaims();

public String getWarnings() {
String warnings = timeClaims().stream()
.map(TimeClaim::warning)
.filter(not(String::isEmpty))
.collect(joining(", "));

return warnings.isEmpty() ? "" : warnings + ".";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package com.blackberry.jwteditor.model.jose;

import java.util.List;

/**
* Class for a JOSE object change set
*/
Expand Down Expand Up @@ -72,7 +74,7 @@ public String getOriginal() {
return original;
}

public String getWarnings() {
return modified.getWarnings();
public List<TimeClaim> timeClaims() {
return modified.timeClaims();
}
}
31 changes: 19 additions & 12 deletions src/main/java/com/blackberry/jwteditor/model/jose/TimeClaim.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,37 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

import static java.time.ZoneOffset.UTC;
import static java.util.Arrays.stream;
import static java.util.Collections.emptyList;

public record TimeClaim(TimeClaimType type, String data, Long value) {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("EEE MMM dd yyyy HH:mm:ss").withZone(ZoneId.from(UTC));

public boolean isValid() {
return type.isValid(value);
}

public String warning() {
if (isValid()) {
return "";
public String date() {
if (value == null) {
return null;
}

if (value == null || value < 0) {
return "'%s' value is invalid".formatted(type.name);
}
Instant instant = Instant.ofEpochSecond(value);
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, UTC);

String futurePast = type.dateInThePastRequired() ? "future" : "past";
return FORMATTER.format(zonedDateTime);
}

public boolean hasDate() {
return value != null;
}

return "'%s' date is in the %s".formatted(type.name, futurePast);
public boolean isValid() {
return type.isValid(value);
}

static List<TimeClaim> from(String payloadJson) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
import static java.time.Instant.now;

public enum TimeClaimType {
EXPIRATION_TIME("exp"),
NOT_BEFORE_TIME("nbf"),
ISSUED_AT_TIME("iat");
EXPIRATION_TIME("exp", "Expiration Time"),
NOT_BEFORE_TIME("nbf", "Not Before"),
ISSUED_AT_TIME("iat", "Issued At");

final String name;
private final String displayName;

TimeClaimType(String name) {
TimeClaimType(String name, String displayName) {
this.name = name;
this.displayName = displayName;
}

public boolean isValid(Long value) {
Expand All @@ -43,10 +45,15 @@ public boolean isValid(Long value) {
return dateInThePastRequired() ? valueTime.isBefore(now()) : valueTime.isAfter(now());
}

public boolean dateInThePastRequired() {
private boolean dateInThePastRequired() {
return switch (this) {
case EXPIRATION_TIME -> false;
case NOT_BEFORE_TIME, ISSUED_AT_TIME -> true;
};
}

@Override
public String toString() {
return displayName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ public void componentChanged() {
//Highlight the serialized text as changed if it differs from the original, and the change wasn't triggered by onSelectionChanging
view.setSerialized(joseObject.serialize(), mutableJoseObject.changed() && !selectionChanging);

view.setWarnings(mutableJoseObject.getWarnings());
List<Information> information = mutableJoseObject.timeClaims().stream()
.map(Information::from)
.toList();

view.setInformation(information);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/blackberry/jwteditor/presenter/Information.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Author : Dolph Flynn

Copyright 2024 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.presenter;

import com.blackberry.jwteditor.model.jose.TimeClaim;

public record Information(String text, boolean isWarning) {

static Information from(TimeClaim timeClaim) {
StringBuilder sb = new StringBuilder(timeClaim.type().toString()).append(" - ");

if (timeClaim.hasDate()) {
sb.append(timeClaim.date());
} else {
sb.append("invalid value: ").append(timeClaim.data());
}

return new Information(sb.toString(), !timeClaim.isValid());
}
}
59 changes: 41 additions & 18 deletions src/main/java/com/blackberry/jwteditor/view/editor/EditorView.form
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<size top="5" left="0" bottom="0" right="0"/>
</border>
<children>
<splitpane id="8027f" binding="lowerSplitPane">
<splitpane id="8027f" binding="midSplitPane">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
Expand Down Expand Up @@ -275,17 +275,48 @@
</grid>
</children>
</grid>
<grid id="71218" binding="panelSignature" custom-create="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<splitpane id="832b1" binding="lowerSplitPane">
<constraints>
<splitpane position="right"/>
</constraints>
<properties/>
<border type="line" title-resource-bundle="strings" title-key="signature">
<color color="-4473925"/>
</border>
<children/>
</grid>
<properties>
<dividerLocation value="362"/>
</properties>
<border type="none"/>
<children>
<grid id="71218" binding="panelSignature" custom-create="true" layout-manager="GridLayoutManager" row-count="1" 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>
<splitpane position="left"/>
</constraints>
<properties/>
<border type="line" title-resource-bundle="strings" title-key="signature">
<color color="-4473925"/>
</border>
<children/>
</grid>
<grid id="b6bb6" layout-manager="GridLayoutManager" row-count="1" 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>
<splitpane position="right"/>
</constraints>
<properties/>
<border type="line" title-resource-bundle="strings" title-key="information">
<color color="-4473925"/>
</border>
<children>
<scrollpane id="78adf" binding="informationScrollPane">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</scrollpane>
</children>
</grid>
</children>
</splitpane>
</children>
</splitpane>
</children>
Expand Down Expand Up @@ -427,7 +458,7 @@
</tabbedpane>
</children>
</splitpane>
<grid id="b3ff" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="b3ff" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -466,14 +497,6 @@
<text resource-bundle="strings" key="attack"/>
</properties>
</component>
<component id="9b06b" class="javax.swing.JLabel" binding="labelWarnings">
<constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/blackberry/jwteditor/view/editor/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import burp.api.montoya.collaborator.CollaboratorPayloadGenerator;
import burp.api.montoya.ui.Selection;
import com.blackberry.jwteditor.presenter.EditorPresenter;
import com.blackberry.jwteditor.presenter.Information;
import com.blackberry.jwteditor.presenter.PresenterStore;
import com.blackberry.jwteditor.utils.Utils;
import com.blackberry.jwteditor.view.hexcodearea.HexCodeAreaFactory;
Expand All @@ -43,7 +44,6 @@

import static java.awt.Color.RED;
import static java.awt.EventQueue.invokeLater;
import static java.awt.Font.BOLD;
import static org.exbin.deltahex.EditationAllowed.ALLOWED;
import static org.exbin.deltahex.EditationAllowed.READ_ONLY;

Expand All @@ -60,6 +60,7 @@ public abstract class EditorView {
private final RstaFactory rstaFactory;
private final boolean editable;
private final HexCodeAreaFactory hexCodeAreaFactory;
private final InformationPanel informationPanel;
private final boolean isProVersion;

private EditorMode mode;
Expand Down Expand Up @@ -88,8 +89,9 @@ public abstract class EditorView {
private JButton buttonJWSPayloadFormatJSON;
private JCheckBox checkBoxJWSPayloadCompactJSON;
private JSplitPane upperSplitPane;
private JSplitPane midSplitPane;
private JSplitPane lowerSplitPane;
private JLabel labelWarnings;
private JScrollPane informationScrollPane;

private CodeArea codeAreaSignature;
private CodeArea codeAreaEncryptedKey;
Expand All @@ -103,19 +105,24 @@ public abstract class EditorView {
HexCodeAreaFactory hexAreaCodeFactory,
CollaboratorPayloadGenerator collaboratorPayloadGenerator,
ErrorLoggingActionListenerFactory actionListenerFactory,
InformationPanelFactory informationPanelFactory,
boolean editable,
boolean isProVersion) {
this.rstaFactory = rstaFactory;
this.editable = editable;
this.hexCodeAreaFactory = hexAreaCodeFactory;
this.isProVersion = isProVersion;
this.presenter = new EditorPresenter(this, collaboratorPayloadGenerator, actionListenerFactory, presenters);
this.informationPanel = informationPanelFactory.build();

informationScrollPane.setViewportView(informationPanel);

panel.addHierarchyListener(new RunEDTActionOnFirstRenderHierarchyListener(
panel,
() -> {
upperSplitPane.setDividerLocation(0.25);
lowerSplitPane.setDividerLocation(0.75);
lowerSplitPane.setDividerLocation(0.5);
invokeLater(() -> midSplitPane.setDividerLocation(0.693));
}
));

Expand Down Expand Up @@ -549,10 +556,7 @@ private void createUIComponents() {
textAreaPayload = rstaFactory.buildDefaultTextArea();
}

public void setWarnings(String text) {
invokeLater(() -> {
labelWarnings.setFont(labelWarnings.getFont().deriveFont(BOLD));
labelWarnings.setText(text);
});
public void setInformation(List<Information> information) {
informationPanel.updateInformation(information);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class HttpEditorView extends EditorView implements ExtensionProvidedEdi
HexCodeAreaFactory hexAreaCodeFactory,
CollaboratorPayloadGenerator collaboratorPayloadGenerator,
ErrorLoggingActionListenerFactory actionListenerFactory,
InformationPanelFactory informationPanelFactory,
boolean editable,
boolean isProVersion) {
super(
Expand All @@ -41,6 +42,7 @@ abstract class HttpEditorView extends EditorView implements ExtensionProvidedEdi
hexAreaCodeFactory,
collaboratorPayloadGenerator,
actionListenerFactory,
informationPanelFactory,
editable,
isProVersion
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public HttpRequestEditorView(
new HexCodeAreaFactory(logging, userInterface),
collaboratorPayloadGenerator,
new ErrorLoggingActionListenerFactory(logging),
new InformationPanelFactory(userInterface, logging),
editable,
isProVersion
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public HttpResponseEditorView(
new HexCodeAreaFactory(logging, userInterface),
collaboratorPayloadGenerator,
new ErrorLoggingActionListenerFactory(logging),
new InformationPanelFactory(userInterface, logging),
editable,
isProVersion
);
Expand Down
Loading
Loading