From 336b9883d551ea0f8e646838ad3bae2f9bd43e66 Mon Sep 17 00:00:00 2001 From: bmeeks8 Date: Thu, 14 May 2015 00:02:18 -0400 Subject: Add TLS Certs Store directory size mgmt settings feature. --- config/suricata/suricata_check_cron_misc.inc | 20 ++++++++++++++++++++ config/suricata/suricata_logs_mgmt.php | 18 ++++++++++++++++++ config/suricata/suricata_migrate_config.php | 5 +++++ 3 files changed, 43 insertions(+) diff --git a/config/suricata/suricata_check_cron_misc.inc b/config/suricata/suricata_check_cron_misc.inc index eb1ba2d0..ab2f864f 100644 --- a/config/suricata/suricata_check_cron_misc.inc +++ b/config/suricata/suricata_check_cron_misc.inc @@ -104,6 +104,9 @@ function suricata_check_dir_size_limit($suricataloglimitsize) { // Check for any captured stored files and clean them up unlink_if_exists("{$suricata_log_dir}/files/*"); + // Check for any captured stored TLS certs and clean them up + unlink_if_exists("{$suricata_log_dir}/certs/*"); + // This is needed if suricata is run as suricata user mwexec('/bin/chmod 660 /var/log/suricata/*', true); } @@ -237,6 +240,23 @@ if ($config['installedpackages']['suricata']['config'][0]['enable_log_mgmt'] == unset($files); } + // Prune aged-out TLS Certs Store files if any exist + if (is_dir("{$suricata_log_dir}/certs") && + $config['installedpackages']['suricata']['config'][0]['tls_certs_store_retention'] > 0) { + $now = time(); + $files = glob("{$suricata_log_dir}/certs/*.*"); + $prune_count = 0; + foreach ($files as $f) { + if (($now - filemtime($f)) > ($config['installedpackages']['suricata']['config'][0]['tls_certs_store_retention'] * 3600)) { + $prune_count++; + unlink_if_exists($f); + } + } + if ($prune_count > 0) + log_error(gettext("[Suricata] TLS Certs Store cleanup job removed {$prune_count} file(s) from {$suricata_log_dir}/certs/...")); + unset($files); + } + // Prune any pcap log files over configured limit $files = glob("{$suricata_log_dir}/log.pcap.*"); if (count($files) > $value['max_pcap_log_files']) { diff --git a/config/suricata/suricata_logs_mgmt.php b/config/suricata/suricata_logs_mgmt.php index aa353d6f..4bb49958 100644 --- a/config/suricata/suricata_logs_mgmt.php +++ b/config/suricata/suricata_logs_mgmt.php @@ -67,6 +67,7 @@ $pconfig['tls_log_retention'] = $config['installedpackages']['suricata']['config $pconfig['unified2_log_limit'] = $config['installedpackages']['suricata']['config'][0]['unified2_log_limit']; $pconfig['u2_archive_log_retention'] = $config['installedpackages']['suricata']['config'][0]['u2_archive_log_retention']; $pconfig['file_store_retention'] = $config['installedpackages']['suricata']['config'][0]['file_store_retention']; +$pconfig['tls_certs_store_retention'] = $config['installedpackages']['suricata']['config'][0]['tls_certs_store_retention']; $pconfig['dns_log_limit_size'] = $config['installedpackages']['suricata']['config'][0]['dns_log_limit_size']; $pconfig['dns_log_retention'] = $config['installedpackages']['suricata']['config'][0]['dns_log_retention']; $pconfig['eve_log_limit_size'] = $config['installedpackages']['suricata']['config'][0]['eve_log_limit_size']; @@ -112,6 +113,8 @@ if (!isset($pconfig['u2_archive_log_retention'])) $pconfig['u2_archive_log_retention'] = "168"; if (!isset($pconfig['file_store_retention'])) $pconfig['file_store_retention'] = "168"; +if (!isset($pconfig['tls_certs_store_retention'])) + $pconfig['tls_certs_store_retention'] = "168"; if (!isset($pconfig['eve_log_retention'])) $pconfig['eve_log_retention'] = "168"; if (!isset($pconfig['sid_changes_log_retention'])) @@ -151,6 +154,7 @@ if ($_POST['ResetAll']) { $pconfig['tls_log_retention'] = "336"; $pconfig['u2_archive_log_retention'] = "168"; $pconfig['file_store_retention'] = "168"; + $pconfig['tls_certs_store_retention'] = "168"; $pconfig['eve_log_retention'] = "168"; $pconfig['sid_changes_log_retention'] = "336"; @@ -216,6 +220,7 @@ if ($_POST["save"] || $_POST['apply']) { $config['installedpackages']['suricata']['config'][0]['unified2_log_limit'] = $_POST['unified2_log_limit']; $config['installedpackages']['suricata']['config'][0]['u2_archive_log_retention'] = $_POST['u2_archive_log_retention']; $config['installedpackages']['suricata']['config'][0]['file_store_retention'] = $_POST['file_store_retention']; + $config['installedpackages']['suricata']['config'][0]['tls_certs_store_retention'] = $_POST['tls_certs_store_retention']; $config['installedpackages']['suricata']['config'][0]['dns_log_limit_size'] = $_POST['dns_log_limit_size']; $config['installedpackages']['suricata']['config'][0]['dns_log_retention'] = $_POST['dns_log_retention']; $config['installedpackages']['suricata']['config'][0]['eve_log_limit_size'] = $_POST['eve_log_limit_size']; @@ -587,6 +592,19 @@ if ($savemsg) { gettext("for later analysis. This setting determines how long files remain in the File Store folder before they are automatically deleted.");?> + + +  " . gettext("7 days."). "";?>

+ + + diff --git a/config/suricata/suricata_migrate_config.php b/config/suricata/suricata_migrate_config.php index afbedd94..384033b3 100644 --- a/config/suricata/suricata_migrate_config.php +++ b/config/suricata/suricata_migrate_config.php @@ -174,6 +174,11 @@ if (!isset($config['installedpackages']['suricata']['config'][0]['file_store_ret $updated_cfg = true; } +if (!isset($config['installedpackages']['suricata']['config'][0]['tls_certs_store_retention']) && $config['installedpackages']['suricata']['config'][0]['tls_certs_store_retention'] != '0') { + $config['installedpackages']['suricata']['config'][0]['tls_certs_store_retention'] = "168"; + $updated_cfg = true; +} + if (!isset($config['installedpackages']['suricata']['config'][0]['u2_archive_log_retention']) && $config['installedpackages']['suricata']['config'][0]['u2_archive_log_retention'] != '0') { $config['installedpackages']['suricata']['config'][0]['u2_archive_log_retention'] = "168"; $updated_cfg = true; -- cgit v1.2.3