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

feat(bindings): enable multiple cert chains on config #4902

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lucykn
Copy link

@lucykn lucykn commented Nov 18, 2024

Release Summary:

  • Adds add_cert_chain to allow more than one CertificateChain (s2n_cert_chain_and_key in C)
  • Adds clone to CertificateChain to allow multiple configs to share CertificateChains

Resolved issues:

N/A did not see any issues for this

Description of changes:

Prior to this change the only way of using the bindings was to use the older s2n_config_add_cert_chain_and_key C code that sets S2N ownership. This change is to allow use of the newer s2n_config_add_cert_chain which does not set S2N ownership of the cert. This PR does not change any existing C functionality and the older rust functions are still usable. The C code added is to implement drop on config and CertificateChain.

This change is needed to support more than one cert chain while using Rust.

Call-outs:

load_public_pem was not added on CertificateChain but would likely need to be implemented in the future. I left it out as it would need more C code and can be added independently of this PR.

I went with documentation about which Config Builder functions can be used together. The setters will fail due to the C code checking the condition. LMK if you think there is a better way to communicate when to pick one function over the other.

from_owned_ptr_reference vs from_ptr_reference requires knowing the implementation details of the ownership. Not sure how to get around that and still keep backwards compatibility.

I did not create a builder for CertificateChain as it seemed a bit superfluous since the build would not be able to validate anything.

Testing:

Used the following to execute the tests

cmake3 . -Bbuild \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=./s2n-tls-install \
    -DCMAKE_EXE_LINKER_FLAGS="-lcrypto -lz"
cmake3 --build build -j $(nproc)
cd build
CTEST_PARALLEL_LEVEL=$(nproc) ctest3
cd ..
cmake3 --install build


./bindings/rust/generate.sh

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

Adds ref counting and load_pem to cert chain. Makes use of newer
C functions that default to app owned instead of lib owned.

Config builder extended to make use of cert_chain instead of
only creating certs. This will enable multiple cert_chains.

Still work in progress. Need to implement C function to
get all cert chain and keys on the config. Need to add unit tests.
// original reference prevents other threads from erroneously deleting
// the object.
// https://github.com/rust-lang/rust/blob/e012a191d768adeda1ee36a99ef8b92d51920154/library/alloc/src/sync.rs#L1329
let _count = context.refcount.fetch_add(1, Ordering::Relaxed);
Copy link
Author

Choose a reason for hiding this comment

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

Clone and drop are nearly the same as Config

// count, which happens before this fence, which happens before the
// deletion of the data.
// https://github.com/rust-lang/rust/blob/e012a191d768adeda1ee36a99ef8b92d51920154/library/alloc/src/sync.rs#L1637
std::sync::atomic::fence(Ordering::Acquire);
Copy link
Author

@lucykn lucykn Nov 18, 2024

Choose a reason for hiding this comment

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

I'm not sure if this fence is actually required. I followed drop from Config here but Config is a bit more complicated than cert_chain so it's possible this isn't needed.

Copy link
Contributor

@jmayclin jmayclin left a comment

Choose a reason for hiding this comment

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

Hey Nathan! Thanks so much for the PR! Especially since this is a pretty ticky one.

At a high level, I'd prefer to see an approach that focused on having the main add_cert_chain api accept an Arc<CertificateChain>, as I worry that other approaches are going to be very tricky for library consumers to use correctly.

I'd actually advise that you hold off on addressing any comments for now, because I'd like to chat with the team about whether we can flex (break 😬)the existing apis a little bit, because I think a different CertificateChain struct would make this feature much easier to deliver.

I'll let you know once I've talked with my team and we'll go from there!

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.

2 participants