You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "bneradt (via GitHub)" <gi...@apache.org> on 2026/07/13 21:36:49 UTC
[PR] Log TLS signature algorithms [trafficserver]
bneradt opened a new pull request, #13378:
URL: https://github.com/apache/trafficserver/pull/13378
Certificate selection decisions require visibility into the signature
algorithms clients offer, but access logs currently expose only TLS
cipher and group details. This makes it difficult to identify clients
that depend on a particular certificate signature type.
This adds native fields for the offered signature-algorithm list and
the algorithm used by ATS, with GREASE filtering and resumption-aware
capture. It documents the fields and covers TLS 1.2 and TLS 1.3 full
and resumed handshakes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-4964049271
[approve ci autest 1]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "cmcfarlen (via GitHub) via github" <gi...@trafficserver.apache.org>.
cmcfarlen commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-6593219167
[approve ci urtest clang-tidy]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-4963547816
[approve ci ubuntu]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-4963654976
[approve ci ubuntu freebsd]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r4201359233
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -2531,6 +2568,212 @@ SSLGetGroupName([[maybe_unused]] SSL *ssl)
#endif // HAVE_SSL_GET0_GROUP_NAME
}
+namespace
+{
+bool
+is_grease_signature_algorithm(uint16_t algorithm)
+{
+ return (algorithm & 0x0f0f) == 0x0a0a && (algorithm >> 12) == ((algorithm >> 4) & 0x0f);
+}
+
+#if HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+bool
+signature_algorithm_matches_private_key(SSL *ssl, uint16_t algorithm)
+{
+ EVP_PKEY *private_key = SSL_get_privatekey(ssl);
+
+ if (private_key == nullptr) {
+ return false;
+ }
+
+ int const key_type = EVP_PKEY_base_id(private_key);
+
+ switch (algorithm) {
+ case 0x0804: // rsa_pss_rsae_sha256
+ case 0x0805: // rsa_pss_rsae_sha384
+ case 0x0806: // rsa_pss_rsae_sha512
+ return key_type == EVP_PKEY_RSA;
+ case 0x0809: // rsa_pss_pss_sha256
+ case 0x080a: // rsa_pss_pss_sha384
+ case 0x080b: // rsa_pss_pss_sha512
+ return key_type == EVP_PKEY_RSA_PSS;
+ default:
+ break;
+ }
+
+#if defined(TLS1_3_VERSION)
+ if (SSL_version(ssl) >= TLS1_3_VERSION && key_type == EVP_PKEY_EC) {
+ int expected_curve = NID_undef;
+
+ switch (algorithm) {
+ case 0x0403: // ecdsa_secp256r1_sha256
+ expected_curve = NID_X9_62_prime256v1;
+ break;
+ case 0x0503: // ecdsa_secp384r1_sha384
+ expected_curve = NID_secp384r1;
+ break;
+ case 0x0603: // ecdsa_secp521r1_sha512
+ expected_curve = NID_secp521r1;
+ break;
+ case 0x081a: // ecdsa_brainpoolP256r1tls13_sha256
+ expected_curve = NID_brainpoolP256r1;
+ break;
+ case 0x081b: // ecdsa_brainpoolP384r1tls13_sha384
+ expected_curve = NID_brainpoolP384r1;
+ break;
+ case 0x081c: // ecdsa_brainpoolP512r1tls13_sha512
+ expected_curve = NID_brainpoolP512r1;
+ break;
+ default:
+ break;
+ }
+
+ if (expected_curve != NID_undef) {
+#ifdef OPENSSL_IS_AT_LEAST_OPENSSL3
+ char group_name[80];
+ size_t group_name_length = 0;
+
+ return EVP_PKEY_get_utf8_string_param(private_key, OSSL_PKEY_PARAM_GROUP_NAME, group_name, sizeof(group_name),
+ &group_name_length) == 1 &&
+ OBJ_txt2nid(group_name) == expected_curve;
+#else
+ EC_KEY const *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
+
+ if (ec_key != nullptr) {
+ EC_GROUP const *group = EC_KEY_get0_group(ec_key);
+ return group != nullptr && EC_GROUP_get_curve_name(group) == expected_curve;
+ }
+#endif
+ }
+ }
+#endif
+
+ return true;
+}
+#endif
+} // namespace
+
+std::string
+SSLFormatSignatureAlgorithms(swoc::MemSpan<uint16_t const> algorithms)
+{
+ std::string result;
+
+ for (uint16_t const algorithm : algorithms) {
+ if (is_grease_signature_algorithm(algorithm)) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.push_back('-');
+ }
+ result.append(std::to_string(algorithm));
+ }
+
+ return result;
+}
+
+std::string
+SSLGetOfferedSignatureAlgorithms([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS
+ uint16_t const *algorithms = nullptr;
+ size_t const count = SSL_get0_peer_verify_algorithms(ssl, &algorithms);
+
+ return SSLFormatSignatureAlgorithms({algorithms, count});
+#elif HAVE_SSL_GET_SIGALGS
+ int const count = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
Review Comment:
`SSL_get_sigalgs` uses `idx == -1` to return the number of peer schemes; with `idx == 0` this returns only the validity of entry 0 (typically 1), so this fallback formats at most the first offered scheme on OpenSSL versions without `SSL_get0_peer_verify_algorithms`. Use `-1` for the count query so the loop covers the complete list.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub) via github" <gi...@trafficserver.apache.org>.
bneradt merged PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r3857936398
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -2514,6 +2549,183 @@ SSLGetGroupName([[maybe_unused]] SSL *ssl)
#endif // HAVE_SSL_GET0_GROUP_NAME
}
+namespace
+{
+bool
+is_grease_signature_algorithm(uint16_t algorithm)
+{
+ return (algorithm & 0x0f0f) == 0x0a0a && (algorithm >> 12) == ((algorithm >> 4) & 0x0f);
+}
+
+#if HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+bool
+signature_algorithm_matches_private_key(SSL *ssl, uint16_t algorithm)
+{
+ EVP_PKEY *private_key = SSL_get_privatekey(ssl);
+
+ if (private_key == nullptr) {
+ return false;
+ }
+
+ int const key_type = EVP_PKEY_base_id(private_key);
+
+ switch (algorithm) {
+ case 0x0804: // rsa_pss_rsae_sha256
+ case 0x0805: // rsa_pss_rsae_sha384
+ case 0x0806: // rsa_pss_rsae_sha512
+ return key_type == EVP_PKEY_RSA;
+ case 0x0809: // rsa_pss_pss_sha256
+ case 0x080a: // rsa_pss_pss_sha384
+ case 0x080b: // rsa_pss_pss_sha512
+ return key_type == EVP_PKEY_RSA_PSS;
+ default:
+ break;
+ }
+
+#if defined(TLS1_3_VERSION)
+ if (SSL_version(ssl) >= TLS1_3_VERSION && key_type == EVP_PKEY_EC) {
+ int expected_curve = NID_undef;
+
+ switch (algorithm) {
+ case 0x0403: // ecdsa_secp256r1_sha256
+ expected_curve = NID_X9_62_prime256v1;
+ break;
+ case 0x0503: // ecdsa_secp384r1_sha384
+ expected_curve = NID_secp384r1;
+ break;
+ case 0x0603: // ecdsa_secp521r1_sha512
+ expected_curve = NID_secp521r1;
+ break;
+ case 0x081a: // ecdsa_brainpoolP256r1tls13_sha256
+ expected_curve = NID_brainpoolP256r1;
+ break;
+ case 0x081b: // ecdsa_brainpoolP384r1tls13_sha384
+ expected_curve = NID_brainpoolP384r1;
+ break;
+ case 0x081c: // ecdsa_brainpoolP512r1tls13_sha512
+ expected_curve = NID_brainpoolP512r1;
+ break;
+ default:
+ break;
+ }
+
+ if (expected_curve != NID_undef) {
+ EC_KEY const *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
+
+ if (ec_key != nullptr) {
+ EC_GROUP const *group = EC_KEY_get0_group(ec_key);
+ return group != nullptr && EC_GROUP_get_curve_name(group) == expected_curve;
+ }
+ }
+ }
+#endif
+
+ return true;
+}
+#endif
+} // namespace
+
+std::string
+SSLFormatSignatureAlgorithms(swoc::MemSpan<uint16_t const> algorithms)
+{
+ std::string result;
+
+ for (uint16_t const algorithm : algorithms) {
+ if (is_grease_signature_algorithm(algorithm)) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.push_back('-');
+ }
+ result.append(std::to_string(algorithm));
+ }
+
+ return result;
+}
+
+std::string
+SSLGetOfferedSignatureAlgorithms([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS
+ uint16_t const *algorithms = nullptr;
+ size_t const count = SSL_get0_peer_verify_algorithms(ssl, &algorithms);
+
+ return SSLFormatSignatureAlgorithms({algorithms, count});
+#elif HAVE_SSL_GET_SIGALGS
+ int const count = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
+
+ if (count <= 0) {
+ return {};
+ }
+
+ std::vector<uint16_t> algorithms;
+ algorithms.reserve(count);
+ for (int index = 0; index < count; ++index) {
+ unsigned char signature = 0;
+ unsigned char hash = 0;
+
+ if (SSL_get_sigalgs(ssl, index, nullptr, nullptr, nullptr, &signature, &hash) > 0) {
+ algorithms.push_back(static_cast<uint16_t>(hash) << 8 | signature);
+ }
+ }
+
+ return SSLFormatSignatureAlgorithms(algorithms);
+#else
+ return {};
+#endif
+}
+
+std::string
+SSLGetNegotiatedSignatureAlgorithm([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET_SIGNATURE_ALGORITHM_USED
+ uint16_t const algorithm = SSL_get_signature_algorithm_used(ssl);
+
+ return algorithm == 0 ? "" : std::to_string(algorithm);
+#elif HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+ int signature_type = NID_undef;
+ int hash = NID_undef;
+
+ if (SSL_get_signature_type_nid(ssl, &signature_type) != 1 || SSL_get_signature_nid(ssl, &hash) != 1) {
+ return {};
+ }
+
+ int const count = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
+ for (int index = 0; index < count; ++index) {
+ int shared_signature_type = NID_undef;
+ int shared_hash = NID_undef;
+ unsigned char signature = 0;
+ unsigned char raw_hash = 0;
+
+ if (SSL_get_shared_sigalgs(ssl, index, &shared_signature_type, &shared_hash, nullptr, &signature, &raw_hash) <= 0 ||
+ shared_signature_type != signature_type || shared_hash != hash) {
+ continue;
+ }
+
+ uint16_t const algorithm = static_cast<uint16_t>(raw_hash) << 8 | signature;
+ if (signature_algorithm_matches_private_key(ssl, algorithm)) {
+ return std::to_string(algorithm);
+ }
+ }
Review Comment:
OpenSSL distinguishes PSS through the signature-type NID. The fallback was nevertheless hardened to return - whenever multiple distinct compatible schemes remain, avoiding list-order dependence. ([OpenSSL documentation](https://docs.openssl.org/3.5/man3/SSL_get_peer_signature_nid/))
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r4201327090
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -2531,6 +2568,203 @@ SSLGetGroupName([[maybe_unused]] SSL *ssl)
#endif // HAVE_SSL_GET0_GROUP_NAME
}
+namespace
+{
+bool
+is_grease_signature_algorithm(uint16_t algorithm)
+{
+ return (algorithm & 0x0f0f) == 0x0a0a && (algorithm >> 12) == ((algorithm >> 4) & 0x0f);
+}
+
+#if HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+bool
+signature_algorithm_matches_private_key(SSL *ssl, uint16_t algorithm)
+{
+ EVP_PKEY *private_key = SSL_get_privatekey(ssl);
+
+ if (private_key == nullptr) {
+ return false;
+ }
+
+ int const key_type = EVP_PKEY_base_id(private_key);
+
+ switch (algorithm) {
+ case 0x0804: // rsa_pss_rsae_sha256
+ case 0x0805: // rsa_pss_rsae_sha384
+ case 0x0806: // rsa_pss_rsae_sha512
+ return key_type == EVP_PKEY_RSA;
+ case 0x0809: // rsa_pss_pss_sha256
+ case 0x080a: // rsa_pss_pss_sha384
+ case 0x080b: // rsa_pss_pss_sha512
+ return key_type == EVP_PKEY_RSA_PSS;
+ default:
+ break;
+ }
+
+#if defined(TLS1_3_VERSION)
+ if (SSL_version(ssl) >= TLS1_3_VERSION && key_type == EVP_PKEY_EC) {
+ int expected_curve = NID_undef;
+
+ switch (algorithm) {
+ case 0x0403: // ecdsa_secp256r1_sha256
+ expected_curve = NID_X9_62_prime256v1;
+ break;
+ case 0x0503: // ecdsa_secp384r1_sha384
+ expected_curve = NID_secp384r1;
+ break;
+ case 0x0603: // ecdsa_secp521r1_sha512
+ expected_curve = NID_secp521r1;
+ break;
+ case 0x081a: // ecdsa_brainpoolP256r1tls13_sha256
+ expected_curve = NID_brainpoolP256r1;
+ break;
+ case 0x081b: // ecdsa_brainpoolP384r1tls13_sha384
+ expected_curve = NID_brainpoolP384r1;
+ break;
+ case 0x081c: // ecdsa_brainpoolP512r1tls13_sha512
+ expected_curve = NID_brainpoolP512r1;
+ break;
+ default:
+ break;
+ }
+
+ if (expected_curve != NID_undef) {
+#ifdef OPENSSL_IS_AT_LEAST_OPENSSL3
+ char group_name[80];
+ size_t group_name_length = 0;
+
+ return EVP_PKEY_get_utf8_string_param(private_key, OSSL_PKEY_PARAM_GROUP_NAME, group_name, sizeof(group_name),
+ &group_name_length) == 1 &&
+ OBJ_txt2nid(group_name) == expected_curve;
+#else
+ EC_KEY const *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
+
+ if (ec_key != nullptr) {
+ EC_GROUP const *group = EC_KEY_get0_group(ec_key);
+ return group != nullptr && EC_GROUP_get_curve_name(group) == expected_curve;
+ }
+#endif
+ }
+ }
+#endif
+
+ return true;
+}
+#endif
+} // namespace
+
+std::string
+SSLFormatSignatureAlgorithms(swoc::MemSpan<uint16_t const> algorithms)
+{
+ std::string result;
+
+ for (uint16_t const algorithm : algorithms) {
+ if (is_grease_signature_algorithm(algorithm)) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.push_back('-');
+ }
+ result.append(std::to_string(algorithm));
+ }
+
+ return result;
+}
+
+std::string
+SSLGetOfferedSignatureAlgorithms([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS
+ uint16_t const *algorithms = nullptr;
+ size_t const count = SSL_get0_peer_verify_algorithms(ssl, &algorithms);
+
+ return SSLFormatSignatureAlgorithms({algorithms, count});
+#elif HAVE_SSL_GET_SIGALGS
+ int const count = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
+
+ if (count <= 0) {
+ return {};
+ }
+
+ std::vector<uint16_t> algorithms;
+ algorithms.reserve(count);
+ for (int index = 0; index < count; ++index) {
+ unsigned char signature = 0;
+ unsigned char hash = 0;
+
+ if (SSL_get_sigalgs(ssl, index, nullptr, nullptr, nullptr, &signature, &hash) > 0) {
+ algorithms.push_back(static_cast<uint16_t>(hash) << 8 | signature);
+ }
+ }
+
+ return SSLFormatSignatureAlgorithms(algorithms);
+#else
+ return {};
+#endif
+}
+
+std::string
+SSLGetNegotiatedSignatureAlgorithm(SSL *ssl)
+{
+ // A resumed handshake creates no new signature, even if the library retains signature metadata.
+ if (ssl == nullptr || SSL_session_reused(ssl)) {
+ return {};
+ }
+
+#if HAVE_SSL_GET_SIGNATURE_ALGORITHM_USED
+ uint16_t const algorithm = SSL_get_signature_algorithm_used(ssl);
+
+ return algorithm == 0 ? "" : std::to_string(algorithm);
+#elif HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+ // When the TLS library does not expose the exact IANA scheme, derive it from the local signature type and digest, the
+ // shared list, and the certificate key. Return no value if more than one compatible code point remains.
+ int signature_type = NID_undef;
+ int hash = NID_undef;
+
+ if (SSL_get_signature_type_nid(ssl, &signature_type) != 1 || SSL_get_signature_nid(ssl, &hash) != 1) {
Review Comment:
Confirmed and fixed. I reproduced it first with a new gold line before touching the code — a TLS 1.2 handshake forced to `AES128-GCM-SHA256` logged `cqssin 1025` even though the server never signed anything:
```
- tls12-static-rsa TLSv1.2 1025 - 0 0
+ tls12-static-rsa TLSv1.2 1025 1025 0 0
```
Took your guard, with a null check on the cipher, in the `#elif` branch ahead of the `SSL_get_signature_type_nid()` call:
```cpp
SSL_CIPHER const *cipher = SSL_get_current_cipher(ssl);
if (cipher == nullptr || SSL_CIPHER_get_kx_nid(cipher) == NID_kx_rsa) {
return {};
}
```
I dropped the `SSL_version(ssl) < TLS1_3_VERSION` half of your suggestion: TLS 1.3 suites report `NID_kx_any`, so the kx test alone can't fire there, and leaving the version check out avoids another `TLS1_3_VERSION` guard. Say the word if you'd rather keep it explicit.
The BoringSSL branch needs nothing — `SSL_get_signature_algorithm_used()` already returns 0 when nothing was signed.
Also added a `/tls12-static-rsa` run to `tls_signature_algorithms.test.py` asserting `-`, so the OpenSSL path is pinned, and a sentence in `formatting.en.rst` noting static RSA key exchange alongside the resumption case.
Verified on Fedora with OpenSSL 3.5.7: all 72 `gold_tests/tls` autests pass, `test_net` signature cases pass, docs build clean. Reverting just the `SSLUtils.cc` hunk puts the gold failure back, so the new case is doing real work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-5318987292
[approve ci]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r3574346219
##########
src/iocore/net/TLSBasicSupport.cc:
##########
@@ -170,6 +172,47 @@ TLSBasicSupport::get_tls_group() const
return this->_get_tls_group();
}
+std::string_view
+TLSBasicSupport::get_tls_offered_signature_algorithms() const
+{
+ if (!this->_tls_offered_signature_algorithms.has_value()) {
+ this->_tls_offered_signature_algorithms =
+ this->_get_ssl_object() == nullptr ? "" : this->_get_tls_offered_signature_algorithms();
+ }
+
+ return *this->_tls_offered_signature_algorithms;
+}
+
+std::string_view
+TLSBasicSupport::get_tls_negotiated_signature_algorithm() const
+{
+ if (!this->_tls_negotiated_signature_algorithm.has_value()) {
+ this->_tls_negotiated_signature_algorithm =
+ this->_get_ssl_object() == nullptr ? "" : this->_get_tls_negotiated_signature_algorithm();
+ }
+
+ return *this->_tls_negotiated_signature_algorithm;
+}
+
+void
+TLSBasicSupport::capture_tls_offered_signature_algorithms()
+{
+ this->_tls_offered_signature_algorithms = this->_get_ssl_object() == nullptr ? "" : this->_get_tls_offered_signature_algorithms();
+}
Review Comment:
capture_tls_offered_signature_algorithms() overwrites any previously captured non-empty ClientHello-derived list with whatever the SSL API returns at cert-callback time. If that later query returns an empty string (e.g., not available yet / not supported), this clobbers a valid earlier capture and causes cqssig to log as "-" even though the client offered algorithms.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub) via github" <gi...@trafficserver.apache.org>.
bneradt commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r4474241628
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -2531,6 +2568,212 @@ SSLGetGroupName([[maybe_unused]] SSL *ssl)
#endif // HAVE_SSL_GET0_GROUP_NAME
}
+namespace
+{
+bool
+is_grease_signature_algorithm(uint16_t algorithm)
+{
+ return (algorithm & 0x0f0f) == 0x0a0a && (algorithm >> 12) == ((algorithm >> 4) & 0x0f);
+}
+
+#if HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+bool
+signature_algorithm_matches_private_key(SSL *ssl, uint16_t algorithm)
+{
+ EVP_PKEY *private_key = SSL_get_privatekey(ssl);
+
+ if (private_key == nullptr) {
+ return false;
+ }
+
+ int const key_type = EVP_PKEY_base_id(private_key);
+
+ switch (algorithm) {
+ case 0x0804: // rsa_pss_rsae_sha256
+ case 0x0805: // rsa_pss_rsae_sha384
+ case 0x0806: // rsa_pss_rsae_sha512
+ return key_type == EVP_PKEY_RSA;
+ case 0x0809: // rsa_pss_pss_sha256
+ case 0x080a: // rsa_pss_pss_sha384
+ case 0x080b: // rsa_pss_pss_sha512
+ return key_type == EVP_PKEY_RSA_PSS;
+ default:
+ break;
+ }
+
+#if defined(TLS1_3_VERSION)
+ if (SSL_version(ssl) >= TLS1_3_VERSION && key_type == EVP_PKEY_EC) {
+ int expected_curve = NID_undef;
+
+ switch (algorithm) {
+ case 0x0403: // ecdsa_secp256r1_sha256
+ expected_curve = NID_X9_62_prime256v1;
+ break;
+ case 0x0503: // ecdsa_secp384r1_sha384
+ expected_curve = NID_secp384r1;
+ break;
+ case 0x0603: // ecdsa_secp521r1_sha512
+ expected_curve = NID_secp521r1;
+ break;
+ case 0x081a: // ecdsa_brainpoolP256r1tls13_sha256
+ expected_curve = NID_brainpoolP256r1;
+ break;
+ case 0x081b: // ecdsa_brainpoolP384r1tls13_sha384
+ expected_curve = NID_brainpoolP384r1;
+ break;
+ case 0x081c: // ecdsa_brainpoolP512r1tls13_sha512
+ expected_curve = NID_brainpoolP512r1;
+ break;
+ default:
+ break;
+ }
+
+ if (expected_curve != NID_undef) {
+#ifdef OPENSSL_IS_AT_LEAST_OPENSSL3
+ char group_name[80];
+ size_t group_name_length = 0;
+
+ return EVP_PKEY_get_utf8_string_param(private_key, OSSL_PKEY_PARAM_GROUP_NAME, group_name, sizeof(group_name),
+ &group_name_length) == 1 &&
+ OBJ_txt2nid(group_name) == expected_curve;
+#else
+ EC_KEY const *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
+
+ if (ec_key != nullptr) {
+ EC_GROUP const *group = EC_KEY_get0_group(ec_key);
+ return group != nullptr && EC_GROUP_get_curve_name(group) == expected_curve;
+ }
+#endif
+ }
+ }
+#endif
+
+ return true;
+}
+#endif
+} // namespace
+
+std::string
+SSLFormatSignatureAlgorithms(swoc::MemSpan<uint16_t const> algorithms)
+{
+ std::string result;
+
+ for (uint16_t const algorithm : algorithms) {
+ if (is_grease_signature_algorithm(algorithm)) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.push_back('-');
+ }
+ result.append(std::to_string(algorithm));
+ }
+
+ return result;
+}
+
+std::string
+SSLGetOfferedSignatureAlgorithms([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS
+ uint16_t const *algorithms = nullptr;
+ size_t const count = SSL_get0_peer_verify_algorithms(ssl, &algorithms);
+
+ return SSLFormatSignatureAlgorithms({algorithms, count});
+#elif HAVE_SSL_GET_SIGALGS
+ int const count = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
Review Comment:
Fixed in 79f55c1873: the fallback now queries the count with `idx == -1`, the documented form. (OpenSSL also returns the full count for any in-range `idx`, so `0` only lost the list when the peer offered none, but `-1` states the intent and has no such edge.) Verified on an OpenSSL 3.5 build that takes this `SSL_get_sigalgs` path: `test_tls_signature_algorithms` passes.
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -2531,6 +2568,212 @@ SSLGetGroupName([[maybe_unused]] SSL *ssl)
#endif // HAVE_SSL_GET0_GROUP_NAME
}
+namespace
+{
+bool
+is_grease_signature_algorithm(uint16_t algorithm)
+{
+ return (algorithm & 0x0f0f) == 0x0a0a && (algorithm >> 12) == ((algorithm >> 4) & 0x0f);
+}
+
+#if HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+bool
+signature_algorithm_matches_private_key(SSL *ssl, uint16_t algorithm)
+{
+ EVP_PKEY *private_key = SSL_get_privatekey(ssl);
+
+ if (private_key == nullptr) {
+ return false;
+ }
+
+ int const key_type = EVP_PKEY_base_id(private_key);
+
+ switch (algorithm) {
+ case 0x0804: // rsa_pss_rsae_sha256
+ case 0x0805: // rsa_pss_rsae_sha384
+ case 0x0806: // rsa_pss_rsae_sha512
+ return key_type == EVP_PKEY_RSA;
+ case 0x0809: // rsa_pss_pss_sha256
+ case 0x080a: // rsa_pss_pss_sha384
+ case 0x080b: // rsa_pss_pss_sha512
+ return key_type == EVP_PKEY_RSA_PSS;
+ default:
+ break;
+ }
+
+#if defined(TLS1_3_VERSION)
+ if (SSL_version(ssl) >= TLS1_3_VERSION && key_type == EVP_PKEY_EC) {
+ int expected_curve = NID_undef;
+
+ switch (algorithm) {
+ case 0x0403: // ecdsa_secp256r1_sha256
+ expected_curve = NID_X9_62_prime256v1;
+ break;
+ case 0x0503: // ecdsa_secp384r1_sha384
+ expected_curve = NID_secp384r1;
+ break;
+ case 0x0603: // ecdsa_secp521r1_sha512
+ expected_curve = NID_secp521r1;
+ break;
+ case 0x081a: // ecdsa_brainpoolP256r1tls13_sha256
+ expected_curve = NID_brainpoolP256r1;
+ break;
+ case 0x081b: // ecdsa_brainpoolP384r1tls13_sha384
+ expected_curve = NID_brainpoolP384r1;
+ break;
+ case 0x081c: // ecdsa_brainpoolP512r1tls13_sha512
+ expected_curve = NID_brainpoolP512r1;
+ break;
+ default:
+ break;
+ }
+
+ if (expected_curve != NID_undef) {
+#ifdef OPENSSL_IS_AT_LEAST_OPENSSL3
+ char group_name[80];
+ size_t group_name_length = 0;
+
+ return EVP_PKEY_get_utf8_string_param(private_key, OSSL_PKEY_PARAM_GROUP_NAME, group_name, sizeof(group_name),
+ &group_name_length) == 1 &&
+ OBJ_txt2nid(group_name) == expected_curve;
+#else
+ EC_KEY const *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
+
+ if (ec_key != nullptr) {
+ EC_GROUP const *group = EC_KEY_get0_group(ec_key);
+ return group != nullptr && EC_GROUP_get_curve_name(group) == expected_curve;
+ }
+#endif
+ }
+ }
+#endif
+
+ return true;
+}
+#endif
+} // namespace
+
+std::string
+SSLFormatSignatureAlgorithms(swoc::MemSpan<uint16_t const> algorithms)
+{
+ std::string result;
+
+ for (uint16_t const algorithm : algorithms) {
+ if (is_grease_signature_algorithm(algorithm)) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.push_back('-');
+ }
+ result.append(std::to_string(algorithm));
+ }
+
+ return result;
+}
+
+std::string
+SSLGetOfferedSignatureAlgorithms([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS
+ uint16_t const *algorithms = nullptr;
+ size_t const count = SSL_get0_peer_verify_algorithms(ssl, &algorithms);
+
+ return SSLFormatSignatureAlgorithms({algorithms, count});
+#elif HAVE_SSL_GET_SIGALGS
+ int const count = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
Review Comment:
Fixed in 79f55c1873: the fallback now queries the count with `idx == -1`, the documented form. (OpenSSL returns the full count for any in-range `idx` too, so `0` happened to work, but `-1` states the intent.) Verified on an OpenSSL 3.5 build that takes this `SSL_get_sigalgs` path: `test_tls_signature_algorithms` passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r3574405121
##########
src/iocore/net/TLSBasicSupport.cc:
##########
@@ -170,6 +172,47 @@ TLSBasicSupport::get_tls_group() const
return this->_get_tls_group();
}
+std::string_view
+TLSBasicSupport::get_tls_offered_signature_algorithms() const
+{
+ if (!this->_tls_offered_signature_algorithms.has_value()) {
+ this->_tls_offered_signature_algorithms =
+ this->_get_ssl_object() == nullptr ? "" : this->_get_tls_offered_signature_algorithms();
+ }
+
+ return *this->_tls_offered_signature_algorithms;
+}
+
+std::string_view
+TLSBasicSupport::get_tls_negotiated_signature_algorithm() const
+{
+ if (!this->_tls_negotiated_signature_algorithm.has_value()) {
+ this->_tls_negotiated_signature_algorithm =
+ this->_get_ssl_object() == nullptr ? "" : this->_get_tls_negotiated_signature_algorithm();
+ }
+
+ return *this->_tls_negotiated_signature_algorithm;
+}
+
+void
+TLSBasicSupport::capture_tls_offered_signature_algorithms()
+{
+ this->_tls_offered_signature_algorithms = this->_get_ssl_object() == nullptr ? "" : this->_get_tls_offered_signature_algorithms();
+}
Review Comment:
Good catch. The later capture now preserves a non-empty ClientHello-derived value when the SSL API returns empty. I also added a regression test covering this callback sequence.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "cmcfarlen (via GitHub)" <gi...@apache.org>.
cmcfarlen commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r4168482019
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -2531,6 +2568,203 @@ SSLGetGroupName([[maybe_unused]] SSL *ssl)
#endif // HAVE_SSL_GET0_GROUP_NAME
}
+namespace
+{
+bool
+is_grease_signature_algorithm(uint16_t algorithm)
+{
+ return (algorithm & 0x0f0f) == 0x0a0a && (algorithm >> 12) == ((algorithm >> 4) & 0x0f);
+}
+
+#if HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+bool
+signature_algorithm_matches_private_key(SSL *ssl, uint16_t algorithm)
+{
+ EVP_PKEY *private_key = SSL_get_privatekey(ssl);
+
+ if (private_key == nullptr) {
+ return false;
+ }
+
+ int const key_type = EVP_PKEY_base_id(private_key);
+
+ switch (algorithm) {
+ case 0x0804: // rsa_pss_rsae_sha256
+ case 0x0805: // rsa_pss_rsae_sha384
+ case 0x0806: // rsa_pss_rsae_sha512
+ return key_type == EVP_PKEY_RSA;
+ case 0x0809: // rsa_pss_pss_sha256
+ case 0x080a: // rsa_pss_pss_sha384
+ case 0x080b: // rsa_pss_pss_sha512
+ return key_type == EVP_PKEY_RSA_PSS;
+ default:
+ break;
+ }
+
+#if defined(TLS1_3_VERSION)
+ if (SSL_version(ssl) >= TLS1_3_VERSION && key_type == EVP_PKEY_EC) {
+ int expected_curve = NID_undef;
+
+ switch (algorithm) {
+ case 0x0403: // ecdsa_secp256r1_sha256
+ expected_curve = NID_X9_62_prime256v1;
+ break;
+ case 0x0503: // ecdsa_secp384r1_sha384
+ expected_curve = NID_secp384r1;
+ break;
+ case 0x0603: // ecdsa_secp521r1_sha512
+ expected_curve = NID_secp521r1;
+ break;
+ case 0x081a: // ecdsa_brainpoolP256r1tls13_sha256
+ expected_curve = NID_brainpoolP256r1;
+ break;
+ case 0x081b: // ecdsa_brainpoolP384r1tls13_sha384
+ expected_curve = NID_brainpoolP384r1;
+ break;
+ case 0x081c: // ecdsa_brainpoolP512r1tls13_sha512
+ expected_curve = NID_brainpoolP512r1;
+ break;
+ default:
+ break;
+ }
+
+ if (expected_curve != NID_undef) {
+#ifdef OPENSSL_IS_AT_LEAST_OPENSSL3
+ char group_name[80];
+ size_t group_name_length = 0;
+
+ return EVP_PKEY_get_utf8_string_param(private_key, OSSL_PKEY_PARAM_GROUP_NAME, group_name, sizeof(group_name),
+ &group_name_length) == 1 &&
+ OBJ_txt2nid(group_name) == expected_curve;
+#else
+ EC_KEY const *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
+
+ if (ec_key != nullptr) {
+ EC_GROUP const *group = EC_KEY_get0_group(ec_key);
+ return group != nullptr && EC_GROUP_get_curve_name(group) == expected_curve;
+ }
+#endif
+ }
+ }
+#endif
+
+ return true;
+}
+#endif
+} // namespace
+
+std::string
+SSLFormatSignatureAlgorithms(swoc::MemSpan<uint16_t const> algorithms)
+{
+ std::string result;
+
+ for (uint16_t const algorithm : algorithms) {
+ if (is_grease_signature_algorithm(algorithm)) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.push_back('-');
+ }
+ result.append(std::to_string(algorithm));
+ }
+
+ return result;
+}
+
+std::string
+SSLGetOfferedSignatureAlgorithms([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS
+ uint16_t const *algorithms = nullptr;
+ size_t const count = SSL_get0_peer_verify_algorithms(ssl, &algorithms);
+
+ return SSLFormatSignatureAlgorithms({algorithms, count});
+#elif HAVE_SSL_GET_SIGALGS
+ int const count = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
+
+ if (count <= 0) {
+ return {};
+ }
+
+ std::vector<uint16_t> algorithms;
+ algorithms.reserve(count);
+ for (int index = 0; index < count; ++index) {
+ unsigned char signature = 0;
+ unsigned char hash = 0;
+
+ if (SSL_get_sigalgs(ssl, index, nullptr, nullptr, nullptr, &signature, &hash) > 0) {
+ algorithms.push_back(static_cast<uint16_t>(hash) << 8 | signature);
+ }
+ }
+
+ return SSLFormatSignatureAlgorithms(algorithms);
+#else
+ return {};
+#endif
+}
+
+std::string
+SSLGetNegotiatedSignatureAlgorithm(SSL *ssl)
+{
+ // A resumed handshake creates no new signature, even if the library retains signature metadata.
+ if (ssl == nullptr || SSL_session_reused(ssl)) {
+ return {};
+ }
+
+#if HAVE_SSL_GET_SIGNATURE_ALGORITHM_USED
+ uint16_t const algorithm = SSL_get_signature_algorithm_used(ssl);
+
+ return algorithm == 0 ? "" : std::to_string(algorithm);
+#elif HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+ // When the TLS library does not expose the exact IANA scheme, derive it from the local signature type and digest, the
+ // shared list, and the certificate key. Return no value if more than one compatible code point remains.
+ int signature_type = NID_undef;
+ int hash = NID_undef;
+
+ if (SSL_get_signature_type_nid(ssl, &signature_type) != 1 || SSL_get_signature_nid(ssl, &hash) != 1) {
Review Comment:
On OpenSSL, `tls_choose_sigalg()` sets `s3.tmp.sigalg` for any TLS 1.2 cipher that uses a certificate, including static-RSA key exchange suites like `AES128-GCM-SHA256` / `AES256-GCM-SHA384` (both in the default `proxy.config.ssl.server.cipher_suite`). Those suites send no ServerKeyExchange, so nothing is signed, but `SSL_get_signature_type_nid()` / `SSL_get_signature_nid()` still succeed and `cqssin` logs e.g. `1025` instead of `-`.
Since the docs describe this as the scheme used to authenticate the handshake, it seems worth returning empty here when the key exchange is static RSA, e.g.:
```cpp
if (SSL_version(ssl) < TLS1_3_VERSION && SSL_CIPHER_get_kx_nid(SSL_get_current_cipher(ssl)) == NID_kx_rsa) {
return {};
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bryancall (via GitHub) via github" <gi...@trafficserver.apache.org>.
bryancall commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-6748820098
[approve ci doxygen]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "cmcfarlen (via GitHub)" <gi...@apache.org>.
cmcfarlen commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-6069191858
[approve ci autest 2]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#discussion_r3815397451
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -2514,6 +2549,183 @@ SSLGetGroupName([[maybe_unused]] SSL *ssl)
#endif // HAVE_SSL_GET0_GROUP_NAME
}
+namespace
+{
+bool
+is_grease_signature_algorithm(uint16_t algorithm)
+{
+ return (algorithm & 0x0f0f) == 0x0a0a && (algorithm >> 12) == ((algorithm >> 4) & 0x0f);
+}
+
+#if HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+bool
+signature_algorithm_matches_private_key(SSL *ssl, uint16_t algorithm)
+{
+ EVP_PKEY *private_key = SSL_get_privatekey(ssl);
+
+ if (private_key == nullptr) {
+ return false;
+ }
+
+ int const key_type = EVP_PKEY_base_id(private_key);
+
+ switch (algorithm) {
+ case 0x0804: // rsa_pss_rsae_sha256
+ case 0x0805: // rsa_pss_rsae_sha384
+ case 0x0806: // rsa_pss_rsae_sha512
+ return key_type == EVP_PKEY_RSA;
+ case 0x0809: // rsa_pss_pss_sha256
+ case 0x080a: // rsa_pss_pss_sha384
+ case 0x080b: // rsa_pss_pss_sha512
+ return key_type == EVP_PKEY_RSA_PSS;
+ default:
+ break;
+ }
+
+#if defined(TLS1_3_VERSION)
+ if (SSL_version(ssl) >= TLS1_3_VERSION && key_type == EVP_PKEY_EC) {
+ int expected_curve = NID_undef;
+
+ switch (algorithm) {
+ case 0x0403: // ecdsa_secp256r1_sha256
+ expected_curve = NID_X9_62_prime256v1;
+ break;
+ case 0x0503: // ecdsa_secp384r1_sha384
+ expected_curve = NID_secp384r1;
+ break;
+ case 0x0603: // ecdsa_secp521r1_sha512
+ expected_curve = NID_secp521r1;
+ break;
+ case 0x081a: // ecdsa_brainpoolP256r1tls13_sha256
+ expected_curve = NID_brainpoolP256r1;
+ break;
+ case 0x081b: // ecdsa_brainpoolP384r1tls13_sha384
+ expected_curve = NID_brainpoolP384r1;
+ break;
+ case 0x081c: // ecdsa_brainpoolP512r1tls13_sha512
+ expected_curve = NID_brainpoolP512r1;
+ break;
+ default:
+ break;
+ }
+
+ if (expected_curve != NID_undef) {
+ EC_KEY const *ec_key = EVP_PKEY_get0_EC_KEY(private_key);
+
+ if (ec_key != nullptr) {
+ EC_GROUP const *group = EC_KEY_get0_group(ec_key);
+ return group != nullptr && EC_GROUP_get_curve_name(group) == expected_curve;
+ }
+ }
+ }
+#endif
+
+ return true;
+}
+#endif
+} // namespace
+
+std::string
+SSLFormatSignatureAlgorithms(swoc::MemSpan<uint16_t const> algorithms)
+{
+ std::string result;
+
+ for (uint16_t const algorithm : algorithms) {
+ if (is_grease_signature_algorithm(algorithm)) {
+ continue;
+ }
+ if (!result.empty()) {
+ result.push_back('-');
+ }
+ result.append(std::to_string(algorithm));
+ }
+
+ return result;
+}
+
+std::string
+SSLGetOfferedSignatureAlgorithms([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS
+ uint16_t const *algorithms = nullptr;
+ size_t const count = SSL_get0_peer_verify_algorithms(ssl, &algorithms);
+
+ return SSLFormatSignatureAlgorithms({algorithms, count});
+#elif HAVE_SSL_GET_SIGALGS
+ int const count = SSL_get_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
+
+ if (count <= 0) {
+ return {};
+ }
+
+ std::vector<uint16_t> algorithms;
+ algorithms.reserve(count);
+ for (int index = 0; index < count; ++index) {
+ unsigned char signature = 0;
+ unsigned char hash = 0;
+
+ if (SSL_get_sigalgs(ssl, index, nullptr, nullptr, nullptr, &signature, &hash) > 0) {
+ algorithms.push_back(static_cast<uint16_t>(hash) << 8 | signature);
+ }
+ }
+
+ return SSLFormatSignatureAlgorithms(algorithms);
+#else
+ return {};
+#endif
+}
+
+std::string
+SSLGetNegotiatedSignatureAlgorithm([[maybe_unused]] SSL *ssl)
+{
+#if HAVE_SSL_GET_SIGNATURE_ALGORITHM_USED
+ uint16_t const algorithm = SSL_get_signature_algorithm_used(ssl);
+
+ return algorithm == 0 ? "" : std::to_string(algorithm);
+#elif HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS && HAVE_SSL_GET_SHARED_SIGALGS
+ int signature_type = NID_undef;
+ int hash = NID_undef;
+
+ if (SSL_get_signature_type_nid(ssl, &signature_type) != 1 || SSL_get_signature_nid(ssl, &hash) != 1) {
+ return {};
+ }
+
+ int const count = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr);
+ for (int index = 0; index < count; ++index) {
+ int shared_signature_type = NID_undef;
+ int shared_hash = NID_undef;
+ unsigned char signature = 0;
+ unsigned char raw_hash = 0;
+
+ if (SSL_get_shared_sigalgs(ssl, index, &shared_signature_type, &shared_hash, nullptr, &signature, &raw_hash) <= 0 ||
+ shared_signature_type != signature_type || shared_hash != hash) {
+ continue;
+ }
+
+ uint16_t const algorithm = static_cast<uint16_t>(raw_hash) << 8 | signature;
+ if (signature_algorithm_matches_private_key(ssl, algorithm)) {
+ return std::to_string(algorithm);
+ }
+ }
Review Comment:
The fallback implementation for `SSLGetNegotiatedSignatureAlgorithm()` can return an incorrect TLS 1.3 signature *scheme* because `SSL_get_signature_type_nid`/`SSL_get_signature_nid` only provide (signature type, digest) and multiple TLS 1.3 schemes can map to the same pair (e.g., `rsa_pss_rsae_sha256` vs `rsa_pkcs1_sha256` on an RSA key). This means the value logged may depend on the ordering returned by `SSL_get_shared_sigalgs`, not the actual scheme used. A safer approach is to (a) return empty/\"-\" for TLS 1.3 in this fallback path when the scheme cannot be disambiguated, or (b) gate this inference to TLS 1.2 only (where the mapping is unambiguous), relying on `SSL_get_signature_algorithm_used` when available.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-5417597262
Updated cqssin documentation to explain its derived behavior. OpenSSL 3 now uses provider-based curve lookup, the fallback requires a unique compatible scheme, and the AuTest includes a P-256 ECDSA TLS 1.3 handshake.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Log TLS signature algorithms [trafficserver]
Posted by "bneradt (via GitHub) via github" <gi...@trafficserver.apache.org>.
bneradt commented on PR #13378:
URL: https://github.com/apache/trafficserver/pull/13378#issuecomment-6641814518
[approve ci urtest 3]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org