5

I've parsed openssl certificate by openssl_x509_parse() function and got an array as a result.

Now I need to get the expiration time of that certificate. In parsed array I have validTo_time_t element which contains a valid unix timestamp. But how to determine what timezone this timestamp belongs for?

So I can't get the real expiration time because that timestamp because it means deifferent dates on different timezones.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
ozahorulia
  • 9,798
  • 8
  • 48
  • 72

2 Answers2

2

php formats this field using it's default timezone. you can get it using http://docs.php.net/date_default_timezone_get function

and once you know the timezone you can convert it to UTC or whatever you need

JimiDini
  • 2,039
  • 12
  • 19
  • So when `openssl_x509_parse()` parses data it automatically converts certificate `validTo` date to the current timezone? Does that mean that this timestamp will be the real expiration date for the current php default timezone? – ozahorulia Jul 17 '13 at 16:19
  • @hast that's what I think it does, yes. at least, it does so on unix-systems (on windows it might be broken. see here: https://bugs.php.net/bug.php?id=46747) – JimiDini Jul 17 '13 at 16:23
2

Unix TimeStamp have no timezone. It's defined as number of seconds since January 1st, 1970 at UTC. It's not a defined as a real date but just a bunch of seconds. No timezone = no problems.

This is why it's a perfect measure of time across different server and different regions. You can just store unix timestamp, and when you convert it to a date it will use your local timezone to determinate the date, this is completly automatic and this means that when you convert givin a different timezone it will convert to the correct date. Always.

This is true for all timestamp not just for the SSL output. Major info on Timestamp http://www.unixtimestamp.com/

Max Cuttins
  • 614
  • 2
  • 6
  • 20