Skip to content
Snippets Groups Projects
Commit bfa0c4b7 authored by Robin Appelman's avatar Robin Appelman
Browse files

Explicitly set the timezones

parent 4bc9980f
No related branches found
No related tags found
No related merge requests found
...@@ -35,12 +35,13 @@ class Certificate implements ICertificate { ...@@ -35,12 +35,13 @@ class Certificate implements ICertificate {
public function __construct($data, $name) { public function __construct($data, $name) {
$this->name = $name; $this->name = $name;
try { try {
$gmt = new \DateTimeZone('GMT');
$info = openssl_x509_parse($data); $info = openssl_x509_parse($data);
$this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null;
$this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null;
$this->serial = $this->formatSerial($info['serialNumber']); $this->serial = $this->formatSerial($info['serialNumber']);
$this->issueDate = new \DateTime('@' . $info['validFrom_time_t']); $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt);
$this->expireDate = new \DateTime('@' . $info['validTo_time_t']); $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt);
$this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null;
$this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null;
} catch (\Exception $e) { } catch (\Exception $e) {
......
...@@ -55,14 +55,14 @@ class CertificateTest extends \PHPUnit_Framework_TestCase { ...@@ -55,14 +55,14 @@ class CertificateTest extends \PHPUnit_Framework_TestCase {
} }
function testGetIssueDate() { function testGetIssueDate() {
$this->assertEquals(new DateTime('2014-08-27 08:45:52'), $this->goodCertificate->getIssueDate()); $this->assertEquals((new DateTime('2014-08-27 08:45:52 GMT'))->getTimestamp(), $this->goodCertificate->getIssueDate()->getTimestamp());
$this->assertEquals(new DateTime('2014-08-27 08:48:51'), $this->invalidCertificate->getIssueDate()); $this->assertEquals((new DateTime('2014-08-27 08:48:51 GMT'))->getTimestamp(), $this->invalidCertificate->getIssueDate()->getTimestamp());
} }
function testGetExpireDate() { function testGetExpireDate() {
$this->assertEquals(new DateTime('2015-08-27 08:45:52'), $this->goodCertificate->getExpireDate()); $this->assertEquals((new DateTime('2015-08-27 08:45:52 GMT'))->getTimestamp(), $this->goodCertificate->getExpireDate()->getTimestamp());
$this->assertEquals(new DateTime('2015-08-27 08:48:51'), $this->invalidCertificate->getExpireDate()); $this->assertEquals((new DateTime('2015-08-27 08:48:51 GMT'))->getTimestamp(), $this->invalidCertificate->getExpireDate()->getTimestamp());
$this->assertEquals(new DateTime('2014-08-28 09:12:43'), $this->expiredCertificate->getExpireDate()); $this->assertEquals((new DateTime('2014-08-28 09:12:43 GMT'))->getTimestamp(), $this->expiredCertificate->getExpireDate()->getTimestamp());
} }
/** /**
...@@ -85,4 +85,4 @@ class CertificateTest extends \PHPUnit_Framework_TestCase { ...@@ -85,4 +85,4 @@ class CertificateTest extends \PHPUnit_Framework_TestCase {
$this->assertSame('Internet Widgits Pty Ltd', $this->invalidCertificate->getIssuerOrganization()); $this->assertSame('Internet Widgits Pty Ltd', $this->invalidCertificate->getIssuerOrganization());
$this->assertSame('Internet Widgits Pty Ltd', $this->expiredCertificate->getIssuerOrganization()); $this->assertSame('Internet Widgits Pty Ltd', $this->expiredCertificate->getIssuerOrganization());
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment