Skip to content

Commit

Permalink
Strip everything but hostnames from cname validations
Browse files Browse the repository at this point in the history
  • Loading branch information
punkstar committed Oct 17, 2017
1 parent 4aea99f commit 38971ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Punkstar/Ssl/Validator/CommonNameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public function __construct(Certificate $certificate)

public function isValid($domain) : bool
{
foreach ($this->getNameVariations($domain) as $nameVariation) {
$hostname = parse_url($domain, PHP_URL_HOST);

if (!$hostname) {
$hostname = $domain;
}

foreach ($this->getNameVariations($hostname) as $nameVariation) {
if (in_array($nameVariation, $this->getAllowedNames(), true)) {
return true;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Punkstar/SslTest/Validator/CommonNameValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public function testWildcards()
$this->assertFalse($validator->isValid('www.secure.google.com'));
}

/**
* @test
*/
public function testWithPorts()
{
$validator = new CommonNameValidator($this->loadExampleCertificate('wildcard-google-com.crt'));

$this->assertTrue($validator->isValid('www.google.com:443'));
$this->assertTrue($validator->isValid('google.com:443'));
$this->assertTrue($validator->isValid('secure.google.com:443'));
$this->assertFalse($validator->isValid('www.secure.google.com:443'));
}

/**
* @return Certificate
*/
Expand Down

0 comments on commit 38971ef

Please sign in to comment.