Example #1
0
    /**
     * 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;
    }
Example #2
0
    /**
     * 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;
    }
Example #3
0
 /**
  * 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 = $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;
 }
Example #4
0
 /**
  * expands the domain name stored at a given offset in a DNS Packet
  *
  * This logic was based on the Net::DNS::Packet::dn_expand() function
  * by Michanel Fuhr
  *
  * @param Net_DNS2_Packet &$packet the DNS packet to look in for the domain name
  * @param integer         &$offset the offset into the given packet object
  *
  * @return mixed either the domain name or null if it's not found.
  * @access public
  *
  */
 public static function expand(Net_DNS2_Packet &$packet, &$offset)
 {
     $name = '';
     while (1) {
         if ($packet->rdlength < $offset + 1) {
             return null;
         }
         $xlen = ord($packet->rdata[$offset]);
         if ($xlen == 0) {
             ++$offset;
             break;
         } else {
             if (($xlen & 0xc0) == 0xc0) {
                 if ($packet->rdlength < $offset + 2) {
                     return null;
                 }
                 $ptr = ord($packet->rdata[$offset]) << 8 | ord($packet->rdata[$offset + 1]);
                 $ptr = $ptr & 0x3fff;
                 $name2 = Net_DNS2_Packet::expand($packet, $ptr);
                 if (is_null($name2)) {
                     return null;
                 }
                 $name .= $name2;
                 $offset += 2;
                 break;
             } else {
                 ++$offset;
                 if ($packet->rdlength < $offset + $xlen) {
                     return null;
                 }
                 $elem = '';
                 $elem = substr($packet->rdata, $offset, $xlen);
                 $name .= $elem . '.';
                 $offset += $xlen;
             }
         }
     }
     return trim($name, '.');
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
    /**
     * 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;
    }
Example #7
0
 /**
  * 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);
         //
         // 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;
 }
Example #8
0
 /**
  * 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', $this->rdata);
         $this->priority = $x['priority'];
         $this->weight = $x['weight'];
         $offset = $packet->offset + 4;
         $this->target = Net_DNS2_Packet::expand($packet, $offset);
         return true;
     }
     return false;
 }
Example #9
0
    /**
     * 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;
    }
Example #10
0
    /**
     * 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);
            $this->txtdname     = Net_DNS2_Packet::expand($packet, $offset);

            return true;
        }

        return false;
    }
Example #11
0
 /**
  * builds a new Net_DNS2_Header object from a Net_DNS2_Packet object
  *
  * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet object
  *
  * @return boolean
  * @throws Net_DNS2_Exception
  * @access public
  *
  */
 public function set(Net_DNS2_Packet &$packet)
 {
     //
     // expand the name
     //
     $this->qname = $packet->expand($packet, $packet->offset);
     if ($packet->rdlength < $packet->offset + 4) {
         throw new Net_DNS2_Exception('invalid question section: to small', Net_DNS2_Lookups::E_QUESTION_INVALID);
     }
     //
     // unpack the type and class
     //
     $type = ord($packet->rdata[$packet->offset++]) << 8 | ord($packet->rdata[$packet->offset++]);
     $class = ord($packet->rdata[$packet->offset++]) << 8 | ord($packet->rdata[$packet->offset++]);
     //
     // validate it
     //
     $type_name = Net_DNS2_Lookups::$rr_types_by_id[$type];
     $class_name = Net_DNS2_Lookups::$classes_by_id[$class];
     if (!isset($type_name) || !isset($class_name)) {
         throw new Net_DNS2_Exception('invalid question section: invalid type (' . $type . ') or class (' . $class . ') specified.', Net_DNS2_Lookups::E_QUESTION_INVALID);
     }
     //
     // store it
     //
     $this->qtype = $type_name;
     $this->qclass = $class_name;
     return true;
 }
Example #12
0
 /**
  * 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;
 }
Example #13
0
    /**
     * 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;
    }
Example #14
0
 /**
  * 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;
 }
Example #15
0
 /**
  * parses a binary packet, and returns the appropriate Net_DNS2_RR object,
  * based on the RR type of the binary content.
  *
  * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet used for
  *                                 decompressing names
  *
  * @return mixed                   returns a new Net_DNS2_RR_* object for
  *                                 the given RR
  * @throws Net_DNS2_Exception
  * @access public
  *
  */
 public static function parse(Net_DNS2_Packet &$packet)
 {
     $object = array();
     //
     // expand the name
     //
     $object['name'] = $packet->expand($packet, $packet->offset);
     if (is_null($object['name'])) {
         throw new Net_DNS2_Exception('failed to parse resource record: failed to expand name.', Net_DNS2_Lookups::E_PARSE_ERROR);
     }
     if ($packet->rdlength < $packet->offset + 10) {
         throw new Net_DNS2_Exception('failed to parse resource record: packet too small.', Net_DNS2_Lookups::E_PARSE_ERROR);
     }
     //
     // unpack the RR details
     //
     $object['type'] = ord($packet->rdata[$packet->offset++]) << 8 | ord($packet->rdata[$packet->offset++]);
     $object['class'] = ord($packet->rdata[$packet->offset++]) << 8 | ord($packet->rdata[$packet->offset++]);
     $object['ttl'] = ord($packet->rdata[$packet->offset++]) << 24 | ord($packet->rdata[$packet->offset++]) << 16 | ord($packet->rdata[$packet->offset++]) << 8 | ord($packet->rdata[$packet->offset++]);
     $object['rdlength'] = ord($packet->rdata[$packet->offset++]) << 8 | ord($packet->rdata[$packet->offset++]);
     if ($packet->rdlength < $packet->offset + $object['rdlength']) {
         return null;
     }
     //
     // lookup the class to use
     //
     $o = null;
     $class = Net_DNS2_Lookups::$rr_types_id_to_class[$object['type']];
     if (isset($class)) {
         $o = new $class($packet, $object);
         if ($o) {
             $packet->offset += $object['rdlength'];
         }
     } else {
         throw new Net_DNS2_Exception('un-implemented resource record type: ' . $object['type'], Net_DNS2_Lookups::E_RR_INVALID);
     }
     return $o;
 }
Example #16
0
 /**
  * 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;
 }