From daff88c0871af4aeee0eff7f6d9a489f3c91afda Mon Sep 17 00:00:00 2001 From: Stricted Date: Sun, 22 Feb 2015 15:42:33 +0100 Subject: [PATCH] add class to calculate DSset for dnssec --- lib/util/DNSSECUtil.class.php | 51 +++++++++++++++++++++++++++++++++++ lib/util/ParseZone.class.php | 1 + templates/default/secList.tpl | 4 +-- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 lib/util/DNSSECUtil.class.php diff --git a/lib/util/DNSSECUtil.class.php b/lib/util/DNSSECUtil.class.php new file mode 100644 index 0000000..e34f800 --- /dev/null +++ b/lib/util/DNSSECUtil.class.php @@ -0,0 +1,51 @@ + + * @copyright 2015 Jan Altensen (Stricted) + */ +class DNSSECUtil { + + function calculateDS ($owner, $algorithm, $publicKey) { + $owner = $this->convertOwner($owner); + $flags = '0101'; + $protocol = '03'; + $algorithm = '0'.dechex($algorithm); + $publicKey = bin2hex(base64_decode($publicKey)); + + $string = hex2bin($owner.$flags.$protocol.$algorithm.$publicKey); + + $sha1 = sha1($string); + $sha256 = hash('sha256', $string); + + return array('sha1' => $sha1, 'sha256' => $sha256); + } + + function convertOwner ($owner) { + $return = ''; + + $data = explode(".", $owner); + $return .= '0'.dechex(strlen($data[0])); + $data[0] = str_split($data[0]); + for ($i = 0; $i < count($data[0]); $i++) { + $byte = strtoupper(dechex(ord($data[0][$i]))); + $byte = str_repeat('0', 2 - strlen($byte)).$byte; + $return .= $byte; + } + + $return .= '0'.dechex(strlen($data[1])); + $data[1] = str_split($data[1]); + + for ($i = 0; $i < count($data[1]); $i++) { + $byte = strtoupper(dechex(ord($data[1][$i]))); + $byte = str_repeat('0', 2 - strlen($byte)).$byte; + $return .= $byte; + } + + $return .= '00'; + + return $return; + } +} diff --git a/lib/util/ParseZone.class.php b/lib/util/ParseZone.class.php index 2806522..2a85663 100644 --- a/lib/util/ParseZone.class.php +++ b/lib/util/ParseZone.class.php @@ -269,6 +269,7 @@ class ParseZone { if (!empty($matches[2])) { $this->soa['minimum'] = $matches[2]; $this->soa['ttl'] = $matches[2]; + $this->ttl = $this->soa['ttl']; } else { $this->soa['minimum'] = $this->ttl; diff --git a/templates/default/secList.tpl b/templates/default/secList.tpl index adb5104..90d5ead 100644 --- a/templates/default/secList.tpl +++ b/templates/default/secList.tpl @@ -32,9 +32,9 @@ {$record['public']|substr:0:20}… {$record['private']|substr:0:20}… +   +   - - {/foreach} -- 2.20.1