Badcow /
DNS
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of Badcow DNS Library. |
||
| 7 | * |
||
| 8 | * (c) Samuel Williams <[email protected]> |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Badcow\DNS\Tests\Rdata; |
||
| 15 | |||
| 16 | use Badcow\DNS\Algorithms; |
||
| 17 | use Badcow\DNS\Parser\Parser; |
||
| 18 | use Badcow\DNS\Rdata\A; |
||
| 19 | use Badcow\DNS\Rdata\Factory; |
||
| 20 | use Badcow\DNS\Rdata\RRSIG; |
||
| 21 | use Badcow\DNS\Rdata\UnsupportedTypeException; |
||
| 22 | use PHPUnit\Framework\TestCase; |
||
| 23 | |||
| 24 | class RrsigTest extends TestCase |
||
| 25 | { |
||
| 26 | private static $signature = 'oJB1W6WNGv+ldvQ3WDG0MQkg5IEhjRip8WTrPYGv07h108dUKGMeDPKijVCHX3DDKdfb+v6oB9wfuh3DTJXUA'. |
||
| 27 | 'fI/M0zmO/zz8bW0Rznl8O3tGNazPwQKkRN20XPXV6nwwfoXmJQbsLNrLfkGJ5D6fwFm8nN+6pBzeDQfsS3Ap3o='; |
||
| 28 | |||
| 29 | public function testToText(): void |
||
| 30 | { |
||
| 31 | if (2147483647 === PHP_INT_MAX) { |
||
| 32 | $this->markTestSkipped('RRSIG test does not work on 32-bit systems.'); |
||
| 33 | } |
||
| 34 | |||
| 35 | $expectation = 'A 5 3 86400 20050322173103 20030220173103 2642 example.com. '.self::$signature; |
||
| 36 | |||
| 37 | $rrsig = new RRSIG(); |
||
| 38 | |||
| 39 | $rrsig->setTypeCovered('A'); |
||
| 40 | $rrsig->setAlgorithm(Algorithms::RSASHA1); |
||
| 41 | $rrsig->setLabels(3); |
||
| 42 | $rrsig->setOriginalTtl(86400); |
||
| 43 | $rrsig->setSignatureExpiration(\DateTime::createFromFormat(RRSIG::TIME_FORMAT, '20050322173103')); |
||
|
0 ignored issues
–
show
Security
Bug
introduced
by
Loading history...
|
|||
| 44 | $rrsig->setSignatureInception(\DateTime::createFromFormat(RRSIG::TIME_FORMAT, '20030220173103')); |
||
|
0 ignored issues
–
show
It seems like
\DateTime::createFromFor...RMAT, '20030220173103') targeting DateTime::createFromFormat() can also be of type false; however, Badcow\DNS\Rdata\RRSIG::setSignatureInception() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
|
|||
| 45 | $rrsig->setKeyTag(2642); |
||
| 46 | $rrsig->setSignersName('example.com.'); |
||
| 47 | $rrsig->setSignature(base64_decode(self::$signature)); |
||
| 48 | |||
| 49 | $this->assertEquals($expectation, $rrsig->toText()); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function testFactory(): void |
||
| 53 | { |
||
| 54 | $rrsig = Factory::RRSIG( |
||
| 55 | A::TYPE, |
||
| 56 | Algorithms::RSASHA1, |
||
| 57 | 3, |
||
| 58 | 86400, |
||
| 59 | \DateTime::createFromFormat('Ymd', '20220101'), |
||
|
0 ignored issues
–
show
|
|||
| 60 | \DateTime::createFromFormat('Ymd', '20180101'), |
||
|
0 ignored issues
–
show
|
|||
| 61 | 2642, |
||
| 62 | 'example.com.', |
||
| 63 | self::$signature |
||
| 64 | ); |
||
| 65 | |||
| 66 | $this->assertEquals(A::TYPE, $rrsig->getTypeCovered()); |
||
| 67 | $this->assertEquals(Algorithms::RSASHA1, $rrsig->getAlgorithm()); |
||
| 68 | $this->assertEquals(3, $rrsig->getLabels()); |
||
| 69 | $this->assertEquals(86400, $rrsig->getOriginalTtl()); |
||
| 70 | $this->assertEquals(\DateTime::createFromFormat('Ymd', '20220101'), $rrsig->getSignatureExpiration()); |
||
| 71 | $this->assertEquals(\DateTime::createFromFormat('Ymd', '20180101'), $rrsig->getSignatureInception()); |
||
| 72 | $this->assertEquals(2642, $rrsig->getKeyTag()); |
||
| 73 | $this->assertEquals('example.com.', $rrsig->getSignersName()); |
||
| 74 | $this->assertEquals(self::$signature, $rrsig->getSignature()); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function testFromText(): void |
||
| 78 | { |
||
| 79 | $text = 'A 5 3 86400 20050322173103 20030220173103 2642 example.com. '.self::$signature; |
||
| 80 | |||
| 81 | $rrsig = new RRSIG(); |
||
| 82 | $rrsig->setTypeCovered('A'); |
||
| 83 | $rrsig->setAlgorithm(Algorithms::RSASHA1); |
||
| 84 | $rrsig->setLabels(3); |
||
| 85 | $rrsig->setOriginalTtl(86400); |
||
| 86 | $rrsig->setSignatureExpiration(\DateTime::createFromFormat(RRSIG::TIME_FORMAT, '20050322173103')); |
||
|
0 ignored issues
–
show
It seems like
\DateTime::createFromFor...RMAT, '20050322173103') targeting DateTime::createFromFormat() can also be of type false; however, Badcow\DNS\Rdata\RRSIG::setSignatureExpiration() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
|
|||
| 87 | $rrsig->setSignatureInception(\DateTime::createFromFormat(RRSIG::TIME_FORMAT, '20030220173103')); |
||
|
0 ignored issues
–
show
It seems like
\DateTime::createFromFor...RMAT, '20030220173103') targeting DateTime::createFromFormat() can also be of type false; however, Badcow\DNS\Rdata\RRSIG::setSignatureInception() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
|
|||
| 88 | $rrsig->setKeyTag(2642); |
||
| 89 | $rrsig->setSignersName('example.com.'); |
||
| 90 | $rrsig->setSignature(base64_decode(self::$signature)); |
||
| 91 | |||
| 92 | $fromText = new RRSIG(); |
||
| 93 | $fromText->fromText($text); |
||
| 94 | $this->assertEquals($rrsig, $fromText); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @throws UnsupportedTypeException |
||
| 99 | */ |
||
| 100 | public function testWire(): void |
||
| 101 | { |
||
| 102 | $rrsig = new RRSIG(); |
||
| 103 | $rrsig->setTypeCovered('A'); |
||
| 104 | $rrsig->setAlgorithm(Algorithms::RSASHA1); |
||
| 105 | $rrsig->setLabels(3); |
||
| 106 | $rrsig->setOriginalTtl(86400); |
||
| 107 | $rrsig->setSignatureExpiration(\DateTime::createFromFormat(RRSIG::TIME_FORMAT, '20050322173103')); |
||
|
0 ignored issues
–
show
It seems like
\DateTime::createFromFor...RMAT, '20050322173103') targeting DateTime::createFromFormat() can also be of type false; however, Badcow\DNS\Rdata\RRSIG::setSignatureExpiration() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
|
|||
| 108 | $rrsig->setSignatureInception(\DateTime::createFromFormat(RRSIG::TIME_FORMAT, '20030220173103')); |
||
|
0 ignored issues
–
show
It seems like
\DateTime::createFromFor...RMAT, '20030220173103') targeting DateTime::createFromFormat() can also be of type false; however, Badcow\DNS\Rdata\RRSIG::setSignatureInception() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
|
|||
| 109 | $rrsig->setKeyTag(2642); |
||
| 110 | $rrsig->setSignersName('example.com.'); |
||
| 111 | $rrsig->setSignature(self::$signature); |
||
| 112 | |||
| 113 | $wireFormat = $rrsig->toWire(); |
||
| 114 | $rdLength = strlen($wireFormat); |
||
| 115 | $wireFormat = 'abcd'.$wireFormat; |
||
| 116 | $offset = 4; |
||
| 117 | |||
| 118 | $fromWire = new RRSIG(); |
||
| 119 | $fromWire->fromWire($wireFormat, $offset, $rdLength); |
||
| 120 | $this->assertEquals($rrsig, $fromWire); |
||
| 121 | $this->assertEquals(4 + $rdLength, $offset); |
||
| 122 | } |
||
| 123 | |||
| 124 | public function testIssue75(): void |
||
| 125 | { |
||
| 126 | $string = <<<'DNS' |
||
| 127 | $ORIGIN example.com. |
||
| 128 | RRSIG A 5 3 86400 20050322173103 20030220173103 2642 example.com. ( |
||
| 129 | sLGSfcmcvXQ4EGMXrUFFE1JO17AxhspZY8xXiCLEDN95 |
||
| 130 | S90KgnDUKzzIUTjjGao0G7XpzhoCgsXyAyJeTgTwa4v5 |
||
| 131 | ICV8xCF1dpUMb7aHRw2l0MA2dDZ30w33QTqU7TEbETpy |
||
| 132 | NqTbK9qaabsTTXSIGg2ChKV8MwiGm/TyjnARjVo= ) |
||
| 133 | DNS; |
||
| 134 | $binarySignature = base64_decode('sLGSfcmcvXQ4EGMXrUFFE1JO17AxhspZY8xXiCLEDN95 |
||
| 135 | S90KgnDUKzzIUTjjGao0G7XpzhoCgsXyAyJeTgTwa4v5 |
||
| 136 | ICV8xCF1dpUMb7aHRw2l0MA2dDZ30w33QTqU7TEbETpy |
||
| 137 | NqTbK9qaabsTTXSIGg2ChKV8MwiGm/TyjnARjVo='); |
||
| 138 | |||
| 139 | $zone = Parser::parse('example.com.', $string); |
||
| 140 | $this->assertCount(1, $zone); |
||
| 141 | $rr = $zone[0]; |
||
| 142 | $rrsig = $rr->getRdata(); |
||
| 143 | |||
| 144 | $this->assertEquals('example.com.', $rr->getName()); |
||
| 145 | $this->assertEquals(RRSIG::TYPE, $rrsig->getType()); |
||
| 146 | |||
| 147 | $this->assertEquals(A::TYPE, $rrsig->getTypeCovered()); |
||
| 148 | $this->assertEquals(Algorithms::RSASHA1, $rrsig->getAlgorithm()); |
||
| 149 | $this->assertEquals(3, $rrsig->getLabels()); |
||
| 150 | $this->assertEquals(86400, $rrsig->getOriginalTtl()); |
||
| 151 | $this->assertEquals(\DateTime::createFromFormat('YmdHis', '20050322173103'), $rrsig->getSignatureExpiration()); |
||
| 152 | $this->assertEquals(\DateTime::createFromFormat('YmdHis', '20030220173103'), $rrsig->getSignatureInception()); |
||
| 153 | $this->assertEquals(2642, $rrsig->getKeyTag()); |
||
| 154 | $this->assertEquals('example.com.', $rrsig->getSignersName()); |
||
| 155 | $this->assertEquals($binarySignature, $rrsig->getSignature()); |
||
| 156 | } |
||
| 157 | } |
||
| 158 |