Autopsy  4.6.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 final class EncryptionDetectionIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel {
33 
34  private static final int MEGABYTE_SIZE = 1048576;
35  private static final int INVALID_TEXT_FIELD_INPUT_RETURN = -1;
36 
37  private final Logger logger = Logger.getLogger(EncryptionDetectionIngestJobSettingsPanel.class.getName());
38 
39  private final DefaultFormatterFactory minimumFileSizeTextFormatterFactory = new DefaultFormatterFactory(new StringIntegerFormatter());
40  private final DefaultFormatterFactory minimumEntropyTextFormatterFactory = new DefaultFormatterFactory(new StringDoubleFormatter());
41 
47  public EncryptionDetectionIngestJobSettingsPanel(EncryptionDetectionIngestJobSettings settings) {
48  initComponents();
49  customizeComponents(settings);
50  }
51 
57  private void customizeComponents(EncryptionDetectionIngestJobSettings settings) {
58  minimumEntropyTextbox.setText(String.valueOf(settings.getMinimumEntropy()));
59  minimumFileSizeTextbox.setText(String.valueOf(settings.getMinimumFileSize() / MEGABYTE_SIZE));
60  fileSizeMultiplesEnforcedCheckbox.setSelected(settings.isFileSizeMultipleEnforced());
61  slackFilesAllowedCheckbox.setSelected(settings.isSlackFilesAllowed());
62  }
63 
64  @Override
65  public IngestModuleIngestJobSettings getSettings() {
66  return new EncryptionDetectionIngestJobSettings(
67  Double.valueOf(minimumEntropyTextbox.getText()),
68  Integer.valueOf(minimumFileSizeTextbox.getText()) * MEGABYTE_SIZE,
69  fileSizeMultiplesEnforcedCheckbox.isSelected(),
70  slackFilesAllowedCheckbox.isSelected());
71  }
72 
76  private final class StringDoubleFormatter extends DefaultFormatter {
77 
78  @Override
79  public Object stringToValue(String string) throws ParseException {
80  try {
81  return Double.parseDouble(string);
82  } catch (NumberFormatException ex) {
83  logger.log(Level.WARNING, String.format("The String input '%s' is not valid for Double conversion.", string), ex);
84  /*
85  * Return a valid number outside the acceptable value range so
86  * it can be run through the validator in the file ingest
87  * module.
88  */
89  return new Double(INVALID_TEXT_FIELD_INPUT_RETURN);
90  }
91  }
92  }
93 
97  private final class StringIntegerFormatter extends DefaultFormatter {
98 
99  @Override
100  public Object stringToValue(String string) throws ParseException {
101  try {
102  return Integer.parseInt(string);
103  } catch (NumberFormatException ex) {
104  logger.log(Level.WARNING, String.format("The String input '%s' is not valid for Integer conversion.", string), ex);
105  /*
106  * Return a valid number outside the acceptable value range so
107  * it can still be run through the validator in the file ingest
108  * module.
109  */
110  return INVALID_TEXT_FIELD_INPUT_RETURN;
111  }
112  }
113  }
114 
120  @SuppressWarnings("unchecked")
121  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
122  private void initComponents() {
123 
124  fileSizeMultiplesEnforcedCheckbox = new javax.swing.JCheckBox();
125  slackFilesAllowedCheckbox = new javax.swing.JCheckBox();
126  minimumEntropyLabel = new javax.swing.JLabel();
127  minimumFileSizeLabel = new javax.swing.JLabel();
128  mbLabel = new javax.swing.JLabel();
129  detectionSettingsLabel = new javax.swing.JLabel();
130  minimumFileSizeTextbox = new javax.swing.JFormattedTextField();
131  minimumEntropyTextbox = new javax.swing.JFormattedTextField();
132 
133  org.openide.awt.Mnemonics.setLocalizedText(fileSizeMultiplesEnforcedCheckbox, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.fileSizeMultiplesEnforcedCheckbox.text")); // NOI18N
134 
135  org.openide.awt.Mnemonics.setLocalizedText(slackFilesAllowedCheckbox, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.slackFilesAllowedCheckbox.text")); // NOI18N
136 
137  org.openide.awt.Mnemonics.setLocalizedText(minimumEntropyLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumEntropyLabel.text")); // NOI18N
138 
139  org.openide.awt.Mnemonics.setLocalizedText(minimumFileSizeLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumFileSizeLabel.text")); // NOI18N
140 
141  org.openide.awt.Mnemonics.setLocalizedText(mbLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.mbLabel.text")); // NOI18N
142 
143  detectionSettingsLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
144  org.openide.awt.Mnemonics.setLocalizedText(detectionSettingsLabel, org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.detectionSettingsLabel.text")); // NOI18N
145 
146  minimumFileSizeTextbox.setFormatterFactory(minimumFileSizeTextFormatterFactory);
147  minimumFileSizeTextbox.setText(org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumFileSizeTextbox.text")); // NOI18N
148  minimumFileSizeTextbox.addActionListener(new java.awt.event.ActionListener() {
149  public void actionPerformed(java.awt.event.ActionEvent evt) {
150  minimumFileSizeTextboxActionPerformed(evt);
151  }
152  });
153 
154  minimumEntropyTextbox.setFormatterFactory(minimumEntropyTextFormatterFactory);
155  minimumEntropyTextbox.setText(org.openide.util.NbBundle.getMessage(EncryptionDetectionIngestJobSettingsPanel.class, "EncryptionDetectionIngestJobSettingsPanel.minimumEntropyTextbox.text")); // NOI18N
156 
157  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
158  this.setLayout(layout);
159  layout.setHorizontalGroup(
160  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
161  .addGroup(layout.createSequentialGroup()
162  .addContainerGap()
163  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164  .addComponent(slackFilesAllowedCheckbox)
165  .addComponent(detectionSettingsLabel)
166  .addComponent(fileSizeMultiplesEnforcedCheckbox)
167  .addGroup(layout.createSequentialGroup()
168  .addComponent(minimumFileSizeLabel)
169  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
170  .addComponent(minimumFileSizeTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
171  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
172  .addComponent(mbLabel))
173  .addGroup(layout.createSequentialGroup()
174  .addComponent(minimumEntropyLabel)
175  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
176  .addComponent(minimumEntropyTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
177  .addContainerGap(33, Short.MAX_VALUE))
178  );
179  layout.setVerticalGroup(
180  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
181  .addGroup(layout.createSequentialGroup()
182  .addContainerGap()
183  .addComponent(detectionSettingsLabel)
184  .addGap(16, 16, 16)
185  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
186  .addComponent(minimumEntropyLabel)
187  .addComponent(minimumEntropyTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
188  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
189  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
190  .addComponent(mbLabel)
191  .addComponent(minimumFileSizeLabel)
192  .addComponent(minimumFileSizeTextbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
193  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
194  .addComponent(fileSizeMultiplesEnforcedCheckbox)
195  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
196  .addComponent(slackFilesAllowedCheckbox)
197  .addContainerGap(60, Short.MAX_VALUE))
198  );
199  }// </editor-fold>//GEN-END:initComponents
200 
201  private void minimumFileSizeTextboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minimumFileSizeTextboxActionPerformed
202  // TODO add your handling code here:
203  }//GEN-LAST:event_minimumFileSizeTextboxActionPerformed
204 
205  // Variables declaration - do not modify//GEN-BEGIN:variables
206  private javax.swing.JLabel detectionSettingsLabel;
207  private javax.swing.JCheckBox fileSizeMultiplesEnforcedCheckbox;
208  private javax.swing.JLabel mbLabel;
209  private javax.swing.JLabel minimumEntropyLabel;
210  private javax.swing.JFormattedTextField minimumEntropyTextbox;
211  private javax.swing.JLabel minimumFileSizeLabel;
212  private javax.swing.JFormattedTextField minimumFileSizeTextbox;
213  private javax.swing.JCheckBox slackFilesAllowedCheckbox;
214  // End of variables declaration//GEN-END:variables
215 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.