eula improvements

This commit is contained in:
Greg DiCristofaro 2023-07-24 07:59:27 -04:00
parent 14546f0047
commit b16cbe6c1d
5 changed files with 139 additions and 104 deletions

View File

@ -26,6 +26,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.logging.Level;
@ -55,7 +56,11 @@ public class CTLicensePersistence {
File licenseFile = getCTLicenseFile();
try {
licenseFile.getParentFile().mkdirs();
objectMapper.writeValue(licenseFile, licenseResponse);
if (licenseResponse != null) {
objectMapper.writeValue(licenseFile, licenseResponse);
} else if (licenseFile.exists()) {
Files.delete(licenseFile.toPath());
}
return true;
} catch (IOException ex) {
logger.log(Level.WARNING, "There was an error writing CyberTriage license to file: " + licenseFile.getAbsolutePath(), ex);

View File

@ -27,11 +27,9 @@ import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseInfo;
import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseResponse;
import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil;
import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil.InvalidLicenseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
@ -42,6 +40,7 @@ import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import org.apache.commons.lang3.StringUtils;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.ServiceProvider;
@ -445,8 +444,7 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
return total - used;
}
private void acceptEulaAndSave(LicenseResponse licenseResponse) {
LicenseInfo licenseInfo = null;
private void acceptEula(LicenseResponse licenseResponse) {
try {
final EULADialog eulaDialog = new EULADialog(WindowManager.getDefault().getMainWindow(), true);
eulaDialog.setLocationRelativeTo(this);
@ -454,8 +452,9 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
eulaDialog.setVisible(true);
if (eulaDialog.isAcceptPressed()) {
ctPersistence.saveLicenseResponse(licenseResponse);
licenseInfo = LicenseDecryptorUtil.getInstance().createLicenseInfo(licenseResponse);
// only indicate a change to save if we have accepted EULA for a license
this.licenseInfo = LicenseDecryptorUtil.getInstance().createLicenseInfo(licenseResponse);
this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
}
} catch (IOException | InvalidLicenseException ex) {
logger.log(Level.WARNING, "An error occurred while fetching data", ex);
@ -465,11 +464,8 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title(),
JOptionPane.ERROR_MESSAGE);
} finally {
synchronized (this) {
this.licenseFetcher = null;
setLicenseDisplay(licenseInfo, null);
loadMalwareScansInfo(licenseInfo);
}
setLicenseDisplay(this.licenseInfo, null);
loadMalwareScansInfo(this.licenseInfo);
}
}
@ -497,9 +493,11 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
protected void done() {
try {
LicenseResponse licenseResponse = get();
SwingUtilities.invokeLater(() -> acceptEulaAndSave(licenseResponse));
SwingUtilities.invokeLater(() -> acceptEula(licenseResponse));
} catch (InterruptedException ex) {
// ignore cancellation
// ignore cancellation; just load current license
setLicenseDisplay(licenseInfo, null);
loadMalwareScansInfo(licenseInfo);
} catch (ExecutionException ex) {
if (ex.getCause() != null && ex.getCause() instanceof CTCloudException cloudEx) {
logger.log(Level.WARNING, "An API error occurred while fetching license information", cloudEx);
@ -516,13 +514,11 @@ public class CTMalwareScannerOptionsPanel extends CTOptionsSubPanel {
Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title(),
JOptionPane.ERROR_MESSAGE);
}
setLicenseDisplay(licenseInfo, null);
loadMalwareScansInfo(licenseInfo);
} finally {
synchronized (CTMalwareScannerOptionsPanel.this) {
CTMalwareScannerOptionsPanel.this.licenseFetcher = null;
if (!this.isCancelled()) {
setLicenseDisplay(licenseInfo, null);
loadMalwareScansInfo(licenseInfo);
}
}
}
}

View File

@ -6,8 +6,11 @@
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/Bundle.properties" key="EULADialog.title" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 32767]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[500, 500]"/>
<Dimension value="[550, 550]"/>
</Property>
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[550, 550]"/>
@ -32,6 +35,52 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="viewablePanel">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 32767]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="null"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="3" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="10" weightX="1.0" weightY="1.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
</Container>
<Container class="javax.swing.JPanel" name="paddingPanel">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 0]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Component class="javax.swing.JButton" name="acceptButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
@ -67,38 +116,5 @@
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="paddingPanel">
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Container class="javax.swing.JPanel" name="viewablePanel">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="3" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="5" insetsBottom="5" insetsRight="5" anchor="10" weightX="1.0" weightY="1.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
</Container>
</SubComponents>
</Form>

View File

