0

I have written a program that gets SSL certificate expiration date/time using libcurl. But, the problem is that they are being returned in two different format when I run my program on two different operating systems.

Windows: 2031-04-13 23:59:59 GMT

CentOS7: Mar 14 23:59:59 2023 GMT

I don't know if the format would be different again if ran on another OS.

I want to get time since epoch in seconds till that date /time for both of them. Libcurl provides a function to handle the CentOS7 format CURL_GETDATE, and for Windows version I am using boost/date_time . I was wondering if there is something that exist that can do this job i.e. provide date/time in any format!!, and it returns time since epoch in seconds till mentioned date. Or some sort of generic implementation to achieve that?

I found this and this while searching, which is what I am looking for, but this code doesn't work, throwing exception:

Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFFB0254FD9 in BoostHttp.exe: Microsoft C++ exception: boost::wrapexcept<boost::gregorian::bad_month> at memory location 0x000000FB1FAFD1F8.


 output:

 ptime is not-a-date-time
 seconds from epoch are 9223372036854
 ptime is not-a-date-time
 seconds from epoch are 9223372036854
 ptime is not-a-date-time
 seconds from epoch are 9223372036854
 ptime is not-a-date-time
 seconds from epoch are 9223372036854

Any help would be appreciated. Thanks

Anees
  • 49
  • 5
  • Can you not obtain information about the format in some way? Or enforce the format to be something you want? Converting from any format is pretty much trying all reasonable format one can come up with until succeeding. Which isn't a particularly recommended or reliable route – ALX23z Jul 19 '22 at 17:53
  • Can you not make the library return it in a more sensible data structure than a string of a random format? – ALX23z Jul 19 '22 at 17:55
  • I couldn't find anything that would let me achieve that using that library. – Anees Jul 19 '22 at 18:11
  • As far as I understood `curl_getdate` should be able to parse pretty much any format. So what are you even looking for? – ALX23z Jul 20 '22 at 01:13
  • Yeah it does most of the formats, but not the format in case of Windows OS (2031-04-13 23:59:59 GMT). I need to remove "-" from the string, which I can by by putting a line of code or two. I wrote my code on Windows and was expecting it to run fine on CentOS7 as well, but it was crashing, and it took me sometime to figure out that the format of the date returned by libcurl was causing the issue. So, I thought It would be better to put some logic in my code, which can handle any format in case if happens again on another OS. – Anees Jul 20 '22 at 05:03
  • consider sending it as a bug report on windows that it fails to handle that format. – ALX23z Jul 20 '22 at 06:12

0 Answers0