maskit commented on code in PR #14006:
URL: https://github.com/apache/trafficserver/pull/14006#discussion_r4570945260
##########
src/iocore/net/SSLSNIConfig.cc:
##########
@@ -122,6 +123,28 @@ SNIConfigParams::get_property_config(std::string_view
servername) const
return nps;
}
+/// Load the client raw public keys @a item's verify_client_rpk_ca names, for
its verify_client action.
+static bool
+load_verify_client_rpk_ca(YamlSNIConfig::Item &item)
+{
+ if (item.verify_client_rpk_ca.empty()) {
+ return true;
+ }
+#if TS_USE_RPK
+ SSLConfig::scoped_config params;
+ std::string const path =
Layout::get()->relative_to(params->serverCACertPath,
item.verify_client_rpk_ca.data());
Review Comment:
I kept `verify_client_rpk_ca` on `proxy.config.ssl.CA.cert.path`. Every
other TLS file setting resolves against a records.yaml path, including sni.yaml
`client_cert`, `client_key` and `verify_server_rpk_ca`.
`verify_client_ca_certs` is the only one that uses the configuration directory,
and PR 7130, which added it, doesn't say why. Copying it would leave the two
raw public key keys on different rules.
Both doc rows now call out that the two keys in one entry resolve against
different directories. Changing `verify_client_ca_certs` itself would break
relative paths in existing configs, so I left it out of this PR.
##########
src/iocore/net/SSLClientUtils.cc:
##########
@@ -520,6 +520,15 @@ resolve_verify_server_policy(YamlSNIConfig::Policy
txn_policy, const NextHopProp
return params->verifyServerPolicy;
}
+OriginTrustedRPK
+origin_trusted_rpk(const NextHopProperty *nps, const SSLConfigParams *params)
+{
+ if (nps != nullptr && nps->verify_server_rpk_ca != nullptr) {
+ return {nps->verify_server_rpk_ca, nps->verify_server_rpk_ca_digest};
+ }
+ return {params->clientRPKCA, params->clientRPKCADigest};
Review Comment:
I made `proxy.config.ssl.client.CA.rpk.filename` overridable, so a remap can
narrow or widen the raw public key set the same way it can the CA.
- **Precedence:** it follows the other outbound settings. A transaction's
override comes first, then the next hop's `verify_server_rpk_ca`, then the
global value. The handshake and the pool reuse check both select the set this
way.
- **Relative paths:** an override resolves against the transaction's
`proxy.config.ssl.client.CA.cert.path`.
- **Loading:** the file is read the first time a transaction names it and
kept with the TLS configuration. If it can't be loaded, no key is trusted
through it.
- **Tests:** new tests cover precedence over sni.yaml and over the global
set in both directions, the CA path, an unloadable file, and pool reuse.
##########
src/iocore/net/SSLUtils.cc:
##########
@@ -152,14 +159,91 @@ warn_client_rpk_mismatch(const char *servername)
log_msg.warning(MakeSourceLocation(), "client raw public key did not match
any trusted key for %s", servername);
}
-/// @return the client raw public keys @a ctx's entry trusts, or nullptr if it
pins none.
-static TrustedClientRPK const *
-trusted_client_rpk(SSL_CTX *ctx)
+/// @return the client credentials @a ssl's connection trusts beyond the
global X.509 settings, or
+/// nullptr if only the global X.509 trust applies and no raw public key is
accepted.
+static ClientTrust const *
+client_trust(const SSL *ssl)
{
- return static_cast<TrustedClientRPK const *>(SSL_CTX_get_ex_data(ctx,
ssl_client_rpk_ca_index));
+ if (ssl_client_trust_index < 0) {
+ return nullptr;
+ }
+ return static_cast<ClientTrust const *>(SSL_get_ex_data(ssl,
ssl_client_trust_index));
+}
+
+/// @return the raw public keys a client of @a ssl's connection may present,
or nullptr if it may present none.
+static SSLRPKUtils::TrustedKeySet const *
+trusted_client_rpk(const SSL *ssl)
+{
+ auto const *trust = client_trust(ssl);
+
+ return trust != nullptr ? trust->rpk_keys.get() : nullptr;
+}
+
+/// Drop the client trust @a ssl's connection was given. @return false if it
could not be dropped.
+static bool
+clear_client_trust(SSL *ssl)
+{
+ auto *trust = client_trust(ssl);
+
+ if (trust == nullptr) {
+ return true;
+ }
+ if (!SSL_set_ex_data(ssl, ssl_client_trust_index, nullptr)) {
+ SSLError("failed to drop the client trust of the connection");
+ return false;
+ }
+ delete trust;
+ return true;
+}
+
+/// For a connection that no sni.yaml verify_client action gave its own trust,
pin client raw public
+/// keys against those proxy.config.ssl.CA.rpk.filename names, as an X.509
client certificate falls
+/// back to proxy.config.ssl.CA.cert.filename. @return false if the set could
not be attached.
+static bool
+pin_client_rpk_to_global_set(SSL *ssl)
+{
+ // Nothing is attached where no client credential is requested, which spares
the allocation.
+ if (client_trust(ssl) != nullptr || (SSL_get_verify_mode(ssl) &
SSL_VERIFY_PEER) == 0) {
+ return true;
+ }
+
+ SSLConfig::scoped_config params;
+
+ if (params->serverRPKCA == nullptr) {
+ return true;
+ }
+ return setClientTrust(ssl, params->serverRPKCA, params->serverRPKCADigest,
true);
}
#endif
+bool
+setClientTrust([[maybe_unused]] SSL *ssl, std::shared_ptr<const
SSLRPKUtils::TrustedKeySet> rpk_keys,
+ [[maybe_unused]] std::string_view rpk_digest, [[maybe_unused]]
bool x509)
+{
+#if TS_USE_RPK
+ if (ssl_client_trust_index < 0) {
+ SSLError("failed to reserve an ex_data index for the client trust of a
connection");
+ return false;
+ }
+
+ auto holder =
std::make_unique<ClientTrust>(ClientTrust{std::move(rpk_keys),
std::string{rpk_digest}, x509});
Review Comment:
Done. Each sni.yaml entry, and the global setting, now builds one immutable,
reference-counted `ClientTrust` when the configuration loads. A handshake only
takes a reference to it, with no allocation and no digest copy.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]