mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-15 09:07:00 +02:00
Milliseconds are now fully supported
This commit is contained in:
parent
ea754362f8
commit
63aa36ff0a
13 changed files with 425 additions and 321 deletions
|
@ -10,7 +10,8 @@ function checkLogin($db, $clID, $pw) {
|
|||
|
||||
function sendGreeting($conn) {
|
||||
global $c;
|
||||
$currentDate = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$currentDateTime = new DateTime("now", new DateTimeZone("UTC"));
|
||||
$currentDate = $currentDateTime->format("Y-m-d\TH:i:s.v\Z");
|
||||
|
||||
$response = [
|
||||
'command' => 'greeting',
|
||||
|
@ -224,8 +225,9 @@ function createTransaction($db, $clid, $clTRID, $clTRIDframe) {
|
|||
$stmt = $db->prepare("INSERT INTO `registryTransaction`.`transaction_identifier` (`registrar_id`,`clTRID`,`clTRIDframe`,`cldate`,`clmicrosecond`) VALUES(?,?,?,?,?)");
|
||||
|
||||
// Get date and microsecond for cl transaction
|
||||
$currentDateTime = new DateTime("now", new DateTimeZone("UTC"));
|
||||
$cldate = $currentDateTime->format("Y-m-d H:i:s.v");
|
||||
$dateForClTransaction = microtime(true);
|
||||
$cldate = date("Y-m-d H:i:s", $dateForClTransaction);
|
||||
$clmicrosecond = sprintf("%06d", ($dateForClTransaction - floor($dateForClTransaction)) * 1000000);
|
||||
|
||||
if (empty($clTRID)) {
|
||||
|
@ -253,8 +255,9 @@ function updateTransaction($db, $cmd, $obj_type, $obj_id, $code, $msg, $svTRID,
|
|||
$stmt = $db->prepare("UPDATE `registryTransaction`.`transaction_identifier` SET `cmd` = ?, `obj_type` = ?, `obj_id` = ?, `code` = ?, `msg` = ?, `svTRID` = ?, `svTRIDframe` = ?, `svdate` = ?, `svmicrosecond` = ? WHERE `id` = ?");
|
||||
|
||||
// Get date and microsecond for sv transaction
|
||||
$currentDateTime = new DateTime("now", new DateTimeZone("UTC"));
|
||||
$svdate = $currentDateTime->format("Y-m-d H:i:s.v");
|
||||
$dateForSvTransaction = microtime(true);
|
||||
$svdate = date("Y-m-d H:i:s", $dateForSvTransaction);
|
||||
$svmicrosecond = sprintf("%06d", ($dateForSvTransaction - floor($dateForSvTransaction)) * 1000000);
|
||||
|
||||
// Execute the statement
|
||||
|
@ -320,68 +323,68 @@ function getClid(PDO $db, string $clid): ?int {
|
|||
* -5, unsupported publickey
|
||||
*/
|
||||
function dnssec_key2ds($owner, $flags, $protocol, $algorithm, $publickey) {
|
||||
// define paramenter check variants
|
||||
$regex_owner = '/^[a-z0-9\-]+\.[a-z]+\.$/';
|
||||
$allowed_flags = array(256, 257);
|
||||
$allowed_protocol = array(3);
|
||||
$allowed_algorithm = array(2, 3, 5, 6, 7, 8, 10, 13, 14, 15, 16);
|
||||
$regex_publickey = '/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/';
|
||||
|
||||
// do parameter checks and break if failed
|
||||
if(!preg_match($regex_owner, $owner)) return -1;
|
||||
if(!in_array($flags, $allowed_flags)) return -2;
|
||||
if(!in_array($protocol, $allowed_protocol)) return -3;
|
||||
if(!in_array($algorithm, $allowed_algorithm)) return -4;
|
||||
if(!preg_match($regex_publickey, $publickey)) return -5;
|
||||
|
||||
// calculate hex of parameters
|
||||
$owner_hex = '';
|
||||
$parts = explode(".", substr($owner, 0, -1));
|
||||
foreach ($parts as $part) {
|
||||
$len = dechex(strlen($part));
|
||||
$owner_hex .= str_repeat('0', 2 - strlen($len)).$len;
|
||||
$part = str_split($part);
|
||||
for ($i = 0; $i < count($part); $i++) {
|
||||
$byte = strtoupper(dechex(ord($part[$i])));
|
||||
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
|
||||
$owner_hex .= $byte;
|
||||
}
|
||||
}
|
||||
$owner_hex .= '00';
|
||||
$flags_hex = sprintf("%04d", dechex($flags));
|
||||
$protocol_hex = sprintf("%02d", dechex($protocol));
|
||||
$algorithm_hex = sprintf("%02d", dechex($algorithm));
|
||||
$publickey_hex = bin2hex(base64_decode($publickey));
|
||||
|
||||
// calculate keytag using algorithm defined in rfc
|
||||
$string = hex2bin($flags_hex.$protocol_hex.$algorithm_hex.$publickey_hex);
|
||||
$sum = 0;
|
||||
for($i = 0; $i < strlen($string); $i++) {
|
||||
$b = ord($string[$i]);
|
||||
$sum += ($i & 1) ? $b : $b << 8;
|
||||
}
|
||||
$keytag = 0xffff & ($sum + ($sum >> 16));
|
||||
|
||||
// calculate digest using rfc specified hashing algorithms
|
||||
$string = hex2bin($owner_hex.$flags_hex.$protocol_hex.$algorithm_hex.$publickey_hex);
|
||||
$digest_sha1 = strtoupper(sha1($string));
|
||||
$digest_sha256 = strtoupper(hash('sha256', $string));
|
||||
|
||||
// return results and also copied parameters
|
||||
return array(
|
||||
//'debug' => array($owner_hex, $flags_hex, $protocol_hex, $algorithm_hex, $publickey_hex),
|
||||
'owner' => $owner,
|
||||
'keytag' => $keytag,
|
||||
'algorithm' => $algorithm,
|
||||
'digest' => array(
|
||||
array(
|
||||
'type' => 1,
|
||||
'hash' => $digest_sha1
|
||||
),
|
||||
array(
|
||||
'type' => 2,
|
||||
'hash' => $digest_sha256
|
||||
)
|
||||
)
|
||||
);
|
||||
// define paramenter check variants
|
||||
$regex_owner = '/^[a-z0-9\-]+\.[a-z]+\.$/';
|
||||
$allowed_flags = array(256, 257);
|
||||
$allowed_protocol = array(3);
|
||||
$allowed_algorithm = array(2, 3, 5, 6, 7, 8, 10, 13, 14, 15, 16);
|
||||
$regex_publickey = '/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/';
|
||||
|
||||
// do parameter checks and break if failed
|
||||
if(!preg_match($regex_owner, $owner)) return -1;
|
||||
if(!in_array($flags, $allowed_flags)) return -2;
|
||||
if(!in_array($protocol, $allowed_protocol)) return -3;
|
||||
if(!in_array($algorithm, $allowed_algorithm)) return -4;
|
||||
if(!preg_match($regex_publickey, $publickey)) return -5;
|
||||
|
||||
// calculate hex of parameters
|
||||
$owner_hex = '';
|
||||
$parts = explode(".", substr($owner, 0, -1));
|
||||
foreach ($parts as $part) {
|
||||
$len = dechex(strlen($part));
|
||||
$owner_hex .= str_repeat('0', 2 - strlen($len)).$len;
|
||||
$part = str_split($part);
|
||||
for ($i = 0; $i < count($part); $i++) {
|
||||
$byte = strtoupper(dechex(ord($part[$i])));
|
||||
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
|
||||
$owner_hex .= $byte;
|
||||
}
|
||||
}
|
||||
$owner_hex .= '00';
|
||||
$flags_hex = sprintf("%04d", dechex($flags));
|
||||
$protocol_hex = sprintf("%02d", dechex($protocol));
|
||||
$algorithm_hex = sprintf("%02d", dechex($algorithm));
|
||||
$publickey_hex = bin2hex(base64_decode($publickey));
|
||||
|
||||
// calculate keytag using algorithm defined in rfc
|
||||
$string = hex2bin($flags_hex.$protocol_hex.$algorithm_hex.$publickey_hex);
|
||||
$sum = 0;
|
||||
for($i = 0; $i < strlen($string); $i++) {
|
||||
$b = ord($string[$i]);
|
||||
$sum += ($i & 1) ? $b : $b << 8;
|
||||
}
|
||||
$keytag = 0xffff & ($sum + ($sum >> 16));
|
||||
|
||||
// calculate digest using rfc specified hashing algorithms
|
||||
$string = hex2bin($owner_hex.$flags_hex.$protocol_hex.$algorithm_hex.$publickey_hex);
|
||||
$digest_sha1 = strtoupper(sha1($string));
|
||||
$digest_sha256 = strtoupper(hash('sha256', $string));
|
||||
|
||||
// return results and also copied parameters
|
||||
return array(
|
||||
//'debug' => array($owner_hex, $flags_hex, $protocol_hex, $algorithm_hex, $publickey_hex),
|
||||
'owner' => $owner,
|
||||
'keytag' => $keytag,
|
||||
'algorithm' => $algorithm,
|
||||
'digest' => array(
|
||||
array(
|
||||
'type' => 1,
|
||||
'hash' => $digest_sha1
|
||||
),
|
||||
array(
|
||||
'type' => 2,
|
||||
'hash' => $digest_sha256
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue