php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46747 validFrom_time_t of certificate in Windows is difference with Unix system
Submitted: 2008-12-04 06:27 UTC Modified: 2009-01-16 02:18 UTC
From: hunreal at gmail dot com Assigned:
Status: Not a bug Package: OpenSSL related
PHP Version: 5.2.6 OS: Windows, FreeBSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hunreal at gmail dot com
New email:
PHP Version: OS:

 

 [2008-12-04 06:27 UTC] hunreal at gmail dot com
Description:
------------
I used openssl_x509_parse() to get certificate infomation. But the values, 'validFrom_time_t' and 'validTo_time_t' in Windows is difference with Unix system.
It's same php code, same certificate file. But two result is not the same.
By used openssl CLI, I am sure that is Windows PHP issue.

Reproduce code:
---------------
PHP code:
<?php
$crtinfo = openssl_x509_parse(file_get_contents("my.cer"));
echo $crtinfo['validFrom']," ",$crtinfo['validFrom_time_t'],"\n";
echo $crtinfo['validTo']," ",$crtinfo['validTo_time_t'],"\n";
echo date("Y-m-d H:i:s", $crtinfo['validFrom_time_t']),"\n";
echo date("Y-m-d H:i:s", $crtinfo['validTo_time_t']),"\n";
?>

Openssl CLI:
openssl x509 -dates -noout -in my.cer

You can use any certificate.

Expected result:
----------------
In windows, PHP code output,
070126220002Z 1169845202
090126033531Z 1232937331
2007-01-27 05:00:02
2009-01-26 10:35:31
------------------------------
In Unix, PHP code output,
070126220002Z 1169848802
090126033531Z 1232940931
2007-01-27 06:00:02
2009-01-26 11:35:31
------------------------------
BTW, my timezone is set to Asia/Shanghai, GMT+8

Actual result:
--------------
OpenSSL CLI output,
notBefore=Jan 26 22:00:02 2007 GMT
notAfter=Jan 26 03:35:31 2009 GMT

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-08 11:41 UTC] jani@php.net
One of those machines has wrong timezone set. Use the date_default_timezone_set() function in your script to set the correct one in both. And check those machines' system time too. This is not a PHP bug.
 [2009-01-16 02:18 UTC] hunreal at gmail dot com
Tried set date_default_timezone_set('Asia/Shanghai');
but the problem is still exists.
OS: Windows Vista
 [2013-05-27 03:22 UTC] cheef-daniel at freenet dot de
If this is not a bug, can you please explain why I get wrong results too on Windows Server 2008 R2 + Apache?

wrong: 27.03.2021 22:59:59
expected: 28.03.2021 00:59:59

echo phpversion();
5.3.16

echo date_default_timezone_get();
Europe/Berlin

echo $timestamp = $certInfo["validTo_time_t"]
1616882399

echo date("d.m.Y H:i:s", $timestamp)
27.03.2021 22:59:59

openssl x509 -dates -noout -in my.crt
notAfter=Mar 27 22:59:59 2021 GMT
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 01:01:29 2025 UTC