Net_DNS
[ class tree: Net_DNS ] [ index: Net_DNS ] [ all elements ]

Source for file TSIG.php

Documentation is available at TSIG.php

  1. <?php
  2. /*
  3.  *  License Information:
  4.  *
  5.  *    Net_DNS:  A resolver library for PHP
  6.  *    Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net
  7.  *
  8.  *    This library is free software; you can redistribute it and/or
  9.  *    modify it under the terms of the GNU Lesser General Public
  10.  *    License as published by the Free Software Foundation; either
  11.  *    version 2.1 of the License, or (at your option) any later version.
  12.  *
  13.  *    This library is distributed in the hope that it will be useful,
  14.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  *    Lesser General Public License for more details.
  17.  *
  18.  *    You should have received a copy of the GNU Lesser General Public
  19.  *    License along with this library; if not, write to the Free Software
  20.  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  */
  22.  
  23. define('NET_DNS_DEFAULT_ALGORITHM''hmac-md5.sig-alg.reg.int');
  24. define('NET_DNS_DEFAULT_FUDGE'300);
  25.  
  26. /* Net_DNS_RR_TSIG definition {{{ */
  27. /**
  28.  * A representation of a resource record of type <b>TSIG</b>
  29.  *
  30.  * @package Net_DNS
  31.  */
  32. class Net_DNS_RR_TSIG extends Net_DNS_RR
  33. {
  34.     /* class variable definitions {{{ */
  35.     var $name;
  36.     var $type;
  37.     var $class;
  38.     var $ttl;
  39.     var $rdlength;
  40.     var $rdata;
  41.     var $time_signed;
  42.     var $fudge;
  43.     var $mac_size;
  44.     var $mac;
  45.     var $original_id;
  46.     var $error;
  47.     var $other_len;
  48.     var $other_data;
  49.     var $key;
  50.  
  51.     /* }}} */
  52.     /* class constructor - RR(&$rro, $data, $offset = '') {{{ */
  53.     function Net_DNS_RR_TSIG(&$rro$data$offset '')
  54.     {
  55.         $this->name = $rro->name;
  56.         $this->type = $rro->type;
  57.         $this->class = $rro->class;
  58.         $this->ttl = $rro->ttl;
  59.         $this->rdlength = $rro->rdlength;
  60.         $this->rdata = $rro->rdata;
  61.  
  62.         if ($offset{
  63.             if ($this->rdlength > 0{
  64.                 list($alg$offsetNet_DNS_Packet::dn_expand($data$offset);
  65.                 $this->algorithm $alg;
  66.  
  67.                 $d unpack("\@$offset/nth/Ntl/nfudge/nmac_size"$data);
  68.                 $time_high $d['th'];
  69.                 $time_low $d['tl'];
  70.                 $this->time_signed = $time_low;
  71.                 $this->fudge = $d['fudge'];
  72.                 $this->mac_size = $d['mac_size'];
  73.                 $offset += 10;
  74.  
  75.                 $this->mac = substr($data$offset$this->mac_size);
  76.                 $offset += $this->mac_size;
  77.  
  78.                 $d unpack("@$offset/noid/nerror/nolen"$data);
  79.                 $this->original_id = $d['oid'];
  80.                 $this->error = $d['error'];
  81.                 $this->other_len = $d['olen'];
  82.                 $offset += 6;
  83.  
  84.                 $odata substr($data$offset$this->other_len);
  85.                 $d unpack('nodata_high/Nodata_low'$odata);
  86.                 $this->other_data = $d['odata_low'];
  87.             }
  88.         else {
  89.             if (strlen($data&& preg_match('/^(.*)$/'$data$regs)) {
  90.                 $this->key = $regs[1];
  91.             }
  92.  
  93.             $this->algorithm   NET_DNS_DEFAULT_ALGORITHM;
  94.             $this->time_signed = time();
  95.  
  96.             $this->fudge       = NET_DNS_DEFAULT_FUDGE;
  97.             $this->mac_size    = 0;
  98.             $this->mac         = '';
  99.             $this->original_id = 0;
  100.             $this->error       = 0;
  101.             $this->other_len   = 0;
  102.             $this->other_data  = '';
  103.  
  104.             // RFC 2845 Section 2.3
  105.             $this->class = 'ANY';
  106.         }
  107.     }
  108.  
  109.     /* }}} */
  110.     /* Net_DNS_RR_TSIG::rdatastr() {{{ */
  111.     function rdatastr()
  112.     {
  113.         $error $this->error;
  114.         if ($error{
  115.             $error 'UNDEFINED';
  116.         }
  117.  
  118.         if (strlen($this->algorithm)) {
  119.             $rdatastr $this->algorithm '. ' $this->time_signed . ' ' .
  120.                 $this->fudge . ' ';
  121.             if ($this->mac_size && strlen($this->mac)) {
  122.                 $rdatastr .= ' ' $this->mac_size . ' ' base64_encode($this->mac);
  123.             else {
  124.                 $rdatastr .= ' 0 ';
  125.             }
  126.             $rdatastr .= ' ' $this->original_id . ' ' $error;
  127.             if ($this->other_len && strlen($this->other_data)) {
  128.                 $rdatastr .= ' ' $this->other_data;
  129.             else {
  130.                 $rdatastr .= ' 0 ';
  131.             }
  132.         else {
  133.             $rdatastr '; no data';
  134.         }
  135.  
  136.         return $rdatastr;
  137.     }
  138.  
  139.     /* }}} */
  140.     /* Net_DNS_RR_TSIG::rr_rdata($packet, $offset) {{{ */
  141.     function rr_rdata($packet$offset)
  142.     {
  143.         $rdata '';
  144.         $sigdata '';
  145.  
  146.         if (strlen($this->key)) {
  147.             $key $this->key;
  148.             $key ereg_replace(' '''$key);
  149.             $key base64_decode($key);
  150.  
  151.             $newpacket $packet;
  152.             $newoffset $offset;
  153.             array_pop($newpacket->additional);
  154.             $newpacket->header->arcount--;
  155.             $newpacket->compnames = array();
  156.  
  157.             /*
  158.              * Add the request MAC if present (used to validate responses).
  159.              */
  160.             if (isset($this->request_mac)) {
  161.                 $sigdata .= pack('H*'$this->request_mac);
  162.             }
  163.             $sigdata .= $newpacket->data();
  164.  
  165.             /*
  166.              * Don't compress the record (key) name.
  167.              */
  168.             $tmppacket = new Net_DNS_Packet;
  169.             $sigdata .= $tmppacket->dn_comp(strtolower($this->name)0);
  170.  
  171.             $sigdata .= pack('n'Net_DNS::classesbyname(strtoupper($this->class)));
  172.             $sigdata .= pack('N'$this->ttl);
  173.  
  174.             /*
  175.              * Don't compress the algorithm name.
  176.              */
  177.             $tmppacket->compnames = array();
  178.             $sigdata .= $tmppacket->dn_comp(strtolower($this->algorithm)0);
  179.  
  180.             $sigdata .= pack('nN'0$this->time_signed);
  181.             $sigdata .= pack('n'$this->fudge);
  182.             $sigdata .= pack('nn'$this->error$this->other_len);
  183.  
  184.             if (strlen($this->other_data)) {
  185.                 $sigdata .= pack('nN'0$this->other_data);
  186.             }
  187.  
  188.             $this->mac = mhash(MHASH_MD5$sigdata$key);
  189.             $this->mac_size = strlen($this->mac);
  190.  
  191.             /*
  192.              * Don't compress the algorithm name.
  193.              */
  194.             unset($tmppacket);
  195.             $tmppacket = new Net_DNS_Packet;
  196.             $rdata .= $tmppacket->dn_comp(strtolower($this->algorithm)0);
  197.  
  198.             $rdata .= pack('nN'0$this->time_signed);
  199.             $rdata .= pack('nn'$this->fudge$this->mac_size);
  200.             $rdata .= $this->mac;
  201.  
  202.             $rdata .= pack('nnn',$packet->header->id,
  203.                     $this->error,
  204.                     $this->other_len);
  205.  
  206.             if ($this->other_data{
  207.                 $rdata .= pack('nN'0$this->other_data);
  208.             }
  209.         }
  210.         return $rdata;
  211.     }
  212.     /* }}} */
  213.     /* Net_DNS_RR_TSIG::error() {{{ */
  214.     function error()
  215.     {
  216.         if ($this->error != 0{
  217.             $rcode Net_DNS::rcodesbyval($error);
  218.         }
  219.         return $rcode;
  220.     }
  221.  
  222.     /* }}} */
  223. }
  224. /* }}} */
  225. /* VIM settings {{{
  226.  * Local variables:
  227.  * tab-width: 4
  228.  * c-basic-offset: 4
  229.  * soft-stop-width: 4
  230.  * c indent on
  231.  * expandtab on
  232.  * End:
  233.  * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  234.  * vim<600: sw=4 ts=4
  235.  * }}} */
  236. ?>

Documentation generated on Mon, 11 Mar 2019 14:35:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.