Skip to content

Commit

Permalink
- finished support for the HIP RR
Browse files Browse the repository at this point in the history
- added a test for the HIP RR
- changed version to 1.0.0
  • Loading branch information
mike.pultz committed Oct 25, 2010
1 parent f95aa81 commit 1b3d96c
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Net/DNS2.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
*/
$GLOBALS['_Net_DNS2_Lookups'] = new Net_DNS2_Lookups();


/**
* This is the base class for the Net_DNS2_Resolver and Net_DNS2_Updater
* classes.
Expand All @@ -79,7 +78,7 @@ class Net_DNS2
/*
* the current version of this library
*/
const VERSION = "0.6.0";
const VERSION = "1.0.0";

/*
* use TCP only (true/false)
Expand Down
132 changes: 132 additions & 0 deletions Net/DNS2/RR/HIP.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@
*/
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 = array();

/**
* method to return the rdata portion of the packet as a string
*
Expand All @@ -94,6 +124,15 @@ class Net_DNS2_RR_HIP extends Net_DNS2_RR
*/
protected function rrToString()
{
$out = $this->pk_algorithm . ' ' .
$this->hit . ' ' . $this->public_key . ' ';

foreach ($this->rendezvous_servers as $index => $server) {

$out .= $server . '. ';
}

return trim($out);
}

/**
Expand All @@ -107,6 +146,26 @@ protected function rrToString()
*/
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;
}

/**
Expand All @@ -120,6 +179,49 @@ protected function rrFromString(array $rdata)
*/
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;
}

/**
Expand All @@ -135,6 +237,36 @@ protected function rrSet(Net_DNS2_Packet &$packet)
*/
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 each rendezvous server
//
foreach ($this->rendezvous_servers as $index => $server) {

$data .= $packet->compress($server, $packet->offset + strlen($data));
}

return $data;
}

return null;
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/Net_DNS2_ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function testParser()
'DHCID' => 'example.com. 300 IN DHCID AAIBY2/AuCccgoJbsaxcQc9TUapptP69lOjxfNuVAA2kjEA=',
'NSEC3' => 'example.com. 300 IN NSEC3 1 1 12 AABBCCDD b4um86eghhds6nea196smvmlo4ors995 NS DS RRSIG',
'NSEC3PARAM' => 'example.com. 300 IN NSEC3PARAM 1 0 1 D399EAAB',
'HIP' => 'example.com. 300 IN HIP 2 200100107B1A74DF365639CC39F1D578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs.example.com. another.example.com. test.domain.org.',
'SPF' => 'example.com. 300 IN SPF "v=spf1 ip4:192.168.0.1/24 mx ?all"',
'TKEY' => 'example.com. 300 IN TKEY gss.microsoft.com. 3 123456.',
'DLV' => 'example.com. 300 IN DLV 21366 7 2 96eeb2ffd9b00cd4694e78278b5efdab0a80446567b69f634da078f0d90f01ba',
Expand Down

0 comments on commit 1b3d96c

Please sign in to comment.