implement gettime_secs for Windows (_MSC_VER) in tests/api.c#6733
implement gettime_secs for Windows (_MSC_VER) in tests/api.c#6733JacobBarthelmeh merged 6 commits intowolfSSL:masterfrom
Conversation
7645f11 to
d19548c
Compare
d19548c to
321f748
Compare
| LIBCALL_CHECK_RET(gettimeofday(&tv, 0)); | ||
| #if defined(_MSC_VER) && defined(_WIN32) | ||
| { | ||
| /* there's no gettimeofday for Windows, so we'll use system time */ |
There was a problem hiding this comment.
Can this be a call to XTIME() ? It's how wolfSSL is checking certificate validity on Windows and looks like could even replace the previous gettimeofday call.
There was a problem hiding this comment.
Ah, good idea. But after going down that road I realized XTIME() is only granular to the level of whole seconds. In contrast, the double gettime_secs() is a double as it has 5 decimal places of fractional seconds.
I've updated this PR to instead pull out the TimeNowInMilliseconds() from tls13.c and make it a WOLFSSL_API in the internal.h file, thus allowing gettime_secs() in api.c to use TimeNowInMilliseconds().
We still lose 2 digits of precision, but I wonder how much more granular the measurements need to be than milliseconds? This change also results in gettime_secs() being available for many different platforms,
There was a problem hiding this comment.
For greater precision it looks like there is the macro XTIME_MS(). The suggestion was more to avoid duplication of code if we had a way to collect the number of seconds/microseconds already. If a large refactor or new public API is needed to achieve that then please just use the initial approach of adding a new ifelse macro case in tests/api.c.
There was a problem hiding this comment.
Can you help me understand how to use XTIME_MS()? It appears it is defined as m2mb_xtime_ms((tl)) and only in wc_port.h when gated with WOLFSSL_TELIT_M2MB and WOLFSSL_TLS13. The implementation of m2mb_xtime_ms appears to be very platform specific, using the m2mb_rtc_open("/dev/rtc0", 0).
I like the multi-platform implementation of TimeNowInMilliseconds() as having a common global millisecond timer for all platforms would be very handy, and not specific to only TLS1.3.
It's not so much that I wanted a new public API, but that was not only way I could see how to make it visible in api.c. I probably don't understand the wolfSSL visibility macros as well as I'd like.
Given this, how would you prefer that I proceed? Back to the initial approach adding Windows support? Do you think it is possible to get this working without being a WOLFSSL_API function?
There was a problem hiding this comment.
Please go back to the initial approach. Would prefer that over having the new public API. Sorry for the hassle the initial XTIME suggestion caused.
There was a problem hiding this comment.
No problem, it was a valid idea. It may be valuable to have a wolfSSL time library at some point.
For now in this PR I've reverted to the initial approach as requested.
Description
When using
cmakeon Windows, the call togettime_secsfails as this is not implemented on the Windows platform.This change checks for the Windows environment via the
_MSC_VERand conditionally defines an alternate calculation.As with #6600, but on Windows: Open a Visual Studio Developer Command Prompt:
There are many warnings when building. This is a separate issue, but for reference messages such as :
and
So to see any errors beyond the build warnings, just run
cmake --build .a second time, or suppress the warnings.Fixes zd# n/a
Testing
Add the source code function to something like
clientexample on Windows, build with 'cmake' and observe output:and compare to Linux command:
Run examples via:
You may need to manually copy the wolfSSL DLL files from
\Debugto\examples\client\Debug.Checklist