Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EncryptionDetectionIngestJobSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.encryptiondetection;
20 
21 import java.text.ParseException;
22 import java.util.logging.Level;
23 import javax.swing.text.DefaultFormatter;
24 import javax.swing.text.DefaultFormatterFactory;
28 
32 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
33 final class EncryptionDetectionIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel {
34 
35  private static final int MEGABYTE_SIZE = 1048576;
36  private static final int INVALID_TEXT_FIELD_INPUT_RETURN = -1;
37 
38  private final Logger logger = Logger.getLogger(EncryptionDetectionIngestJobSettingsPanel.class.getName());
39 
40  private final DefaultFormatterFactory minimumFileSizeTextFormatterFactory = new DefaultFormatterFactory(new StringIntegerFormatter());
41  private final DefaultFormatterFactory minimumEntropyTextFormatterFactory = new DefaultFormatterFactory(new StringDoubleFormatter());
42 
48  public EncryptionDetectionIngestJobSettingsPanel(EncryptionDetectionIngestJobSettings settings) {
49  initComponents();
50  customizeComponents(settings);
51  }
52 
58  private void customizeComponents(EncryptionDetectionIngestJobSettings settings) {
59  minimumEntropyTextbox.setText(String.valueOf(settings.getMinimumEntropy()));
60  minimumFileSizeTextbox.setText(String.valueOf(settings.getMinimumFileSize() / MEGABYTE_SIZE));
61  fileSizeMultiplesEnforcedCheckbox.setSelected(settings.isFileSizeMultipleEnforced());
62  slackFilesAllowedCheckbox.setSelected(settings.isSlackFilesAllowed());
63  }
64 
65  @Override
66  public IngestModuleIngestJobSettings getSettings() {
67  return new EncryptionDetectionIngestJobSettings(
68  Double.valueOf(minimumEntropyTextbox.getText()),
69  Integer.valueOf(minimumFileSizeTextbox.getText()) * MEGABYTE_SIZE,
70  fileSizeMultiplesEnforcedCheckbox.isSelected(),
71  slackFilesAllowedCheckbox.isSelected());
72  }
73 
77  private final class StringDoubleFormatter extends DefaultFormatter {
78 
79  @Override
80  public Object stringToValue(String string) throws ParseException {
81  try {
82  return Double.parseDouble(string);
83  } catch (NumberFormatException ex) {
84  logger.log(Level.WARNING, String.format("The String input '%s' is not valid for Double conversion.", string), ex);
85  /*
86  * Return a valid number outside the acceptable value range so
87  * it can be run through the validator in the file ingest
88  * module.
89  */
90  return new Double(INVALID_TEXT_FIELD_INPUT_RETURN);
91  }
92  }
93  }
94 
98  private final class StringIntegerFormatter extends DefaultFormatter {
99 
100  @Override
101  public Object stringToValue(String string) throws ParseException {
102  try {
103  return Integer.parseInt(string);
104  } catch (NumberFormatException ex) {
105  logger.log(Level.WARNING, String.format("The String input '%s' is not valid for Integer conversion.", string), ex);
106  /*
107  * Return a valid number outside the acceptable value range so
108  * it can still be run through the validator in the file ingest
109  * module.
110  */
111  return INVALID_TEXT_FIELD_INPUT_RETURN;
112  }
113  }
114  }
115 
121  @SuppressWarnings("unchecked")
122  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
123  private void initComponents() {
124 
125  fileSizeMultiplesEnforcedCheckbox = new javax.swing.JCheckBox();
126  slackFilesAllowedCheckbox = new javax.swing.JCheckBox();
127  minimumEntropyLabel = new javax.swing.JLabel();
128  minimumFileSizeLabel = new javax.swing.JLabel();
129  mbLabel = new javax.swing.JLabel();
130  detectionSettingsLabel = new javax.swing.JLabel();
131  minimumFileSizeTextbox = new javax.swing.JFormattedTextField();
132  minimumEntropyTextbox = new javax.swing.JFormattedTextField();
133 
134  org.openide.awt.Mnemonics.setLocalizedText(fileSizeMultiplesEnforcedCheckbox, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.fileSizeMultiplesEnforcedCheckbox.text")); // NOI18N
135 
136  org.openide.awt.Mnemonics.setLocalizedText(slackFilesAllowedCheckbox, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.slackFilesAllowedCheckbox.text")); // NOI18N
137 
138  org.openide.awt.Mnemonics.setLocalizedText(minimumEntropyLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumEntropyLabel.text")); // NOI18N
139 
140  org.openide.awt.Mnemonics.setLocalizedText(minimumFileSizeLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumFileSizeLabel.text")); // NOI18N
141 
142  org.openide.awt.Mnemonics.setLocalizedText(mbLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.mbLabel.text")); // NOI18N
143 
144  detectionSettingsLabel.setFont(detectionSettingsLabel.getFont().deriveFont(detectionSettingsLabel.getFont().getStyle() | java.awt.Font.BOLD));
145  org.openide.awt.Mnemonics.setLocalizedText(detectionSettingsLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.detectionSettingsLabel.text")); // NOI18N
146 
147  minimumFileSizeTextbox.setFormatterFactory(minimumFileSizeTextFormatterFactory);
148  minimumFileSizeTextbox.setText(org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumFileSizeTextbox.text")); // NOI18N
149  minimumFileSizeTextbox.addActionListener(new java.awt.event.ActionListener() {
150  public void actionPerformed(java.awt.event.ActionEvent evt) {
151  minimumFileSizeTextboxActionPerformed(evt);
152  }
153  });
154 
155  minimumEntropyTextbox.setFormatterFactory(minimumEntropyTextFormatterFactory);
156  minimumEntropyTextbox.setText(org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumEntropyTextbox.text")); // NOI18N
157 
158  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
159  this.setLayout(layout);
160  layout.setHorizontalGroup(
161  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162  .addGroup(layout.createSequentialGroup()
163  .addContainerGap()
164  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
165  .addComponent(slackFilesAllowedCheckbox)
166  .addComponent(detectionSettingsLabel)
167  .addComponent(fileSizeMultiplesEnforcedCheckbox)
168  .addGroup(layout.createSequentialGroup()
169  .addComponent(minimumFileSizeLabel)
170  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
171  .addComponent(minimumFileSizeTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
172  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
173  .addComponent(mbLabel))
174  .addGroup(layout.createSequentialGroup()
175  .addComponent(minimumEntropyLabel)
176  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
177  .addComponent(minimumEntropyTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
178  .addContainerGap(33, Short.MAX_VALUE))
179  );
180  layout.setVerticalGroup(
181  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
182  .addGroup(layout.createSequentialGroup()
183  .addContainerGap()
184  .addComponent(detectionSettingsLabel)
185  .addGap(16, 16, 16)
186  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
187  .addComponent(minimumEntropyLabel)
188  .addComponent(minimumEntropyTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
189  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
190  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
191  .addComponent(mbLabel)
192  .addComponent(minimumFileSizeLabel)
193  .addComponent(minimumFileSizeTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
194  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
195  .addComponent(fileSizeMultiplesEnforcedCheckbox)
196  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
197  .addComponent(slackFilesAllowedCheckbox)
198  .addContainerGap(60, Short.MAX_VALUE))
199  );
200  }// </editor-fold>//GEN-END:initComponents
201 
202  private void minimumFileSizeTextboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minimumFileSizeTextboxActionPerformed
203  // TODO add your handling code here:
204  }//GEN-LAST:event_minimumFileSizeTextboxActionPerformed
205 
206  // Variables declaration - do not modify//GEN-BEGIN:variables
207  private javax.swing.JLabel detectionSettingsLabel;
208  private javax.swing.JCheckBox fileSizeMultiplesEnforcedCheckbox;
209  private javax.swing.JLabel mbLabel;
210  private javax.swing.JLabel minimumEntropyLabel;
211  private javax.swing.JFormattedTextField minimumEntropyTextbox;
212  private javax.swing.JLabel minimumFileSizeLabel;
213  private javax.swing.JFormattedTextField minimumFileSizeTextbox;
214  private javax.swing.JCheckBox slackFilesAllowedCheckbox;
215  // End of variables declaration//GEN-END:variables
216 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.