update DNSSECUtil class
authorStricted <info@stricted.de>
Sun, 22 Feb 2015 18:36:03 +0000 (19:36 +0100)
committerStricted <info@stricted.de>
Sun, 22 Feb 2015 18:36:03 +0000 (19:36 +0100)
lib/util/DNSSECUtil.class.php

index e34f800a37bbc7fff6c1a63ae99cda8aa0271298..42a741937d2779ec05afe02540dc0b5cabacc8c9 100644 (file)
@@ -8,8 +8,8 @@ namespace dns\util;
  */
 class DNSSECUtil {
        
-       function calculateDS ($owner, $algorithm, $publicKey) {
-               $owner = $this->convertOwner($owner);
+       public static function calculateDS ($owner, $algorithm, $publicKey) {
+               $owner = self::convertOwner($owner);
                $flags = '0101';
                $protocol = '03';
                $algorithm = '0'.dechex($algorithm);
@@ -23,7 +23,7 @@ class DNSSECUtil {
                return array('sha1' => $sha1, 'sha256' => $sha256);
        }
        
-       function convertOwner ($owner) {
+       public static convertOwner ($owner) {
                $return = '';
                
                $data = explode(".", $owner);
@@ -48,4 +48,51 @@ class DNSSECUtil {
                
                return $return;
        }
+       
+       public static function validatePublicKey ($content) {
+               $pattern = "; This is a (key|zone)-signing key, keyid (?P<keyid>[0-9]+), for (?P<domain>[\s\S]+)\.\n";
+               $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 (?P<type>[0-9]+) ([0-9]+) (?P<algorithm>[0-9]+) (?P<key>[\s\S]+)";
+               preg_match('/'.$pattern.'/i', $content, $matches);
+               if (!empty($matches)) {
+                       $data = explode(' ', $matches['key']);
+                       foreach ($data as $d) {
+                               if (base64_encode(base64_decode($d, true)) !== $d) {
+                                       return false;
+                               }
+                       }
+               }
+               else {
+                       return false;
+               }
+               
+               return true;
+       }
+       
+       public static function validatePrivateKey ($content) {
+               $pattern = "Private-key-format: v([0-9a-z.]+)\n";
+               $pattern .= "Algorithm: (?P<algorithm>[0-9]+) \(([0-9a-z\-]+)\)\n";
+               $pattern .= "Modulus: (?P<modulus>[\s\S]+)\n";
+               $pattern .= "PublicExponent: (?P<publicexponent>[\s\S]+)\n";
+               $pattern .= "Prime1: (?P<prime1>[\s\S]+)\n";
+               $pattern .= "Prime2: (?P<prime2>[\s\S]+)\n";
+               $pattern .= "Exponent1: (?P<exponent1>[\s\S]+)\n";
+               $pattern .= "Exponent2: (?P<exponent2>[\s\S]+)\n";
+               $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]+)";
+
+               preg_match('/'.$pattern.'/i', $content, $matches);
+               if (!empty($matches)) {
+                       /* to be continued */
+               }
+               else {
+                       return false;
+               }
+               
+               return true;
+       }
 }