From 9163097d3cf42a7df39e33989fb363b0d7c7048a Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 10 Mar 2020 16:33:29 -0400 Subject: [PATCH 1/3] 6028 Restrict ability to add hash sets to CR --- .../autopsy/featureaccess/FeatureAccessUtils.java | 12 +++++++++++- .../hashdatabase/HashDbImportDatabaseDialog.java | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/featureaccess/FeatureAccessUtils.java b/Core/src/org/sleuthkit/autopsy/featureaccess/FeatureAccessUtils.java index 87b4fed4f7..780ceb054e 100644 --- a/Core/src/org/sleuthkit/autopsy/featureaccess/FeatureAccessUtils.java +++ b/Core/src/org/sleuthkit/autopsy/featureaccess/FeatureAccessUtils.java @@ -73,6 +73,16 @@ final public class FeatureAccessUtils { return dataSourceDeletionAllowed; } + /** + * Indicates whether or not a user can add hash sets to the central + * repository. + * + * @return True or false. + */ + public static boolean canAddHashSetsToCentralRepo() { + return multiUserCaseRestrictionsFileAbsent(); + } + /** * Indicates whether or not the current case is a single-user case. * @@ -88,7 +98,7 @@ final public class FeatureAccessUtils { * * @return True or false. */ - public static boolean multiUserCaseRestrictionsFileAbsent() { + private static boolean multiUserCaseRestrictionsFileAbsent() { File accessLimitingFile = new File(MULTIUSER_CASE_RESTRICTED_FILE_PATH); return !accessLimitingFile.exists(); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index 1e34c9bbda..f3bd39148f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2018 Basis Technology Corp. + * Copyright 2014-2020 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,6 +42,7 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFile import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDbManagerException; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository; +import org.sleuthkit.autopsy.featureaccess.FeatureAccessUtils; /** * Instances of this class allow a user to select an existing hash database and @@ -108,8 +109,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private void enableComponents(){ - - if(! CentralRepository.isEnabled()){ + if(!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()){ centralRepoRadioButton.setEnabled(false); fileTypeRadioButton.setSelected(true); } else { From 20ba2b77c5a05db5f23ad5dd3d41352387345f1b Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 11 Mar 2020 19:02:03 -0400 Subject: [PATCH 2/3] 6028 Restrict ability to add hash sets to CR --- .../HashDbCreateDatabaseDialog.java | 85 ++++++++++--------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java index 6f68a3defc..5470b385fb 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013-2018 Basis Technology Corp. + * Copyright 2013-2020 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,6 +44,7 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDbManagerExc import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository; +import org.sleuthkit.autopsy.featureaccess.FeatureAccessUtils; /** * Instances of this class allow a user to create a new hash database and add it @@ -124,29 +125,29 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { setLocationRelativeTo(getOwner()); setVisible(true); } - - private void enableComponents(){ - - if(! CentralRepository.isEnabled()){ + + private void enableComponents() { + + if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) { centralRepoRadioButton.setEnabled(false); fileTypeRadioButton.setSelected(true); } else { populateCombobox(); } - + boolean isFileType = fileTypeRadioButton.isSelected(); // Type type only databasePathLabel.setEnabled(isFileType); databasePathTextField.setEnabled(isFileType); saveAsButton.setEnabled(isFileType); - + // Central repo only - lbOrg.setEnabled(! isFileType); - orgButton.setEnabled(! isFileType); - orgComboBox.setEnabled(! isFileType); + lbOrg.setEnabled(!isFileType); + orgButton.setEnabled(!isFileType); + orgComboBox.setEnabled(!isFileType); } - + @NbBundle.Messages({"HashDbCreateDatabaseDialog.populateOrgsError.message=Failure loading organizations."}) private void populateCombobox() { orgComboBox.removeAllItems(); @@ -155,7 +156,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { orgs = dbManager.getOrganizations(); orgs.forEach((org) -> { orgComboBox.addItem(org.getName()); - if(CentralRepoDbUtil.isDefaultOrg(org)){ + if (CentralRepoDbUtil.isDefaultOrg(org)) { orgComboBox.setSelectedItem(org.getName()); selectedOrg = org; } @@ -167,7 +168,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { JOptionPane.showMessageDialog(this, Bundle.HashDbCreateDatabaseDialog_populateOrgsError_message()); Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Failure loading organizations", ex); } - } + } /** * This method is called from within the constructor to initialize the form. @@ -413,7 +414,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { path.append(lastBaseDirectory); File hashDbFolder = new File(path.toString()); // create the folder if it doesn't exist - if (!hashDbFolder.exists()){ + if (!hashDbFolder.exists()) { hashDbFolder.mkdir(); } if (!hashSetNameTextField.getText().isEmpty()) { @@ -452,7 +453,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { return; } - if(fileTypeRadioButton.isSelected()){ + if (fileTypeRadioButton.isSelected()) { if (databasePathTextField.getText().isEmpty()) { JOptionPane.showMessageDialog(this, NbBundle.getMessage(this.getClass(), @@ -463,13 +464,13 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { return; } } else { - if(selectedOrg == null){ + if (selectedOrg == null) { JOptionPane.showMessageDialog(this, - NbBundle.getMessage(this.getClass(), - "HashDbCreateDatabaseDialog.missingOrg"), - NbBundle.getMessage(this.getClass(), - "HashDbCreateDatabaseDialog.createHashDbErr"), - JOptionPane.ERROR_MESSAGE); + NbBundle.getMessage(this.getClass(), + "HashDbCreateDatabaseDialog.missingOrg"), + NbBundle.getMessage(this.getClass(), + "HashDbCreateDatabaseDialog.createHashDbErr"), + JOptionPane.ERROR_MESSAGE); return; } } @@ -487,7 +488,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { String errorMessage = NbBundle .getMessage(this.getClass(), "HashDbCreateDatabaseDialog.errMsg.hashDbCreationErr"); - if(fileTypeRadioButton.isSelected()){ + if (fileTypeRadioButton.isSelected()) { try { newHashDb = HashDbManager.getInstance().addNewHashDatabaseNoSave(hashSetNameTextField.getText(), fileChooser.getSelectedFile().getCanonicalPath(), true, sendIngestMessagesCheckbox.isSelected(), type); } catch (IOException ex) { @@ -510,17 +511,17 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { } } else { // Check if a hash set with the same name/version already exists - try{ - if(CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), "")){ + try { + if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), "")) { JOptionPane.showMessageDialog(this, - NbBundle.getMessage(this.getClass(), - "HashDbCreateDatabaseDialog.duplicateName"), - NbBundle.getMessage(this.getClass(), - "HashDbCreateDatabaseDialog.createHashDbErr"), - JOptionPane.ERROR_MESSAGE); + NbBundle.getMessage(this.getClass(), + "HashDbCreateDatabaseDialog.duplicateName"), + NbBundle.getMessage(this.getClass(), + "HashDbCreateDatabaseDialog.createHashDbErr"), + JOptionPane.ERROR_MESSAGE); return; } - } catch (CentralRepoException ex){ + } catch (CentralRepoException ex) { Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error looking up reference set", ex); JOptionPane.showMessageDialog(this, NbBundle.getMessage(this.getClass(), @@ -528,16 +529,16 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { NbBundle.getMessage(this.getClass(), "HashDbCreateDatabaseDialog.createHashDbErr"), JOptionPane.ERROR_MESSAGE); - return; + return; } - - try{ - int referenceSetID = CentralRepository.getInstance().newReferenceSet(new CentralRepoFileSet(selectedOrg.getOrgID(), hashSetNameTextField.getText(), + + try { + int referenceSetID = CentralRepository.getInstance().newReferenceSet(new CentralRepoFileSet(selectedOrg.getOrgID(), hashSetNameTextField.getText(), "", fileKnown, false, CentralRepository.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID))); - newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetNameTextField.getText(), - "", referenceSetID, + newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetNameTextField.getText(), + "", referenceSetID, true, sendIngestMessagesCheckbox.isSelected(), type, false); - } catch (CentralRepoException | TskCoreException ex){ + } catch (CentralRepoException | TskCoreException ex) { Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error creating new reference set", ex); JOptionPane.showMessageDialog(this, NbBundle.getMessage(this.getClass(), @@ -545,8 +546,8 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { NbBundle.getMessage(this.getClass(), "HashDbCreateDatabaseDialog.createHashDbErr"), JOptionPane.ERROR_MESSAGE); - return; - } + return; + } } dispose(); @@ -561,11 +562,13 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { // update the combobox options if (dialog.isChanged()) { populateCombobox(); - } + } }//GEN-LAST:event_orgButtonActionPerformed private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed - if (null == orgComboBox.getSelectedItem()) return; + if (null == orgComboBox.getSelectedItem()) { + return; + } String orgName = this.orgComboBox.getSelectedItem().toString(); for (CentralRepoOrganization org : orgs) { if (org.getName().equals(orgName)) { From c9982d4440f272a957032eab0c22fabe12edd594 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 11 Mar 2020 19:03:58 -0400 Subject: [PATCH 3/3] 6028 Restrict ability to add hash sets to CR --- .../HashDbImportDatabaseDialog.java | 112 +++++++++--------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index f3bd39148f..a08f324a44 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2014-2020 Basis Technology Corp. + * Copyright 2013-2020 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -90,7 +90,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { String[] EXTENSION = new String[]{"txt", "kdb", "idx", "hash", "Hash", "hsh"}; //NON-NLS FileNameExtensionFilter filter = new FileNameExtensionFilter( NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION); - fileChooser.setFileFilter(filter); + fileChooser.setFileFilter(filter); fileChooser.setMultiSelectionEnabled(false); } @@ -106,28 +106,28 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { } return shortenedPath; } - - private void enableComponents(){ - - if(!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()){ + + private void enableComponents() { + + if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) { centralRepoRadioButton.setEnabled(false); fileTypeRadioButton.setSelected(true); } else { populateCombobox(); } - + boolean isFileType = fileTypeRadioButton.isSelected(); // Central repo only - lbVersion.setEnabled((! isFileType) && (readOnlyCheckbox.isSelected())); - versionTextField.setEnabled((! isFileType) && (readOnlyCheckbox.isSelected())); - - lbOrg.setEnabled(! isFileType); - orgButton.setEnabled(! isFileType); - orgComboBox.setEnabled(! isFileType); - readOnlyCheckbox.setEnabled(! isFileType); + lbVersion.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected())); + versionTextField.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected())); + + lbOrg.setEnabled(!isFileType); + orgButton.setEnabled(!isFileType); + orgComboBox.setEnabled(!isFileType); + readOnlyCheckbox.setEnabled(!isFileType); } - + @NbBundle.Messages({"HashDbImportDatabaseDialog.populateOrgsError.message=Failure loading organizations."}) private void populateCombobox() { orgComboBox.removeAllItems(); @@ -136,7 +136,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { orgs = dbManager.getOrganizations(); orgs.forEach((org) -> { orgComboBox.addItem(org.getName()); - if(CentralRepoDbUtil.isDefaultOrg(org)){ + if (CentralRepoDbUtil.isDefaultOrg(org)) { orgComboBox.setSelectedItem(org.getName()); selectedOrg = org; } @@ -468,28 +468,28 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { JOptionPane.ERROR_MESSAGE); return; } - - if(centralRepoRadioButton.isSelected()){ - if(readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()){ + + if (centralRepoRadioButton.isSelected()) { + if (readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()) { JOptionPane.showMessageDialog(this, - NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.missingVersion"), - NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.importHashDbErr"), - JOptionPane.ERROR_MESSAGE); + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.missingVersion"), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); return; } - - if(selectedOrg == null){ + + if (selectedOrg == null) { JOptionPane.showMessageDialog(this, - NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.missingOrg"), - NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.importHashDbErr"), - JOptionPane.ERROR_MESSAGE); + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.missingOrg"), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); return; } - } + } if (selectedFilePath.isEmpty()) { JOptionPane.showMessageDialog(this, @@ -500,7 +500,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { JOptionPane.ERROR_MESSAGE); return; } - + File file = new File(selectedFilePath); if (!file.exists()) { JOptionPane.showMessageDialog(this, @@ -523,11 +523,11 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { String errorMessage = NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.unableToCopyToUserDirMsg", locationInUserConfigDir); Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex); JOptionPane.showMessageDialog(this, errorMessage, NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.importHashDbErr"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.ERROR_MESSAGE); return; } } - + KnownFilesType type; if (knownRadioButton.isSelected()) { type = KnownFilesType.KNOWN; @@ -536,9 +536,9 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { } String errorMessage = NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg", - selectedFilePath); - if(fileTypeRadioButton.isSelected()){ + "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg", + selectedFilePath); + if (fileTypeRadioButton.isSelected()) { try { selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type); @@ -552,19 +552,19 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { return; } } else { - + // Check if a hash set with the same name/version already exists - try{ - if(CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())){ + try { + if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())) { JOptionPane.showMessageDialog(this, - NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.duplicateName"), - NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.importHashDbErr"), - JOptionPane.ERROR_MESSAGE); + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.duplicateName"), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); return; } - } catch (CentralRepoException ex){ + } catch (CentralRepoException ex) { Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error looking up reference set", ex); JOptionPane.showMessageDialog(this, NbBundle.getMessage(this.getClass(), @@ -572,20 +572,20 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.importHashDbErr"), JOptionPane.ERROR_MESSAGE); - return; + return; } - + String version; - if(readOnlyCheckbox.isSelected()){ + if (readOnlyCheckbox.isSelected()) { version = versionTextField.getText(); } else { // Editable databases don't have a version version = ""; } ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog(); - progressDialog.importFile(hashSetNameTextField.getText(), version, - selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type, - readOnlyCheckbox.isSelected(), selectedFilePath); + progressDialog.importFile(hashSetNameTextField.getText(), version, + selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type, + readOnlyCheckbox.isSelected(), selectedFilePath); selectedHashDb = progressDialog.getDatabase(); } @@ -609,11 +609,13 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { // update the combobox options if (dialog.isChanged()) { populateCombobox(); - } + } }//GEN-LAST:event_orgButtonActionPerformed private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed - if (null == orgComboBox.getSelectedItem()) return; + if (null == orgComboBox.getSelectedItem()) { + return; + } String orgName = this.orgComboBox.getSelectedItem().toString(); for (CentralRepoOrganization org : orgs) { if (org.getName().equals(orgName)) {