-
Notifications
You must be signed in to change notification settings - Fork 160
Expose peer signature algorithm and ML-DSA constants #511
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
Open
johnhurt
wants to merge
1
commit into
cloudflare:master
Choose a base branch
from
johnhurt:mldsa-signature-algorithm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -741,6 +741,44 @@ impl SslSignatureAlgorithm { | |||||
| SslSignatureAlgorithm(ffi::SSL_SIGN_RSA_PSS_RSAE_SHA512 as _); | ||||||
|
|
||||||
| pub const ED25519: SslSignatureAlgorithm = SslSignatureAlgorithm(ffi::SSL_SIGN_ED25519 as _); | ||||||
|
|
||||||
| pub const ML_DSA_44: SslSignatureAlgorithm = | ||||||
| SslSignatureAlgorithm(ffi::SSL_SIGN_ML_DSA_44 as _); | ||||||
|
|
||||||
| pub const ML_DSA_65: SslSignatureAlgorithm = | ||||||
| SslSignatureAlgorithm(ffi::SSL_SIGN_ML_DSA_65 as _); | ||||||
|
|
||||||
| pub const ML_DSA_87: SslSignatureAlgorithm = | ||||||
| SslSignatureAlgorithm(ffi::SSL_SIGN_ML_DSA_87 as _); | ||||||
|
|
||||||
| /// Returns a human-readable name for this signature algorithm, or `None` if the | ||||||
| /// underlying BoringSSL build does not recognize the codepoint. | ||||||
| #[corresponds(SSL_get_signature_algorithm_name)] | ||||||
| #[must_use] | ||||||
| pub fn name(&self) -> Option<&'static str> { | ||||||
| unsafe { | ||||||
| // `include_curve = true` returns the TLS 1.3 form for ECDSA algorithms | ||||||
| // (e.g. `ecdsa_secp256r1_sha256` rather than the TLS 1.2 `ecdsa_sha256`), | ||||||
| // matching what BoringSSL keylogs and modern TLS tooling use. | ||||||
| let ptr = ffi::SSL_get_signature_algorithm_name(self.0, true as c_int); | ||||||
| if ptr.is_null() { | ||||||
| None | ||||||
| } else { | ||||||
| // SAFETY: BoringSSL returns a pointer to a static, NUL-terminated C string | ||||||
| // when non-null, and the documented contract guarantees valid UTF-8. | ||||||
| Some(str::from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To match surrounding style in the codebase (https://github.com/cloudflare/boring/blob/master/boring/src/ssl/error.rs#L89, https://github.com/cloudflare/boring/blob/master/boring/src/error.rs#L264), and then we can drop the
Suggested change
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl fmt::Display for SslSignatureAlgorithm { | ||||||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
| match self.name() { | ||||||
| Some(name) => f.write_str(name), | ||||||
| None => write!(f, "unknown ({:#06x})", self.0), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl From<u16> for SslSignatureAlgorithm { | ||||||
|
|
@@ -3146,6 +3184,19 @@ impl SslRef { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Returns the signature algorithm used by the peer to authenticate the most recent TLS | ||||||
| /// handshake, or `None` if no signature was produced (e.g. session resumption). | ||||||
| #[corresponds(SSL_get_peer_signature_algorithm)] | ||||||
| #[must_use] | ||||||
| pub fn peer_signature_algorithm(&self) -> Option<SslSignatureAlgorithm> { | ||||||
| let sigalg = unsafe { ffi::SSL_get_peer_signature_algorithm(self.as_ptr()) }; | ||||||
| if sigalg == 0 { | ||||||
| None | ||||||
| } else { | ||||||
| Some(SslSignatureAlgorithm(sigalg)) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Returns a short string describing the state of the session. | ||||||
| /// | ||||||
| /// Returns empty string if the state wasn't valid UTF-8. | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match surrounding style in the codebase: