From b2bf1c7092fe9f061703c8cf623d49ff44eb89e2 Mon Sep 17 00:00:00 2001 From: Samuel Behrens Date: Wed, 12 May 2021 14:02:25 -0500 Subject: [PATCH 1/2] Signed off by: Samuel Behrens Signed-off-by: Samuel Behrens --- misc/runTest.sh | 0 src/Common/.classpath | 0 src/Common/.project | 0 src/HTML_Renderer/.classpath | 0 src/HTML_Renderer/.project | 0 src/HTML_Renderer/COBRA-ACK.txt | 0 src/HTML_Renderer/COBRA-README.txt | 0 src/HTML_Renderer/LICENSE.txt | 0 src/HTML_Renderer/build.xml | 2 +- src/HTML_Renderer/org/w3c/COPYRIGHT.html | 0 .../org/lobobrowser/gui/FramePanel.java | 3 ++ .../security/PermissionSystem.java | 8 +++- .../lobobrowser/security/PermissionTable.java | 5 +++ .../lobobrowser/security/RequestManager.java | 40 +++++++++++++++++-- .../API_Doc_Builder.launch | 0 .../.externalToolBuilders/Ant Builder.launch | 0 .../Installer Builder.launch | 0 src/XAMJ_Build/.project | 0 src/XAMJ_Build/build.xml.disabled | 0 src/XAMJ_Build/default-shortcut-spec.xml | 0 src/XAMJ_Build/install.xml | 0 src/XAMJ_Build/re_manifest.mf | 0 src/XAMJ_Build/windows-shortcut-spec.xml | 0 23 files changed, 52 insertions(+), 6 deletions(-) mode change 100755 => 100644 misc/runTest.sh mode change 100755 => 100644 src/Common/.classpath mode change 100755 => 100644 src/Common/.project mode change 100755 => 100644 src/HTML_Renderer/.classpath mode change 100755 => 100644 src/HTML_Renderer/.project mode change 100755 => 100644 src/HTML_Renderer/COBRA-ACK.txt mode change 100755 => 100644 src/HTML_Renderer/COBRA-README.txt mode change 100755 => 100644 src/HTML_Renderer/LICENSE.txt mode change 100755 => 100644 src/HTML_Renderer/org/w3c/COPYRIGHT.html mode change 100755 => 100644 src/XAMJ_Build/.externalToolBuilders/API_Doc_Builder.launch mode change 100755 => 100644 src/XAMJ_Build/.externalToolBuilders/Ant Builder.launch mode change 100755 => 100644 src/XAMJ_Build/.externalToolBuilders/Installer Builder.launch mode change 100755 => 100644 src/XAMJ_Build/.project mode change 100755 => 100644 src/XAMJ_Build/build.xml.disabled mode change 100755 => 100644 src/XAMJ_Build/default-shortcut-spec.xml mode change 100755 => 100644 src/XAMJ_Build/install.xml mode change 100755 => 100644 src/XAMJ_Build/re_manifest.mf mode change 100755 => 100644 src/XAMJ_Build/windows-shortcut-spec.xml diff --git a/misc/runTest.sh b/misc/runTest.sh old mode 100755 new mode 100644 diff --git a/src/Common/.classpath b/src/Common/.classpath old mode 100755 new mode 100644 diff --git a/src/Common/.project b/src/Common/.project old mode 100755 new mode 100644 diff --git a/src/HTML_Renderer/.classpath b/src/HTML_Renderer/.classpath old mode 100755 new mode 100644 diff --git a/src/HTML_Renderer/.project b/src/HTML_Renderer/.project old mode 100755 new mode 100644 diff --git a/src/HTML_Renderer/COBRA-ACK.txt b/src/HTML_Renderer/COBRA-ACK.txt old mode 100755 new mode 100644 diff --git a/src/HTML_Renderer/COBRA-README.txt b/src/HTML_Renderer/COBRA-README.txt old mode 100755 new mode 100644 diff --git a/src/HTML_Renderer/LICENSE.txt b/src/HTML_Renderer/LICENSE.txt old mode 100755 new mode 100644 diff --git a/src/HTML_Renderer/build.xml b/src/HTML_Renderer/build.xml index 0745489f..4d0fcc78 100644 --- a/src/HTML_Renderer/build.xml +++ b/src/HTML_Renderer/build.xml @@ -72,7 +72,7 @@ - + diff --git a/src/HTML_Renderer/org/w3c/COPYRIGHT.html b/src/HTML_Renderer/org/w3c/COPYRIGHT.html old mode 100755 new mode 100644 diff --git a/src/Platform_Core/org/lobobrowser/gui/FramePanel.java b/src/Platform_Core/org/lobobrowser/gui/FramePanel.java index 623b300b..2f0afb0d 100644 --- a/src/Platform_Core/org/lobobrowser/gui/FramePanel.java +++ b/src/Platform_Core/org/lobobrowser/gui/FramePanel.java @@ -739,6 +739,7 @@ private void navigateLocal(final @NonNull URL url, final String method, final Re } private void navigateLocal(final NavigationEvent event) { + // request Manager reset!!! requestManager.reset(event.getURL()); try { this.dispatchBeforeLocalNavigate(event); @@ -878,6 +879,7 @@ public NavigatorWindowImpl run() { }); final FramePanel newFrame = wcontext.getFramePanel(); + // ATTENTION!!! Frame Panel request manager reset! newFrame.requestManager.reset(url); final UserAgentContext uaContext = new SilentUserAgentContextImpl(newFrame); @@ -1323,6 +1325,7 @@ private void updateContentProperties(final ComponentContent content) { } } + // New request manager. private final RequestManager requestManager = new RequestManager(this); public boolean isRequestPermitted(final Request request) { diff --git a/src/Platform_Core/org/lobobrowser/security/PermissionSystem.java b/src/Platform_Core/org/lobobrowser/security/PermissionSystem.java index f8f141f0..12f25f98 100644 --- a/src/Platform_Core/org/lobobrowser/security/PermissionSystem.java +++ b/src/Platform_Core/org/lobobrowser/security/PermissionSystem.java @@ -16,6 +16,7 @@ import org.lobobrowser.ua.UserAgentContext.RequestKind; public class PermissionSystem { + static enum Permission { Allow, Deny, Undecided; @@ -315,7 +316,12 @@ public void setPermission(final Permission permission) { myPermission = permission; store.storePermissions(hostPattern, requestHost, kindOpt, permission); } - + + // A method that returns the permission in here. + public Permission getMyPermission() { + return myPermission; + } + } } diff --git a/src/Platform_Core/org/lobobrowser/security/PermissionTable.java b/src/Platform_Core/org/lobobrowser/security/PermissionTable.java index 6add87f5..80790d1f 100644 --- a/src/Platform_Core/org/lobobrowser/security/PermissionTable.java +++ b/src/Platform_Core/org/lobobrowser/security/PermissionTable.java @@ -55,6 +55,7 @@ protected int calculateTabWidth(final int tabPlacement, final int tabIndex, fina private static JPanel makeBoardView(final PermissionBoard board, final String[] columnNames, final String[][] requestData, final List buttons, final ChangeListener listener) { + final JPanel grid = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; @@ -72,6 +73,9 @@ private static JPanel makeBoardView(final PermissionBoard board, final String[] for (int i = 0, numRows = board.getRowCount(); i < numRows; i++) { gbc.gridy = i + 1; final PermissionRow row = rows.get(i).getValue(); + + // calculate the values + addRowToGrid(grid, gbc, row, requestData[i], listener, buttons); } } @@ -88,6 +92,7 @@ private static void addRowToGrid(final JPanel grid, final GridBagConstraints gbc if (j == 0) { gbc.weightx = 1d; cell = row.getHostCell(); + } else { gbc.weightx = 0d; cell = row.getRequestCell(j - 1); diff --git a/src/Platform_Core/org/lobobrowser/security/RequestManager.java b/src/Platform_Core/org/lobobrowser/security/RequestManager.java index d485afac..8cda1a0d 100644 --- a/src/Platform_Core/org/lobobrowser/security/RequestManager.java +++ b/src/Platform_Core/org/lobobrowser/security/RequestManager.java @@ -26,7 +26,9 @@ import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JPanel; +import javax.swing.JLabel; import javax.swing.JScrollPane; +import javax.swing.SwingConstants; import org.lobobrowser.security.PermissionSystem.Permission; import org.lobobrowser.security.PermissionSystem.PermissionBoard.PermissionRow; @@ -41,7 +43,10 @@ public final class RequestManager { private static final Logger logger = Logger.getLogger(RequestManager.class.getName()); private final NavigatorFrame frame; - + + // Values that track whether or not a request is accepted or rejected. + int accepted; + int rejected; public RequestManager(final NavigatorFrame frame) { this.frame = frame; @@ -110,6 +115,7 @@ private Request rewriteRequest(final Request request) { } } + // A method that determines whether or not a given request is permitted. public boolean isRequestPermitted(final Request request) { final Request finalRequest = rewriteRequest(request); @@ -125,15 +131,26 @@ public boolean isRequestPermitted(final Request request) { if (protocolTest.equals("http") && frameProtocol.equals("https")) { updateCounter(finalRequest.url.getHost(), RequestKind.UnsecuredHTTP); if (!httpPermitted) { + // The request isn't permitted, so it's rejected. + rejected++; return false; } } } - + // dumpCounters(); + if (permitted == true) { + // The request is permitted, so we increment accepted. + accepted++; + } else { + // The request is not permitted, so we increment rejected. + rejected++; + } return permitted; } else { logger.severe("Unexpected permission system state. Request without context!"); + // The request is not permitted, so we increment rejected. + rejected++; return false; } } @@ -141,6 +158,10 @@ public boolean isRequestPermitted(final Request request) { private void setupPermissionSystem(final String frameHost) { final RequestRuleStore permissionStore = RequestRuleStore.getStore(); final PermissionSystem system = new PermissionSystem(frameHost, permissionStore); + + // Initialize the accept and reject details. + accepted = 0; + rejected = 0; // Prime the boards with atleast one row system.getLastBoard().getRow(frameHost); @@ -174,14 +195,12 @@ public synchronized void reset(final URL frameUrl) { } public void manageRequests(final JComponent initiatorComponent) { - // permissionSystemOpt.ifPresent(r -> r.dump()); final ManageDialog dlg = new ManageDialog(new JFrame(), getFrameURL().map(u -> u.toExternalForm()).orElse("Empty!"), initiatorComponent); dlg.setVisible(true); } private synchronized String[][] getRequestData() { - // hostToCounterMap.keySet().stream().forEach(System.out::println); return hostToCounterMap.entrySet().stream().map(entry -> { final List rowElements = new LinkedList<>(); @@ -219,7 +238,15 @@ public ManageDialog(final JFrame parent, final String title, final JComponent in final JPanel buttonPane = new JPanel(); final JButton button = new JButton("OK"); + + JLabel aLabel = new JLabel("Accepted Requests: " + accepted); + buttonPane.add(aLabel); buttonPane.add(button); + + // Add relevant statistics to button pane. + JLabel oLabel = new JLabel("Total Requests: " + (accepted + rejected)); + buttonPane.add(oLabel); + button.addActionListener(this); getContentPane().add(buttonPane, BorderLayout.SOUTH); setDefaultCloseOperation(DISPOSE_ON_CLOSE); @@ -296,6 +323,11 @@ public void windowActivated(final WindowEvent e) { public void allowAllFirstPartyRequests() { permissionSystemOpt.ifPresent(p -> { final PermissionRow row = p.getLastBoard().getRow(getFrameHost().get()); + // Was the request we are changing initially denied? + if (row.getHostCell().getMyPermission() == Permission.Deny) { + rejected--; + } + accepted++; row.getHostCell().setPermission(Permission.Allow); }); } diff --git a/src/XAMJ_Build/.externalToolBuilders/API_Doc_Builder.launch b/src/XAMJ_Build/.externalToolBuilders/API_Doc_Builder.launch old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/.externalToolBuilders/Ant Builder.launch b/src/XAMJ_Build/.externalToolBuilders/Ant Builder.launch old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/.externalToolBuilders/Installer Builder.launch b/src/XAMJ_Build/.externalToolBuilders/Installer Builder.launch old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/.project b/src/XAMJ_Build/.project old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/build.xml.disabled b/src/XAMJ_Build/build.xml.disabled old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/default-shortcut-spec.xml b/src/XAMJ_Build/default-shortcut-spec.xml old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/install.xml b/src/XAMJ_Build/install.xml old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/re_manifest.mf b/src/XAMJ_Build/re_manifest.mf old mode 100755 new mode 100644 diff --git a/src/XAMJ_Build/windows-shortcut-spec.xml b/src/XAMJ_Build/windows-shortcut-spec.xml old mode 100755 new mode 100644 From dc6be3e111410746bdb9ed92e80abf96927a460e Mon Sep 17 00:00:00 2001 From: Samuel Behrens Date: Wed, 12 May 2021 14:37:27 -0500 Subject: [PATCH 2/2] Signed off by: Samuel Behrens Signed-off-by: Samuel Behrens --- src/Platform_Core/org/lobobrowser/security/RequestManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Platform_Core/org/lobobrowser/security/RequestManager.java b/src/Platform_Core/org/lobobrowser/security/RequestManager.java index 8cda1a0d..25be0dd6 100644 --- a/src/Platform_Core/org/lobobrowser/security/RequestManager.java +++ b/src/Platform_Core/org/lobobrowser/security/RequestManager.java @@ -138,7 +138,6 @@ public boolean isRequestPermitted(final Request request) { } } - // dumpCounters(); if (permitted == true) { // The request is permitted, so we increment accepted. accepted++;