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

Make use of sha1 crate an optional feature #577

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

xnorpx
Copy link
Collaborator

@xnorpx xnorpx commented Oct 23, 2024

For security reasons rust crypto might need to be disabled and one would want use pure OpenSSL.

This change adds a feature flag for sha1 crate.

  • Allows users to not use sha1 and only use OpenSSL
  • Allows users to use sha1 only (for ice/stun) and no OpenSSL
  • Allows users to turn on sha1 and use Open SSL for rest

@xnorpx xnorpx changed the title Make sha1 crate optional and a feature Make use of sha1 crate an optional feature Oct 23, 2024
@xnorpx xnorpx marked this pull request as draft October 23, 2024 19:28
@xnorpx
Copy link
Collaborator Author

xnorpx commented Oct 23, 2024

I will run this change through our CI and deployment and also figure out github

@algesten
Copy link
Owner

I think we should separate the idea of win crypto vs openssl and this. The sha1 crate is effectively an optimization regardless of which "base" crypto provider you select.

Ultimately the features would be like this:

default = ["openssl", "sha1"]
openssl = ["dep:openssl", "_base_crypto"]
wincng = ["dep:str0m-cng", "_base_crypto"]
sha1 = ["dep:sha1"]

Then the internal check will be that we at least have something provides _base_crypto feature.

sha1 just "takes over" from whatever is doing sha1 if that's not installed.

@xnorpx
Copy link
Collaborator Author

xnorpx commented Oct 23, 2024

I think we should separate the idea of win crypto vs openssl and this. The sha1 crate is effectively an optimization regardless of which "base" crypto provider you select.

Ultimately the features would be like this:

default = ["openssl", "sha1"]
openssl = ["dep:openssl", "_base_crypto"]
wincng = ["dep:str0m-cng", "_base_crypto"]
sha1 = ["dep:sha1"]

Then the internal check will be that we at least have something provides _base_crypto feature.

sha1 just "takes over" from whatever is doing sha1 if that's not installed.

Ok I think I see what you mean, let me try add that.

@xnorpx
Copy link
Collaborator Author

xnorpx commented Oct 23, 2024

I think we should separate the idea of win crypto vs openssl and this. The sha1 crate is effectively an optimization regardless of which "base" crypto provider you select.

Ultimately the features would be like this:

default = ["openssl", "sha1"]
openssl = ["dep:openssl", "_base_crypto"]
wincng = ["dep:str0m-cng", "_base_crypto"]
sha1 = ["dep:sha1"]

Then the internal check will be that we at least have something provides _base_crypto feature.

sha1 just "takes over" from whatever is doing sha1 if that's not installed.

So I enabled the sha1 by default so there should be no changes for current users. (except the ones that disables all features)

I think we can add the base_crypto check and features once we add the cng crate.

Cargo.toml Outdated Show resolved Hide resolved
@xnorpx xnorpx marked this pull request as ready for review October 23, 2024 19:59
@xnorpx
Copy link
Collaborator Author

xnorpx commented Oct 23, 2024

@algesten ok I tested it in our repo and end2end and seem to work fine. So ready for merge unless more comments.

@xnorpx
Copy link
Collaborator Author

xnorpx commented Oct 23, 2024

@thomaseizinger you might need to add

"feature["sha1"]"

on your side after this change.

@thomaseizinger
Copy link
Collaborator

@thomaseizinger you might need to add

"feature["sha1"]"

on your side after this change.

That is a semver-breaking change then. Is the plan to make the corresponding version bump too?

@thomaseizinger
Copy link
Collaborator

FWIW, changing code paths with features can be problematic because features get aggregated by cargo. As a rule of thumb, features should only add new APIs, not modify existing code paths.

To select a "backend" for a certain functionality, I'd recommend to use regular cfgs instead. Those need to be set at compile-time by the final binary. The dalek folks do this for example: https://github.com/dalek-cryptography/curve25519-dalek/tree/main/curve25519-dalek#manual-backend-override

@xnorpx
Copy link
Collaborator Author

xnorpx commented Oct 24, 2024

cfg feels a little bit much in this case, but whatever @algesten see fit.

@thomaseizinger
Copy link
Collaborator

cfg feels a little bit much in this case, but whatever @algesten see fit.

I tend to agree. The risk is more on your end because there is no way to disable the sha1 feature if it is enabled somehow.

@algesten
Copy link
Owner

That is a semver-breaking change then. Is the plan to make the corresponding version bump too?

Yeah, let's bump to 0.7.0.

FWIW, changing code paths with features can be problematic because features get aggregated by cargo. As a rule of thumb, features should only add new APIs, not modify existing code paths.

I hear ya. Got very deep into this problem in ureq wrt crypto provider. There I decided to require both a feature flag and a configuration change to enable another crypto backend. However for str0m/sha1 I reason like this:

  • str0m should be optimized for maximum performance
  • sha1 crate should be enabled by default
  • That some people forbid random crates without analyzing the situation is not really str0m's problem. However we also want to encourage adoption and not take hard stances that preclude groups of users (or force forks) when we can avoid it
  • Diamond dependencies with str0m is very unlikely (compared to ureq for instance)
  • If you are forbidding the sha1 crate, you probably have tools that would detect a diamond dependency accidentally enabling the feature

@algesten
Copy link
Owner

Just testing to see if the asm feature works on windows now.

@thomaseizinger
Copy link
Collaborator

FWIW, changing code paths with features can be problematic because features get aggregated by cargo. As a rule of thumb, features should only add new APIs, not modify existing code paths.

I hear ya. Got very deep into this problem in ureq wrt crypto provider. There I decided to require both a feature flag and a configuration change to enable another crypto backend. However for str0m/sha1 I reason like this:

* str0m should be optimized for maximum performance

* sha1 crate should be enabled by default

* That some people forbid random crates without analyzing the situation is not really str0m's problem. However we also want to encourage adoption and not take hard stances that preclude groups of users (or force forks) when we can avoid it

* Diamond dependencies with str0m is very unlikely (compared to ureq for instance)

* If you are forbidding the sha1 crate, you probably have tools that would detect a diamond dependency accidentally enabling the feature

All sounds very reasonable to me!

@algesten
Copy link
Owner

The asm feature is still not working.

@algesten algesten merged commit 7c28a1f into algesten:main Oct 24, 2024
22 checks passed
@xnorpx
Copy link
Collaborator Author

xnorpx commented Oct 24, 2024

  • If you are forbidding the sha1 crate, you probably have tools that would detect a diamond dependency accidentally enabling the feature

Yes, the prod build pipelines have checks that are injected. But I also added cargo tree | grep sha1 check in our own gate as well.

Thanks for quick review!

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.

3 participants