Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/Sslurp/MozillaCertData.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ class MozillaCertData extends AbstractCaRootData
*/
protected $context = null;

/**
* Option name
*
* @var string
*/
private $peerNameOption;

/**
* Set the name of the peet_name / CN_match ssl context option
* depending on the PHP version.
*/
public function __construct()
{
if (version_compare(PHP_VERSION, '5.6', '>=')) {
$this->peerNameOption = 'peer_name';
} else {
$this->peerNameOption = 'CN_match';
}
}

/**
* Get the name of the peer_name /CN_match option
*
* @return string
*/
public function getPeerNameOption()
{
return $this->peerNameOption;
}

/**
* Get the raw certdata.txt contents from mxr.mozilla.org
*
Expand Down Expand Up @@ -64,11 +94,11 @@ public function getStreamContext()
{
if (!$this->context) {
$this->context = stream_context_create(array('ssl' => array(
'capture_peer_cert' => true,
'verify_peer' => true,
'allow_self_signed' => false,
'cafile' => $this->getRootCaBundlePath(),
'CN_match' => 'mxr.mozilla.org',
'capture_peer_cert' => true,
'verify_peer' => true,
'allow_self_signed' => false,
'cafile' => $this->getRootCaBundlePath(),
$this->getPeerNameOption() => 'mxr.mozilla.org',
)));
}

Expand Down
2 changes: 1 addition & 1 deletion test/SslurpTest/MozillaCertDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testContextOptionsAreSecureDefaults()
$this->assertSame(true, $opts['ssl']['verify_peer']);
$this->assertSame(false, $opts['ssl']['allow_self_signed']);
$this->assertRegExp('/^.+\.(pem|crt)$/', $opts['ssl']['cafile']);
$this->assertSame('mxr.mozilla.org', $opts['ssl']['CN_match']);
$this->assertSame('mxr.mozilla.org', $opts['ssl'][$this->mozCertData->getPeerNameOption()]);
}

public function testCanParseVersionAndDateDataProperly()
Expand Down