initial commit; version 22.5.12042

This commit is contained in:
2022-12-12 23:28:25 -05:00
commit af1b03d79f
17653 changed files with 22692970 additions and 0 deletions

108
libs/pear/Net/DNS2/RR/A.php Normal file
View File

@ -0,0 +1,108 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* A Resource Record - RFC1035 section 3.4.1
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ADDRESS |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_A extends Net_DNS2_RR
{
/*
* The IPv4 address in quad-dotted notation
*/
public $address;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->address;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$value = array_shift($rdata);
if (Net_DNS2::isIPv4($value) == true) {
$this->address = $value;
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$this->address = inet_ntop($this->rdata);
if ($this->address !== false) {
return true;
}
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$packet->offset += 4;
return inet_pton($this->address);
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* A Resource Record - RFC1035 section 3.4.1
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | |
* | |
* | |
* | ADDRESS |
* | |
* | (128 bit) |
* | |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_AAAA extends Net_DNS2_RR
{
/*
* the IPv6 address in the preferred hexadecimal values of the eight
* 16-bit pieces
* per RFC1884
*
*/
public $address;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->address;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// expand out compressed formats
//
$value = array_shift($rdata);
if (Net_DNS2::isIPv6($value) == true) {
$this->address = $value;
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
//
// must be 8 x 16bit chunks, or 16 x 8bit
//
if ($this->rdlength == 16) {
//
// PHP's inet_ntop returns IPv6 addresses in their compressed form,
// but we want to keep with the preferred standard, so we'll parse
// it manually.
//
$x = unpack('n8', $this->rdata);
if (count($x) == 8) {
$this->address = vsprintf('%x:%x:%x:%x:%x:%x:%x:%x', $x);
return true;
}
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$packet->offset += 16;
return inet_pton($this->address);
}
}

View File

@ -0,0 +1,126 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* AFSDB Resource Record - RFC1183 section 1
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | SUBTYPE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / HOSTNAME /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_AFSDB extends Net_DNS2_RR
{
/*
* The AFSDB sub type
*/
public $subtype;
/*
* The AFSDB hostname
*/
public $hostname;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->subtype . ' ' . $this->cleanString($this->hostname) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->subtype = array_shift($rdata);
$this->hostname = $this->cleanString(array_shift($rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the subtype
//
$x = unpack('nsubtype', $this->rdata);
$this->subtype = $x['subtype'];
$offset = $packet->offset + 2;
$this->hostname = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->hostname) > 0) {
$data = pack('n', $this->subtype);
$packet->offset += 2;
$data .= $packet->compress($this->hostname, $packet->offset);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,259 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.4.5
*
*/
/**
* AMTRELAY Resource Record - RFC8777 section 4.2
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | precedence |D| type | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
* ~ relay ~
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_AMTRELAY extends Net_DNS2_RR
{
/*
* type definitions that match the "type" field below
*/
const AMTRELAY_TYPE_NONE = 0;
const AMTRELAY_TYPE_IPV4 = 1;
const AMTRELAY_TYPE_IPV6 = 2;
const AMTRELAY_TYPE_DOMAIN = 3;
/*
* the precedence for this record
*/
public $precedence;
/*
* "Discovery Optional" flag
*/
public $discovery;
/*
* The type field indicates the format of the information that is stored in the relay field.
*/
public $relay_type;
/*
* The relay field is the address or domain name of the AMT relay.
*/
public $relay;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->precedence . ' ' . $this->discovery . ' ' . $this->relay_type . ' ' . $this->relay;
//
// 4.3.1 - If the relay type field is 0, the relay field MUST be ".".
//
if ( ($this->relay_type == self::AMTRELAY_TYPE_NONE) || ($this->relay_type == self::AMTRELAY_TYPE_DOMAIN) )
{
$out .= '.';
}
return $out;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// extract the values from the array
//
$this->precedence = array_shift($rdata);
$this->discovery = array_shift($rdata);
$this->relay_type = array_shift($rdata);
$this->relay = trim(strtolower(trim(array_shift($rdata))), '.');
//
// if there's anything else other than 0 in the discovery value, then force it to one, so
// that it effectively is either "true" or "false".
//
if ($this->discovery != 0) {
$this->discovery = 1;
}
//
// validate the type & relay values
//
switch($this->relay_type) {
case self::AMTRELAY_TYPE_NONE:
$this->relay = '';
break;
case self::AMTRELAY_TYPE_IPV4:
if (Net_DNS2::isIPv4($this->relay) == false) {
return false;
}
break;
case self::AMTRELAY_TYPE_IPV6:
if (Net_DNS2::isIPv6($this->relay) == false) {
return false;
}
break;
case self::AMTRELAY_TYPE_DOMAIN:
; // do nothing
break;
default:
//
// invalid type value
//
return false;
}
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// parse off the first two octets
//
$x = unpack('Cprecedence/Csecond', $this->rdata);
$this->precedence = $x['precedence'];
$this->discovery = ($x['second'] >> 7) & 0x1;
$this->relay_type = $x['second'] & 0xf;
$offset = 2;
//
// parse the relay value based on the type
//
switch($this->relay_type) {
case self::AMTRELAY_TYPE_NONE:
$this->relay = '';
break;
case self::AMTRELAY_TYPE_IPV4:
$this->relay = inet_ntop(substr($this->rdata, $offset, 4));
break;
case self::AMTRELAY_TYPE_IPV6:
//
// PHP's inet_ntop returns IPv6 addresses in their compressed form, but we want to keep
// with the preferred standard, so we'll parse it manually.
//
$ip = unpack('n8', substr($this->rdata, $offset, 16));
if (count($ip) == 8) {
$this->relay = vsprintf('%x:%x:%x:%x:%x:%x:%x:%x', $ip);
} else
{
return false;
}
break;
case self::AMTRELAY_TYPE_DOMAIN:
$doffset = $packet->offset + $offset;
$this->relay = Net_DNS2_Packet::label($packet, $doffset);
break;
default:
//
// invalid type value
//
return false;
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
//
// pack the precedence, discovery, and type
//
$data = pack('CC', $this->precedence, ($this->discovery << 7) | $this->relay_type);
//
// add the relay data based on the type
//
switch($this->relay_type) {
case self::AMTRELAY_TYPE_NONE:
; // add nothing
break;
case self::AMTRELAY_TYPE_IPV4:
case self::AMTRELAY_TYPE_IPV6:
$data .= inet_pton($this->relay);
break;
case self::AMTRELAY_TYPE_DOMAIN:
$data .= pack('Ca*', strlen($this->relay), $this->relay);
break;
default:
return null;
}
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* This is only used for generating an empty ANY RR.
*
*/
class Net_DNS2_RR_ANY extends Net_DNS2_RR
{
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return '';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
return true;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
return '';
}
}

View File

@ -0,0 +1,295 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.0.0
*
*/
/**
* APL Resource Record - RFC3123
*
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | ADDRESSFAMILY |
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | PREFIX | N | AFDLENGTH |
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* / AFDPART /
* | |
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
*
*/
class Net_DNS2_RR_APL extends Net_DNS2_RR
{
/*
* a list of all the address prefix list items
*/
public $apl_items = [];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = '';
foreach ($this->apl_items as $item) {
if ($item['n'] == 1) {
$out .= '!';
}
$out .= $item['address_family'] . ':' .
$item['afd_part'] . '/' . $item['prefix'] . ' ';
}
return trim($out);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
foreach ($rdata as $item) {
if (preg_match('/^(!?)([1|2])\:([^\/]*)\/([0-9]{1,3})$/', $item, $m)) {
$i = [
'address_family' => $m[2],
'prefix' => $m[4],
'n' => ($m[1] == '!') ? 1 : 0,
'afd_part' => strtolower($m[3])
];
$address = $this->_trimZeros(
$i['address_family'], $i['afd_part']
);
$i['afd_length'] = count(explode('.', $address));
$this->apl_items[] = $i;
}
}
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = 0;
while ($offset < $this->rdlength) {
//
// unpack the family, prefix, negate and length values
//
$x = unpack(
'naddress_family/Cprefix/Cextra', substr($this->rdata, $offset)
);
$item = [
'address_family' => $x['address_family'],
'prefix' => $x['prefix'],
'n' => ($x['extra'] >> 7) & 0x1,
'afd_length' => $x['extra'] & 0xf
];
switch($item['address_family']) {
case 1:
$r = unpack(
'C*', substr($this->rdata, $offset + 4, $item['afd_length'])
);
if (count($r) < 4) {
for ($c=count($r)+1; $c<4+1; $c++) {
$r[$c] = 0;
}
}
$item['afd_part'] = implode('.', $r);
break;
case 2:
$r = unpack(
'C*', substr($this->rdata, $offset + 4, $item['afd_length'])
);
if (count($r) < 8) {
for ($c=count($r)+1; $c<8+1; $c++) {
$r[$c] = 0;
}
}
$item['afd_part'] = sprintf(
'%x:%x:%x:%x:%x:%x:%x:%x',
$r[1], $r[2], $r[3], $r[4], $r[5], $r[6], $r[7], $r[8]
);
break;
default:
return false;
}
$this->apl_items[] = $item;
$offset += 4 + $item['afd_length'];
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (count($this->apl_items) > 0) {
$data = '';
foreach ($this->apl_items as $item) {
//
// pack the address_family and prefix values
//
$data .= pack(
'nCC',
$item['address_family'],
$item['prefix'],
($item['n'] << 7) | $item['afd_length']
);
switch($item['address_family']) {
case 1:
$address = explode(
'.',
$this->_trimZeros($item['address_family'], $item['afd_part'])
);
foreach ($address as $b) {
$data .= chr($b);
}
break;
case 2:
$address = explode(
':',
$this->_trimZeros($item['address_family'], $item['afd_part'])
);
foreach ($address as $b) {
$data .= pack('H', $b);
}
break;
default:
return null;
}
}
$packet->offset += strlen($data);
return $data;
}
return null;
}
/**
* returns an IP address with the right-hand zero's trimmed
*
* @param integer $family the IP address family from the rdata
* @param string $address the IP address
*
* @return string the trimmed IP addresss.
*
* @access private
*
*/
private function _trimZeros($family, $address)
{
$a = [];
switch($family) {
case 1:
$a = array_reverse(explode('.', $address));
break;
case 2:
$a = array_reverse(explode(':', $address));
break;
default:
return '';
}
foreach ($a as $value) {
if ($value === '0') {
array_shift($a);
}
}
$out = '';
switch($family) {
case 1:
$out = implode('.', array_reverse($a));
break;
case 2:
$out = implode(':', array_reverse($a));
break;
default:
return '';
}
return $out;
}
}

View File

@ -0,0 +1,162 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.1.0
*
*/
/**
* ATMA Resource Record
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | FORMAT | |
* | +--+--+--+--+--+--+--+--+
* / ADDRESS /
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_ATMA extends Net_DNS2_RR
{
/*
* One octet that indicates the format of ADDRESS. The two possible values
* for FORMAT are value 0 indicating ATM End System Address (AESA) format
* and value 1 indicating E.164 format
*/
public $format;
/*
* The IPv4 address in quad-dotted notation
*/
public $address;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->address;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$value = array_shift($rdata);
if (ctype_xdigit($value) == true) {
$this->format = 0;
$this->address = $value;
} else if (is_numeric($value) == true) {
$this->format = 1;
$this->address = $value;
} else {
return false;
}
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the format
//
$x = unpack('Cformat/N*address', $this->rdata);
$this->format = $x['format'];
if ($this->format == 0) {
$a = unpack('@1/H*address', $this->rdata);
$this->address = $a['address'];
} else if ($this->format == 1) {
$this->address = substr($this->rdata, 1, $this->rdlength - 1);
} else {
return false;
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$data = chr($this->format);
if ($this->format == 0) {
$data .= pack('H*', $this->address);
} else if ($this->format == 1) {
$data .= $this->address;
} else {
return null;
}
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.4.2
*
*/
/**
* The AVC RR is implemented exactly like the TXT record, so
* for now we just extend the TXT RR and use it.
*
*/
class Net_DNS2_RR_AVC extends Net_DNS2_RR_TXT
{
}

View File

@ -0,0 +1,138 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.2.0
*
*/
/**
* CAA Resource Record - http://tools.ietf.org/html/draft-ietf-pkix-caa-03
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | FLAGS | TAG LENGTH |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / TAG /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / DATA /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_CAA extends Net_DNS2_RR
{
/*
* The critcal flag
*/
public $flags;
/*
* The property identifier
*/
public $tag;
/*
* The property value
*/
public $value;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->flags . ' ' . $this->tag . ' "' .
trim($this->cleanString($this->value), '"') . '"';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->flags = array_shift($rdata);
$this->tag = array_shift($rdata);
$this->value = trim($this->cleanString(implode(' ', $rdata)), '"');
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the flags and tag length
//
$x = unpack('Cflags/Ctag_length', $this->rdata);
$this->flags = $x['flags'];
$offset = 2;
$this->tag = substr($this->rdata, $offset, $x['tag_length']);
$offset += $x['tag_length'];
$this->value = substr($this->rdata, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->value) > 0) {
$data = chr($this->flags);
$data .= chr(strlen($this->tag)) . $this->tag . $this->value;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.4.0
*
*/
/**
* The CDNSKEY RR is implemented exactly like the DNSKEY record, so
* for now we just extend the DNSKEY RR and use it.
*
* http://www.rfc-editor.org/rfc/rfc7344.txt
*
*/
class Net_DNS2_RR_CDNSKEY extends Net_DNS2_RR_DNSKEY
{
}

View File

@ -0,0 +1,29 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.2.0
*
*/
/**
* The CDS RR is implemented exactly like the DS record, so
* for now we just extend the DS RR and use it.
*
* http://www.rfc-editor.org/rfc/rfc7344.txt
*
*/
class Net_DNS2_RR_CDS extends Net_DNS2_RR_DS
{
}

View File

@ -0,0 +1,243 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* CERT Resource Record - RFC4398 section 2
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | format | key tag |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | algorithm | /
* +---------------+ certificate or CRL /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
*
*/
class Net_DNS2_RR_CERT extends Net_DNS2_RR
{
/*
* format's allowed for certificates
*/
const CERT_FORMAT_RES = 0;
const CERT_FORMAT_PKIX = 1;
const CERT_FORMAT_SPKI = 2;
const CERT_FORMAT_PGP = 3;
const CERT_FORMAT_IPKIX = 4;
const CERT_FORMAT_ISPKI = 5;
const CERT_FORMAT_IPGP = 6;
const CERT_FORMAT_ACPKIX = 7;
const CERT_FORMAT_IACPKIX = 8;
const CERT_FORMAT_URI = 253;
const CERT_FORMAT_OID = 254;
public $cert_format_name_to_id = [];
public $cert_format_id_to_name = [
self::CERT_FORMAT_RES => 'Reserved',
self::CERT_FORMAT_PKIX => 'PKIX',
self::CERT_FORMAT_SPKI => 'SPKI',
self::CERT_FORMAT_PGP => 'PGP',
self::CERT_FORMAT_IPKIX => 'IPKIX',
self::CERT_FORMAT_ISPKI => 'ISPKI',
self::CERT_FORMAT_IPGP => 'IPGP',
self::CERT_FORMAT_ACPKIX => 'ACPKIX',
self::CERT_FORMAT_IACPKIX => 'IACPKIX',
self::CERT_FORMAT_URI => 'URI',
self::CERT_FORMAT_OID => 'OID'
];
/*
* certificate format
*/
public $format;
/*
* key tag
*/
public $keytag;
/*
* The algorithm used for the CERt
*/
public $algorithm;
/*
* certificate
*/
public $certificate;
/**
* we have our own constructor so that we can load our certificate
* information for parsing.
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
* @param array $rr a array with parsed RR values
*
* @return
*
*/
public function __construct(Net_DNS2_Packet &$packet = null, array $rr = null)
{
parent::__construct($packet, $rr);
//
// load the lookup values
//
$this->cert_format_name_to_id = array_flip($this->cert_format_id_to_name);
}
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->format . ' ' . $this->keytag . ' ' . $this->algorithm .
' ' . base64_encode($this->certificate);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// load and check the format; can be an int, or a mnemonic symbol
//
$this->format = array_shift($rdata);
if (!is_numeric($this->format)) {
$mnemonic = strtoupper(trim($this->format));
if (!isset($this->cert_format_name_to_id[$mnemonic])) {
return false;
}
$this->format = $this->cert_format_name_to_id[$mnemonic];
} else {
if (!isset($this->cert_format_id_to_name[$this->format])) {
return false;
}
}
$this->keytag = array_shift($rdata);
//
// parse and check the algorithm; can be an int, or a mnemonic symbol
//
$this->algorithm = array_shift($rdata);
if (!is_numeric($this->algorithm)) {
$mnemonic = strtoupper(trim($this->algorithm));
if (!isset(Net_DNS2_Lookups::$algorithm_name_to_id[$mnemonic])) {
return false;
}
$this->algorithm = Net_DNS2_Lookups::$algorithm_name_to_id[
$mnemonic
];
} else {
if (!isset(Net_DNS2_Lookups::$algorithm_id_to_name[$this->algorithm])) {
return false;
}
}
//
// parse and base64 decode the certificate
//
// certificates MUST be provided base64 encoded, if not, everything will
// be broken after this point, as we assume it's base64 encoded.
//
$this->certificate = base64_decode(implode(' ', $rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the format, keytag and algorithm
//
$x = unpack('nformat/nkeytag/Calgorithm', $this->rdata);
$this->format = $x['format'];
$this->keytag = $x['keytag'];
$this->algorithm = $x['algorithm'];
//
// copy the certificate
//
$this->certificate = substr($this->rdata, 5, $this->rdlength - 5);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->certificate) > 0) {
$data = pack('nnC', $this->format, $this->keytag, $this->algorithm) . $this->certificate;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* CNAME Resource Record - RFC1035 section 3.3.1
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / CNAME /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_CNAME extends Net_DNS2_RR
{
/*
* The canonical name
*/
public $cname;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cleanString($this->cname) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->cname = $this->cleanString(array_shift($rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = $packet->offset;
$this->cname = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->cname) > 0) {
return $packet->compress($this->cname, $packet->offset);
}
return null;
}
}

View File

@ -0,0 +1,155 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.4.1
*
*/
/**
* CSYNC Resource Record - RFC 7477 seciond 2.1.1
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | SOA Serial |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | Flags |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / Type Bit Map /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_CSYNC extends Net_DNS2_RR
{
/*
* serial number
*/
public $serial;
/*
* flags
*/
public $flags;
/*
* array of RR type names
*/
public $type_bit_maps = [];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->serial . ' ' . $this->flags;
//
// show the RR's
//
foreach ($this->type_bit_maps as $rr) {
$out .= ' ' . strtoupper($rr);
}
return $out;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->serial = array_shift($rdata);
$this->flags = array_shift($rdata);
$this->type_bit_maps = $rdata;
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the serial and flags values
//
$x = unpack('@' . $packet->offset . '/Nserial/nflags', $packet->rdata);
$this->serial = Net_DNS2::expandUint32($x['serial']);
$this->flags = $x['flags'];
//
// parse out the RR bitmap
//
$this->type_bit_maps = Net_DNS2_BitMap::bitMapToArray(
substr($this->rdata, 6)
);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
//
// pack the serial and flags values
//
$data = pack('Nn', $this->serial, $this->flags);
//
// convert the array of RR names to a type bitmap
//
$data .= Net_DNS2_BitMap::arrayToBitMap($this->type_bit_maps);
//
// advance the offset
//
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* DHCID Resource Record - RFC4701 section 3.1
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ID Type Code |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | Digest Type | /
* +--+--+--+--+--+--+--+--+ /
* / /
* / Digest /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_DHCID extends Net_DNS2_RR
{
/*
* Identifier type
*/
public $id_type;
/*
* Digest Type
*/
public $digest_type;
/*
* The digest
*/
public $digest;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = pack('nC', $this->id_type, $this->digest_type);
$out .= base64_decode($this->digest);
return base64_encode($out);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$data = base64_decode(array_shift($rdata));
if (strlen($data) > 0) {
//
// unpack the id type and digest type
//
$x = unpack('nid_type/Cdigest_type', $data);
$this->id_type = $x['id_type'];
$this->digest_type = $x['digest_type'];
//
// copy out the digest
//
$this->digest = base64_encode(substr($data, 3, strlen($data) - 3));
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the id type and digest type
//
$x = unpack('nid_type/Cdigest_type', $this->rdata);
$this->id_type = $x['id_type'];
$this->digest_type = $x['digest_type'];
//
// copy out the digest
//
$this->digest = base64_encode(
substr($this->rdata, 3, $this->rdlength - 3)
);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->digest) > 0) {
$data = pack('nC', $this->id_type, $this->digest_type) .
base64_decode($this->digest);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* The DLV RR is implemented exactly like the DS RR; so we just extend that
* class, and use all of it's methods
*
*/
class Net_DNS2_RR_DLV extends Net_DNS2_RR_DS
{
}

View File

@ -0,0 +1,105 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* DNAME Resource Record - RFC2672 section 3
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / DNAME /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_DNAME extends Net_DNS2_RR
{
/*
* The target name
*/
public $dname;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cleanString($this->dname) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->dname = $this->cleanString(array_shift($rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = $packet->offset;
$this->dname = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->dname) > 0) {
return $packet->compress($this->dname, $packet->offset);
}
return null;
}
}

View File

@ -0,0 +1,150 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* DNSKEY Resource Record - RFC4034 sction 2.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Flags | Protocol | Algorithm |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / Public Key /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_DNSKEY extends Net_DNS2_RR
{
/*
* flags
*/
public $flags;
/*
* protocol
*/
public $protocol;
/*
* algorithm used
*/
public $algorithm;
/*
* the public key
*/
public $key;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->flags . ' ' . $this->protocol . ' ' .
$this->algorithm . ' ' . $this->key;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->flags = array_shift($rdata);
$this->protocol = array_shift($rdata);
$this->algorithm = array_shift($rdata);
$this->key = implode(' ', $rdata);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the flags, protocol and algorithm
//
$x = unpack('nflags/Cprotocol/Calgorithm', $this->rdata);
//
// TODO: right now we're just displaying what's in DNS; we really
// should be parsing bit 7 and bit 15 of the flags field, and store
// those separately.
//
// right now the DNSSEC implementation is really just for display,
// we don't validate or handle any of the keys
//
$this->flags = $x['flags'];
$this->protocol = $x['protocol'];
$this->algorithm = $x['algorithm'];
$this->key = base64_encode(substr($this->rdata, 4));
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->key) > 0) {
$data = pack('nCC', $this->flags, $this->protocol, $this->algorithm);
$data .= base64_decode($this->key);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,139 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* DS Resource Record - RFC4034 sction 5.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Key Tag | Algorithm | Digest Type |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / Digest /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_DS extends Net_DNS2_RR
{
/*
* key tag
*/
public $keytag;
/*
* algorithm number
*/
public $algorithm;
/*
* algorithm used to construct the digest
*/
public $digesttype;
/*
* the digest data
*/
public $digest;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->keytag . ' ' . $this->algorithm . ' ' . $this->digesttype . ' ' . $this->digest;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->keytag = array_shift($rdata);
$this->algorithm = array_shift($rdata);
$this->digesttype = array_shift($rdata);
$this->digest = implode('', $rdata);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the keytag, algorithm and digesttype
//
$x = unpack('nkeytag/Calgorithm/Cdigesttype/H*digest', $this->rdata);
$this->keytag = $x['keytag'];
$this->algorithm = $x['algorithm'];
$this->digesttype = $x['digesttype'];
$this->digest = $x['digest'];
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->digest) > 0) {
$data = pack('nCCH*', $this->keytag, $this->algorithm, $this->digesttype, $this->digest);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* EID Resource Record - undefined; the rdata is simply used as-is in it's
* binary format, so not process has to be done.
*
*/
class Net_DNS2_RR_EID extends Net_DNS2_RR
{
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return '';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
return true;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
return $this->rdata;
}
}

View File

@ -0,0 +1,139 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.3.2
*
*/
/**
* EUI48 Resource Record - RFC7043 section 3.1
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | EUI-48 Address |
* | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_EUI48 extends Net_DNS2_RR
{
/*
* The EUI48 address, in hex format
*/
public $address;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->address;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$value = array_shift($rdata);
//
// re: RFC 7043, the field must be represented as six two-digit hex numbers
// separated by hyphens.
//
$a = explode('-', $value);
if (count($a) != 6) {
return false;
}
//
// make sure they're all hex values
//
foreach ($a as $i) {
if (ctype_xdigit($i) == false) {
return false;
}
}
//
// store it
//
$this->address = strtolower($value);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$x = unpack('C6', $this->rdata);
if (count($x) == 6) {
$this->address = vsprintf('%02x-%02x-%02x-%02x-%02x-%02x', $x);
return true;
}
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$data = '';
$a = explode('-', $this->address);
foreach ($a as $b) {
$data .= chr(hexdec($b));
}
$packet->offset += 6;
return $data;
}
}

View File

@ -0,0 +1,140 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.3.2
*
*/
/**
* EUI64 Resource Record - RFC7043 section 4.1
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | EUI-64 Address |
* | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_EUI64 extends Net_DNS2_RR
{
/*
* The EUI64 address, in hex format
*/
public $address;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->address;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$value = array_shift($rdata);
//
// re: RFC 7043, the field must be represented as 8 two-digit hex numbers
// separated by hyphens.
//
$a = explode('-', $value);
if (count($a) != 8) {
return false;
}
//
// make sure they're all hex values
//
foreach ($a as $i) {
if (ctype_xdigit($i) == false) {
return false;
}
}
//
// store it
//
$this->address = strtolower($value);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$x = unpack('C8', $this->rdata);
if (count($x) == 8) {
$this->address = vsprintf(
'%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x', $x
);
return true;
}
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$data = '';
$a = explode('-', $this->address);
foreach ($a as $b) {
$data .= chr(hexdec($b));
}
$packet->offset += 8;
return $data;
}
}

View File

@ -0,0 +1,125 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* HINFO Resource Record - RFC1035 section 3.3.2
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / CPU /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / OS /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_HINFO extends Net_DNS2_RR
{
/*
* computer informatino
*/
public $cpu;
/*
* operataing system
*/
public $os;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->formatString($this->cpu) . ' ' . $this->formatString($this->os);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$data = $this->buildString($rdata);
if (count($data) == 2) {
$this->cpu = trim($data[0], '"');
$this->os = trim($data[1], '"');
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = $packet->offset;
$this->cpu = Net_DNS2_Packet::label($packet, $offset);
$this->os = Net_DNS2_Packet::label($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->cpu) > 0) {
$data = pack('Ca*Ca*', strlen($this->cpu), $this->cpu, strlen($this->os), $this->os);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,239 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.0.0
*
*/
/**
* HIP Resource Record - RFC5205 section 5
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | HIT length | PK algorithm | PK length |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | |
* ~ HIT ~
* | |
* + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | | |
* +-+-+-+-+-+-+-+-+-+-+-+ +
* | Public Key |
* ~ ~
* | |
* + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
* | |
* ~ Rendezvous Servers ~
* | |
* + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | |
* +-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_HIP extends Net_DNS2_RR
{
/*
* The length of the HIT field
*/
public $hit_length;
/*
* the public key cryptographic algorithm
*/
public $pk_algorithm;
/*
* the length of the public key field
*/
public $pk_length;
/*
* The HIT is stored as a binary value in network byte order.
*/
public $hit;
/*
* The public key
*/
public $public_key;
/*
* a list of rendezvous servers
*/
public $rendezvous_servers = [];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->pk_algorithm . ' ' .
$this->hit . ' ' . $this->public_key . ' ';
foreach ($this->rendezvous_servers as $index => $server) {
$out .= $server . '. ';
}
return trim($out);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->pk_algorithm = array_shift($rdata);
$this->hit = strtoupper(array_shift($rdata));
$this->public_key = array_shift($rdata);
//
// anything left on the array, must be one or more rendezevous servers. add
// them and strip off the trailing dot
//
if (count($rdata) > 0) {
$this->rendezvous_servers = preg_replace('/\.$/', '', $rdata);
}
//
// store the lengths;
//
$this->hit_length = strlen(pack('H*', $this->hit));
$this->pk_length = strlen(base64_decode($this->public_key));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the algorithm and length values
//
$x = unpack('Chit_length/Cpk_algorithm/npk_length', $this->rdata);
$this->hit_length = $x['hit_length'];
$this->pk_algorithm = $x['pk_algorithm'];
$this->pk_length = $x['pk_length'];
$offset = 4;
//
// copy out the HIT value
//
$hit = unpack('H*', substr($this->rdata, $offset, $this->hit_length));
$this->hit = strtoupper($hit[1]);
$offset += $this->hit_length;
//
// copy out the public key
//
$this->public_key = base64_encode(
substr($this->rdata, $offset, $this->pk_length)
);
$offset += $this->pk_length;
//
// copy out any possible rendezvous servers
//
$offset = $packet->offset + $offset;
while ( ($offset - $packet->offset) < $this->rdlength) {
$this->rendezvous_servers[] = Net_DNS2_Packet::expand(
$packet, $offset
);
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if ( (strlen($this->hit) > 0) && (strlen($this->public_key) > 0) ) {
//
// pack the length, algorithm and HIT values
//
$data = pack(
'CCnH*',
$this->hit_length,
$this->pk_algorithm,
$this->pk_length,
$this->hit
);
//
// add the public key
//
$data .= base64_decode($this->public_key);
//
// add the offset
//
$packet->offset += strlen($data);
//
// add each rendezvous server
//
foreach ($this->rendezvous_servers as $index => $server) {
$data .= $packet->compress($server, $packet->offset);
}
return $data;
}
return null;
}
}

View File

@ -0,0 +1,338 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* IPSECKEY Resource Record - RFC4025 section 2.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | precedence | gateway type | algorithm | gateway |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------+ +
* ~ gateway ~
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | /
* / public key /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
*
*/
class Net_DNS2_RR_IPSECKEY extends Net_DNS2_RR
{
const GATEWAY_TYPE_NONE = 0;
const GATEWAY_TYPE_IPV4 = 1;
const GATEWAY_TYPE_IPV6 = 2;
const GATEWAY_TYPE_DOMAIN = 3;
const ALGORITHM_NONE = 0;
const ALGORITHM_DSA = 1;
const ALGORITHM_RSA = 2;
/*
* Precedence (used the same was as a preference field)
*/
public $precedence;
/*
* Gateway type - specifies the format of the gataway information
* This can be either:
*
* 0 No Gateway
* 1 IPv4 address
* 2 IPV6 address
* 3 wire-encoded domain name (not compressed)
*
*/
public $gateway_type;
/*
* The algorithm used
*
* This can be:
*
* 0 No key is present
* 1 DSA key is present
* 2 RSA key is present
*
*/
public $algorithm;
/*
* The gatway information
*/
public $gateway;
/*
* the public key
*/
public $key;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->precedence . ' ' . $this->gateway_type . ' ' .
$this->algorithm . ' ';
switch($this->gateway_type) {
case self::GATEWAY_TYPE_NONE:
$out .= '. ';
break;
case self::GATEWAY_TYPE_IPV4:
case self::GATEWAY_TYPE_IPV6:
$out .= $this->gateway . ' ';
break;
case self::GATEWAY_TYPE_DOMAIN:
$out .= $this->gateway . '. ';
break;
}
$out .= $this->key;
return $out;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// load the data
//
$precedence = array_shift($rdata);
$gateway_type = array_shift($rdata);
$algorithm = array_shift($rdata);
$gateway = trim(strtolower(trim(array_shift($rdata))), '.');
$key = array_shift($rdata);
//
// validate it
//
switch($gateway_type) {
case self::GATEWAY_TYPE_NONE:
$gateway = '';
break;
case self::GATEWAY_TYPE_IPV4:
if (Net_DNS2::isIPv4($gateway) == false) {
return false;
}
break;
case self::GATEWAY_TYPE_IPV6:
if (Net_DNS2::isIPv6($gateway) == false) {
return false;
}
break;
case self::GATEWAY_TYPE_DOMAIN:
; // do nothing
break;
default:
return false;
}
//
// check the algorithm and key
//
switch($algorithm) {
case self::ALGORITHM_NONE:
$key = '';
break;
case self::ALGORITHM_DSA:
case self::ALGORITHM_RSA:
; // do nothing
break;
default:
return false;
}
//
// store the values
//
$this->precedence = $precedence;
$this->gateway_type = $gateway_type;
$this->algorithm = $algorithm;
$this->gateway = $gateway;
$this->key = $key;
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// parse off the precedence, gateway type and algorithm
//
$x = unpack('Cprecedence/Cgateway_type/Calgorithm', $this->rdata);
$this->precedence = $x['precedence'];
$this->gateway_type = $x['gateway_type'];
$this->algorithm = $x['algorithm'];
$offset = 3;
//
// extract the gatway based on the type
//
switch($this->gateway_type) {
case self::GATEWAY_TYPE_NONE:
$this->gateway = '';
break;
case self::GATEWAY_TYPE_IPV4:
$this->gateway = inet_ntop(substr($this->rdata, $offset, 4));
$offset += 4;
break;
case self::GATEWAY_TYPE_IPV6:
$ip = unpack('n8', substr($this->rdata, $offset, 16));
if (count($ip) == 8) {
$this->gateway = vsprintf('%x:%x:%x:%x:%x:%x:%x:%x', $ip);
$offset += 16;
} else {
return false;
}
break;
case self::GATEWAY_TYPE_DOMAIN:
$doffset = $offset + $packet->offset;
$this->gateway = Net_DNS2_Packet::expand($packet, $doffset);
$offset = ($doffset - $packet->offset);
break;
default:
return false;
}
//
// extract the key
//
switch($this->algorithm) {
case self::ALGORITHM_NONE:
$this->key = '';
break;
case self::ALGORITHM_DSA:
case self::ALGORITHM_RSA:
$this->key = base64_encode(substr($this->rdata, $offset));
break;
default:
return false;
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
//
// pack the precedence, gateway type and algorithm
//
$data = pack(
'CCC', $this->precedence, $this->gateway_type, $this->algorithm
);
//
// add the gateway based on the type
//
switch($this->gateway_type) {
case self::GATEWAY_TYPE_NONE:
; // add nothing
break;
case self::GATEWAY_TYPE_IPV4:
case self::GATEWAY_TYPE_IPV6:
$data .= inet_pton($this->gateway);
break;
case self::GATEWAY_TYPE_DOMAIN:
$data .= chr(strlen($this->gateway)) . $this->gateway;
break;
default:
return null;
}
//
// add the key if there's one specified
//
switch($this->algorithm) {
case self::ALGORITHM_NONE:
; // add nothing
break;
case self::ALGORITHM_DSA:
case self::ALGORITHM_RSA:
$data .= base64_decode($this->key);
break;
default:
return null;
}
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,142 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* ISDN Resource Record - RFC1183 section 3.2
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / ISDN-address /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / SA /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_ISDN extends Net_DNS2_RR
{
/*
* ISDN Number
*/
public $isdnaddress;
/*
* Sub-Address
*/
public $sa;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->formatString($this->isdnaddress) . ' ' .
$this->formatString($this->sa);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$data = $this->buildString($rdata);
if (count($data) >= 1) {
$this->isdnaddress = $data[0];
if (isset($data[1])) {
$this->sa = $data[1];
}
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$this->isdnaddress = Net_DNS2_Packet::label($packet, $packet->offset);
//
// look for a SA (sub address) - it's optional
//
if ( (strlen($this->isdnaddress) + 1) < $this->rdlength) {
$this->sa = Net_DNS2_Packet::label($packet, $packet->offset);
} else {
$this->sa = '';
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->isdnaddress) > 0) {
$data = chr(strlen($this->isdnaddress)) . $this->isdnaddress;
if (!empty($this->sa)) {
$data .= chr(strlen($this->sa));
$data .= $this->sa;
}
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* the KEY RR is implemented the same as the DNSKEY RR, the only difference
* is how the flags data is parsed.
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | A/C | Z | XT| Z | Z | NAMTYP| Z | Z | Z | Z | SIG |
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
*
* DNSKEY only uses bits 7 and 15
*
* We're not doing anything with these flags right now, so duplicating the
* class like this is fine.
*
*/
class Net_DNS2_RR_KEY extends Net_DNS2_RR_DNSKEY
{
}

View File

@ -0,0 +1,131 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* KX Resource Record - RFC2230 section 3.1
*
* This class is almost identical to MX, except that the the exchanger
* domain is not compressed, it's added as a label
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PREFERENCE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / EXCHANGER /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_KX extends Net_DNS2_RR
{
/*
* the preference for this mail exchanger
*/
public $preference;
/*
* the hostname of the mail exchanger
*/
public $exchange;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' . $this->cleanString($this->exchange) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = array_shift($rdata);
$this->exchange = $this->cleanString(array_shift($rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// parse the preference
//
$x = unpack('npreference', $this->rdata);
$this->preference = $x['preference'];
//
// get the exchange entry server)
//
$offset = $packet->offset + 2;
$this->exchange = Net_DNS2_Packet::label($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->exchange) > 0) {
$data = pack('nC', $this->preference, strlen($this->exchange)) .
$this->exchange;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,132 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.3.1
*
*/
/**
* L32 Resource Record - RFC6742 section 2.2
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Preference | Locator32 (16 MSBs) |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Locator32 (16 LSBs) |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_L32 extends Net_DNS2_RR
{
/*
* The preference
*/
public $preference;
/*
* The locator32 field
*/
public $locator32;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' . $this->locator32;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = array_shift($rdata);
$this->locator32 = array_shift($rdata);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the values
//
$x = unpack('npreference/C4locator', $this->rdata);
$this->preference = $x['preference'];
//
// build the locator value
//
$this->locator32 = $x['locator1'] . '.' . $x['locator2'] . '.' .
$x['locator3'] . '.' . $x['locator4'];
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->locator32) > 0) {
//
// break out the locator value
//
$n = explode('.', $this->locator32);
//
// pack the data
//
return pack('nC4', $this->preference, $n[0], $n[1], $n[2], $n[3]);
}
return null;
}
}

View File

@ -0,0 +1,139 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.3.1
*
*/
/**
* L64 Resource Record - RFC6742 section 2.3
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Preference | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
* | Locator64 |
* + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_L64 extends Net_DNS2_RR
{
/*
* The preference
*/
public $preference;
/*
* The locator64 field
*/
public $locator64;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' . $this->locator64;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = array_shift($rdata);
$this->locator64 = array_shift($rdata);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the values
//
$x = unpack('npreference/n4locator', $this->rdata);
$this->preference = $x['preference'];
//
// build the locator64
//
$this->locator64 = dechex($x['locator1']) . ':' .
dechex($x['locator2']) . ':' .
dechex($x['locator3']) . ':' .
dechex($x['locator4']);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->locator64) > 0) {
//
// break out the locator64
//
$n = explode(':', $this->locator64);
//
// pack the data
//
return pack(
'n5', $this->preference, hexdec($n[0]), hexdec($n[1]),
hexdec($n[2]), hexdec($n[3])
);
}
return null;
}
}

View File

@ -0,0 +1,392 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* LOC Resource Record - RFC1876 section 2
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | VERSION | SIZE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | HORIZ PRE | VERT PRE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | LATITUDE |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | LONGITUDE |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ALTITUDE |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_LOC extends Net_DNS2_RR
{
/*
* the LOC version- should only ever be 0
*/
public $version;
/*
* The diameter of a sphere enclosing the described entity
*/
public $size;
/*
* The horizontal precision of the data
*/
public $horiz_pre;
/*
* The vertical precision of the data
*/
public $vert_pre;
/*
* The latitude - stored in decimal degrees
*/
public $latitude;
/*
* The longitude - stored in decimal degrees
*/
public $longitude;
/*
* The altitude - stored in decimal
*/
public $altitude;
/*
* used for quick power-of-ten lookups
*/
private $_powerOfTen = [ 1, 10, 100, 1000, 10000, 100000,
1000000,10000000,100000000,1000000000 ];
/*
* some conversion values
*/
const CONV_SEC = 1000;
const CONV_MIN = 60000;
const CONV_DEG = 3600000;
const REFERENCE_ALT = 10000000;
const REFERENCE_LATLON = 2147483648;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
if ($this->version == 0) {
return $this->_d2Dms($this->latitude, 'LAT') . ' ' .
$this->_d2Dms($this->longitude, 'LNG') . ' ' .
sprintf('%.2fm', $this->altitude) . ' ' .
sprintf('%.2fm', $this->size) . ' ' .
sprintf('%.2fm', $this->horiz_pre) . ' ' .
sprintf('%.2fm', $this->vert_pre);
}
return '';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// format as defined by RFC1876 section 3
//
// d1 [m1 [s1]] {"N"|"S"} d2 [m2 [s2]] {"E"|"W"} alt["m"]
// [siz["m"] [hp["m"] [vp["m"]]]]
//
$res = preg_match(
'/^(\d+) \s+((\d+) \s+)?(([\d.]+) \s+)?(N|S) \s+(\d+) ' .
'\s+((\d+) \s+)?(([\d.]+) \s+)?(E|W) \s+(-?[\d.]+) m?(\s+ ' .
'([\d.]+) m?)?(\s+ ([\d.]+) m?)?(\s+ ([\d.]+) m?)?/ix',
implode(' ', $rdata), $x
);
if ($res) {
//
// latitude
//
$latdeg = $x[1];
$latmin = (isset($x[3])) ? $x[3] : 0;
$latsec = (isset($x[5])) ? $x[5] : 0;
$lathem = strtoupper($x[6]);
$this->latitude = $this->_dms2d($latdeg, $latmin, $latsec, $lathem);
//
// longitude
//
$londeg = $x[7];
$lonmin = (isset($x[9])) ? $x[9] : 0;
$lonsec = (isset($x[11])) ? $x[11] : 0;
$lonhem = strtoupper($x[12]);
$this->longitude = $this->_dms2d($londeg, $lonmin, $lonsec, $lonhem);
//
// the rest of teh values
//
$version = 0;
$this->size = (isset($x[15])) ? $x[15] : 1;
$this->horiz_pre = ((isset($x[17])) ? $x[17] : 10000);
$this->vert_pre = ((isset($x[19])) ? $x[19] : 10);
$this->altitude = $x[13];
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack all the values
//
$x = unpack(
'Cver/Csize/Choriz_pre/Cvert_pre/Nlatitude/Nlongitude/Naltitude',
$this->rdata
);
//
// version must be 0 per RFC 1876 section 2
//
$this->version = $x['ver'];
if ($this->version == 0) {
$this->size = $this->_precsizeNtoA($x['size']);
$this->horiz_pre = $this->_precsizeNtoA($x['horiz_pre']);
$this->vert_pre = $this->_precsizeNtoA($x['vert_pre']);
//
// convert the latitude and longitude to degress in decimal
//
if ($x['latitude'] < 0) {
$this->latitude = ($x['latitude'] +
self::REFERENCE_LATLON) / self::CONV_DEG;
} else {
$this->latitude = ($x['latitude'] -
self::REFERENCE_LATLON) / self::CONV_DEG;
}
if ($x['longitude'] < 0) {
$this->longitude = ($x['longitude'] +
self::REFERENCE_LATLON) / self::CONV_DEG;
} else {
$this->longitude = ($x['longitude'] -
self::REFERENCE_LATLON) / self::CONV_DEG;
}
//
// convert down the altitude
//
$this->altitude = ($x['altitude'] - self::REFERENCE_ALT) / 100;
return true;
} else {
return false;
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if ($this->version == 0) {
$lat = 0;
$lng = 0;
if ($this->latitude < 0) {
$lat = ($this->latitude * self::CONV_DEG) - self::REFERENCE_LATLON;
} else {
$lat = ($this->latitude * self::CONV_DEG) + self::REFERENCE_LATLON;
}
if ($this->longitude < 0) {
$lng = ($this->longitude * self::CONV_DEG) - self::REFERENCE_LATLON;
} else {
$lng = ($this->longitude * self::CONV_DEG) + self::REFERENCE_LATLON;
}
$packet->offset += 16;
return pack(
'CCCCNNN',
$this->version,
$this->_precsizeAtoN($this->size),
$this->_precsizeAtoN($this->horiz_pre),
$this->_precsizeAtoN($this->vert_pre),
$lat, $lng,
($this->altitude * 100) + self::REFERENCE_ALT
);
}
return null;
}
/**
* takes an XeY precision/size value, returns a string representation.
* shamlessly stolen from RFC1876 Appendix A
*
* @param integer $prec the value to convert
*
* @return string
* @access private
*
*/
private function _precsizeNtoA($prec)
{
$mantissa = (($prec >> 4) & 0x0f) % 10;
$exponent = (($prec >> 0) & 0x0f) % 10;
return $mantissa * $this->_powerOfTen[$exponent];
}
/**
* converts ascii size/precision X * 10**Y(cm) to 0xXY.
* shamlessly stolen from RFC1876 Appendix A
*
* @param string $prec the value to convert
*
* @return integer
* @access private
*
*/
private function _precsizeAtoN($prec)
{
$exponent = 0;
while ($prec >= 10) {
$prec /= 10;
++$exponent;
}
return ($prec << 4) | ($exponent & 0x0f);
}
/**
* convert lat/lng in deg/min/sec/hem to decimal value
*
* @param integer $deg the degree value
* @param integer $min the minutes value
* @param integer $sec the seconds value
* @param string $hem the hemisphere (N/E/S/W)
*
* @return float the decinmal value
* @access private
*
*/
private function _dms2d($deg, $min, $sec, $hem)
{
$deg = $deg - 0;
$min = $min - 0;
$sign = ($hem == 'W' || $hem == 'S') ? -1 : 1;
return ((($sec/60+$min)/60)+$deg) * $sign;
}
/**
* convert lat/lng in decimal to deg/min/sec/hem
*
* @param float $data the decimal value
* @param string $latlng either LAT or LNG so we can determine the HEM value
*
* @return string
* @access private
*
*/
private function _d2Dms($data, $latlng)
{
$deg = 0;
$min = 0;
$sec = 0;
$msec = 0;
$hem = '';
if ($latlng == 'LAT') {
$hem = ($data > 0) ? 'N' : 'S';
} else {
$hem = ($data > 0) ? 'E' : 'W';
}
$data = abs($data);
$deg = (int)$data;
$min = (int)(($data - $deg) * 60);
$sec = (int)(((($data - $deg) * 60) - $min) * 60);
$msec = round((((((($data - $deg) * 60) - $min) * 60) - $sec) * 1000));
return sprintf('%d %02d %02d.%03d %s', $deg, $min, $sec, round($msec), $hem);
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.3.1
*
*/
/**
* LP Resource Record - RFC6742 section 2.4
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Preference | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
* / /
* / FQDN /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_LP extends Net_DNS2_RR
{
/*
* The preference
*/
public $preference;
/*
* The fdqn field
*/
public $fqdn;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' . $this->fqdn . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = array_shift($rdata);
$this->fqdn = trim(array_shift($rdata), '.');
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// parse the preference
//
$x = unpack('npreference', $this->rdata);
$this->preference = $x['preference'];
$offset = $packet->offset + 2;
//
// get the hostname
//
$this->fqdn = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->fqdn) > 0) {
$data = pack('n', $this->preference);
$packet->offset += 2;
$data .= $packet->compress($this->fqdn, $packet->offset);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,127 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* MX Resource Record - RFC1035 section 3.3.9
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PREFERENCE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / EXCHANGE /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_MX extends Net_DNS2_RR
{
/*
* the preference for this mail exchanger
*/
public $preference;
/*
* the hostname of the mail exchanger
*/
public $exchange;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' . $this->cleanString($this->exchange) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = array_shift($rdata);
$this->exchange = $this->cleanString(array_shift($rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// parse the preference
//
$x = unpack('npreference', $this->rdata);
$this->preference = $x['preference'];
//
// get the exchange entry server)
//
$offset = $packet->offset + 2;
$this->exchange = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->exchange) > 0) {
$data = pack('n', $this->preference);
$packet->offset += 2;
$data .= $packet->compress($this->exchange, $packet->offset);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,183 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* NAPTR Resource Record - RFC2915
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ORDER |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PREFERENCE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / FLAGS /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / SERVICES /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / REGEXP /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / REPLACEMENT /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_NAPTR extends Net_DNS2_RR
{
/*
* the order in which the NAPTR records MUST be processed
*/
public $order;
/*
* specifies the order in which NAPTR records with equal "order"
* values SHOULD be processed
*/
public $preference;
/*
* rewrite flags
*/
public $flags;
/*
* Specifies the service(s) available down this rewrite path
*/
public $services;
/*
* regular expression
*/
public $regexp;
/*
* The next NAME to query for NAPTR, SRV, or address records
* depending on the value of the flags field
*/
public $replacement;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->order . ' ' . $this->preference . ' ' .
$this->formatString($this->flags) . ' ' .
$this->formatString($this->services) . ' ' .
$this->formatString($this->regexp) . ' ' .
$this->cleanString($this->replacement) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->order = array_shift($rdata);
$this->preference = array_shift($rdata);
$data = $this->buildString($rdata);
if (count($data) == 4) {
$this->flags = $data[0];
$this->services = $data[1];
$this->regexp = $data[2];
$this->replacement = $this->cleanString($data[3]);
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the order and preference
//
$x = unpack('norder/npreference', $this->rdata);
$this->order = $x['order'];
$this->preference = $x['preference'];
$offset = $packet->offset + 4;
$this->flags = Net_DNS2_Packet::label($packet, $offset);
$this->services = Net_DNS2_Packet::label($packet, $offset);
$this->regexp = Net_DNS2_Packet::label($packet, $offset);
$this->replacement = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if ( (isset($this->order)) && (strlen($this->services) > 0) ) {
$data = pack('nn', $this->order, $this->preference);
$data .= chr(strlen($this->flags)) . $this->flags;
$data .= chr(strlen($this->services)) . $this->services;
$data .= chr(strlen($this->regexp)) . $this->regexp;
$packet->offset += strlen($data);
$data .= $packet->compress($this->replacement, $packet->offset);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,139 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.3.1
*
*/
/**
* NID Resource Record - RFC6742 section 2.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Preference | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
* | NodeID |
* + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_NID extends Net_DNS2_RR
{
/*
* The preference
*/
public $preference;
/*
* The node ID field
*/
public $nodeid;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' . $this->nodeid;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = array_shift($rdata);
$this->nodeid = array_shift($rdata);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the values
//
$x = unpack('npreference/n4nodeid', $this->rdata);
$this->preference = $x['preference'];
//
// build the node id
//
$this->nodeid = dechex($x['nodeid1']) . ':' .
dechex($x['nodeid2']) . ':' .
dechex($x['nodeid3']) . ':' .
dechex($x['nodeid4']);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->nodeid) > 0) {
//
// break out the node id
//
$n = explode(':', $this->nodeid);
//
// pack the data
//
return pack(
'n5', $this->preference, hexdec($n[0]), hexdec($n[1]),
hexdec($n[2]), hexdec($n[3])
);
}
return null;
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* NIMLOC Resource Record - undefined; the rdata is simply used as-is in it's
* binary format, so not process has to be done.
*
*/
class Net_DNS2_RR_NIMLOC extends Net_DNS2_RR
{
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return '';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
return true;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
return $this->rdata;
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* NS Resource Record - RFC1035 section 3.3.11
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / NSDNAME /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_NS extends Net_DNS2_RR
{
/*
* the hostname of the DNS server
*/
public $nsdname;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cleanString($this->nsdname) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->nsdname = $this->cleanString(array_shift($rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = $packet->offset;
$this->nsdname = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->nsdname) > 0) {
return $packet->compress($this->nsdname, $packet->offset);
}
return null;
}
}

View File

@ -0,0 +1,214 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* NSAP Resource Record - RFC1706
*
* |--------------|
* | <-- IDP --> |
* |--------------|-------------------------------------|
* | AFI | IDI | <-- DSP --> |
* |-----|--------|-------------------------------------|
* | 47 | 0005 | DFI | AA |Rsvd | RD |Area | ID |Sel |
* |-----|--------|-----|----|-----|----|-----|----|----|
* octets | 1 | 2 | 1 | 3 | 2 | 2 | 2 | 6 | 1 |
* |-----|--------|-----|----|-----|----|-----|----|----|
*
*/
class Net_DNS2_RR_NSAP extends Net_DNS2_RR
{
public $afi;
public $idi;
public $dfi;
public $aa;
public $rsvd;
public $rd;
public $area;
public $id;
public $sel;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cleanString($this->afi) . '.' .
$this->cleanString($this->idi) . '.' .
$this->cleanString($this->dfi) . '.' .
$this->cleanString($this->aa) . '.' .
$this->cleanString($this->rsvd) . '.' .
$this->cleanString($this->rd) . '.' .
$this->cleanString($this->area) . '.' .
$this->cleanString($this->id) . '.' .
$this->sel;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$data = strtolower(trim(array_shift($rdata)));
//
// there is no real standard for format, so we can't rely on the fact that
// the value will come in with periods separating the values- so strip
// them out if they're included, and parse without them.
//
$data = str_replace([ '.', '0x' ], '', $data);
//
// unpack it as ascii characters
//
$x = unpack('A2afi/A4idi/A2dfi/A6aa/A4rsvd/A4rd/A4area/A12id/A2sel', $data);
//
// make sure the afi value is 47
//
if ($x['afi'] == '47') {
$this->afi = '0x' . $x['afi'];
$this->idi = $x['idi'];
$this->dfi = $x['dfi'];
$this->aa = $x['aa'];
$this->rsvd = $x['rsvd'];
$this->rd = $x['rd'];
$this->area = $x['area'];
$this->id = $x['id'];
$this->sel = $x['sel'];
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength == 20) {
//
// get the AFI value
//
$this->afi = dechex(ord($this->rdata[0]));
//
// we only support AFI 47- there arent' any others defined.
//
if ($this->afi == '47') {
//
// unpack the rest of the values
//
$x = unpack(
'Cafi/nidi/Cdfi/C3aa/nrsvd/nrd/narea/Nidh/nidl/Csel',
$this->rdata
);
$this->afi = sprintf('0x%02x', $x['afi']);
$this->idi = sprintf('%04x', $x['idi']);
$this->dfi = sprintf('%02x', $x['dfi']);
$this->aa = sprintf(
'%06x', $x['aa1'] << 16 | $x['aa2'] << 8 | $x['aa3']
);
$this->rsvd = sprintf('%04x', $x['rsvd']);
$this->rd = sprintf('%04x', $x['rd']);
$this->area = sprintf('%04x', $x['area']);
$this->id = sprintf('%08x', $x['idh']) .
sprintf('%04x', $x['idl']);
$this->sel = sprintf('%02x', $x['sel']);
return true;
}
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if ($this->afi == '0x47') {
//
// build the aa field
//
$aa = unpack('A2x/A2y/A2z', $this->aa);
//
// build the id field
//
$id = unpack('A8a/A4b', $this->id);
//
$data = pack(
'CnCCCCnnnNnC',
hexdec($this->afi),
hexdec($this->idi),
hexdec($this->dfi),
hexdec($aa['x']),
hexdec($aa['y']),
hexdec($aa['z']),
hexdec($this->rsvd),
hexdec($this->rd),
hexdec($this->area),
hexdec($id['a']),
hexdec($id['b']),
hexdec($this->sel)
);
if (strlen($data) == 20) {
$packet->offset += 20;
return $data;
}
}
return null;
}
}

View File

@ -0,0 +1,136 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* NSEC Resource Record - RFC3845 section 2.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / Next Domain Name /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / List of Type Bit Map(s) /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_NSEC extends Net_DNS2_RR
{
/*
* The next owner name
*/
public $next_domain_name;
/*
* identifies the RRset types that exist at the NSEC RR's owner name.
*/
public $type_bit_maps = [];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$data = $this->cleanString($this->next_domain_name) . '.';
foreach ($this->type_bit_maps as $rr) {
$data .= ' ' . $rr;
}
return $data;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->next_domain_name = $this->cleanString(array_shift($rdata));
$this->type_bit_maps = $rdata;
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// expand the next domain name
//
$offset = $packet->offset;
$this->next_domain_name = Net_DNS2_Packet::expand($packet, $offset);
//
// parse out the RR's from the bitmap
//
$this->type_bit_maps = Net_DNS2_BitMap::bitMapToArray(
substr($this->rdata, $offset - $packet->offset)
);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->next_domain_name) > 0) {
$data = $packet->compress($this->next_domain_name, $packet->offset);
$bitmap = Net_DNS2_BitMap::arrayToBitMap($this->type_bit_maps);
$packet->offset += strlen($bitmap);
return $data . $bitmap;
}
return null;
}
}

View File

@ -0,0 +1,262 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* NSEC3 Resource Record - RFC5155 section 3.2
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Hash Alg. | Flags | Iterations |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Salt Length | Salt /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Hash Length | Next Hashed Owner Name /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / Type Bit Maps /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_NSEC3 extends Net_DNS2_RR
{
/*
* Algorithm to use
*/
public $algorithm;
/*
* flags
*/
public $flags;
/*
* defines the number of additional times the hash is performed.
*/
public $iterations;
/*
* the length of the salt- not displayed
*/
public $salt_length;
/*
* the salt
*/
public $salt;
/*
* the length of the hash value
*/
public $hash_length;
/*
* the hashed value of the owner name
*/
public $hashed_owner_name;
/*
* array of RR type names
*/
public $type_bit_maps = [];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->algorithm . ' ' . $this->flags . ' ' . $this->iterations . ' ';
//
// per RFC5155, the salt_length value isn't displayed, and if the salt
// is empty, the salt is displayed as '-'
//
if ($this->salt_length > 0) {
$out .= $this->salt;
} else {
$out .= '-';
}
//
// per RFC5255 the hash length isn't shown
//
$out .= ' ' . $this->hashed_owner_name;
//
// show the RR's
//
foreach ($this->type_bit_maps as $rr) {
$out .= ' ' . strtoupper($rr);
}
return $out;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->algorithm = array_shift($rdata);
$this->flags = array_shift($rdata);
$this->iterations = array_shift($rdata);
//
// an empty salt is represented as '-' per RFC5155 section 3.3
//
$salt = array_shift($rdata);
if ($salt == '-') {
$this->salt_length = 0;
$this->salt = '';
} else {
$this->salt_length = strlen(pack('H*', $salt));
$this->salt = strtoupper($salt);
}
$this->hashed_owner_name = array_shift($rdata);
$this->hash_length = strlen(base64_decode($this->hashed_owner_name));
$this->type_bit_maps = $rdata;
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the first values
//
$x = unpack('Calgorithm/Cflags/niterations/Csalt_length', $this->rdata);
$this->algorithm = $x['algorithm'];
$this->flags = $x['flags'];
$this->iterations = $x['iterations'];
$this->salt_length = $x['salt_length'];
$offset = 5;
if ($this->salt_length > 0) {
$x = unpack('H*', substr($this->rdata, $offset, $this->salt_length));
$this->salt = strtoupper($x[1]);
$offset += $this->salt_length;
}
//
// unpack the hash length
//
$x = unpack('@' . $offset . '/Chash_length', $this->rdata);
$offset++;
//
// copy out the hash
//
$this->hash_length = $x['hash_length'];
if ($this->hash_length > 0) {
$this->hashed_owner_name = base64_encode(
substr($this->rdata, $offset, $this->hash_length)
);
$offset += $this->hash_length;
}
//
// parse out the RR bitmap
//
$this->type_bit_maps = Net_DNS2_BitMap::bitMapToArray(
substr($this->rdata, $offset)
);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
//
// pull the salt and build the length
//
$salt = pack('H*', $this->salt);
$this->salt_length = strlen($salt);
//
// pack the algorithm, flags, iterations and salt length
//
$data = pack(
'CCnC',
$this->algorithm, $this->flags, $this->iterations, $this->salt_length
);
$data .= $salt;
//
// add the hash length and hash
//
$data .= chr($this->hash_length);
if ($this->hash_length > 0) {
$data .= base64_decode($this->hashed_owner_name);
}
//
// conver the array of RR names to a type bitmap
//
$data .= Net_DNS2_BitMap::arrayToBitMap($this->type_bit_maps);
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,172 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* NSEC3PARAM Resource Record - RFC5155 section 4.2
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Hash Alg. | Flags | Iterations |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Salt Length | Salt /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_NSEC3PARAM extends Net_DNS2_RR
{
/*
* Algorithm to use
*
* TODO: same as the NSEC3
*/
public $algorithm;
/*
* flags
*/
public $flags;
/*
* defines the number of additional times the hash is performed.
*/
public $iterations;
/*
* the length of the salt- not displayed
*/
public $salt_length;
/*
* the salt
*/
public $salt;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->algorithm . ' ' . $this->flags . ' ' . $this->iterations . ' ';
//
// per RFC5155, the salt_length value isn't displayed, and if the salt
// is empty, the salt is displayed as "-"
//
if ($this->salt_length > 0) {
$out .= $this->salt;
} else {
$out .= '-';
}
return $out;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->algorithm = array_shift($rdata);
$this->flags = array_shift($rdata);
$this->iterations = array_shift($rdata);
$salt = array_shift($rdata);
if ($salt == '-') {
$this->salt_length = 0;
$this->salt = '';
} else {
$this->salt_length = strlen(pack('H*', $salt));
$this->salt = strtoupper($salt);
}
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$x = unpack('Calgorithm/Cflags/niterations/Csalt_length', $this->rdata);
$this->algorithm = $x['algorithm'];
$this->flags = $x['flags'];
$this->iterations = $x['iterations'];
$this->salt_length = $x['salt_length'];
if ($this->salt_length > 0) {
$x = unpack('H*', substr($this->rdata, 5, $this->salt_length));
$this->salt = strtoupper($x[1]);
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$salt = pack('H*', $this->salt);
$this->salt_length = strlen($salt);
$data = pack(
'CCnC',
$this->algorithm, $this->flags, $this->iterations, $this->salt_length
) . $salt;
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,111 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.4.0
*
*/
/**
* OPENPGPKEY Resource Record - https://tools.ietf.org/html/draft-ietf-dane-openpgpkey-01
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / OpenPGP Public KeyRing /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_OPENPGPKEY extends Net_DNS2_RR
{
/*
* the public key
*/
public $key;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->key;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->key = array_shift($rdata);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$this->key = base64_encode(substr($this->rdata, 0, $this->rdlength));
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->key) > 0) {
$data = base64_decode($this->key);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,244 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.0.0
*
*/
/**
* OPT Resource Record - RFC2929 section 3.1
*
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | OPTION-CODE |
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | OPTION-LENGTH |
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | |
* / OPTION-DATA /
* / /
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
*
*/
class Net_DNS2_RR_OPT extends Net_DNS2_RR
{
/*
* option code - assigned by IANA
*/
public $option_code;
/*
* the length of the option data
*/
public $option_length;
/*
* the option data
*/
public $option_data;
/*
* the extended response code stored in the TTL
*/
public $extended_rcode;
/*
* the implementation level
*/
public $version;
/*
* the DO bit used for DNSSEC - RFC3225
*/
public $do;
/*
* the extended flags
*/
public $z;
/**
* Constructor - builds a new Net_DNS2_RR_OPT object; normally you wouldn't call
* this directly, but OPT RR's are a little different
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet or null to create
* an empty object
* @param array $rr an array with RR parse values or null to
* create an empty object
*
* @throws Net_DNS2_Exception
* @access public
*
*/
public function __construct(Net_DNS2_Packet &$packet = null, array $rr = null)
{
//
// this is for when we're manually building an OPT RR object; we aren't
// passing in binary data to parse, we just want a clean/empty object.
//
$this->type = 'OPT';
$this->rdlength = 0;
$this->option_length = 0;
$this->extended_rcode = 0;
$this->version = 0;
$this->do = 0;
$this->z = 0;
//
// everthing else gets passed through to the parent.
//
if ( (!is_null($packet)) && (!is_null($rr)) ) {
parent::__construct($packet, $rr);
}
}
/**
* method to return the rdata portion of the packet as a string. There is no
* defintion for returning an OPT RR by string- this is just here to validate
* the binary parsing / building routines.
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->option_code . ' ' . $this->option_data;
}
/**
* parses the rdata portion from a standard DNS config line. There is no
* definition for parsing a OPT RR by string- this is just here to validate
* the binary parsing / building routines.
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->option_code = array_shift($rdata);
$this->option_data = array_shift($rdata);
$this->option_length = strlen($this->option_data);
$x = unpack('Cextended/Cversion/Cdo/Cz', pack('N', $this->ttl));
$this->extended_rcode = $x['extended'];
$this->version = $x['version'];
$this->do = ($x['do'] >> 7);
$this->z = $x['z'];
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
//
// parse out the TTL value
//
$x = unpack('Cextended/Cversion/Cdo/Cz', pack('N', $this->ttl));
$this->extended_rcode = $x['extended'];
$this->version = $x['version'];
$this->do = ($x['do'] >> 7);
$this->z = $x['z'];
//
// parse the data, if there is any
//
if ($this->rdlength > 0) {
//
// unpack the code and length
//
$x = unpack('noption_code/noption_length', $this->rdata);
$this->option_code = $x['option_code'];
$this->option_length = $x['option_length'];
//
// copy out the data based on the length
//
$this->option_data = substr($this->rdata, 4);
}
return true;
}
/**
* pre-builds the TTL value for this record; we needed to separate this out
* from the rrGet() function, as the logic in the Net_DNS2_RR packs the TTL
* value before it builds the rdata value.
*
* @return void
* @access protected
*
*/
protected function preBuild()
{
//
// build the TTL value based on the local values
//
$ttl = unpack(
'N',
pack('CCCC', $this->extended_rcode, $this->version, ($this->do << 7), 0)
);
$this->ttl = $ttl[1];
return;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
//
// if there is an option code, then pack that data too
//
if ($this->option_code) {
$data = pack('nn', $this->option_code, $this->option_length) .
$this->option_data;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,104 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* PTR Resource Record - RFC1035 section 3.3.12
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / PTRDNAME /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_PTR extends Net_DNS2_RR
{
/*
* the hostname of the PTR entry
*/
public $ptrdname;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return rtrim($this->ptrdname, '.') . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->ptrdname = rtrim(implode(' ', $rdata), '.');
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = $packet->offset;
$this->ptrdname = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->ptrdname) > 0) {
return $packet->compress($this->ptrdname, $packet->offset);
}
return null;
}
}

View File

@ -0,0 +1,138 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* PX Resource Record - RFC2163 section 4
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PREFERENCE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / MAP822 /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / MAPX400 /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
*
*/
class Net_DNS2_RR_PX extends Net_DNS2_RR
{
/*
* preference
*/
public $preference;
/*
* the RFC822 part of the MCGAM
*/
public $map822;
/*
* the X.400 part of the MCGAM
*/
public $mapx400;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' . $this->cleanString($this->map822) . '. ' .
$this->cleanString($this->mapx400) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = $rdata[0];
$this->map822 = $this->cleanString($rdata[1]);
$this->mapx400 = $this->cleanString($rdata[2]);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// parse the preference
//
$x = unpack('npreference', $this->rdata);
$this->preference = $x['preference'];
$offset = $packet->offset + 2;
$this->map822 = Net_DNS2_Packet::expand($packet, $offset);
$this->mapx400 = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->map822) > 0) {
$data = pack('n', $this->preference);
$packet->offset += 2;
$data .= $packet->compress($this->map822, $packet->offset);
$data .= $packet->compress($this->mapx400, $packet->offset);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* RP Resource Record - RFC1183 section 2.2
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / mboxdname /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / txtdname /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_RP extends Net_DNS2_RR
{
/*
* mailbox for the responsible person
*/
public $mboxdname;
/*
* is a domain name for which TXT RR's exists
*/
public $txtdname;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cleanString($this->mboxdname) . '. ' . $this->cleanString($this->txtdname) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->mboxdname = $this->cleanString($rdata[0]);
$this->txtdname = $this->cleanString($rdata[1]);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = $packet->offset;
$this->mboxdname = Net_DNS2_Packet::expand($packet, $offset, true);
$this->txtdname = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->mboxdname) > 0) {
return $packet->compress($this->mboxdname, $packet->offset) .
$packet->compress($this->txtdname, $packet->offset);
}
return null;
}
}

View File

@ -0,0 +1,280 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
* This file contains code based off the Net::DNS::SEC Perl module by Olaf M. Kolkman
*
* This is the copyright notice from the PERL Net::DNS::SEC module:
*
* Copyright (c) 2001 - 2005 RIPE NCC. Author Olaf M. Kolkman
* Copyright (c) 2007 - 2008 NLnet Labs. Author Olaf M. Kolkman
* <olaf@net-dns.org>
*
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of the author not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
* AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/**
* RRSIG Resource Record - RFC4034 sction 3.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Type Covered | Algorithm | Labels |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Original TTL |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Signature Expiration |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Signature Inception |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Key Tag | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Signer's Name /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / Signature /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_RRSIG extends Net_DNS2_RR
{
/*
* the RR type covered by this signature
*/
public $typecovered;
/*
* the algorithm used for the signature
*/
public $algorithm;
/*
* the number of labels in the name
*/
public $labels;
/*
* the original TTL
*/
public $origttl;
/*
* the signature expiration
*/
public $sigexp;
/*
* the inception of the signature
*/
public $sigincep;
/*
* the keytag used
*/
public $keytag;
/*
* the signer's name
*/
public $signname;
/*
* the signature
*/
public $signature;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->typecovered . ' ' . $this->algorithm . ' ' .
$this->labels . ' ' . $this->origttl . ' ' .
$this->sigexp . ' ' . $this->sigincep . ' ' .
$this->keytag . ' ' . $this->cleanString($this->signname) . '. ' .
$this->signature;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->typecovered = strtoupper(array_shift($rdata));
$this->algorithm = array_shift($rdata);
$this->labels = array_shift($rdata);
$this->origttl = array_shift($rdata);
$this->sigexp = array_shift($rdata);
$this->sigincep = array_shift($rdata);
$this->keytag = array_shift($rdata);
$this->signname = $this->cleanString(array_shift($rdata));
foreach ($rdata as $line) {
$this->signature .= $line;
}
$this->signature = trim($this->signature);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack
//
$x = unpack(
'ntc/Calgorithm/Clabels/Norigttl/Nsigexp/Nsigincep/nkeytag',
$this->rdata
);
$this->typecovered = Net_DNS2_Lookups::$rr_types_by_id[$x['tc']];
$this->algorithm = $x['algorithm'];
$this->labels = $x['labels'];
$this->origttl = Net_DNS2::expandUint32($x['origttl']);
//
// the dates are in GM time
//
$this->sigexp = gmdate('YmdHis', $x['sigexp']);
$this->sigincep = gmdate('YmdHis', $x['sigincep']);
//
// get the keytag
//
$this->keytag = $x['keytag'];
//
// get teh signers name and signature
//
$offset = $packet->offset + 18;
$sigoffset = $offset;
$this->signname = strtolower(
Net_DNS2_Packet::expand($packet, $sigoffset)
);
$this->signature = base64_encode(
substr($this->rdata, 18 + ($sigoffset - $offset))
);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->signature) > 0) {
//
// parse the values out of the dates
//
preg_match(
'/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $this->sigexp, $e
);
preg_match(
'/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $this->sigincep, $i
);
//
// pack the value
//
$data = pack(
'nCCNNNn',
Net_DNS2_Lookups::$rr_types_by_name[$this->typecovered],
$this->algorithm,
$this->labels,
$this->origttl,
gmmktime($e[4], $e[5], $e[6], $e[2], $e[3], $e[1]),
gmmktime($i[4], $i[5], $i[6], $i[2], $i[3], $i[1]),
$this->keytag
);
//
// the signer name is special; it's not allowed to be compressed
// (see section 3.1.7)
//
$names = explode('.', strtolower($this->signname));
foreach ($names as $name) {
$data .= chr(strlen($name));
$data .= $name;
}
$data .= "\0";
//
// add the signature
//
$data .= base64_decode($this->signature);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,127 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* RT Resource Record - RFC1183 section 3.3
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | preference |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / intermediate-host /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_RT extends Net_DNS2_RR
{
/*
* the preference of this route
*/
public $preference;
/*
* host which will servce as an intermediate in reaching the owner host
*/
public $intermediatehost;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->preference . ' ' .
$this->cleanString($this->intermediatehost) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->preference = $rdata[0];
$this->intermediatehost = $this->cleanString($rdata[1]);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the preference
//
$x = unpack('npreference', $this->rdata);
$this->preference = $x['preference'];
$offset = $packet->offset + 2;
$this->intermediatehost = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->intermediatehost) > 0) {
$data = pack('n', $this->preference);
$packet->offset += 2;
$data .= $packet->compress($this->intermediatehost, $packet->offset);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,410 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
* This file contains code based off the Net::DNS::SEC Perl module by Olaf M. Kolkman
*
* This is the copyright notice from the PERL Net::DNS::SEC module:
*
* Copyright (c) 2001 - 2005 RIPE NCC. Author Olaf M. Kolkman
* Copyright (c) 2007 - 2008 NLnet Labs. Author Olaf M. Kolkman
* <olaf@net-dns.org>
*
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of the author not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
* AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/**
* SIG Resource Record - RFC2535 section 4.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Type Covered | Algorithm | Labels |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Original TTL |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Signature Expiration |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Signature Inception |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Key Tag | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Signer's Name /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / Signature /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_SIG extends Net_DNS2_RR
{
/*
* and instance of a Net_DNS2_PrivateKey object
*/
public $private_key = null;
/*
* the RR type covered by this signature
*/
public $typecovered;
/*
* the algorithm used for the signature
*/
public $algorithm;
/*
* the number of labels in the name
*/
public $labels;
/*
* the original TTL
*/
public $origttl;
/*
* the signature expiration
*/
public $sigexp;
/*
* the inception of the signature
*/
public $sigincep;
/*
* the keytag used
*/
public $keytag;
/*
* the signer's name
*/
public $signname;
/*
* the signature
*/
public $signature;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->typecovered . ' ' . $this->algorithm . ' ' .
$this->labels . ' ' . $this->origttl . ' ' .
$this->sigexp . ' ' . $this->sigincep . ' ' .
$this->keytag . ' ' . $this->cleanString($this->signname) . '. ' .
$this->signature;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->typecovered = strtoupper(array_shift($rdata));
$this->algorithm = array_shift($rdata);
$this->labels = array_shift($rdata);
$this->origttl = array_shift($rdata);
$this->sigexp = array_shift($rdata);
$this->sigincep = array_shift($rdata);
$this->keytag = array_shift($rdata);
$this->signname = $this->cleanString(array_shift($rdata));
foreach ($rdata as $line) {
$this->signature .= $line;
}
$this->signature = trim($this->signature);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack
//
$x = unpack(
'ntc/Calgorithm/Clabels/Norigttl/Nsigexp/Nsigincep/nkeytag',
$this->rdata
);
$this->typecovered = Net_DNS2_Lookups::$rr_types_by_id[$x['tc']];
$this->algorithm = $x['algorithm'];
$this->labels = $x['labels'];
$this->origttl = Net_DNS2::expandUint32($x['origttl']);
//
// the dates are in GM time
//
$this->sigexp = gmdate('YmdHis', $x['sigexp']);
$this->sigincep = gmdate('YmdHis', $x['sigincep']);
//
// get the keytag
//
$this->keytag = $x['keytag'];
//
// get teh signers name and signature
//
$offset = $packet->offset + 18;
$sigoffset = $offset;
$this->signname = strtolower(
Net_DNS2_Packet::expand($packet, $sigoffset)
);
$this->signature = base64_encode(
substr($this->rdata, 18 + ($sigoffset - $offset))
);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
//
// parse the values out of the dates
//
preg_match(
'/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $this->sigexp, $e
);
preg_match(
'/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $this->sigincep, $i
);
//
// pack the value
//
$data = pack(
'nCCNNNn',
Net_DNS2_Lookups::$rr_types_by_name[$this->typecovered],
$this->algorithm,
$this->labels,
$this->origttl,
gmmktime($e[4], $e[5], $e[6], $e[2], $e[3], $e[1]),
gmmktime($i[4], $i[5], $i[6], $i[2], $i[3], $i[1]),
$this->keytag
);
//
// the signer name is special; it's not allowed to be compressed
// (see section 3.1.7)
//
$names = explode('.', strtolower($this->signname));
foreach ($names as $name) {
$data .= chr(strlen($name));
$data .= $name;
}
$data .= chr('0');
//
// if the signature is empty, and $this->private_key is an instance of a
// private key object, and we have access to openssl, then assume this
// is a SIG(0), and generate a new signature
//
if ( (strlen($this->signature) == 0)
&& ($this->private_key instanceof Net_DNS2_PrivateKey)
&& (extension_loaded('openssl') === true)
) {
//
// create a new packet for the signature-
//
$new_packet = new Net_DNS2_Packet_Request('example.com', 'SOA', 'IN');
//
// copy the packet data over
//
$new_packet->copy($packet);
//
// remove the SIG object from the additional list
//
array_pop($new_packet->additional);
$new_packet->header->arcount = count($new_packet->additional);
//
// copy out the data
//
$sigdata = $data . $new_packet->get();
//
// based on the algorithm
//
$algorithm = 0;
switch($this->algorithm) {
//
// MD5
//
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSAMD5:
$algorithm = OPENSSL_ALGO_MD5;
break;
//
// SHA1
//
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA1:
$algorithm = OPENSSL_ALGO_SHA1;
break;
//
// SHA256 (PHP 5.4.8 or higher)
//
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA256:
if (version_compare(PHP_VERSION, '5.4.8', '<') == true) {
throw new Net_DNS2_Exception(
'SHA256 support is only available in PHP >= 5.4.8',
Net_DNS2_Lookups::E_OPENSSL_INV_ALGO
);
}
$algorithm = OPENSSL_ALGO_SHA256;
break;
//
// SHA512 (PHP 5.4.8 or higher)
//
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA512:
if (version_compare(PHP_VERSION, '5.4.8', '<') == true) {
throw new Net_DNS2_Exception(
'SHA512 support is only available in PHP >= 5.4.8',
Net_DNS2_Lookups::E_OPENSSL_INV_ALGO
);
}
$algorithm = OPENSSL_ALGO_SHA512;
break;
//
// unsupported at the moment
//
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_DSA:
case Net_DNS2_Lookups::DSNSEC_ALGORITHM_RSASHA1NSEC3SHA1:
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_DSANSEC3SHA1:
default:
throw new Net_DNS2_Exception(
'invalid or unsupported algorithm',
Net_DNS2_Lookups::E_OPENSSL_INV_ALGO
);
break;
}
//
// sign the data
//
if (openssl_sign($sigdata, $this->signature, $this->private_key->instance, $algorithm) == false) {
throw new Net_DNS2_Exception(
openssl_error_string(),
Net_DNS2_Lookups::E_OPENSSL_ERROR
);
}
//
// build the signature value based
//
switch($this->algorithm) {
//
// RSA- add it directly
//
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSAMD5:
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA1:
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA256:
case Net_DNS2_Lookups::DNSSEC_ALGORITHM_RSASHA512:
$this->signature = base64_encode($this->signature);
break;
}
}
//
// add the signature
//
$data .= base64_decode($this->signature);
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.4.2
*
*/
/**
* The SMIMEA RR is implemented exactly like the TLSA record, so
* for now we just extend the TLSA RR and use it.
*
*/
class Net_DNS2_RR_SMIMEA extends Net_DNS2_RR_TLSA
{
}

View File

@ -0,0 +1,192 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* SOA Resource Record - RFC1035 section 3.3.13
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / MNAME /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / RNAME /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | SERIAL |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | REFRESH |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | RETRY |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | EXPIRE |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | MINIMUM |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_SOA extends Net_DNS2_RR
{
/*
* The master DNS server
*/
public $mname;
/*
* mailbox of the responsible person
*/
public $rname;
/*
* serial number
*/
public $serial;
/*
* refresh time
*/
public $refresh;
/*
* retry interval
*/
public $retry;
/*
* expire time
*/
public $expire;
/*
* minimum TTL for any RR in this zone
*/
public $minimum;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cleanString($this->mname) . '. ' .
$this->cleanString($this->rname) . '. ' .
$this->serial . ' ' . $this->refresh . ' ' . $this->retry . ' ' .
$this->expire . ' ' . $this->minimum;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->mname = $this->cleanString($rdata[0]);
$this->rname = $this->cleanString($rdata[1]);
$this->serial = $rdata[2];
$this->refresh = $rdata[3];
$this->retry = $rdata[4];
$this->expire = $rdata[5];
$this->minimum = $rdata[6];
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// parse the
//
$offset = $packet->offset;
$this->mname = Net_DNS2_Packet::expand($packet, $offset);
$this->rname = Net_DNS2_Packet::expand($packet, $offset, true);
//
// get the SOA values
//
$x = unpack(
'@' . $offset . '/Nserial/Nrefresh/Nretry/Nexpire/Nminimum/',
$packet->rdata
);
$this->serial = Net_DNS2::expandUint32($x['serial']);
$this->refresh = Net_DNS2::expandUint32($x['refresh']);
$this->retry = Net_DNS2::expandUint32($x['retry']);
$this->expire = Net_DNS2::expandUint32($x['expire']);
$this->minimum = Net_DNS2::expandUint32($x['minimum']);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->mname) > 0) {
$data = $packet->compress($this->mname, $packet->offset);
$data .= $packet->compress($this->rname, $packet->offset);
$data .= pack(
'N5', $this->serial, $this->refresh, $this->retry,
$this->expire, $this->minimum
);
$packet->offset += 20;
return $data;
}
return null;
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* The SPF RR is implemented exactly like the TXT record, so
* for now we just extend the TXT RR and use it.
*
*/
class Net_DNS2_RR_SPF extends Net_DNS2_RR_TXT
{
}

View File

@ -0,0 +1,145 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* SRV Resource Record - RFC2782
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PRIORITY |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | WEIGHT |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PORT |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / TARGET /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_SRV extends Net_DNS2_RR
{
/*
* The priority of this target host.
*/
public $priority;
/*
* a relative weight for entries with the same priority
*/
public $weight;
/*
* The port on this target host of this service.
*/
public $port;
/*
* The domain name of the target host
*/
public $target;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->priority . ' ' . $this->weight . ' ' .
$this->port . ' ' . $this->cleanString($this->target) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->priority = $rdata[0];
$this->weight = $rdata[1];
$this->port = $rdata[2];
$this->target = $this->cleanString($rdata[3]);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the priority, weight and port
//
$x = unpack('npriority/nweight/nport', $this->rdata);
$this->priority = $x['priority'];
$this->weight = $x['weight'];
$this->port = $x['port'];
$offset = $packet->offset + 6;
$this->target = Net_DNS2_Packet::expand($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->target) > 0) {
$data = pack('nnn', $this->priority, $this->weight, $this->port);
$packet->offset += 6;
$data .= $packet->compress($this->target, $packet->offset);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,205 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* SSHFP Resource Record - RFC4255 section 3.1
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | algorithm | fp type | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
* / /
* / fingerprint /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_SSHFP extends Net_DNS2_RR
{
/*
* the algorithm used
*/
public $algorithm;
/*
* The finger print type
*/
public $fp_type;
/*
* the finger print data
*/
public $fingerprint;
/*
* Algorithms
*/
const SSHFP_ALGORITHM_RES = 0;
const SSHFP_ALGORITHM_RSA = 1;
const SSHFP_ALGORITHM_DSS = 2;
const SSHFP_ALGORITHM_ECDSA = 3;
const SSHFP_ALGORITHM_ED25519 = 4;
/*
* Fingerprint Types
*/
const SSHFP_FPTYPE_RES = 0;
const SSHFP_FPTYPE_SHA1 = 1;
const SSHFP_FPTYPE_SHA256 = 2;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->algorithm . ' ' . $this->fp_type . ' ' . $this->fingerprint;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// "The use of mnemonics instead of numbers is not allowed."
//
// RFC4255 section 3.2
//
$algorithm = array_shift($rdata);
$fp_type = array_shift($rdata);
$fingerprint = strtolower(implode('', $rdata));
//
// There are only two algorithm's defined
//
if ( ($algorithm != self::SSHFP_ALGORITHM_RSA)
&& ($algorithm != self::SSHFP_ALGORITHM_DSS)
&& ($algorithm != self::SSHFP_ALGORITHM_ECDSA)
&& ($algorithm != self::SSHFP_ALGORITHM_ED25519)
) {
return false;
}
//
// there are only two fingerprints defined
//
if ( ($fp_type != self::SSHFP_FPTYPE_SHA1)
&& ($fp_type != self::SSHFP_FPTYPE_SHA256)
) {
return false;
}
$this->algorithm = $algorithm;
$this->fp_type = $fp_type;
$this->fingerprint = $fingerprint;
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the algorithm and finger print type
//
$x = unpack('Calgorithm/Cfp_type', $this->rdata);
$this->algorithm = $x['algorithm'];
$this->fp_type = $x['fp_type'];
//
// There are only three algorithm's defined
//
if ( ($this->algorithm != self::SSHFP_ALGORITHM_RSA)
&& ($this->algorithm != self::SSHFP_ALGORITHM_DSS)
&& ($this->algorithm != self::SSHFP_ALGORITHM_ECDSA)
&& ($this->algorithm != self::SSHFP_ALGORITHM_ED25519)
) {
return false;
}
//
// there are only two fingerprints defined
//
if ( ($this->fp_type != self::SSHFP_FPTYPE_SHA1)
&& ($this->fp_type != self::SSHFP_FPTYPE_SHA256)
) {
return false;
}
//
// parse the finger print; this assumes SHA-1
//
$fp = unpack('H*a', substr($this->rdata, 2));
$this->fingerprint = strtolower($fp['a']);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->fingerprint) > 0) {
$data = pack(
'CCH*', $this->algorithm, $this->fp_type, $this->fingerprint
);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.2.0
*
*/
/**
* The TA RR is implemented exactly like the DS record, so
* for now we just extend the DS RR and use it.
*
*/
class Net_DNS2_RR_TA extends Net_DNS2_RR_DS
{
}

View File

@ -0,0 +1,121 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.2.0
*
*/
/**
* TALINK Resource Record - DNSSEC Trust Anchor
*
* http://tools.ietf.org/id/draft-ietf-dnsop-dnssec-trust-history-00.txt
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / PREVIOUS /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / NEXT /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_TALINK extends Net_DNS2_RR
{
/*
* the previous domain name
*/
public $previous;
/*
* the next domain name
*/
public $next;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cleanString($this->previous) . '. ' .
$this->cleanString($this->next) . '.';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->previous = $this->cleanString($rdata[0]);
$this->next = $this->cleanString($rdata[1]);
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$offset = $packet->offset;
$this->previous = Net_DNS2_Packet::label($packet, $offset);
$this->next = Net_DNS2_Packet::label($packet, $offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if ( (strlen($this->previous) > 0) || (strlen($this->next) > 0) ) {
$data = chr(strlen($this->previous)) . $this->previous .
chr(strlen($this->next)) . $this->next;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,259 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* TKEY Resource Record - RFC 2930 section 2
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / ALGORITHM /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | INCEPTION |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | EXPIRATION |
* | |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | MODE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ERROR |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | KEY SIZE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / KEY DATA /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | OTHER SIZE |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / OTHER DATA /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_TKEY extends Net_DNS2_RR
{
public $algorithm;
public $inception;
public $expiration;
public $mode;
public $error;
public $key_size;
public $key_data;
public $other_size;
public $other_data;
/*
* TSIG Modes
*/
const TSIG_MODE_RES = 0;
const TSIG_MODE_SERV_ASSIGN = 1;
const TSIG_MODE_DH = 2;
const TSIG_MODE_GSS_API = 3;
const TSIG_MODE_RESV_ASSIGN = 4;
const TSIG_MODE_KEY_DELE = 5;
/*
* map the mod id's to names so we can validate
*/
public $tsgi_mode_id_to_name = [
self::TSIG_MODE_RES => 'Reserved',
self::TSIG_MODE_SERV_ASSIGN => 'Server Assignment',
self::TSIG_MODE_DH => 'Diffie-Hellman',
self::TSIG_MODE_GSS_API => 'GSS-API',
self::TSIG_MODE_RESV_ASSIGN => 'Resolver Assignment',
self::TSIG_MODE_KEY_DELE => 'Key Deletion'
];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->cleanString($this->algorithm) . '. ' . $this->mode;
if ($this->key_size > 0) {
$out .= ' ' . trim($this->key_data, '.') . '.';
} else {
$out .= ' .';
}
return $out;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// data passed in is assumed: <algorithm> <mode> <key>
//
$this->algorithm = $this->cleanString(array_shift($rdata));
$this->mode = array_shift($rdata);
$this->key_data = trim(array_shift($rdata), '.');
//
// the rest of the data is set manually
//
$this->inception = time();
$this->expiration = time() + 86400; // 1 day
$this->error = 0;
$this->key_size = strlen($this->key_data);
$this->other_size = 0;
$this->other_data = '';
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// expand the algorithm
//
$offset = $packet->offset;
$this->algorithm = Net_DNS2_Packet::expand($packet, $offset);
//
// unpack inception, expiration, mode, error and key size
//
$x = unpack(
'@' . $offset . '/Ninception/Nexpiration/nmode/nerror/nkey_size',
$packet->rdata
);
$this->inception = Net_DNS2::expandUint32($x['inception']);
$this->expiration = Net_DNS2::expandUint32($x['expiration']);
$this->mode = $x['mode'];
$this->error = $x['error'];
$this->key_size = $x['key_size'];
$offset += 14;
//
// if key_size > 0, then copy out the key
//
if ($this->key_size > 0) {
$this->key_data = substr($packet->rdata, $offset, $this->key_size);
$offset += $this->key_size;
}
//
// unpack the other length
//
$x = unpack('@' . $offset . '/nother_size', $packet->rdata);
$this->other_size = $x['other_size'];
$offset += 2;
//
// if other_size > 0, then copy out the data
//
if ($this->other_size > 0) {
$this->other_data = substr(
$packet->rdata, $offset, $this->other_size
);
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->algorithm) > 0) {
//
// make sure the size values are correct
//
$this->key_size = strlen($this->key_data);
$this->other_size = strlen($this->other_data);
//
// add the algorithm without compression
//
$data = Net_DNS2_Packet::pack($this->algorithm);
//
// pack in the inception, expiration, mode, error and key size
//
$data .= pack(
'NNnnn', $this->inception, $this->expiration,
$this->mode, 0, $this->key_size
);
//
// if the key_size > 0, then add the key
//
if ($this->key_size > 0) {
$data .= $this->key_data;
}
//
// pack in the other size
//
$data .= pack('n', $this->other_size);
if ($this->other_size > 0) {
$data .= $this->other_data;
}
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,146 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.2.5
*
*/
/**
* TLSA Resource Record - RFC 6698
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Cert. Usage | Selector | Matching Type | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
* / /
* / Certificate Association Data /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_TLSA extends Net_DNS2_RR
{
/*
* The Certificate Usage Field
*/
public $cert_usage;
/*
* The Selector Field
*/
public $selector;
/*
* The Matching Type Field
*/
public $matching_type;
/*
* The Certificate Association Data Field
*/
public $certificate;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->cert_usage . ' ' . $this->selector . ' ' .
$this->matching_type . ' ' . base64_encode($this->certificate);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->cert_usage = array_shift($rdata);
$this->selector = array_shift($rdata);
$this->matching_type = array_shift($rdata);
$this->certificate = base64_decode(implode('', $rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the format, keytag and algorithm
//
$x = unpack('Cusage/Cselector/Ctype', $this->rdata);
$this->cert_usage = $x['usage'];
$this->selector = $x['selector'];
$this->matching_type = $x['type'];
//
// copy the certificate
//
$this->certificate = substr($this->rdata, 3, $this->rdlength - 3);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->certificate) > 0) {
$data = pack(
'CCC', $this->cert_usage, $this->selector, $this->matching_type
) . $this->certificate;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,456 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* TSIG Resource Record - RFC 2845
*
* 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / algorithm /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | time signed |
* | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | | fudge |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | mac size | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
* / mac /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | original id | error |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | other length | /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
* / other data /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_TSIG extends Net_DNS2_RR
{
/*
* TSIG Algorithm Identifiers
*/
const HMAC_MD5 = 'hmac-md5.sig-alg.reg.int'; // RFC 2845, required
const GSS_TSIG = 'gss-tsig'; // unsupported, optional
const HMAC_SHA1 = 'hmac-sha1'; // RFC 4635, required
const HMAC_SHA224 = 'hmac-sha224'; // RFC 4635, optional
const HMAC_SHA256 = 'hmac-sha256'; // RFC 4635, required
const HMAC_SHA384 = 'hmac-sha384'; // RFC 4635, optional
const HMAC_SHA512 = 'hmac-sha512'; // RFC 4635, optional
/*
* the map of hash values to names
*/
public static $hash_algorithms = [
self::HMAC_MD5 => 'md5',
self::HMAC_SHA1 => 'sha1',
self::HMAC_SHA224 => 'sha224',
self::HMAC_SHA256 => 'sha256',
self::HMAC_SHA384 => 'sha384',
self::HMAC_SHA512 => 'sha512'
];
/*
* algorithm used; only supports HMAC-MD5
*/
public $algorithm;
/*
* The time it was signed
*/
public $time_signed;
/*
* fudge- allowed offset from the time signed
*/
public $fudge;
/*
* size of the digest
*/
public $mac_size;
/*
* the digest data
*/
public $mac;
/*
* the original id of the request
*/
public $original_id;
/*
* additional error code
*/
public $error;
/*
* length of the "other" data, should only ever be 0 when there is
* no error, or 6 when there is the error RCODE_BADTIME
*/
public $other_length;
/*
* the other data; should only ever be a timestamp when there is the
* error RCODE_BADTIME
*/
public $other_data;
/*
* the key to use for signing - passed in, not included in the rdata
*/
public $key;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$out = $this->cleanString($this->algorithm) . '. ' .
$this->time_signed . ' ' .
$this->fudge . ' ' . $this->mac_size . ' ' .
base64_encode($this->mac) . ' ' . $this->original_id . ' ' .
$this->error . ' '. $this->other_length;
if ($this->other_length > 0) {
$out .= ' ' . $this->other_data;
}
return $out;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
//
// the only value passed in is the key-
//
// this assumes it's passed in base64 encoded.
//
$this->key = preg_replace('/\s+/', '', array_shift($rdata));
//
// the rest of the data is set to default
//
$this->algorithm = self::HMAC_MD5;
$this->time_signed = time();
$this->fudge = 300;
$this->mac_size = 0;
$this->mac = '';
$this->original_id = 0;
$this->error = 0;
$this->other_length = 0;
$this->other_data = '';
//
// per RFC 2845 section 2.3
//
$this->class = 'ANY';
$this->ttl = 0;
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// expand the algorithm
//
$newoffset = $packet->offset;
$this->algorithm = Net_DNS2_Packet::expand($packet, $newoffset);
$offset = $newoffset - $packet->offset;
//
// unpack time, fudge and mac_size
//
$x = unpack(
'@' . $offset . '/ntime_high/Ntime_low/nfudge/nmac_size',
$this->rdata
);
$this->time_signed = Net_DNS2::expandUint32($x['time_low']);
$this->fudge = $x['fudge'];
$this->mac_size = $x['mac_size'];
$offset += 10;
//
// copy out the mac
//
if ($this->mac_size > 0) {
$this->mac = substr($this->rdata, $offset, $this->mac_size);
$offset += $this->mac_size;
}
//
// unpack the original id, error, and other_length values
//
$x = unpack(
'@' . $offset . '/noriginal_id/nerror/nother_length',
$this->rdata
);
$this->original_id = $x['original_id'];
$this->error = $x['error'];
$this->other_length = $x['other_length'];
//
// the only time there is actually any "other data", is when there's
// a BADTIME error code.
//
// The other length should be 6, and the other data field includes the
// servers current time - per RFC 2845 section 4.5.2
//
if ($this->error == Net_DNS2_Lookups::RCODE_BADTIME) {
if ($this->other_length != 6) {
return false;
}
//
// other data is a 48bit timestamp
//
$x = unpack(
'nhigh/nlow',
substr($this->rdata, $offset + 6, $this->other_length)
);
$this->other_data = $x['low'];
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->key) > 0) {
//
// create a new packet for the signature-
//
$new_packet = new Net_DNS2_Packet_Request('example.com', 'SOA', 'IN');
//
// copy the packet data over
//
$new_packet->copy($packet);
//
// remove the TSIG object from the additional list
//
array_pop($new_packet->additional);
$new_packet->header->arcount = count($new_packet->additional);
//
// copy out the data
//
$sig_data = $new_packet->get();
//
// add the name without compressing
//
$sig_data .= Net_DNS2_Packet::pack($this->name);
//
// add the class and TTL
//
$sig_data .= pack(
'nN', Net_DNS2_Lookups::$classes_by_name[$this->class], $this->ttl
);
//
// add the algorithm name without compression
//
$sig_data .= Net_DNS2_Packet::pack(strtolower($this->algorithm));
//
// add the rest of the values
//
$sig_data .= pack(
'nNnnn', 0, $this->time_signed, $this->fudge,
$this->error, $this->other_length
);
if ($this->other_length > 0) {
$sig_data .= pack('nN', 0, $this->other_data);
}
//
// sign the data
//
$this->mac = $this->_signHMAC(
$sig_data, base64_decode($this->key), $this->algorithm
);
$this->mac_size = strlen($this->mac);
//
// compress the algorithm
//
$data = Net_DNS2_Packet::pack(strtolower($this->algorithm));
//
// pack the time, fudge and mac size
//
$data .= pack(
'nNnn', 0, $this->time_signed, $this->fudge, $this->mac_size
);
$data .= $this->mac;
//
// check the error and other_length
//
if ($this->error == Net_DNS2_Lookups::RCODE_BADTIME) {
$this->other_length = strlen($this->other_data);
if ($this->other_length != 6) {
return null;
}
} else {
$this->other_length = 0;
$this->other_data = '';
}
//
// pack the id, error and other_length
//
$data .= pack(
'nnn', $packet->header->id, $this->error, $this->other_length
);
if ($this->other_length > 0) {
$data .= pack('nN', 0, $this->other_data);
}
$packet->offset += strlen($data);
return $data;
}
return null;
}
/**
* signs the given data with the given key, and returns the result
*
* @param string $data the data to sign
* @param string $key key to use for signing
* @param string $algorithm the algorithm to use; defaults to MD5
*
* @return string the signed digest
* @throws Net_DNS2_Exception
* @access private
*
*/
private function _signHMAC($data, $key = null, $algorithm = self::HMAC_MD5)
{
//
// use the hash extension; this is included by default in >= 5.1.2 which
// is our dependent version anyway- so it's easy to switch to it.
//
if (extension_loaded('hash')) {
if (!isset(self::$hash_algorithms[$algorithm])) {
throw new Net_DNS2_Exception(
'invalid or unsupported algorithm',
Net_DNS2_Lookups::E_PARSE_ERROR
);
}
return hash_hmac(self::$hash_algorithms[$algorithm], $data, $key, true);
}
//
// if the hash extension isn't loaded, and they selected something other
// than MD5, throw an exception
//
if ($algorithm != self::HMAC_MD5) {
throw new Net_DNS2_Exception(
'only HMAC-MD5 supported. please install the php-extension ' .
'"hash" in order to use the sha-family',
Net_DNS2_Lookups::E_PARSE_ERROR
);
}
//
// otherwise, do it ourselves
//
if (is_null($key)) {
return pack('H*', md5($data));
}
$key = str_pad($key, 64, chr(0x00));
if (strlen($key) > 64) {
$key = pack('H*', md5($key));
}
$k_ipad = $key ^ str_repeat(chr(0x36), 64);
$k_opad = $key ^ str_repeat(chr(0x5c), 64);
return $this->_signHMAC(
$k_opad . pack('H*', md5($k_ipad . $data)), null, $algorithm
);
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* TXT Resource Record - RFC1035 section 3.3.14
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / TXT-DATA /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_TXT extends Net_DNS2_RR
{
/*
* an array of the text strings
*/
public $text = [];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
if (count($this->text) == 0) {
return '""';
}
$data = '';
foreach ($this->text as $t) {
$data .= $this->formatString($t) . ' ';
}
return trim($data);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$data = $this->buildString($rdata);
if (count($data) > 0) {
$this->text = $data;
}
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$length = $packet->offset + $this->rdlength;
$offset = $packet->offset;
while ($length > $offset) {
$this->text[] = Net_DNS2_Packet::label($packet, $offset);
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
$data = null;
foreach ($this->text as $t) {
$data .= chr(strlen($t)) . $t;
}
$packet->offset += strlen($data);
return $data;
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.2.5
*
*/
/**
* TYPE65534 - Private space
*
* Since Bind 9.8 beta, it use a private recode as documented
* in the Bind ARM, chapter 4, "Private-type records.
* Basically they store signing process state.
*
*/
class Net_DNS2_RR_TYPE65534 extends Net_DNS2_RR
{
/*
* The Private data field
*/
public $private_data;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return base64_encode($this->private_data);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->private_data = base64_decode(implode('', $rdata));
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$this->private_data = $this->rdata;
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->private_data) > 0) {
$data = $this->private_data;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,135 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.2.0
*
*/
/**
* URI Resource Record - http://tools.ietf.org/html/draft-faltstrom-uri-06
*
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Priority | Weight |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* / /
* / Target /
* / /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
class Net_DNS2_RR_URI extends Net_DNS2_RR
{
/*
* The priority of this target host.
*/
public $priority;
/*
* a relative weight for entries with the same priority
*/
public $weight;
/*
* The domain name of the target host
*/
public $target;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
//
// presentation format has double quotes (") around the target.
//
return $this->priority . ' ' . $this->weight . ' "' . $this->target . '"';
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->priority = $rdata[0];
$this->weight = $rdata[1];
$this->target = trim(strtolower(trim($rdata[2])), '"');
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// unpack the priority and weight
//
$x = unpack('npriority/nweight/a*target', $this->rdata);
$this->priority = $x['priority'];
$this->weight = $x['weight'];
$this->target = $x['target'];
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->target) > 0) {
$data = pack('nna*', $this->priority, $this->weight, $this->target);
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,187 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.0.1
*
*/
/**
* WKS Resource Record - RFC1035 section 3.4.2
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | ADDRESS |
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* | PROTOCOL | |
* +--+--+--+--+--+--+--+--+ |
* | |
* / <BIT MAP> /
* / /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_WKS extends Net_DNS2_RR
{
/*
* The IP address of the service
*/
public $address;
/*
* The protocol of the service
*/
public $protocol;
/*
* bitmap
*/
public $bitmap = [];
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
$data = $this->address . ' ' . $this->protocol;
foreach ($this->bitmap as $port) {
$data .= ' ' . $port;
}
return $data;
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$this->address = strtolower(trim(array_shift($rdata), '.'));
$this->protocol = array_shift($rdata);
$this->bitmap = $rdata;
return true;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
//
// get the address and protocol value
//
$x = unpack('Naddress/Cprotocol', $this->rdata);
$this->address = long2ip($x['address']);
$this->protocol = $x['protocol'];
//
// unpack the port list bitmap
//
$port = 0;
foreach (unpack('@5/C*', $this->rdata) as $set) {
$s = sprintf('%08b', $set);
for ($i=0; $i<8; $i++, $port++) {
if ($s[$i] == '1') {
$this->bitmap[] = $port;
}
}
}
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->address) > 0) {
$data = pack('NC', ip2long($this->address), $this->protocol);
$ports = [];
$n = 0;
foreach ($this->bitmap as $port) {
$ports[$port] = 1;
if ($port > $n) {
$n = $port;
}
}
for ($i=0; $i<ceil($n/8)*8; $i++) {
if (!isset($ports[$i])) {
$ports[$i] = 0;
}
}
ksort($ports);
$string = '';
$n = 0;
foreach ($ports as $s) {
$string .= $s;
$n++;
if ($n == 8) {
$data .= chr(bindec($string));
$string = '';
$n = 0;
}
}
$packet->offset += strlen($data);
return $data;
}
return null;
}
}

View File

@ -0,0 +1,112 @@
<?php
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2020, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2020 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 0.6.0
*
*/
/**
* X25 Resource Record - RFC1183 section 3.1
*
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
* / PSDN-address /
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*
*/
class Net_DNS2_RR_X25 extends Net_DNS2_RR
{
/*
* The PSDN address
*/
public $psdnaddress;
/**
* method to return the rdata portion of the packet as a string
*
* @return string
* @access protected
*
*/
protected function rrToString()
{
return $this->formatString($this->psdnaddress);
}
/**
* parses the rdata portion from a standard DNS config line
*
* @param array $rdata a string split line of values for the rdata
*
* @return boolean
* @access protected
*
*/
protected function rrFromString(array $rdata)
{
$data = $this->buildString($rdata);
if (count($data) == 1) {
$this->psdnaddress = $data[0];
return true;
}
return false;
}
/**
* parses the rdata of the Net_DNS2_Packet object
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
*
* @return boolean
* @access protected
*
*/
protected function rrSet(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {
$this->psdnaddress = Net_DNS2_Packet::label($packet, $packet->offset);
return true;
}
return false;
}
/**
* returns the rdata portion of the DNS packet
*
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
* compressed names
*
* @return mixed either returns a binary packed
* string or null on failure
* @access protected
*
*/
protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->psdnaddress) > 0) {
$data = chr(strlen($this->psdnaddress)) . $this->psdnaddress;
$packet->offset += strlen($data);
return $data;
}
return null;
}
}