Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl(common+storage): remove OpenSSL dependency on Windows #13785

Merged
merged 56 commits into from
Mar 28, 2024

Conversation

teo-tsirpanis
Copy link
Contributor

@teo-tsirpanis teo-tsirpanis commented Mar 16, 2024

Fixes #13746

This PR reimplements the cryptography routines on top of Windows APIs, removing the dependency to OpenSSL on Windows1.

Validated by successfully running the relevant tests locally. I also did some minor cleanups where applicable.


This change is Reviewable

Footnotes

  1. At least for the REST client libraries; gRPC has its own dependency on OpenSSL.

@devbww
Copy link
Contributor

devbww commented Mar 16, 2024

/gcbrun

google/cloud/BUILD.bazel Show resolved Hide resolved
google/cloud/google_cloud_cpp_common.cmake Outdated Show resolved Hide resolved
google/cloud/storage/internal/openssl_util.cc Outdated Show resolved Hide resolved
Copy link

codecov bot commented Mar 16, 2024

Codecov Report

Attention: Patch coverage is 89.34426% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 93.04%. Comparing base (4832108) to head (d2444bd).
Report is 3 commits behind head on main.

Files Patch % Lines
...internal/openssl/parse_service_account_p12_file.cc 79.03% 13 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13785   +/-   ##
=======================================
  Coverage   93.04%   93.04%           
=======================================
  Files        2176     2178    +2     
  Lines      185186   185178    -8     
=======================================
- Hits       172308   172302    -6     
+ Misses      12878    12876    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thank you for preparing this PR. These are difficult APIs and the changes look good.

Second, I think we should take some time to refactor the code so these changes are easier to maintain in the future. Most of my comments below go along those lines.

Third, I think we need to think about the test coverage consequences. For example, our ASAN builds only run on Linux, and that makes sense because the code is (or was) largely identical on Linux, macOS and Windows. This change introduces a number of tricky allocations / deallocations that (to my eyes) look correct, but I would feel better if they were also tested by some dynamic analyzer. @scotthart our infrastructure cannot handle that at the moment, we should consider if (and how) we would support code that is more specialized for Windows.

@teo-tsirpanis you may want to hold off on making more changes until we had a chance to discuss this internally.

google/cloud/BUILD.bazel Show resolved Hide resolved
google/cloud/google_cloud_cpp_common.cmake Outdated Show resolved Hide resolved
google/cloud/google_cloud_cpp_rest_internal.cmake Outdated Show resolved Hide resolved
google/cloud/storage/google_cloud_cpp_storage.cmake Outdated Show resolved Hide resolved
google/cloud/internal/openssl_util.cc Outdated Show resolved Hide resolved
google/cloud/internal/openssl_util.cc Outdated Show resolved Hide resolved
google/cloud/internal/openssl_util.cc Outdated Show resolved Hide resolved
google/cloud/internal/openssl_util.cc Outdated Show resolved Hide resolved
google/cloud/storage/internal/hash_function_impl.cc Outdated Show resolved Hide resolved
We depend on it only when we need to include a header. Bazel takes care of linking.
@coryan
Copy link
Contributor

coryan commented Mar 22, 2024

Thanks for being patient with us, and thanks for sending this PR. I think we really want to break the dependency on OpenSSL on Windows, and your changes are in the right direction.

I think we want to make some refactoring before making these changes. I will be doing the refactoring and CC you on the PRs so you can see where things are going. Feel free to rebase this PR or create a new PR at the end, whatever works for you.

The changes I have in mind include:

  • Remove the duplicate implementation of SingUsingSha256 (see refactor(storage): de-duplicate SignWithPem() #13825).
  • Rename google/cloud/internal/openssl_utils.h to something that does not speak to the library we use to implement these things, maybe google/cloud/internal/sign_using_sha256.{h,cc}.
  • Split the google/cloud/storage/internal/openssl_utils.* into files by function, e.g., .../internal/base64.* and .../internal/md5.*

After you merge your changes I will probably reorganize the code to reduce the number of #ifdefs. I think we would prefer files that are only compiled when needed, or that have a single #ifdef for the whole file. Those changes are not as urgent, and require a deeper understanding of our build scripts, so we will make them. I just mention them because you may find the code changed after your PR.

Again, thanks for this contribution, and let me know how you would like to proceed.

@coryan
Copy link
Contributor

coryan commented Mar 22, 2024

@teo-tsirpanis more refactoring in #13826

@teo-tsirpanis
Copy link
Contributor Author

Thanks for finding out. Is there a way to work around it?

google/cloud/BUILD.bazel Outdated Show resolved Hide resolved
google/cloud/storage/BUILD.bazel Show resolved Hide resolved
@coryan
Copy link
Contributor

coryan commented Mar 28, 2024

/gcbrun

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running clang-format on this file caused all these changes. I initially did not commit them because they were unrelated, but the checkers CI job keeps failing.

No other file changed by this PR gets changed after running clang-format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably have a slightly different version of clang-format. The checkers job is failing for other reasons, the diff is available at

https://github.com/googleapis/google-cloud-cpp/pull/13785/checks?check_run_id=23211048683

There are problems are (mostly) formatting of the CMake files.

google/cloud/google_cloud_cpp_common.cmake Outdated Show resolved Hide resolved
google/cloud/google_cloud_cpp_rest_internal.cmake Outdated Show resolved Hide resolved
google/cloud/storage/google_cloud_cpp_storage.cmake Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably have a slightly different version of clang-format. The checkers job is failing for other reasons, the diff is available at

https://github.com/googleapis/google-cloud-cpp/pull/13785/checks?check_run_id=23211048683

There are problems are (mostly) formatting of the CMake files.

This reverts commit cdd4cfe.
Stop setting `_WIN32_WINNT` (we need it only in Bazel).
Include `absl_str_cat_quiet.h`
@teo-tsirpanis
Copy link
Contributor Author

I installed cmake-format and formatted the files checkers complained about. checkers showed six files in its diff, and my latest commit (919fa1e) changed these six files.

@teo-tsirpanis teo-tsirpanis requested a review from coryan March 28, 2024 18:31
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's wait for the CI robots before declaring success.

@coryan
Copy link
Contributor

coryan commented Mar 28, 2024

/gcbrun

@coryan
Copy link
Contributor

coryan commented Mar 28, 2024

I believe the build failures in https://github.com/googleapis/google-cloud-cpp/actions/runs/8472009569/job/23214103847?pr=13785 are fixed in #13836 . @teo-tsirpanis have you had a chance to rebase since #13836 got merged?

@coryan
Copy link
Contributor

coryan commented Mar 28, 2024

/gcbrun

Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo hoo! Thanks for this change. Not only did we remove the dependency on OpenSSL, I think the code is cleaner.

I will be merging the code once the last build succeeds.

@coryan coryan merged commit 8b7fd79 into googleapis:main Mar 28, 2024
75 checks passed
@coryan
Copy link
Contributor

coryan commented Mar 28, 2024

Thanks again for the large contribution. We do appreciate it.

@teo-tsirpanis teo-tsirpanis deleted the win32-crypto branch March 28, 2024 22:26
coryan pushed a commit to conda-forge/google-cloud-cpp-core-feedstock that referenced this pull request Apr 22, 2024
* Remove OpenSSL dependency on Windows.
See googleapis/google-cloud-cpp#13785.

* MNT: Re-rendered with conda-build 3.27.0, conda-smithy 3.34.1, and conda-forge-pinning 2024.04.22.06.37.48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gha:full-build Trigger a full build in GHA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Windows APIs to do cryptography on Windows.
3 participants