bneradt commented on code in PR #14006:
URL: https://github.com/apache/trafficserver/pull/14006#discussion_r4568102325
##########
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:
Since the goal is to configure RPK trust the same way as X.509:
`verify_client_ca_certs` resolves a relative path against the config dir
(`RecConfigReadConfigDir()` in YamlSNIConfig.cc), while `verify_client_rpk_ca`
resolves against `proxy.config.ssl.CA.cert.path`. The new test even has to
write the two differently. Two sibling keys in the same sni.yaml entry with
different base directories is an easy trap. Since neither RPK key has shipped
yet, this seems like the time to pick one rule; matching
`verify_client_ca_certs` within sni.yaml seems least surprising, though I can
see the argument for mirroring the records.yaml pairing instead. Either way, it
would help for the docs of both keys to call out the difference explicitly.
##########
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:
Minor: this heap-allocates a `ClientTrust` and copies the 64-byte digest
string on every handshake that hits a `verify_client_ca_certs` host (with RPK
builds, even if no raw public key is configured anywhere) and on every verified
handshake under the global set. Since the keys and digest are immutable once
loaded, holding a `shared_ptr<const>` to one `{keys, digest}` object built at
load time would reduce this to a refcount bump plus the `x509` flag. Not
blocking.
##########
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:
X.509 lets a remap rule narrow outbound trust per transaction via the
overridable `proxy.config.ssl.client.CA.cert.filename`, but
`proxy.config.ssl.client.CA.rpk.filename` is not overridable, so an origin
narrowed that way still accepts any key from the global RPK set. Since the docs
already note that any key in this set authenticates every origin without its
own `verify_server_rpk_ca`, I think this is worth either making the record
overridable, or stating in the records.yaml docs that a per-transaction CA
override does not narrow the RPK set (only sni.yaml `verify_server_rpk_ca`
does).
--
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]