From 8a0590a6bd738c951184ac154cbe9505d7a090c0 Mon Sep 17 00:00:00 2001 From: Stricted Date: Sun, 22 Feb 2015 19:36:03 +0100 Subject: [PATCH] update DNSSECUtil class --- lib/util/DNSSECUtil.class.php | 53 +++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/lib/util/DNSSECUtil.class.php b/lib/util/DNSSECUtil.class.php index e34f800..42a7419 100644 --- a/lib/util/DNSSECUtil.class.php +++ b/lib/util/DNSSECUtil.class.php @@ -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[0-9]+), for (?P[\s\S]+)\.\n"; + $pattern .= "; Created: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; + $pattern .= "; Publish: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; + $pattern .= "; Activate: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; + $pattern .= "([\s\S]+). IN DNSKEY (?P[0-9]+) ([0-9]+) (?P[0-9]+) (?P[\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[0-9]+) \(([0-9a-z\-]+)\)\n"; + $pattern .= "Modulus: (?P[\s\S]+)\n"; + $pattern .= "PublicExponent: (?P[\s\S]+)\n"; + $pattern .= "Prime1: (?P[\s\S]+)\n"; + $pattern .= "Prime2: (?P[\s\S]+)\n"; + $pattern .= "Exponent1: (?P[\s\S]+)\n"; + $pattern .= "Exponent2: (?P[\s\S]+)\n"; + $pattern .= "Coefficient: (?P[\s\S]+)\n"; + $pattern .= "Created: (?P[0-9]+)\n"; + $pattern .= "Publish: (?P[0-9]+)\n"; + $pattern .= "Activate: (?P[0-9]+)"; + + preg_match('/'.$pattern.'/i', $content, $matches); + if (!empty($matches)) { + /* to be continued */ + } + else { + return false; + } + + return true; + } } -- 2.20.1