Schannel read from file simplify#21773
Conversation
|
If we do this, we can convert |
There was a problem hiding this comment.
Pull request overview
This PR refactors Schannel CA bundle loading in lib/vtls/schannel_verify.c to use curl’s cross-platform file APIs (curlx_fopen/curlx_fseek/curlx_fclose) and stdio reads instead of Windows CreateFile/ReadFile logic, simplifying the implementation while remaining Windows-only code.
Changes:
- Switch CA file opening/closing from WinAPI handles to
curlx_fopen/curlx_fclose. - Replace WinAPI file sizing/reading with
curlx_fseek+ftell+fread. - Preserve the existing “read whole file into memory (up to 1 MiB)” behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I wonder if its two uses in |
Indeed! Would it be possible to still switch to |
|
I have another suggestion, but I’m not sure where it would be best to discuss it, and it may not be worth opening a separate issue, so I’ll mention it here, as in the nearby PR discussion. In schannel, the This should be fairly easy to implement in the code, and it seems to me that using the system root store could be a good option in some cases. It would be useful for me. |
I may be misunderstanding your question, but with Schannel, the Windows Root Store is Though I suggest https://github.com/curl/curl/discussions for discussing topics not strictly |
|
I answered in discussion. |
It would work but not as well, I would leave it alone even if it leaves us with the CreateFile wrapper. The current code opens the file with only attribute access which is supposed to be faster and unaffected by if the file is already open, regardless of sharing mode. As I understand it Windows allows just attribute access even if the file open shared. If the code is changed to fopen then the file would have to be opened for write to write the attributes. Actually opening the file (not just opening access to presumably NTFS file system for attributes) is likely to be slower. (edit: I may not be right about having to open the file for write because if you do that then maybe it would set the file's last modified time to the time it was open for write? Not sure about this. In any case the file would have to be actually opened and closed with generic access because I assume that's what fopen does and is likely to be slower). |
Fair points. I guess another way to approach this may be to set the timestamp on the |
|
Thanks |
- Refactor CA file reading to use the typical fopen/fread instead of CreateFile/ReadFile. Closes curl#21773
In
schannel_verify.c, curl now usescurlx_CreateFileto readca_file. This code builds only on Windows, which is okay. However, I suggest using a more common and understandable API, such ascurlx_fopen.