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

Support compiling without cryptography primitives #208

Merged
merged 2 commits into from
Jan 29, 2024
Merged

Conversation

corrideat
Copy link
Contributor

This makes all of the crypto libraries optional. My use case requires simply generating the binary ASN.1 structures and all cryptography is handled externally with HSMs.

This change removes unnecessary code and build complexity (for example, I'm targeting WASM, and I need to take extra steps to build the dependencies I don't need).

Note to the maintainer: this is a clean (and ideally better) rework of a previous PR, #207. Because I deleted the older and messier branch, the previous PR couldn't be updated, so I closed it.

@@ -211,6 +229,12 @@ impl KeyPair {
}
}

/// Generate a new random key pair for the specified signature algorithm
#[cfg(not(feature = "crypto"))]
pub fn generate(_alg: &'static SignatureAlgorithm) -> Result<Self, Error> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original comment by @djc: #207 (comment)

It doesn't seem like a great idea to generate an impl that can only error?

Would you rather I remove this entirely and the generate just isn't available without the crypto feature?

Copy link
Member

Choose a reason for hiding this comment

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

yes, that's generally preferable. Rust has strong static checks. the std implementations for wasm are panicking, and now I heard that it is considered to be a mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Well, this has already been done.

Copy link
Member

Choose a reason for hiding this comment

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

Did a commit for this change not get pushed or am I confused about the outcome of the discussion?

The state of the branch at the moment is that there is still a generate impl gated by #[cfg(not(feature = "crypto"))] that will only ever produce an error. I read the above discussion as preferring this impl not exist.

Copy link
Member

Choose a reason for hiding this comment

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

@corrideat I think this piece of feedback is the only merge blocker. Do you think you'll have a chance to fix it?

Copy link
Member

@est31 est31 left a comment

Choose a reason for hiding this comment

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

generally a good idea. I think we should test this in CI as it seems easy to regress to me.

rcgen/src/key_pair.rs Show resolved Hide resolved
rcgen/src/lib.rs Outdated Show resolved Hide resolved
rcgen/src/ring_like.rs Outdated Show resolved Hide resolved
rcgen/Cargo.toml Show resolved Hide resolved
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

This is looking pretty good. Is this scenario exercised in CI already?

@cpu
Copy link
Member

cpu commented Jan 16, 2024

I think this needs a rebase now that the refactoring in #205 has landed. Would you mind tidying up the commit history at the same time? I think all of the commits could be squashed down into one.

@corrideat
Copy link
Contributor Author

@cpu I've now rebased; it probably needs another review just in case.

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Generally looks good to me, thanks!

I had one question/comment about the resolution of the comment thread RE: the generate() impl for not(feature = "crypto").

@@ -211,6 +229,12 @@ impl KeyPair {
}
}

/// Generate a new random key pair for the specified signature algorithm
#[cfg(not(feature = "crypto"))]
pub fn generate(_alg: &'static SignatureAlgorithm) -> Result<Self, Error> {
Copy link
Member

Choose a reason for hiding this comment

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

Did a commit for this change not get pushed or am I confused about the outcome of the discussion?

The state of the branch at the moment is that there is still a generate impl gated by #[cfg(not(feature = "crypto"))] that will only ever produce an error. I read the above discussion as preferring this impl not exist.

@cpu cpu added this pull request to the merge queue Jan 29, 2024
Merged via the queue into rustls:main with commit 4a49584 Jan 29, 2024
21 of 22 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.

4 participants