Skip to content

Commit

Permalink
- added the SHA256, SHA384, and GOST digest defines to Lookups.php.
Browse files Browse the repository at this point in the history
- fixed Net_DNS2_RR_DS so it will be able to support other digest definitions without any other changes.
  • Loading branch information
mikepultz committed Oct 8, 2020
1 parent a80d120 commit c5448f3
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 120 deletions.
8 changes: 7 additions & 1 deletion Net/DNS2/Lookups.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class Net_DNS2_Lookups
*/
const DNSSEC_DIGEST_RES = 0;
const DNSSEC_DIGEST_SHA1 = 1;
const DNSSEC_DIGEST_SHA256 = 2;
const DNSSEC_DIGEST_GOST = 3;
const DNSSEC_DIGEST_SHA384 = 4;

/*
* The packet id used when sending requests
Expand Down Expand Up @@ -491,7 +494,10 @@ class Net_DNS2_Lookups
public static $digest_id_to_name = [

self::DNSSEC_DIGEST_RES => 'RES',
self::DNSSEC_DIGEST_SHA1 => 'SHA-1'
self::DNSSEC_DIGEST_SHA1 => 'SHA-1',
self::DNSSEC_DIGEST_SHA256 => 'SHA-256',
self::DNSSEC_DIGEST_GOST => 'GOST-R-34.11-94',
self::DNSSEC_DIGEST_SHA384 => 'SHA-384'
];

/*
Expand Down
32 changes: 5 additions & 27 deletions Net/DNS2/RR/DS.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class Net_DNS2_RR_DS extends Net_DNS2_RR
*/
protected function rrToString()
{
return $this->keytag . ' ' . $this->algorithm . ' ' .
$this->digesttype . ' ' . $this->digest;
return $this->keytag . ' ' . $this->algorithm . ' ' . $this->digesttype . ' ' . $this->digest;
}

/**
Expand Down Expand Up @@ -100,30 +99,12 @@ protected function rrSet(Net_DNS2_Packet &$packet)
//
// unpack the keytag, algorithm and digesttype
//
$x = unpack('nkeytag/Calgorithm/Cdigesttype', $this->rdata);
$x = unpack('nkeytag/Calgorithm/Cdigesttype/H*digest', $this->rdata);

$this->keytag = $x['keytag'];
$this->algorithm = $x['algorithm'];
$this->digesttype = $x['digesttype'];

//
// figure out the digest size
//
$digest_size = 0;
if ($this->digesttype == 1) {

$digest_size = 20; // SHA1

} else if ($this->digesttype == 2) {

$digest_size = 32; // SHA256
}

//
// copy the digest
//
$x = unpack('H*', substr($this->rdata, 4, $digest_size));
$this->digest = $x[1];
$this->digest = $x['digest'];

return true;
}
Expand All @@ -146,16 +127,13 @@ protected function rrGet(Net_DNS2_Packet &$packet)
{
if (strlen($this->digest) > 0) {

$data = pack(
'nCCH*',
$this->keytag, $this->algorithm, $this->digesttype, $this->digest
);
$data = pack('nCCH*', $this->keytag, $this->algorithm, $this->digesttype, $this->digest);

$packet->offset += strlen($data);

return $data;
}

return null;
}
}
2 changes: 2 additions & 0 deletions package.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
"- added Net_DNS2::closeSockets(), which lets you close all cached network sockets in the resolver object.\n" .
"- added Net_DNS2::getSockets(), which returns the local sockets cache array.\n" .
"- added date_created and date_last_used to the Net_DNS2_Socket object, to track usage stats on each socket object.\n" .
"- added the SHA256, SHA384, and GOST digest defines to Lookups.php.\n" .
"- dropped the Net_DNS2_Socket_Sockets, and switch to just using the streams code. There's no speed difference anymore.\n" .
"- fixed a bug in Net_DNS2_Packet::compress() and Net_DNS2_Packet::expand() related to dot literals in compressed names.\n" .
"- fixed a display issue in the IPSECKEY RR when displaying hostname / domain names in the gateway field.\n" .
"- fixed a couple inconsistencies in the docs.\n" .
"- fixed a PHP 7.4 bug in Sockets.php; accessing a null value as an array throws an exception now.\n" .
"- fixed Net_DNS2_RR_DS so it will be able to support other digest definitions without any other changes.\n" .
"- the Net_DNS2_RR_NIMLOC class was incorrectly named Net_DNS2_RR_NIMLOCK.\n" .
"- Net_DNS2_PrivateKey was using the wrong member variable name for the key_format value.\n" .
"- changed all references to array() to [].\n" .
Expand Down
Loading

0 comments on commit c5448f3

Please sign in to comment.