show ds records on dnssec key list page
authorStricted <info@stricted.de>
Sun, 22 Feb 2015 20:12:41 +0000 (21:12 +0100)
committerStricted <info@stricted.de>
Sun, 22 Feb 2015 20:12:41 +0000 (21:12 +0100)
lib/page/SecListPage.class.php
lib/util/DNSSECUtil.class.php
templates/default/secList.tpl

index 62b7189e48d9a377056e3620cb3d54826e62b7f8..6a205beb8dd0c3b4c4357f6555f34da2b2ff7fe4 100644 (file)
@@ -2,6 +2,7 @@
 namespace dns\page;
 use dns\system\DNS;
 use dns\system\User;
+use dns\util\DNSSECUtil;
 
 /**
  * @author      Jan Altensen (Stricted)
@@ -26,13 +27,25 @@ class SecListPage extends AbstractPage {
                $soa = DNS::getDB()->fetch_array($res);
                
                $records = array();
+               $ds = array();
                
                $sql = "SELECT * FROM dns_sec WHERE zone = ?";
                $res = DNS::getDB()->query($sql, array($_GET['id']));
                while ($row = DNS::getDB()->fetch_array($res)) {
+                       if ($row['type'] == 'KSK') {
+                               preg_match("/".$soa['origin']." IN DNSKEY 257 3 ([0-9]+) ([\s\S]+)/i", $row['public'], $match);
+                               preg_match("/; This is a key-signing key, keyid ([0-9]+), for ".$soa['origin']."/i", $row['public'], $match2);
+                               if (!empty($match) && !empty($match2)) {
+                                       if ($match[1] == $row['algo']) {
+                                               $ds = DNSSECUtil::calculateDS($soa['origin'], $match[1], $match[2]);
+                                               $ds['algo'] = $match[1];
+                                               $ds['keyid'] = $match2[1];
+                                       }
+                               }
+                       }
                        $records[] = $row;
                }
                
-               DNS::getTPL()->assign(array("records" => $records, "soa" => $soa));
+               DNS::getTPL()->assign(array("records" => $records, "soa" => $soa, 'ds' => $ds));
        }
 }
index 62b84c6ce1885eeaf7754413e3ff1776006ada5e..d17f1a480ecc84106e83149d3fd1ed9fe6a94474 100644 (file)
@@ -17,13 +17,13 @@ class DNSSECUtil {
                
                $string = hex2bin($owner.$flags.$protocol.$algorithm.$publicKey);
                
-               $sha1 = sha1($string);
-               $sha256 = hash('sha256', $string);
+               $sha1 = strtoupper(sha1($string));
+               $sha256 = strtoupper(hash('sha256', $string));
                
                return array('sha1' => $sha1, 'sha256' => $sha256);
        }
        
-       public static convertOwner ($owner) {
+       public static function convertOwner ($owner) {
                $return = '';
                
                $data = explode(".", $owner);
@@ -54,7 +54,7 @@ class DNSSECUtil {
                $pattern .= "; Created: (?P<created>[0-9]+) \(([a-z0-9: ]+)\)\n";
                $pattern .= "; Publish: (?P<publish>[0-9]+) \(([a-z0-9: ]+)\)\n";
                $pattern .= "; Activate: (?P<activate>[0-9]+) \(([a-z0-9: ]+)\)\n";
-               $pattern .= "([\s\S]+). IN DNSKEY 25(6|7) 3 (?P<algorithm>[0-9]+) (?P<key>[\s\S]+)";
+               $pattern .= "([\s\S]+). IN DNSKEY 25(6|7) 3 (?P<algorithm>[0-9]+) (?P<key>[\s\S]+)(\n)?";
                preg_match('/'.$pattern.'/i', $content, $matches);
                if (!empty($matches)) {
                        if (!in_array($matches['algorithm'], array(1, 2, 3, 5, 6, 7, 8, 10, 12, 13, 14))) {
@@ -87,7 +87,7 @@ class DNSSECUtil {
                $pattern .= "Coefficient: (?P<coefficient>[\s\S]+)\n";
                $pattern .= "Created: (?P<created>[0-9]+)\n";
                $pattern .= "Publish: (?P<publish>[0-9]+)\n";
-               $pattern .= "Activate: (?P<activate>[0-9]+)";
+               $pattern .= "Activate: (?P<activate>[0-9]+)(\n)?";
 
                preg_match('/'.$pattern.'/i', $content, $matches);
                if (!empty($matches)) {
index 90d5ead51f24cd0ab3674c58ad8f917ae520e8f8..4bf967da0cb79207ab801af81a708cc4c5ae79fc 100644 (file)
@@ -5,6 +5,12 @@
                <li class="active"><a href="index.php?page=SecList&id={$soa['id']}">{$soa['origin']}</a></li>
        </ol>
 </div>
+{if !empty($ds)}
+       <div class="alert alert-icon alert-info">
+               {$soa['origin']} IN DS {$ds['keyid']} {$ds['algo']} 1 {$ds['sha1']}<br />
+               {$soa['origin']} IN DS {$ds['keyid']} {$ds['algo']} 2 {$ds['sha256']}
+       </div>
+{/if}
 {hascontent}
        <div class="row">
                <div class="col-lg-12">