@ -10,12 +10,10 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.web.WebView;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import org.apache.commons.io.IOUtils;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -44,6 +42,25 @@ public class EULADialog extends javax.swing.JDialog {
return acceptPressed;
}
private void loadEULA() throws IOException {
InputStream eulaInputStream = EULADialog.class.getResourceAsStream(EULA_RESOURCE);
final String htmlString = IOUtils.toString(eulaInputStream, StandardCharsets.UTF_8);
final JFXPanel fxPanel = new JFXPanel();
this.viewablePanel.add(fxPanel, BorderLayout.CENTER);
Platform.runLater(() -> {
WebView webView = new WebView();
webView.setMaxSize(Short.MAX_VALUE, Short.MAX_VALUE);
webView.setPrefSize(Short.MAX_VALUE, Short.MAX_VALUE);
webView.setMinSize(100, 100);
webView.getEngine().loadContent(htmlString, "text/html");
VBox root = new VBox(webView);
Scene scene = new Scene(root, Color.RED);
fxPanel.setScene(scene);
SwingUtilities.invokeLater(() -> EULADialog.this.acceptButton.setEnabled(true));
});
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
@ -54,17 +71,51 @@ public class EULADialog extends javax.swing.JDialog {
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
viewablePanel = new javax.swing.JPanel();
javax.swing.JPanel paddingPanel = new javax.swing.JPanel();
acceptButton = new javax.swing.JButton();
javax.swing.JButton cancelButton = new javax.swing.JButton();
javax.swing.JPanel paddingPanel = new javax.swing.JPanel();
viewablePanel = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(org.openide.util.NbBundle.getMessage(EULADialog.class, "EULADialog.title")); // NOI18N
setPreferredSize(new java.awt.Dimension(500, 500));
setMaximumSize(new java.awt.Dimension(32767, 32767));
setPreferredSize(new java.awt.Dimension(550, 550));
setSize(new java.awt.Dimension(550, 550));
getContentPane().setLayout(new java.awt.GridBagLayout());
viewablePanel.setMaximumSize(new java.awt.Dimension(32767, 32767));
viewablePanel.setPreferredSize(null);
viewablePanel.setLayout(new java.awt.BorderLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
getContentPane().add(viewablePanel, gridBagConstraints);
paddingPanel.setMaximumSize(new java.awt.Dimension(32767, 0));
javax.swing.GroupLayout paddingPanelLayout = new javax.swing.GroupLayout(paddingPanel);
paddingPanel.setLayout(paddingPanelLayout);
paddingPanelLayout.setHorizontalGroup(
paddingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
paddingPanelLayout.setVerticalGroup(
paddingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
getContentPane().add(paddingPanel, gridBagConstraints);
org.openide.awt.Mnemonics.setLocalizedText(acceptButton, org.openide.util.NbBundle.getMessage(EULADialog.class, "EULADialog.acceptButton.text")); // NOI18N
acceptButton.setEnabled(false);
acceptButton.addActionListener(new java.awt.event.ActionListener() {
@ -90,35 +141,6 @@ public class EULADialog extends javax.swing.JDialog {
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
getContentPane().add(cancelButton, gridBagConstraints);
javax.swing.GroupLayout paddingPanelLayout = new javax.swing.GroupLayout(paddingPanel);
paddingPanel.setLayout(paddingPanelLayout);
paddingPanelLayout.setHorizontalGroup(
paddingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
paddingPanelLayout.setVerticalGroup(
paddingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
getContentPane().add(paddingPanel, gridBagConstraints);
viewablePanel.setLayout(new java.awt.BorderLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
getContentPane().add(viewablePanel, gridBagConstraints);
pack();
}// </editor-fold>//GEN-END:initComponents
@ -135,20 +157,4 @@ public class EULADialog extends javax.swing.JDialog {
private javax.swing.JButton acceptButton;
private javax.swing.JPanel viewablePanel;
// End of variables declaration//GEN-END:variables
private void loadEULA() throws IOException {
InputStream eulaInputStream = EULADialog.class.getResourceAsStream(EULA_RESOURCE);
final String htmlString = IOUtils.toString(eulaInputStream, StandardCharsets.UTF_8);
final JFXPanel fxPanel = new JFXPanel();
this.viewablePanel.add(fxPanel, BorderLayout.CENTER);
Platform.runLater(() -> {
WebView webView = new WebView();
webView.getEngine().loadContent(htmlString, "text/html");
VBox root = new VBox(webView);
Scene scene = new Scene(root, Color.RED);
fxPanel.setScene(scene);
SwingUtilities.invokeLater(() -> EULADialog.this.acceptButton.setEnabled(true));
});
}
}

View File

@ -371,8 +371,8 @@ public final class IngestJobSettings {
}
List<String> defaultEnabledAndLoaded = new ArrayList<>();
List<String> defaultDisabledAndLoaded = new ArrayList<>();
Set<String> defaultEnabledAndLoaded = new HashSet<>();
Set<String> defaultDisabledAndLoaded = new HashSet<>();
for (String loadedModule: loadedModuleNames) {
if (DEFAULT_DISABLED_MODULES.contains(loadedModule)) {
defaultDisabledAndLoaded.add(loadedModule);
@ -388,6 +388,18 @@ public final class IngestJobSettings {
HashSet<String> enabledModuleNames = getModulesNames(this.executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(defaultEnabledAndLoaded));
HashSet<String> disabledModuleNames = getModulesNames(this.executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, makeCsvList(defaultDisabledAndLoaded)); //NON-NLS
// double check to ensure all loaded modules are present in one of the lists in case more modules (in case settings didn't have a module)
for (String loadedModule : loadedModuleNames) {
// if neither enabled modules or disabled modules contains the loaded module, add it to the default location
if (!enabledModuleNames.contains(loadedModule) && !disabledModuleNames.contains(loadedModule)) {
if (DEFAULT_DISABLED_MODULES.contains(loadedModule)) {
disabledModuleNames.add(loadedModule);
} else {
enabledModuleNames.add(loadedModule);
}
}
}
/**
* Check for missing modules and create warnings if any are found.
*/