Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTMalwareScannerOptionsPanel.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2023 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 */
19package com.basistech.df.cybertriage.autopsy.ctoptions.ctcloud;
20
21import com.basistech.df.cybertriage.autopsy.ctoptions.subpanel.CTOptionsSubPanel;
22import com.basistech.df.cybertriage.autopsy.ctapi.CTCloudException;
23import com.basistech.df.cybertriage.autopsy.ctapi.CTApiDAO;
24import com.basistech.df.cybertriage.autopsy.ctapi.json.AuthTokenResponse;
25import com.basistech.df.cybertriage.autopsy.ctapi.json.DecryptedLicenseResponse;
26import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseInfo;
27import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseLimitType;
28import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseResponse;
29import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil;
30import com.basistech.df.cybertriage.autopsy.ctapi.util.LicenseDecryptorUtil.InvalidLicenseException;
31import org.sleuthkit.autopsy.coreutils.Desktop;
32import java.awt.event.ComponentAdapter;
33import java.awt.event.ComponentEvent;
34import java.io.IOException;
35import java.net.URI;
36import java.net.URISyntaxException;
37import java.time.ZoneId;
38import java.time.format.DateTimeFormatter;
39import java.util.Optional;
40import java.util.concurrent.CancellationException;
41import java.util.concurrent.ExecutionException;
42import java.util.logging.Level;
43import javax.swing.SwingUtilities;
44import javax.swing.SwingWorker;
45import org.apache.commons.lang3.StringUtils;
46import org.netbeans.spi.options.OptionsPanelController;
47import org.openide.util.NbBundle;
48import org.openide.util.NbBundle.Messages;
49import org.openide.util.lookup.ServiceProvider;
50import org.openide.windows.WindowManager;
51import org.sleuthkit.autopsy.core.UserPreferences;
52import org.sleuthkit.autopsy.coreutils.Logger;
53
58@ServiceProvider(service = CTOptionsSubPanel.class)
60
61 private static final Logger logger = Logger.getLogger(CTMalwareScannerOptionsPanel.class.getName());
62
63 private static final DateTimeFormatter LICENSE_EXPIRES_FORMAT = DateTimeFormatter
64 .ofPattern("MMMM d, YYYY")
65 .withZone(ZoneId.of(UserPreferences.getInferredUserTimeZone()));
66
67 private static final DateTimeFormatter MALWARE_SCANS_RESET_FORMAT = DateTimeFormatter
68 .ofPattern("MMM d, YYYY' at 'h:mma")
69 .withZone(ZoneId.of(UserPreferences.getInferredUserTimeZone()));
70
73
74 private volatile LicenseInfo licenseInfo = null;
75 private volatile String licenseInfoMessage = null;
76 private volatile LicenseFetcher licenseFetcher = null;
77
78 private static final String PURCHASE_URL = "https://cybertriage.com/autopsy-malware-module";
79
80 private volatile AuthTokenResponse authTokenResponse = null;
81 private volatile String authTokenMessage = null;
82 private volatile AuthTokenFetcher authTokenFetcher = null;
83 private volatile String authTokenError = null;
84
90
91 this.addComponentListener(new ComponentAdapter() {
92 @Override
93 public void componentHidden(ComponentEvent e) {
94 synchronized (CTMalwareScannerOptionsPanel.this) {
95 if (CTMalwareScannerOptionsPanel.this.isLicenseAddRunning()) {
96 CTMalwareScannerOptionsPanel.this.licenseFetcher.cancel(true);
97 CTMalwareScannerOptionsPanel.this.licenseFetcher = null;
98 }
99
100 if (CTMalwareScannerOptionsPanel.this.isMalwareScansRunning()) {
101 CTMalwareScannerOptionsPanel.this.authTokenFetcher.cancel(true);
102 CTMalwareScannerOptionsPanel.this.authTokenFetcher = null;
103 }
104 }
105 }
106
107 @Override
108 public void componentShown(ComponentEvent e) {
109 synchronized (CTMalwareScannerOptionsPanel.this) {
110 if (CTMalwareScannerOptionsPanel.this.licenseInfo != null) {
112 }
113 }
114 }
115 }
116 );
117 }
118
119 @Override
120 public synchronized void saveSettings() {
121 LicenseResponse licenseResponse = getLicenseInfo();
122 if (licenseResponse == null) {
123 this.ctPersistence.deleteLicenseResponse();
124 } else {
125 ctPersistence.saveLicenseResponse(licenseResponse);
126 }
127 }
128
129 @Override
130 public boolean valid() {
131 return true;
132 }
133
134 @Override
135 public synchronized void loadSettings() {
136 Optional<LicenseInfo> licenseInfoOpt = ctPersistence.loadLicenseInfo();
137 LicenseInfo licenseInfo = licenseInfoOpt.orElse(null);
139 setMalwareScansDisplay(null, null, null);
140 if (licenseInfo != null) {
142 this.purchaseFromLabel.setVisible(false);
143 this.purchaseLink.setVisible(false);
144 } else {
145 this.purchaseFromLabel.setVisible(true);
146 this.purchaseLink.setVisible(true);
147 }
148 }
149
150 private static String getHtmlLink(String url) {
151 return "<html><span style=\"color: blue; text-decoration: underline\">" + url + "</span></html>";
152 }
153
154 private void gotoLink(String url) {
156 try {
157 Desktop.getDesktop().browse(new URI(url));
158 } catch (IOException | URISyntaxException e) {
159 logger.log(Level.SEVERE, "Error opening link to: " + url, e);
160 }
161 } else {
162 logger.log(Level.WARNING, "Desktop API is not supported. Link cannot be opened.");
163 }
164 }
165
166 private synchronized LicenseResponse getLicenseInfo() {
167 return this.licenseInfo == null ? null : this.licenseInfo.getLicenseResponse();
168 }
169
170 private synchronized void setLicenseDisplay(LicenseInfo licenseInfo, String licenseMessage) {
171 this.licenseInfo = licenseInfo;
172 this.licenseInfoMessage = licenseMessage;
174 }
175
177 this.authTokenResponse = authTokenResponse;
178 this.authTokenMessage = authTokenMessage;
179 this.authTokenError = authTokenError;
181 }
182
186 private synchronized boolean isLicenseAddRunning() {
187 return this.licenseFetcher != null && !this.licenseFetcher.isCancelled() && !this.licenseFetcher.isDone();
188 }
189
193 private synchronized boolean isMalwareScansRunning() {
194 return this.authTokenFetcher != null && !this.authTokenFetcher.isCancelled() && !this.authTokenFetcher.isDone();
195 }
196
197 @Messages({
198 "CTOPtionsPanel_loadLicenseInfo_loading=Loading..."
199 })
200 private synchronized void loadLicenseInfo(String licenseNumber) {
201 if (isLicenseAddRunning()) {
202 this.licenseFetcher.cancel(true);
203 }
204 setLicenseDisplay(null, Bundle.CTOPtionsPanel_loadLicenseInfo_loading());
205 setMalwareScansDisplay(null, null, null);
206 this.licenseFetcher = new LicenseFetcher(licenseNumber);
207 this.licenseFetcher.execute();
208 }
209
210 @Messages({
211 "CTOPtionsPanel_loadMalwareScansInfo_loading=Loading..."
212 })
213 private synchronized void loadMalwareScansInfo(LicenseInfo licenseInfo) {
214 if (isMalwareScansRunning()) {
215 this.authTokenFetcher.cancel(true);
216 }
217
218 if (licenseInfo == null || licenseInfo.getDecryptedLicense() == null) {
219 setMalwareScansDisplay(null, null, null);
220 return;
221 }
222
223 setMalwareScansDisplay(null, Bundle.CTOPtionsPanel_loadMalwareScansInfo_loading(), null);
224
225 this.authTokenFetcher = new AuthTokenFetcher(licenseInfo.getDecryptedLicense());
226 this.authTokenFetcher.execute();
227 }
228
229 private static String htmlWrap(String msg) {
230 return msg == null
231 ? null
232 : "<html>" + msg + "</html>";
233 }
234
240 @SuppressWarnings("unchecked")
241 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
242 private void initComponents() {
243 java.awt.GridBagConstraints gridBagConstraints;
244
245 malwareScansPanel = new javax.swing.JPanel();
246 javax.swing.JLabel disclaimer = new javax.swing.JLabel();
247 javax.swing.JPanel licenseInfoPanel = new javax.swing.JPanel();
248 licenseInfoMessageLabel = new javax.swing.JLabel();
249 javax.swing.JPanel buttonSpacer = new javax.swing.JPanel();
250 javax.swing.JPanel buttonPanel = new javax.swing.JPanel();
251 licenseInfoAddButton = new javax.swing.JButton();
252 licenseInfoRemoveButton = new javax.swing.JButton();
253 licenseInfoExpiresLabel = new javax.swing.JLabel();
254 licenseInfoIdLabel = new javax.swing.JLabel();
255 licenseInfoUserLabel = new javax.swing.JLabel();
256 malwareScansMessageLabel = new javax.swing.JLabel();
257 maxHashLookupsLabel = new javax.swing.JLabel();
258 hashLookupsRemainingLabel = new javax.swing.JLabel();
259 maxFileUploadsLabel = new javax.swing.JLabel();
260 fileUploadsRemainingLabel = new javax.swing.JLabel();
261 countersResetLabel = new javax.swing.JLabel();
262 licenseErrorLabel = new javax.swing.JLabel();
263 javax.swing.JPanel purchasePanel = new javax.swing.JPanel();
264 purchaseFromLabel = new javax.swing.JLabel();
265 purchaseLink = new javax.swing.JLabel();
266
267 setMaximumSize(new java.awt.Dimension(650, 32767));
268 setLayout(new java.awt.GridBagLayout());
269
270 malwareScansPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.malwareScansPanel.border.title"))); // NOI18N
271 malwareScansPanel.setMaximumSize(new java.awt.Dimension(650, 2147483647));
272 malwareScansPanel.setLayout(new java.awt.GridBagLayout());
273
274 org.openide.awt.Mnemonics.setLocalizedText(disclaimer, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.text")); // NOI18N
275 disclaimer.setVerticalAlignment(javax.swing.SwingConstants.TOP);
276 disclaimer.setMaximumSize(new java.awt.Dimension(650, 32));
277 disclaimer.setName(""); // NOI18N
278 disclaimer.setPreferredSize(new java.awt.Dimension(650, 32));
279 gridBagConstraints = new java.awt.GridBagConstraints();
280 gridBagConstraints.gridx = 0;
281 gridBagConstraints.gridy = 0;
282 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
283 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
284 gridBagConstraints.weightx = 1.0;
285 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
286 malwareScansPanel.add(disclaimer, gridBagConstraints);
287
288 licenseInfoPanel.setLayout(new java.awt.GridBagLayout());
289
290 org.openide.awt.Mnemonics.setLocalizedText(licenseInfoMessageLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoMessageLabel.text")); // NOI18N
291 gridBagConstraints = new java.awt.GridBagConstraints();
292 gridBagConstraints.gridx = 0;
293 gridBagConstraints.gridy = 0;
294 gridBagConstraints.gridwidth = 3;
295 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
296 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
297 gridBagConstraints.weightx = 1.0;
298 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
299 licenseInfoPanel.add(licenseInfoMessageLabel, gridBagConstraints);
300
301 buttonSpacer.setMaximumSize(new java.awt.Dimension(32767, 0));
302 buttonSpacer.setMinimumSize(new java.awt.Dimension(5, 0));
303 buttonSpacer.setPreferredSize(new java.awt.Dimension(5, 0));
304 gridBagConstraints = new java.awt.GridBagConstraints();
305 gridBagConstraints.gridx = 0;
306 gridBagConstraints.gridy = 2;
307 gridBagConstraints.gridwidth = 2;
308 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
309 gridBagConstraints.weightx = 1.0;
310 licenseInfoPanel.add(buttonSpacer, gridBagConstraints);
311
312 buttonPanel.setLayout(new java.awt.GridBagLayout());
313
314 org.openide.awt.Mnemonics.setLocalizedText(licenseInfoAddButton, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoAddButton.text")); // NOI18N
315 licenseInfoAddButton.addActionListener(new java.awt.event.ActionListener() {
316 public void actionPerformed(java.awt.event.ActionEvent evt) {
317 licenseInfoAddButtonActionPerformed(evt);
318 }
319 });
320 gridBagConstraints = new java.awt.GridBagConstraints();
321 gridBagConstraints.gridx = 0;
322 gridBagConstraints.gridy = 0;
323 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
324 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
325 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
326 buttonPanel.add(licenseInfoAddButton, gridBagConstraints);
327
328 org.openide.awt.Mnemonics.setLocalizedText(licenseInfoRemoveButton, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoRemoveButton.text")); // NOI18N
329 licenseInfoRemoveButton.addActionListener(new java.awt.event.ActionListener() {
330 public void actionPerformed(java.awt.event.ActionEvent evt) {
331 licenseInfoRemoveButtonActionPerformed(evt);
332 }
333 });
334 gridBagConstraints = new java.awt.GridBagConstraints();
335 gridBagConstraints.gridx = 0;
336 gridBagConstraints.gridy = 1;
337 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
338 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
339 gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
340 buttonPanel.add(licenseInfoRemoveButton, gridBagConstraints);
341
342 gridBagConstraints = new java.awt.GridBagConstraints();
343 gridBagConstraints.gridx = 2;
344 gridBagConstraints.gridy = 2;
345 gridBagConstraints.gridheight = 7;
346 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
347 licenseInfoPanel.add(buttonPanel, gridBagConstraints);
348
349 org.openide.awt.Mnemonics.setLocalizedText(licenseInfoExpiresLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoExpiresLabel.text")); // NOI18N
350 gridBagConstraints = new java.awt.GridBagConstraints();
351 gridBagConstraints.gridx = 0;
352 gridBagConstraints.gridy = 3;
353 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
354 gridBagConstraints.weightx = 1.0;
355 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
356 licenseInfoPanel.add(licenseInfoExpiresLabel, gridBagConstraints);
357
358 org.openide.awt.Mnemonics.setLocalizedText(licenseInfoIdLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoIdLabel.text")); // NOI18N
359 gridBagConstraints = new java.awt.GridBagConstraints();
360 gridBagConstraints.gridx = 1;
361 gridBagConstraints.gridy = 3;
362 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
363 gridBagConstraints.weightx = 1.0;
364 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
365 licenseInfoPanel.add(licenseInfoIdLabel, gridBagConstraints);
366
367 org.openide.awt.Mnemonics.setLocalizedText(licenseInfoUserLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseInfoUserLabel.text")); // NOI18N
368 gridBagConstraints = new java.awt.GridBagConstraints();
369 gridBagConstraints.gridx = 0;
370 gridBagConstraints.gridy = 4;
371 gridBagConstraints.gridwidth = 2;
372 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
373 gridBagConstraints.weightx = 1.0;
374 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
375 licenseInfoPanel.add(licenseInfoUserLabel, gridBagConstraints);
376
377 org.openide.awt.Mnemonics.setLocalizedText(malwareScansMessageLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.malwareScansMessageLabel.text")); // NOI18N
378 gridBagConstraints = new java.awt.GridBagConstraints();
379 gridBagConstraints.gridx = 0;
380 gridBagConstraints.gridy = 5;
381 gridBagConstraints.gridwidth = 2;
382 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
383 gridBagConstraints.weightx = 1.0;
384 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
385 licenseInfoPanel.add(malwareScansMessageLabel, gridBagConstraints);
386
387 org.openide.awt.Mnemonics.setLocalizedText(maxHashLookupsLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.maxHashLookupsLabel.text")); // NOI18N
388 gridBagConstraints = new java.awt.GridBagConstraints();
389 gridBagConstraints.gridx = 0;
390 gridBagConstraints.gridy = 6;
391 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
392 gridBagConstraints.weightx = 1.0;
393 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
394 licenseInfoPanel.add(maxHashLookupsLabel, gridBagConstraints);
395
396 org.openide.awt.Mnemonics.setLocalizedText(hashLookupsRemainingLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.hashLookupsRemainingLabel.text")); // NOI18N
397 gridBagConstraints = new java.awt.GridBagConstraints();
398 gridBagConstraints.gridx = 1;
399 gridBagConstraints.gridy = 6;
400 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
401 gridBagConstraints.weightx = 1.0;
402 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
403 licenseInfoPanel.add(hashLookupsRemainingLabel, gridBagConstraints);
404
405 org.openide.awt.Mnemonics.setLocalizedText(maxFileUploadsLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.maxFileUploadsLabel.text")); // NOI18N
406 gridBagConstraints = new java.awt.GridBagConstraints();
407 gridBagConstraints.gridx = 0;
408 gridBagConstraints.gridy = 7;
409 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
410 gridBagConstraints.weightx = 1.0;
411 gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
412 licenseInfoPanel.add(maxFileUploadsLabel, gridBagConstraints);
413
414 org.openide.awt.Mnemonics.setLocalizedText(fileUploadsRemainingLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.fileUploadsRemainingLabel.text")); // NOI18N
415 gridBagConstraints = new java.awt.GridBagConstraints();
416 gridBagConstraints.gridx = 1;
417 gridBagConstraints.gridy = 7;
418 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
419 gridBagConstraints.weightx = 1.0;
420 gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
421 licenseInfoPanel.add(fileUploadsRemainingLabel, gridBagConstraints);
422
423 org.openide.awt.Mnemonics.setLocalizedText(countersResetLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.countersResetLabel.text")); // NOI18N
424 gridBagConstraints = new java.awt.GridBagConstraints();
425 gridBagConstraints.gridx = 0;
426 gridBagConstraints.gridy = 8;
427 gridBagConstraints.gridwidth = 2;
428 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
429 gridBagConstraints.weightx = 1.0;
430 gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
431 licenseInfoPanel.add(countersResetLabel, gridBagConstraints);
432
433 licenseErrorLabel.setForeground(java.awt.Color.RED);
434 org.openide.awt.Mnemonics.setLocalizedText(licenseErrorLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.licenseErrorLabel.text")); // NOI18N
435 gridBagConstraints = new java.awt.GridBagConstraints();
436 gridBagConstraints.gridx = 0;
437 gridBagConstraints.gridy = 1;
438 gridBagConstraints.gridwidth = 3;
439 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
440 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
441 gridBagConstraints.weightx = 1.0;
442 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
443 licenseInfoPanel.add(licenseErrorLabel, gridBagConstraints);
444
445 gridBagConstraints = new java.awt.GridBagConstraints();
446 gridBagConstraints.gridx = 0;
447 gridBagConstraints.gridy = 1;
448 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
449 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
450 gridBagConstraints.weightx = 1.0;
451 malwareScansPanel.add(licenseInfoPanel, gridBagConstraints);
452
453 purchasePanel.setLayout(new java.awt.GridBagLayout());
454
455 org.openide.awt.Mnemonics.setLocalizedText(purchaseFromLabel, org.openide.util.NbBundle.getMessage(CTMalwareScannerOptionsPanel.class, "CTMalwareScannerOptionsPanel.purchaseFromLabel.text")); // NOI18N
456 gridBagConstraints = new java.awt.GridBagConstraints();
457 gridBagConstraints.gridx = 0;
458 gridBagConstraints.gridy = 0;
459 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
460 purchasePanel.add(purchaseFromLabel, gridBagConstraints);
461
462 org.openide.awt.Mnemonics.setLocalizedText(purchaseLink, getHtmlLink(PURCHASE_URL));
463 purchaseLink.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
464 purchaseLink.addMouseListener(new java.awt.event.MouseAdapter() {
465 public void mouseClicked(java.awt.event.MouseEvent evt) {
466 purchaseLinkMouseClicked(evt);
467 }
468 });
469 gridBagConstraints = new java.awt.GridBagConstraints();
470 gridBagConstraints.gridx = 1;
471 gridBagConstraints.gridy = 0;
472 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
473 gridBagConstraints.weightx = 1.0;
474 gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0);
475 purchasePanel.add(purchaseLink, gridBagConstraints);
476
477 gridBagConstraints = new java.awt.GridBagConstraints();
478 gridBagConstraints.gridx = 0;
479 gridBagConstraints.gridy = 2;
480 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
481 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
482 gridBagConstraints.weightx = 1.0;
483 gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
484 malwareScansPanel.add(purchasePanel, gridBagConstraints);
485
486 gridBagConstraints = new java.awt.GridBagConstraints();
487 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
488 gridBagConstraints.weightx = 1.0;
489 add(malwareScansPanel, gridBagConstraints);
490 }// </editor-fold>//GEN-END:initComponents
491
492 @Messages({
493 "CTMalwareScannerOptionsPanel_licenseAddDialog_title=Add a License...",
494 "CTMalwareScannerOptionsPanel_licenseAddDialog_desc=License Number:",
495 "CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_title=License Number Already Entered",
496 "CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_desc=The license number has already been entered",
497 "CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_title=Invalid License Number",
498 "CTMalwareScannerOptionsPanel_licenseAddDialogPatternErr_desc=Please verify that license number is of format 'AUT-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'"})
499 private void licenseInfoAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_licenseInfoAddButtonActionPerformed
500 CTLicenseDialog licenseDialog = new CTLicenseDialog(WindowManager.getDefault().getMainWindow(), true);
501 licenseDialog.setLocationRelativeTo(this);
502 licenseDialog.setVisible(true);
503 String licenseNumber = licenseDialog.getValue();
504 if (licenseNumber != null) {
505 synchronized (this) {
506 if (this.licenseInfo == null || !licenseNumber.trim().equalsIgnoreCase(this.licenseInfo.getDecryptedLicense().getBoostLicenseId())) {
507 loadLicenseInfo(licenseNumber);
508 return;
509 }
510 }
511
512 setMalwareScansDisplay(null, null, htmlWrap(Bundle.CTMalwareScannerOptionsPanel_licenseAddDialogEnteredErr_desc()));
513
514 }
515 }//GEN-LAST:event_licenseInfoAddButtonActionPerformed
516
517 private void purchaseLinkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_purchaseLinkMouseClicked
519 }//GEN-LAST:event_purchaseLinkMouseClicked
520
521 private void licenseInfoRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_licenseInfoRemoveButtonActionPerformed
522 setLicenseDisplay(null, null);
523 setMalwareScansDisplay(null, null, null);
524 this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
525 }//GEN-LAST:event_licenseInfoRemoveButtonActionPerformed
526
527 @NbBundle.Messages({
528 "# {0} - userName",
529 "# {1} - email",
530 "CTMalwareScannerOptionsPanel_licenseInfo_userInfo=<html>User: {0}<br/>Email: {1}</html>",
531 "# {0} - expiresDate",
532 "CTMalwareScannerOptionsPanel_licenseInfo_expires=Expires: {0}",
533 "# {0} - idNumber",
534 "CTMalwareScannerOptionsPanel_licenseInfo_id=ID: {0}",
535 "# {0} - maxDailyLookups",
536 "# {1} - resetSuffix",
537 "CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups=Max Hash lookups: {0}{1}",
538 "# {0} - maxDailyFileLookups",
539 "# {1} - resetSuffix",
540 "CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups=Max file uploads: {0}{1}",
541 "# {0} - countersResetDate",
542 "CTMalwareScannerOptionsPanel_malwareScans_countersReset=Counters reset: {0}",
543 "# {0} - hashLookupsRemaining",
544 "CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining=Hash lookups remaining: {0}",
545 "# {0} - fileUploadsRemaining",
546 "CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining=File uploads remaining: {0}"})
547 private synchronized void renderLicenseState() {
548 this.licenseInfoAddButton.setEnabled(!isLicenseAddRunning());
549 this.licenseInfoRemoveButton.setEnabled(this.licenseInfo != null && !isLicenseAddRunning());
550
551 this.licenseInfoMessageLabel.setVisible(StringUtils.isNotBlank(this.licenseInfoMessage));
552 this.licenseInfoMessageLabel.setText(this.licenseInfoMessage);
553
554 this.licenseErrorLabel.setVisible(StringUtils.isNotBlank(this.authTokenError));
555 this.licenseErrorLabel.setText(this.authTokenError);
556
557 if (licenseInfo == null) {
558 this.licenseInfoExpiresLabel.setVisible(false);
559 this.licenseInfoIdLabel.setVisible(false);
560 this.licenseInfoUserLabel.setVisible(false);
561 this.purchaseFromLabel.setVisible(true);
562 this.purchaseLink.setVisible(true);
563 } else {
564 this.purchaseFromLabel.setVisible(false);
565 this.purchaseLink.setVisible(false);
566
567 this.licenseInfoExpiresLabel.setVisible(true);
568 this.licenseInfoExpiresLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_expires(
569 this.licenseInfo.getDecryptedLicense().getExpirationDate() == null
570 ? ""
571 : LICENSE_EXPIRES_FORMAT.format(this.licenseInfo.getDecryptedLicense().getExpirationDate())));
572 this.licenseInfoIdLabel.setVisible(true);
573 this.licenseInfoIdLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_id(StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getBoostLicenseId())));
574 this.licenseInfoUserLabel.setVisible(true);
575 this.licenseInfoUserLabel.setText(Bundle.CTMalwareScannerOptionsPanel_licenseInfo_userInfo(
576 StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getCustomerName()),
577 StringUtils.defaultString(this.licenseInfo.getDecryptedLicense().getCustomerEmail())));
578 }
579
580 this.malwareScansMessageLabel.setVisible(StringUtils.isNotBlank(this.authTokenMessage));
581 this.malwareScansMessageLabel.setText(this.authTokenMessage);
582
583 if (authTokenResponse == null || this.licenseInfo == null) {
584 this.maxHashLookupsLabel.setVisible(false);
585 this.maxFileUploadsLabel.setVisible(false);
586 this.countersResetLabel.setVisible(false);
587 this.hashLookupsRemainingLabel.setVisible(false);
588 this.fileUploadsRemainingLabel.setVisible(false);
589 } else {
590 this.maxHashLookupsLabel.setVisible(true);
591 this.maxHashLookupsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyHashLookups(
592 this.authTokenResponse.getHashLookupLimit(),
593 getResetSuffix(this.licenseInfo.getDecryptedLicense().getLimitType())));
594
595 this.maxFileUploadsLabel.setVisible(true);
596 this.maxFileUploadsLabel.setText(Bundle.CTMalwareScannerOptionsPanel_malwareScans_maxDailyFileLookups(
597 this.authTokenResponse.getFileUploadLimit(),
598 getResetSuffix(this.licenseInfo.getDecryptedLicense().getLimitType())));
599
600 this.countersResetLabel.setVisible(true);
601 this.countersResetLabel.setText(getCountersResetText(this.licenseInfo.getDecryptedLicense().getLimitType(), this.authTokenResponse));
602
603 this.hashLookupsRemainingLabel.setVisible(true);
604 this.hashLookupsRemainingLabel.setText(
605 Bundle.CTMalwareScannerOptionsPanel_malwareScans_hashLookupsRemaining(
606 remaining(this.authTokenResponse.getHashLookupLimit(), this.authTokenResponse.getHashLookupCount())));
607
608 this.fileUploadsRemainingLabel.setVisible(true);
609 this.fileUploadsRemainingLabel.setText(
610 Bundle.CTMalwareScannerOptionsPanel_malwareScans_fileUploadsRemaining(
611 remaining(this.authTokenResponse.getFileUploadLimit(), this.authTokenResponse.getFileUploadCount())));
612 }
613 }
614
616 if (limitType == null || limitType == LicenseLimitType.NO_RESET) {
617 return "";
618 } else {
619 return Bundle.CTMalwareScannerOptionsPanel_malwareScans_countersReset(
620 MALWARE_SCANS_RESET_FORMAT.format(authTokenResponse.getResetDate()));
621 }
622 }
623
624 @Messages({
625 "CTMalwareScannerOptionsPanel_getResetSuffix_hourly=/hour",
626 "CTMalwareScannerOptionsPanel_getResetSuffix_daily=/day",
627 "CTMalwareScannerOptionsPanel_getResetSuffix_weekly=/week",
628 "CTMalwareScannerOptionsPanel_getResetSuffix_monthly=/month"
629 })
630 private String getResetSuffix(LicenseLimitType limitType) {
631 if (limitType == null) {
632 return "";
633 }
634
635 switch (limitType) {
636 case HOURLY:
637 return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_hourly();
638 case DAILY:
639 return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_daily();
640 case WEEKLY:
641 return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_weekly();
642 case MONTHLY:
643 return Bundle.CTMalwareScannerOptionsPanel_getResetSuffix_monthly();
644 case NO_RESET:
645 default:
646 return "";
647 }
648 }
649
650 private long remaining(Long total, Long used) {
651 total = total == null ? 0 : total;
652 used = used == null ? 0 : used;
653 return total - used;
654 }
655
656 private void acceptEula(LicenseResponse licenseResponse) {
657 try {
658 final EULADialog eulaDialog = new EULADialog(WindowManager.getDefault().getMainWindow(), true);
659 eulaDialog.setLocationRelativeTo(this);
660 eulaDialog.setSize(eulaDialog.getPreferredSize());
661 eulaDialog.setVisible(true);
662
663 if (eulaDialog.isAcceptPressed()) {
664 // only indicate a change to save if we have accepted EULA for a license
665 this.licenseInfo = LicenseDecryptorUtil.getInstance().createLicenseInfo(licenseResponse);
666 this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
667 }
668 setLicenseDisplay(this.licenseInfo, null);
669 loadMalwareScansInfo(this.licenseInfo);
670 } catch (IOException | InvalidLicenseException ex) {
671 logger.log(Level.WARNING, "An error occurred while fetching data", ex);
672 setLicenseDisplay(this.licenseInfo, null);
673 setMalwareScansDisplay(null, null, htmlWrap(Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc()));
674 }
675 }
676
677 @NbBundle.Messages({
678 "CTMalwareScannerOptionsPanel_LicenseFetcher_apiErr_title=Server Error",
679 "CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_title=General Error",
680 "# {0} - licenseCode",
681 "CTMalwareScannerOptionsPanel_LicenseFetcher_defaultErrMsg_desc=Error activating boost license {0}",
682 "CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc=A general error occurred while fetching license information. Please try again later.",})
683 private class LicenseFetcher extends SwingWorker<LicenseResponse, Void> {
684
685 private final String licenseText;
686
688 this.licenseText = licenseText;
689 }
690
691 @Override
692 protected LicenseResponse doInBackground() throws Exception {
693 if (this.isCancelled()) {
694 return null;
695 }
696 return ctApiDAO.getLicenseInfo(licenseText);
697 }
698
699 @Override
700 protected void done() {
701 try {
702 LicenseResponse licenseResponse = get();
703 // if no result, show unauthorized
704 if (licenseResponse == null) {
705 logger.log(Level.WARNING, "An API error occurred while fetching license information. License fetch returned no result.");
706 setLicenseDisplay(null, null);
708 return;
709 }
710
711 // if not successful response
712 if (!Boolean.TRUE.equals(licenseResponse.isSuccess())) {
713 logger.log(Level.WARNING, "An API error occurred while fetching license information. License fetch was not successful");
714 // use default message unless error message specified
715 String message = Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_defaultErrMsg_desc(licenseText);
716 if (!StringUtils.isBlank(licenseResponse.getErrorMsg())) {
717 message = licenseResponse.getErrorMsg();
718 }
719 setLicenseDisplay(null, null);
720 setMalwareScansDisplay(null, null, htmlWrap(message));
721 return;
722 }
723
724 // otherwise, load
725 SwingUtilities.invokeLater(() -> acceptEula(licenseResponse));
726
727 } catch (InterruptedException | CancellationException ex) {
728 // ignore cancellation; just load current license
731 } catch (ExecutionException ex) {
732 String errMessage;
733 if (ex.getCause() != null && ex.getCause() instanceof CTCloudException cloudEx) {
734 logger.log(Level.WARNING, "An API error occurred while fetching license information", cloudEx);
735 errMessage = cloudEx.getErrorDetails();
736 } else {
737 logger.log(Level.WARNING, "An error occurred while fetching data", ex);
738 errMessage = Bundle.CTMalwareScannerOptionsPanel_LicenseFetcher_localErr_desc();
739 }
740 setLicenseDisplay(null, null);
741 setMalwareScansDisplay(null, null, htmlWrap(errMessage));
742 } finally {
743 synchronized (CTMalwareScannerOptionsPanel.this) {
744 CTMalwareScannerOptionsPanel.this.licenseFetcher = null;
745 }
746 }
747 }
748 }
749
750 @NbBundle.Messages({
751 "CTMalwareScannerOptionsPanel_MalwareScansFetcher_apiErr_title=Server Error",
752 "CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_title=General Error",
753 "CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_desc=A general error occurred while fetching malware scans information. Please try again later.",})
754 private class AuthTokenFetcher extends SwingWorker<AuthTokenResponse, Void> {
755
757
761
762 @Override
763 protected AuthTokenResponse doInBackground() throws Exception {
764 if (this.isCancelled()) {
765 return null;
766 }
767
768 return ctApiDAO.getAuthToken(decryptedLicense);
769 }
770
771 @Override
772 protected void done() {
774 String authTokenError = null;
775 try {
776 authTokenResponse = get();
777 } catch (InterruptedException | CancellationException ex) {
778 // ignore cancellation
779 } catch (ExecutionException ex) {
780 if (ex.getCause() != null && ex.getCause() instanceof CTCloudException cloudEx) {
781 logger.log(Level.WARNING, "An API error occurred while fetching malware scans information for license", cloudEx);
782 authTokenError = cloudEx.getErrorDetails();
783 } else {
784 logger.log(Level.WARNING, "An error occurred while fetching data", ex);
785 authTokenError = Bundle.CTMalwareScannerOptionsPanel_MalwareScansFetcher_localErr_desc();
786 }
787 } finally {
788 synchronized (CTMalwareScannerOptionsPanel.this) {
789 CTMalwareScannerOptionsPanel.this.authTokenFetcher = null;
790 if (!this.isCancelled()) {
792 }
793 }
794 }
795 }
796 }
797
798
799 // Variables declaration - do not modify//GEN-BEGIN:variables
800 private javax.swing.JLabel countersResetLabel;
801 private javax.swing.JLabel fileUploadsRemainingLabel;
802 private javax.swing.JLabel hashLookupsRemainingLabel;
803 private javax.swing.JLabel licenseErrorLabel;
804 private javax.swing.JButton licenseInfoAddButton;
805 private javax.swing.JLabel licenseInfoExpiresLabel;
806 private javax.swing.JLabel licenseInfoIdLabel;
807 private javax.swing.JLabel licenseInfoMessageLabel;
808 private javax.swing.JButton licenseInfoRemoveButton;
809 private javax.swing.JLabel licenseInfoUserLabel;
810 private javax.swing.JLabel malwareScansMessageLabel;
811 private javax.swing.JPanel malwareScansPanel;
812 private javax.swing.JLabel maxFileUploadsLabel;
813 private javax.swing.JLabel maxHashLookupsLabel;
814 private javax.swing.JLabel purchaseFromLabel;
815 private javax.swing.JLabel purchaseLink;
816 // End of variables declaration//GEN-END:variables
817}
synchronized void setLicenseDisplay(LicenseInfo licenseInfo, String licenseMessage)
static String getCountersResetText(LicenseLimitType limitType, AuthTokenResponse authTokenResponse)
synchronized void setMalwareScansDisplay(AuthTokenResponse authTokenResponse, String authTokenMessage, String authTokenError)
synchronized static Logger getLogger(String name)
Definition Logger.java:124

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.