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

allows cmake to force crypto linkage. #4383

Merged
merged 1 commit into from
Feb 13, 2024
Merged

allows cmake to force crypto linkage. #4383

merged 1 commit into from
Feb 13, 2024

Conversation

sbiscigl
Copy link
Contributor

Description of changes:

Describe s2n’s current behavior and how your code changes that behavior. If there are no issues this PR is resolving, explain why this change is necessary.

This mirrors the AWS C++ SDK's PR that uses the same FindCrypto module. There is a user that wants to be able to control static linkage outside of the BUILD_SHARED_LIBS variable and force using a dynamic libcrypto while setting BUILD_SHARED_LIBS to OFF this will check two new variables FORCE_SHARED_CRYPTO and FORCE_STATIC_CRYPTO to force the usage of the corresponding library.

Call-outs:

Address any potentially confusing code. Is there code added that needs to be cleaned up later? Is there code that is missing because it’s still in development?

N/A

Testing:

How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?

I tested locally to verify that when using the cpp sdk that the correct crypto was used in linking.

Is this a refactor change? If so, how have you proved that the intended behavior hasn't changed?

No

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

cmake/modules/Findcrypto.cmake Outdated Show resolved Hide resolved
@@ -56,7 +56,10 @@ else()
)

if (NOT crypto_LIBRARY)
if (BUILD_SHARED_LIBS)
if(${AWS_CRYPTO_BUILD_SHARED_LIBS})
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep sounds good, can add it here, since it is your option, but we are using it, are you fine with the name AWS_CRYPTO_BUILD_SHARED_LIBS or would you like S2N_CRYPTO_BUILD_SHARED_LIBS?

from a SDK perspective we want it this way so that a user only has to specify one cmake option, but if you feel differently, im ok with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer S2N_BUILD_SHARED_LIBS so that future combinations of static/dynamic linking don't require any more options to be added.

Also, thoughts on matching the current behavior? E.g.

if (BUILD_SHARED_LIBS || S2N_BUILD_SHARED_LIBS)
...

That feels conceptually simpler to me.

Copy link
Contributor Author

@sbiscigl sbiscigl Feb 5, 2024

Choose a reason for hiding this comment

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

yeah thats makes sense to me, updated

cmake/modules/Findcrypto.cmake Show resolved Hide resolved
@sbiscigl sbiscigl force-pushed the main branch 4 times, most recently from d402be8 to bc8448f Compare February 5, 2024 19:27
@@ -56,7 +56,7 @@ else()
)

if (NOT crypto_LIBRARY)
if (BUILD_SHARED_LIBS)
if (BUILD_SHARED_LIBS OR ${S2N_BUILD_SHARED_LIBS})
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline that we should use ${*} syntax: https://cmake.org/cmake/help/latest/command/if.html#variable-expansion

@@ -56,7 +56,7 @@ else()
)

if (NOT crypto_LIBRARY)
if (BUILD_SHARED_LIBS)
if (BUILD_SHARED_LIBS OR ${S2N_USE_CRYPTO_SHARED_LIBS})
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like cmake doesn't like the syntax here:

CMake Error at /tmp/tmp.xcMT5KADjW/s2n-install-shared/lib/s2n/cmake/modules/Findcrypto.cmake:59 (if):
  if given arguments:

    "BUILD_SHARED_LIBS" "OR"

  Unknown arguments specified

Would something like this maybe work?

Suggested change
if (BUILD_SHARED_LIBS OR ${S2N_USE_CRYPTO_SHARED_LIBS})
if (${BUILD_SHARED_LIBS} OR ${S2N_USE_CRYPTO_SHARED_LIBS})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what cmake version are you using? its working as expected on my machine? got a image i can use to reproduce this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this works on a fresh al2023 image

FROM public.ecr.aws/amazonlinux/amazonlinux:2023

# Install dev tools
RUN yum groupinstall -y "Development Tools"

# Install cmake and ninja
RUN yum install -y cmake3 ninja-build

# Install static and dynamic lc
RUN git clone --depth 1 -b fips-2022-11-02 https://github.com/aws/aws-lc && \
    cd aws-lc && \
    mkdir build && \
    cd build && \
    cmake -G Ninja -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=/lc-install .. && \
    cmake --build . && \
    cmake --install . && \
    rm -rf ./* && \
    cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=/lc-install .. && \
    cmake --build . && \
    cmake --install .

RUN git clone https://github.com/sbiscigl/s2n-tls.git # && \
    cd s2n-tls && \
    mkdir build && \
    cd build && \
    cmake -G Ninja -DCMAKE_PREFIX_PATH=/lc-install .. && \
    cmake --build .

@lrstewart lrstewart merged commit 0998358 into aws:main Feb 13, 2024
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants