Merge pull request #5694 from rcordovano/6028-restrict-adding-hashsets-to-cr

6028 Restrict ability to add hash sets to CR
This commit is contained in:
Richard Cordovano 2020-03-12 10:47:14 -04:00 committed by GitHub
commit e8e05d634e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 97 deletions

View File

@ -82,6 +82,16 @@ final public class FeatureAccessUtils {
return currentCaseIsSingleUserCase() || multiUserCaseRestrictionsFileAbsent();
}
/**
* 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.
*

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2013-2018 Basis Technology Corp.
* Copyright 2013-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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
@ -125,9 +126,9 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
setVisible(true);
}
private void enableComponents(){
private void enableComponents() {
if(! CentralRepository.isEnabled()){
if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) {
centralRepoRadioButton.setEnabled(false);
fileTypeRadioButton.setSelected(true);
} else {
@ -142,9 +143,9 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
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."})
@ -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;
}
@ -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,7 +464,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
return;
}
} else {
if(selectedOrg == null){
if (selectedOrg == null) {
JOptionPane.showMessageDialog(this,
NbBundle.getMessage(this.getClass(),
"HashDbCreateDatabaseDialog.missingOrg"),
@ -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,8 +511,8 @@ 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"),
@ -520,7 +521,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
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(),
@ -531,13 +532,13 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
return;
}
try{
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,
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(),
@ -565,7 +566,9 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
}//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)) {

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2018 Basis Technology Corp.
* Copyright 2013-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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
@ -106,10 +107,9 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
return shortenedPath;
}
private void enableComponents(){
private void enableComponents() {
if(! CentralRepository.isEnabled()){
if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) {
centralRepoRadioButton.setEnabled(false);
fileTypeRadioButton.setSelected(true);
} else {
@ -119,13 +119,13 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
boolean isFileType = fileTypeRadioButton.isSelected();
// Central repo only
lbVersion.setEnabled((! isFileType) && (readOnlyCheckbox.isSelected()));
versionTextField.setEnabled((! isFileType) && (readOnlyCheckbox.isSelected()));
lbVersion.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
versionTextField.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
lbOrg.setEnabled(! isFileType);
orgButton.setEnabled(! isFileType);
orgComboBox.setEnabled(! isFileType);
readOnlyCheckbox.setEnabled(! isFileType);
lbOrg.setEnabled(!isFileType);
orgButton.setEnabled(!isFileType);
orgComboBox.setEnabled(!isFileType);
readOnlyCheckbox.setEnabled(!isFileType);
}
@NbBundle.Messages({"HashDbImportDatabaseDialog.populateOrgsError.message=Failure loading organizations."})
@ -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;
}
@ -469,8 +469,8 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
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"),
@ -480,7 +480,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
return;
}
if(selectedOrg == null){
if (selectedOrg == null) {
JOptionPane.showMessageDialog(this,
NbBundle.getMessage(this.getClass(),
"HashDbImportDatabaseDialog.missingOrg"),
@ -538,7 +538,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
String errorMessage = NbBundle.getMessage(this.getClass(),
"HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg",
selectedFilePath);
if(fileTypeRadioButton.isSelected()){
if (fileTypeRadioButton.isSelected()) {
try {
selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type);
@ -554,8 +554,8 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
} 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"),
@ -564,7 +564,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
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(),
@ -576,7 +576,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
}
String version;
if(readOnlyCheckbox.isSelected()){
if (readOnlyCheckbox.isSelected()) {
version = versionTextField.getText();
} else {
// Editable databases don't have a version
@ -613,7 +613,9 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
}//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)) {