Example #1
0
    /**
     * 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;
    }
Example #2
0
 /**
  * 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;
 }