Skip to content

Commit c7abe26

Browse files
author
A. Täffner
committed
dnssec-create moved to PHP (test)
1 parent 27ff980 commit c7abe26

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

server/plugins-available/bind_plugin.inc.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,46 @@ function onLoad() {
7676

7777
}
7878

79+
//* This creates DNSSEC-Keys but does NOT actually sign the zone.
80+
function soa_dnssec_create(&$data) {
81+
global $app, $conf;
82+
83+
//* Load libraries
84+
$app->uses("getconf,tpl");
85+
86+
//* load the server configuration options
87+
$dns_config = $app->getconf->get_server_config($conf["server_id"], 'dns');
88+
89+
//* Check Entropy
90+
if (file_get_contents('/proc/sys/kernel/random/entropy_avail') < 400) {
91+
if($dns_config['disable_bind_log'] === 'y') {
92+
$app->log('DNSSEC ERROR: We are low on entropy. Not generating new Keys for '.$data['new']['origin'].'. Please consider installing package haveged.', LOGLEVEL_DEBUG);
93+
} else {
94+
$app->log('DNSSEC ERROR: We are low on entropy. Not generating new Keys for '.$data['new']['origin'].'. Please consider installing package haveged.', LOGLEVEL_WARN);
95+
}
96+
return false;
97+
}
98+
99+
//* Verify that we do not already have keys (overwriting-protection)
100+
//TODO : change this when distribution information has been integrated into server record
101+
if (file_exists($dns_config['bind_zonefiles_dir'].'/dsset-'.$data['new']['origin'].'.')) {
102+
return $this->soa_dnssec_update(&$data);
103+
}
104+
105+
//Do some magic...
106+
exec('cd '.escapeshellargs($dns_config['bind_zonefiles_dir']).';'.
107+
'dnssec-keygen -a NSEC3RSASHA1 -b 2048 -n ZONE '.escapeshellargs($data['new']['origin']).';'.
108+
'dnssec-keygen -f KSK -a NSEC3RSASHA1 -b 4096 -n ZONE '.escapeshellargs($data['new']['origin']));
109+
110+
$dnssecdata = "DS-Records:\n\r".file_get_contents($dns_config['bind_zonefiles_dir'].'/dsset-'.$data['new']['origin'].'.');
111+
opendir($dns_config['bind_zonefiles_dir']);
112+
$dnssecdata .= "\n\r------------------------------------\n\r\n\rDNSKEY-Records:\n\r"
113+
foreach (glob('K'.$data['new']['origin'].'*.key') as $keyfile) {
114+
$dnssecdata .= file_get_contents($keyfile)."\n\r\n\r";
115+
}
116+
117+
$app->db->datalogUpdate('dns_soa', array('dnssec_info' => $dnssecdata), 'id', $data['new']['id']);
118+
}
79119

80120
function soa_insert($event_name, $data) {
81121
global $app, $conf;
@@ -149,9 +189,9 @@ function soa_update($event_name, $data) {
149189
//* DNSSEC-Implementation
150190
if($data['old']['origin'] != $data['new']['origin']) {
151191
if (@$data['old']['dnssec_initialized'] == 'Y' && strlen(@$data['old']['origin']) > 3) exec('/usr/local/ispconfig/server/scripts/dnssec-delete.sh '.escapeshellcmd($data['old']['origin'])); //delete old keys
152-
if ($data['new']['dnssec_wanted'] == 'Y') exec('/usr/local/ispconfig/server/scripts/dnssec-create.sh '.escapeshellcmd($data['new']['origin'])); //Create new keys for new origin
192+
if ($data['new']['dnssec_wanted'] == 'Y') $this->soa_dnssec_create($data);
153193
}
154-
else if ($data['new']['dnssec_wanted'] == 'Y' && $data['old']['dnssec_initialized'] == 'N') exec('/usr/local/ispconfig/server/scripts/dnssec-create.sh '.escapeshellcmd($data['new']['origin'])); //Create new keys for new origin
194+
else if ($data['new']['dnssec_wanted'] == 'Y' && $data['old']['dnssec_initialized'] == 'N') $this->soa_dnssec_create($data);
155195
else if ($data['new']['dnssec_wanted'] == 'N' && $data['old']['dnssec_initialized'] == 'Y') { //delete old signed file if dnssec is no longer wanted
156196
//TODO : change this when distribution information has been integrated into server record
157197
if (file_exists('/etc/gentoo-release')) {

0 commit comments

Comments
 (0)