2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
5
* DNS Library for handling lookups and updates.
9
* Copyright (c) 2010, Mike Pultz <mike@mikepultz.com>.
10
* All rights reserved.
12
* Redistribution and use in source and binary forms, with or without
13
* modification, are permitted provided that the following conditions
16
* * Redistributions of source code must retain the above copyright
17
* notice, this list of conditions and the following disclaimer.
19
* * Redistributions in binary form must reproduce the above copyright
20
* notice, this list of conditions and the following disclaimer in
21
* the documentation and/or other materials provided with the
24
* * Neither the name of Mike Pultz nor the names of his contributors
25
* may be used to endorse or promote products derived from this
26
* software without specific prior written permission.
28
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
37
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39
* POSSIBILITY OF SUCH DAMAGE.
41
* @category Networking
43
* @author Mike Pultz <mike@mikepultz.com>
44
* @copyright 2010 Mike Pultz <mike@mikepultz.com>
45
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
46
* @version SVN: $Id: NSEC3.php 179 2012-11-23 05:49:01Z mike.pultz $
47
* @link http://pear.php.net/package/Net_DNS2
48
* @since File available since Release 0.6.0
53
* NSEC3 Resource Record - RFC5155 section 3.2
55
* 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
56
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57
* | Hash Alg. | Flags | Iterations |
58
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59
* | Salt Length | Salt /
60
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61
* | Hash Length | Next Hashed Owner Name /
62
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66
* @category Networking
68
* @author Mike Pultz <mike@mikepultz.com>
69
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
70
* @link http://pear.php.net/package/Net_DNS2
74
class Net_DNS2_RR_NSEC3 extends Net_DNS2_RR
87
* defines the number of additional times the hash is performed.
92
* the length of the salt- not displayed
102
* the length of the hash value
107
* the hashed value of the owner name
109
public $hashed_owner_name;
112
* array of RR type names
114
public $type_bit_maps = array();
117
* method to return the rdata portion of the packet as a string
123
protected function rrToString()
125
$out = $this->algorithm . ' ' . $this->flags . ' ' . $this->iterations . ' ';
128
// per RFC5155, the salt_length value isn't displayed, and if the salt
129
// is empty, the salt is displayed as '-'
131
if ($this->salt_length > 0) {
140
// per RFC5255 the hash length isn't shown
142
$out .= ' ' . $this->hashed_owner_name;
147
foreach ($this->type_bit_maps as $rr) {
149
$out .= ' ' . strtoupper($rr);
156
* parses the rdata portion from a standard DNS config line
158
* @param array $rdata a string split line of values for the rdata
164
protected function rrFromString(array $rdata)
166
$this->algorithm = array_shift($rdata);
167
$this->flags = array_shift($rdata);
168
$this->iterations = array_shift($rdata);
171
// an empty salt is represented as '-' per RFC5155 section 3.3
173
$salt = array_shift($rdata);
176
$this->salt_length = 0;
180
$this->salt_length = strlen(pack('H*', $salt));
181
$this->salt = strtoupper($salt);
184
$this->hashed_owner_name = array_shift($rdata);
185
$this->hash_length = strlen(base64_decode($this->hashed_owner_name));
187
$this->type_bit_maps = $rdata;
193
* parses the rdata of the Net_DNS2_Packet object
195
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from
201
protected function rrSet(Net_DNS2_Packet &$packet)
203
if ($this->rdlength > 0) {
206
// unpack the first values
208
$x = unpack('Calgorithm/Cflags/niterations/Csalt_length', $this->rdata);
210
$this->algorithm = $x['algorithm'];
211
$this->flags = $x['flags'];
212
$this->iterations = $x['iterations'];
213
$this->salt_length = $x['salt_length'];
217
if ($this->salt_length > 0) {
219
$x = unpack('H*', substr($this->rdata, $offset, $this->salt_length));
220
$this->salt = strtoupper($x[1]);
221
$offset += $this->salt_length;
225
// unpack the hash length
227
$x = unpack('@' . $offset . '/Chash_length', $this->rdata);
233
$this->hash_length = $x['hash_length'];
234
if ($this->hash_length > 0) {
236
$this->hashed_owner_name = base64_encode(
237
substr($this->rdata, $offset, $this->hash_length)
239
$offset += $this->hash_length;
243
// parse out the RR bitmap
245
$this->type_bit_maps = Net_DNS2_BitMap::bitMapToArray(
246
substr($this->rdata, $offset)
256
* returns the rdata portion of the DNS packet
258
* @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for
261
* @return mixed either returns a binary packed
262
* string or null on failure
266
protected function rrGet(Net_DNS2_Packet &$packet)
269
// pull the salt and build the length
271
$salt = pack('H*', $this->salt);
272
$this->salt_length = strlen($salt);
275
// pack the algorithm, flags, iterations and salt length
279
$this->algorithm, $this->flags, $this->iterations, $this->salt_length
284
// add the hash length and hash
286
$data .= chr($this->hash_length);
287
if ($this->hash_length > 0) {
289
$data .= base64_decode($this->hashed_owner_name);
293
// conver the array of RR names to a type bitmap
295
$data .= Net_DNS2_BitMap::arrayToBitMap($this->type_bit_maps);
297
$packet->offset += strlen($data);
307
* c-hanging-comment-ender-p: nil