mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

Use native socket type on Windows

Open irwir opened this issue 8 months ago • 3 comments

Description

Define properly socket type on Windows, and adjust checks for invalid socket. Resolves #10097.

PR checklist

  • [x] changelog provided
  • [x] TF-PSA-Crypto PR provided TF-PSA-Crypto/#262
  • [x] framework PR not required
  • [x] 3.6 PR not required because: not planned
  • tests not required because: no additional tests needed

irwir avatar Apr 19 '25 11:04 irwir

Two repositories require changes before test build. There was a question in https://github.com/Mbed-TLS/mbedtls/issues/10097#issuecomment-2797123664; not answered.

irwir avatar Apr 21 '25 20:04 irwir

Our Windows builds in the CI don't like this patch. I guess because a submodule update is also required?

Note: including a TLS-specific system header in a crypto library header doesn't seem right to me. But I'm not familiar with Windows, so for all I know this may be the only way to make it work.

gilles-peskine-arm avatar Apr 22 '25 08:04 gilles-peskine-arm

Our Windows builds in the CI don't like this patch. I guess because a submodule update is also required?

Yes, in the above message "both repositories" implies that build_info.h in TF-PSA-Crypto must be updated. The first error message clearly indicated that SOCKET macro was never defined. VS solution builds successfully here.

Note: including a TLS-specific system header in a crypto library header doesn't seem right to me.

This was the main reason for the question in the issue. Theoretically the point is valid, but the current implementation is not clean in this sense. The list of files including at least windows.h is below:

core\psa_its_file.c
drivers\builtin\src\entropy_poll.c
drivers\builtin\src\platform_util.c
drivers\builtin\src\sha256.c

As said earlier, winsock2.h if ever needed, must be included before windows.h. Since this was an SSL/TLS library, networking should be present. Hence this attempt to make the sequence of headers correct in most cases.

irwir avatar Apr 22 '25 09:04 irwir

Can you please rebase this pull request on top of the latest head (we've made a few incompatible changes recently), then add a commit to update the crypto submodule with https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/262, so that we can get a recent CI run?

gilles-peskine-arm avatar Jul 30 '25 08:07 gilles-peskine-arm

Rebased.

irwir avatar Jul 30 '25 09:07 irwir

add a commit to update the crypto submodule with Mbed-TLS/TF-PSA-Crypto#262, so that we can get a recent CI run

Can this commit be done before merging crypto PR262?

irwir avatar Jul 31 '25 10:07 irwir

Yes. Please update the submodule to the head of https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/262:

cd tf-psa-crypto
git checkout e2a08a0b7f47cbff34d0918297cc313ed9f79625
cd ..
git add tf-psa-crypto
git commit -m "Update crypto submodule with winsock2 header"

Once the crypto PR is merged, you'll need to amend that commit so that it updates the submodule to the result of the merge. (We haven't found a better way to work with submodules and GitHub, so we make an exception to our general guideline to not rewrite the git history.)

gilles-peskine-arm avatar Jul 31 '25 11:07 gilles-peskine-arm

git checkout consistently prints fatal: unable to read tree (e2a08a0b7f47cbff34d0918297cc313ed9f79625) Repository checks, re-cloning and reading a few articles did not help so far. Let's see if .gitmodules can work.

irwir avatar Jul 31 '25 18:07 irwir

@irwir You need to push the submodule first (to your fork is fine), then push the commit that updates the submodule in the parent repository.

gilles-peskine-arm avatar Jul 31 '25 19:07 gilles-peskine-arm

No change to .gitmodules is necessary (or useful).

gilles-peskine-arm avatar Jul 31 '25 19:07 gilles-peskine-arm

Updated submodule tf-psa-crypto to e2a08a0 in winsock2 branch.

irwir avatar Aug 01 '25 21:08 irwir

Patched udp_proxy for CI run. The changes might be improved, but now it should compile without warnings.

irwir avatar Aug 02 '25 08:08 irwir

We haven't found a better way to work with submodules and GitHub

Is it possible to run CI for mbedtls with a framework submodule being different from the framework in TF-PSA-Crypto? This would be not quite right.

irwir avatar Aug 04 '25 10:08 irwir

@gilles-peskine-arm, please run the tests.

irwir avatar Aug 05 '25 09:08 irwir

Tests passed; the needs-ci label could be reset.

irwir avatar Aug 06 '25 13:08 irwir