From 240178eba71d9e9389a874dc18b6bfc07e038a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Kolly?= Date: Sun, 28 Jul 2019 19:49:32 +0200 Subject: [PATCH] Implement global CAA settings --- actions/admin/settings/160.nameserver.php | 16 ++++++++++ install/froxlor.sql | 3 +- .../updates/froxlor/0.10/update_0.10.inc.php | 5 +-- lib/Froxlor/Dns/Dns.php | 31 ++++++++++++------- lng/english.lng.php | 6 ++-- lng/german.lng.php | 6 ++-- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/actions/admin/settings/160.nameserver.php b/actions/admin/settings/160.nameserver.php index a7df3322..8c24f75f 100644 --- a/actions/admin/settings/160.nameserver.php +++ b/actions/admin/settings/160.nameserver.php @@ -107,6 +107,22 @@ return array( 'default' => false, 'save_method' => 'storeSettingField' ), + 'system_dns_createcaaentry' => array( + 'label' => $lng['serversettings']['caa_entry'], + 'settinggroup' => 'system', + 'varname' => 'dns_createcaaentry', + 'type' => 'bool', + 'default' => true, + 'save_method' => 'storeSettingField' + ), + 'caa.caa_entry' => array( + 'label' => $lng['serversettings']['caa_entry_custom'], + 'settinggroup' => 'caa', + 'varname' => 'caa_entry', + 'type' => 'text', + 'default' => '', + 'save_method' => 'storeSettingField' + ), 'system_defaultttl' => array( 'label' => $lng['serversettings']['defaultttl'], 'settinggroup' => 'system', diff --git a/install/froxlor.sql b/install/froxlor.sql index 169d7712..f3cf318c 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -256,7 +256,6 @@ CREATE TABLE `panel_domains` ( `mod_fcgid_maxrequests` int(4) default '-1', `ismainbutsubto` int(11) unsigned NOT NULL default '0', `letsencrypt` tinyint(1) NOT NULL default '0', - `caa` text default NULL, `hsts` varchar(10) NOT NULL default '0', `hsts_sub` tinyint(1) NOT NULL default '0', `hsts_preload` tinyint(1) NOT NULL default '0', @@ -376,6 +375,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('admin', 'show_news_feed', '0'), ('admin', 'show_version_login', '0'), ('admin', 'show_version_footer', '0'), + ('caa', 'caa_entry', ''), ('spf', 'use_spf', '0'), ('spf', 'spf_entry', '"v=spf1 a mx -all"'), ('dkim', 'dkim_algorithm', 'all'), @@ -562,6 +562,7 @@ opcache.interned_strings_buffer'), ('system', 'mod_fcgid_defaultini', '1'), ('system', 'ftpserver', 'proftpd'), ('system', 'dns_createmailentry', '0'), + ('system', 'dns_createcaaentry', '1'), ('system', 'froxlordirectlyviahostname', '0'), ('system', 'report_enable', '1'), ('system', 'report_webmax', '90'), diff --git a/install/updates/froxlor/0.10/update_0.10.inc.php b/install/updates/froxlor/0.10/update_0.10.inc.php index a009fb54..bac449ea 100644 --- a/install/updates/froxlor/0.10/update_0.10.inc.php +++ b/install/updates/froxlor/0.10/update_0.10.inc.php @@ -266,8 +266,9 @@ if (\Froxlor\Froxlor::isFroxlorVersion('0.10.0-rc1')) { if (\Froxlor\Froxlor::isDatabaseVersion('201904250')) { - showUpdateStep("Adding field caa for domains"); - Database::query("ALTER TABLE `" . TABLE_PANEL_DOMAINS . "` ADD `caa` text default NULL AFTER `letsencrypt`;"); + showUpdateStep("Adding new settings for CAA"); + Settings::AddNew('caa.caa_entry', '', true); + Settings::AddNew('system.dns_createcaaentry', 1, true); lastStepStatus(0); \Froxlor\Froxlor::updateToDbVersion('201907270'); diff --git a/lib/Froxlor/Dns/Dns.php b/lib/Froxlor/Dns/Dns.php index 0d754f21..bd0b4a78 100644 --- a/lib/Froxlor/Dns/Dns.php +++ b/lib/Froxlor/Dns/Dns.php @@ -131,15 +131,9 @@ class Dns } // additional required records for CAA if activated - if (!is_null($domain['caa'])) { + if (Settings::Get('system.dns_createcaaentry') && Settings::Get('system.use_ssl') == "1" && !empty($domain['p_ssl_ipandports'])) { // check for CAA content later - self::addRequiredEntry('@', 'CAA', $required_entries); - // additional required records by subdomain setting - if ($domain['iswildcarddomain'] == '1') { - self::addRequiredEntry('*', 'CAA', $required_entries); - } elseif ($domain['wwwserveralias'] == '1') { - self::addRequiredEntry('www', 'CAA', $required_entries); - } + self::addRequiredEntry('@CAA@', 'CAA', $required_entries); } // additional required records for SPF and DKIM if activated @@ -162,6 +156,10 @@ class Dns if (array_key_exists($entry['type'], $required_entries) && array_key_exists(md5($entry['record']), $required_entries[$entry['type']])) { unset($required_entries[$entry['type']][md5($entry['record'])]); } + if (Settings::Get('system.dns_createcaaentry') == '1' && $entry['type'] == 'CAA' && strtolower(substr($entry['content'], 0, 7)) == '"v=caa1') { + // unset special CAA required-entry + unset($required_entries[$entry['type']][md5("@CAA@")]); + } if (Settings::Get('spf.use_spf') == '1' && $entry['type'] == 'TXT' && $entry['record'] == '@' && strtolower(substr($entry['content'], 0, 7)) == '"v=spf1') { // unset special spf required-entry unset($required_entries[$entry['type']][md5("@SPF@")]); @@ -296,9 +294,20 @@ class Dns foreach ($required_entries as $type => $records) { if ($type == 'CAA') { foreach ($records as $record) { - $caa_entries = explode(PHP_EOL, $domain['caa']); - foreach ($caa_entries as $entry) { - $zonerecords[] = new DnsEntry($record, 'CAA', self::encloseTXTContent($entry)); + if ($record == '@CAA@') { + $caa_entries = explode(PHP_EOL, Settings::Get('caa.caa_entry')); + if ($domain['letsencrypt'] == 1) { + $le_entry = $domain['iswildcarddomain'] == '1' ? '0 issuewild "letsencrypt.org"' : '0 issue "letsencrypt.org"'; + array_push($caa_entries, $le_entry); + } + + foreach ($caa_entries as $entry) { + $zonerecords[] = new DnsEntry('@', 'CAA', self::encloseTXTContent($entry)); + // additional required records by subdomain setting + if ($domain['wwwserveralias'] == '1') { + $zonerecords[] = new DnsEntry('www', 'CAA', self::encloseTXTContent($entry)); + } + } } } } diff --git a/lng/english.lng.php b/lng/english.lng.php index e88c4d13..289cdaa7 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1849,10 +1849,8 @@ $lng['serversettings']['leenabled']['description'] = "If activated, customers ar $lng['domains']['ssl_redirect_temporarilydisabled'] = "
The SSL redirect is temporarily deactivated while a new Let's Encrypt certificate is generated. It will be activated again after the certificate was generated."; // Added for CAA record support -$lng['admin']['caa']['title'] = 'Use CAA DNS records'; -$lng['admin']['caa']['description'] = 'DNS Certification Authority Authorization (CAA) is an Internet security policy mechanism which allows domain name holders to indicate to certificate authorities whether they are authorized to issue digital certificates for a particular domain name. It does this by means of a new "CAA" Domain Name System (DNS) resource record.
The content of this field will be included into the DNS zone directly (each line results in a CAA record). An example for the use with Let\'s Encrypt would be:
0 issue "letsencrypt.org"
To enable Incident Reporting, you would need to add an iodef record. An example for sending such report to me@example.com would be:
0 iodef "mailto:me@example.com"
Attention: The code won\'t be checked for any errors. If it contains errors, DNS server might not start again!'; -$lng['customer']['caa']['title'] = 'Use CAA DNS records'; -$lng['customer']['caa']['description'] = 'DNS Certification Authority Authorization (CAA) is an Internet security policy mechanism which allows domain name holders to indicate to certificate authorities whether they are authorized to issue digital certificates for a particular domain name. It does this by means of a new "CAA" Domain Name System (DNS) resource record.
The content of this field will be included into the DNS zone directly (each line results in a CAA record). An example for the use with Let\'s Encrypt would be:
0 issue "letsencrypt.org"
To enable Incident Reporting, you would need to add an iodef record. An example for sending such report to me@example.com would be:
0 iodef "mailto:me@example.com"
Attention: The code won\'t be checked for any errors. If it contains errors, DNS server might not start again!'; +$lng['serversettings']['caa_entry'] = 'Generate CAA DNS records
Automatically generates CAA records for SSL-enabled domains that are using Let\'s Encrypt'; +$lng['serversettings']['caa_custom'] = 'DNS Certification Authority Authorization (CAA) is an Internet security policy mechanism which allows domain name holders to indicate to certificate authorities whether they are authorized to issue digital certificates for a particular domain name. It does this by means of a new "CAA" Domain Name System (DNS) resource record.
The content of this field will be included into the DNS zone directly (each line results in a CAA record). If Let\'s Encrypt is enabled for this domain, this entry will always be added automatically and does not need to be added manually:
0 issue "letsencrypt.org" (If domain is a wildcard domain, issuewild will be used instead).
To enable Incident Reporting, you can add an iodef record. An example for sending such report to me@example.com would be:
0 iodef "mailto:me@example.com"
Attention: The code won\'t be checked for any errors. If it contains errors, your CAA records might not work!'; // Autoupdate $lng['admin']['autoupdate'] = 'Auto-Update'; diff --git a/lng/german.lng.php b/lng/german.lng.php index a838ce0a..f4773dad 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1501,10 +1501,8 @@ $lng['serversettings']['leenabled']['description'] = "Wenn dies aktiviert ist, k $lng['domains']['ssl_redirect_temporarilydisabled'] = "
Die SSL-Umleitung ist, während ein neues Let's Encrypt - Zertifikat erstellt wird, temporär deaktiviert. Die Umleitung wird nach der Zertifikatserstellung wieder aktiviert."; // Added for CAA record support -$lng['admin']['caa']['title'] = 'CAA DNS Einträge erstellen'; -$lng['admin']['caa']['description'] = 'DNS Certification Authority Authorization (CAA) verwendet das Domain Name System, um dem Besitzer einer Domain die Möglichkeit zu bieten, gewisse Zertifizierungsstellen (CAs) dazu zu berechtigen, ein Zertifikat für die betroffene Domain auszustellen. CAA Records sollen verhindern, dass Zertifikate fälschlicherweise für eine Domain ausgestellt werden.
Der Inhalt dieses Feldes wird direkt in die DNS Zone übernommen (eine Zeile pro CAA Record). Ein Beispiel für Let\'s Encrypt wäre:
0 issue "letsencrypt.org"
Um Incident Reporting per Mail zu aktivieren, muss eine iodef Zeile angefügt werden. Ein Beispiel für einen Report an me@example.com wäre:
0 iodef "mailto:me@example.com"
ACHTUNG: Der Code wird nicht auf Fehler geprüft. Etwaige Fehler werden also auch übernommen. Der DNS-Server könnte nicht mehr starten!'; -$lng['customer']['caa']['title'] = 'CAA DNS Einträge erstellen'; -$lng['customer']['caa']['description'] = 'DNS Certification Authority Authorization (CAA) verwendet das Domain Name System, um dem Besitzer einer Domain die Möglichkeit zu bieten, gewisse Zertifizierungsstellen (CAs) dazu zu berechtigen, ein Zertifikat für die betroffene Domain auszustellen. CAA Records sollen verhindern, dass Zertifikate fälschlicherweise für eine Domain ausgestellt werden.
Der Inhalt dieses Feldes wird direkt in die DNS Zone übernommen (eine Zeile pro CAA Record). Ein Beispiel für Let\'s Encrypt wäre:
0 issue "letsencrypt.org"
Um Incident Reporting per Mail zu aktivieren, muss eine iodef Zeile angefügt werden. Ein Beispiel für einen Report an me@example.com wäre:
0 iodef "mailto:me@example.com"
ACHTUNG: Der Code wird nicht auf Fehler geprüft. Etwaige Fehler werden also auch übernommen. Der DNS-Server könnte nicht mehr starten!'; +$lng['serversettings']['caa_entry']= 'CAA DNS Einträge generieren
Generiert CAA Einträge automatisch für alle Domains mit aktiviertem SSL und Let\'s Encrypt'; +$lng['serversettings']['caa_custom']= 'DNS Certification Authority Authorization (CAA) verwendet das Domain Name System, um dem Besitzer einer Domain die Möglichkeit zu bieten, gewisse Zertifizierungsstellen (CAs) dazu zu berechtigen, ein Zertifikat für die betroffene Domain auszustellen. CAA Records sollen verhindern, dass Zertifikate fälschlicherweise für eine Domain ausgestellt werden.
Der Inhalt dieses Feldes wird direkt in die DNS Zone übernommen (eine Zeile pro CAA Record). Wenn Let\'s Encrypt für eine Domain aktiviert wurde und die obige Option aktiviert wurde, wird immer automatisch dieser Eintrag angefügt und muss nicht selber angegeben werden:
0 issue "letsencrypt.org" (Wenn wildcard aktiviert ist, wird statdessen issuewild benutzt).
Um Incident Reporting per Mail zu aktivieren, muss eine iodef Zeile angefügt werden. Ein Beispiel für einen Report an me@example.com wäre:
0 iodef "mailto:me@example.com"
ACHTUNG: Der Code wird nicht auf Fehler geprüft. Etwaige Fehler werden also auch übernommen. Die CAA finalen Einträge könnten daher falsch sein!'; // Autoupdate $lng['admin']['autoupdate'] = 'Auto-Update';