Skip to content

eBPF-based security platform

Add opt-in classical TLS for named hosts

Michi Mutsuzaki3e79c08a5c27
diff --git a/Documentation/architecture.rst b/Documentation/architecture.rst
index f195b6ba..208e2524 100644
--- a/Documentation/architecture.rst
+++ b/Documentation/architecture.rst
@@ -642,9 +642,19 @@ format specification's companion section below.
Registry access honours ``BPM_OCI_SCHEME``, ``BPM_OCI_CA_FILE``,
``BPM_OCI_USERNAME``/``BPM_OCI_PASSWORD``, ``REGISTRY_AUTH_FILE`` and
``DOCKER_CONFIG``. Every libcurl client in shirudo speaks TLS 1.3 with
-a hybrid ML-KEM key exchange only (X25519MLKEM768, SecP256r1MLKEM768);
-there is no classical fallback. The registry is untrusted: it can
-withhold or replay a signed publication, it cannot forge one.
+a hybrid ML-KEM key exchange by default (X25519MLKEM768,
+SecP256r1MLKEM768). ``tls.classical_hosts`` in
+``/etc/shirudo/shirudo.conf`` opts exact HTTPS DNS names into classical
+key exchange, for example ``ghcr.io,quay.io``. Operator commands read
+this key from the root-managed host config; target commands read it only
+from the immutable runtime image's config. The list rejects wildcards
+and IP addresses, and redirects are checked against each destination
+host. TLS 1.3 and certificate verification remain unchanged. Shirudo
+warns if an opted-in connection negotiates a non-hybrid group. An empty
+list requires hybrid exchange everywhere. A classical exception
+weakens transport confidentiality for that host, but signed publications
+remain authenticated and cannot be forged by the registry, which can
+still withhold or replay them.
Tree publication format. The ``stable`` manifest has two layers, the
publication and its detached CMS signature. The publication is::
diff --git a/Documentation/config-images.rst b/Documentation/config-images.rst
index 82aff48b..cd70df7e 100644
--- a/Documentation/config-images.rst
+++ b/Documentation/config-images.rst
@@ -97,10 +97,18 @@ certificate inside the image. Other absolute paths and traversal are refused.
Tree publications are verified against the runtime image's initial BPF
certificate. Repository indexes use their configured repository certificate.
-The initial BPF certificate and TPM configuration belong in the runtime
-image. Config settings that try to override bootstrap settings are refused.
-Unknown settings, invalid values and inconsistent export limits are rejected
-before the config PCR is extended.
+The initial BPF certificate, TPM configuration and
+``tls.classical_hosts`` policy belong in the runtime image's
+``etc/shirudo/shirudo.conf``. For example::
+
+ tls.classical_hosts = ghcr.io,quay.io
+
+The target reads this policy from the immutable runtime image; operator
+commands read it from the root-managed host config. The updateable config
+image cannot set or change ``tls.classical_hosts``. More generally, attempts
+to override settings owned by the runtime bootstrap are rejected. Shirudo
+rejects these and other invalid config images before extending the config
+PCR.
Config images must not contain symbolic links or special files.
Writable state still includes downloaded upatch archives, repository
diff --git a/Documentation/getting-started.rst b/Documentation/getting-started.rst
index e0c473db..53e5ac38 100644
--- a/Documentation/getting-started.rst
+++ b/Documentation/getting-started.rst
@@ -408,8 +408,16 @@ the initrd and the anchor. Neither command needs the other machine.
Registry fetch failures
Check the ``oci://`` endpoint, the ``BPM_OCI_*`` environment, the
certificate registered under ``/etc/shirudo/bpm``, and that the
- registry offers TLS 1.3 with a hybrid ML-KEM group; shirudo never
- falls back to classical TLS.
+ registry offers TLS 1.3 with a hybrid ML-KEM group. For registries
+ that do not, add their exact hostnames as a comma-separated list in
+ ``tls.classical_hosts`` in ``/etc/shirudo/shirudo.conf`` on the
+ operator. For a target, the
+ setting must be in the immutable runtime image's config. This does
+ not change certificate verification, but permits classical key
+ exchange with no post-quantum confidentiality. Hybrid-only policy
+ remains active for every other host::
+
+ tls.classical_hosts = ghcr.io,quay.io
The `operations <operations.rst>`__ guide has the full table of
categories with the action for each, and the recovery procedures.
diff --git a/Documentation/requirements.rst b/Documentation/requirements.rst
index 0415cc8a..238ea11f 100644
--- a/Documentation/requirements.rst
+++ b/Documentation/requirements.rst
@@ -316,11 +316,12 @@ since the libguestfs appliance resolves names through DNS alone.
holds the public key in the frozen identity map to provision the TPM with
for each session.
* - TLS (registries, OTLP and S3 export)
- - TLS 1.3 only with hybrid ML-KEM key exchange only
- (X25519MLKEM768, SecP256r1MLKEM768), on every libcurl client in
- both profiles. A server that offers only classical groups is
- refused; there is no fallback. Server certificates are whatever
- the registry or collector presents.
+ - TLS 1.3 on every libcurl client in both profiles. Hybrid ML-KEM
+ groups (X25519MLKEM768, SecP256r1MLKEM768) are required unless
+ an exact host is opted in through ``tls.classical_hosts`` in the
+ root-managed operator config or immutable target runtime config.
+ The exception does not change certificate verification. Server
+ certificates are whatever the registry or collector presents.
4) Operator host
----------------
diff --git a/Documentation/telemetry.rst b/Documentation/telemetry.rst
index c8ccde5c..1f292746 100644
--- a/Documentation/telemetry.rst
+++ b/Documentation/telemetry.rst
@@ -279,9 +279,12 @@ compresses the body.
TLS. Like every libcurl client in shirudo, the exporter speaks TLS 1.3
with a hybrid ML-KEM key exchange only (X25519MLKEM768,
-SecP256r1MLKEM768); a collector that offers only classical groups is
-refused. ``OTEL_EXPORTER_OTLP_CERTIFICATE`` names a CA bundle,
-``OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE`` and
+SecP256r1MLKEM768) by default; a collector that offers only classical
+groups is refused unless its exact DNS hostname is listed in
+``tls.classical_hosts`` in the immutable runtime config. See the BPM
+transport notes for the format and scope of that opt-in.
+``OTEL_EXPORTER_OTLP_CERTIFICATE``
+names a CA bundle; ``OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE`` and
``OTEL_EXPORTER_OTLP_CLIENT_KEY`` a client certificate for mutual TLS.
Cleartext ``http://`` is allowed only to loopback. ``--otel-insecure``
(``map_export.otel_insecure``) permits cleartext to other hosts and
@@ -375,9 +378,12 @@ pipeline that lands logs and metrics in ClickHouse and Splunk::
processors: [batch]
exporters: [clickhouse, splunk_hec]
-The collector must offer a hybrid ML-KEM group; Go's TLS stack, which
-the collector uses, enables X25519MLKEM768 by default since Go 1.24.
-Terminate TLS in a proxy that does if a build cannot.
+Go's TLS stack, which the collector uses, enables X25519MLKEM768 by
+default since Go 1.24. If using the classical-host setting, the
+collector hostname must be listed explicitly in the runtime image; the
+transport then lacks
+post-quantum confidentiality. Otherwise, terminate TLS in a proxy that
+offers a hybrid group if a build cannot.
ClickHouse. The ``clickhouse`` exporter stores each log record with
its ``Body``, ``SeverityNumber``, ``ResourceAttributes`` and
diff --git a/Documentation/threat-model.rst b/Documentation/threat-model.rst
index fb6fbd2f..ad8c5a48 100644
--- a/Documentation/threat-model.rst
+++ b/Documentation/threat-model.rst
@@ -317,8 +317,12 @@ T7 The delivery path
in that signed index; a tree publication is signed, carries
per-operation digests and sequence continuity, and a ``delete`` is
accepted only for an id loaded from the same tree. TLS is 1.3 with
- hybrid ML-KEM only, so the transport is not the weak link even
- though it is not the trust anchor.
+ hybrid ML-KEM by default. ``tls.classical_hosts`` in operator or
+ immutable target runtime config can opt exact HTTPS DNS hosts into
+ classical key exchange; for those hosts,
+ transport confidentiality is not post-quantum. Certificate checks
+ and signed artifact verification remain in force, but a registry can
+ still withhold or replay signed data.
T8 Quantum-capable adversaries against the trust anchor
Signing is ML-DSA-87 (FIPS 204) only: ``genkey`` makes nothing else,
@@ -515,9 +519,12 @@ Each of these is known, documented and bounded; none is silent.
9. Classical pieces outside the boundary: WebPKI server certificates
on registries and collectors (they authenticate the transport, not
- the artifacts), and the attestation key, which is ECDSA P-256
- because TPMs sign with nothing post-quantum today. The evidence is
- therefore classical even though the artifacts it describes are not.
+ the artifacts); transport confidentiality for any host opted into
+ ``tls.classical_hosts``; and the attestation key, which is
+ ECDSA P-256 because TPMs sign with nothing post-quantum today. For
+ an opted-in host, recorded traffic may be exposed to a future
+ quantum-capable adversary. The evidence is therefore classical
+ even though the artifacts it describes are not.
10. Endorsement key trust. Credential activation ties the attestation
key to the endorsement key in the evidence, and the endorsement
diff --git a/Documentation/upatch.rst b/Documentation/upatch.rst
index ea77523d..43f7fca4 100644
--- a/Documentation/upatch.rst
+++ b/Documentation/upatch.rst
@@ -428,8 +428,22 @@ the version with other digests is refused, so a published version
cannot be replaced. Credentials and transport come from
``BPM_OCI_USERNAME`` and ``BPM_OCI_PASSWORD``, ``REGISTRY_AUTH_FILE``
or ``DOCKER_CONFIG``, ``BPM_OCI_CA_FILE`` for a private CA and
-``BPM_OCI_SCHEME=http`` for a cleartext local registry; TLS is 1.3 with
-hybrid ML-KEM key exchange only.
+``BPM_OCI_SCHEME=http`` for a cleartext local registry. HTTPS uses TLS
+1.3 and hybrid ML-KEM key exchange by default. To use a registry that
+does not support hybrid groups, set ``tls.classical_hosts`` to an exact,
+comma-separated DNS hostname list in the operator's root-managed
+``/etc/shirudo/shirudo.conf``. For target pulls, put the key in the
+immutable runtime image's ``etc/shirudo/shirudo.conf``; updateable config
+images cannot set it. For example::
+
+ tls.classical_hosts = ghcr.io,quay.io
+
+Wildcards and IP addresses are rejected, and each redirect destination
+must be listed separately. This setting does not change certificate
+verification; shirudo warns if the negotiated group is not one of the
+advertised hybrid groups. It applies to all shirudo libcurl clients,
+including OTLP and S3. Classical key exchange does not provide
+post-quantum transport confidentiality.
The upatch tree
~~~~~~~~~~~~~~~
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 9a15bbe0..eab00eb6 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -128,7 +128,7 @@ INCLUDES := \
-I$(BPF_UAPI_INCLUDE)
CFLAGS := $(CFLAGS_BASE) $(INCLUDES) \
- $(LIBCRYPTO_CFLAGS) $(TSS2_CFLAGS) \
+ $(LIBSSL_CFLAGS) $(LIBCRYPTO_CFLAGS) $(TSS2_CFLAGS) \
$(LIBELF_CFLAGS) $(ZLIB_CFLAGS) $(LIBCURL_CFLAGS) \
$(CRYPTO_CFLAGS)
@@ -138,7 +138,7 @@ STATIC_LIBS = \
$(LIBBPF_A)
DYNAMIC_LIBS := \
- $(LIBCRYPTO_LIBS) -lssl $(TSS2_LIBS) \
+ $(LIBSSL_LIBS) $(LIBCRYPTO_LIBS) $(TSS2_LIBS) \
$(LIBELF_LIBS) $(ZLIB_LIBS) $(LIBCURL_LIBS)
CFLAGS += $(LUAJIT_CFLAGS) -DSHIRUDO_HAVE_LUAJIT
diff --git a/builtin-config.c b/builtin-config.c
index c474f861..ad723747 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -113,6 +113,13 @@ int cmd_config(int argc, const char **argv)
printf("# tpm.tcti = (unset -- using device:/dev/tpmrm0)\n\n");
}
+ printf("# Exact DNS hosts that may use classical TLS key exchange.\n"
+ "# Targets honor this only from the immutable runtime image;\n"
+ "# operators use the root-managed /etc/shirudo/shirudo.conf.\n"
+ "# Leave empty for hybrid-only TLS.\n");
+ printf("tls.classical_hosts = %s\n\n",
+ cfg.tls_classical_hosts);
+
printf("# Periodic `shirudo upatch map --all` export. Empty JSON and\n"
"# OTLP destinations leave the installed timer idle. Every emitted\n"
"# map must carry a signed Lua decoder declaring log or metric.\n"
@@ -132,5 +139,5 @@ int cmd_config(int argc, const char **argv)
printf("map_export.otlp_max_bytes = %u\n",
cfg.map_export_otlp_max_bytes);
- return cfg.map_export_valid ? 0 : 1;
+ return cfg.map_export_valid && cfg.tls_classical_hosts_valid ? 0 : 1;
}
diff --git a/util/config.c b/util/config.c
index e87d8372..ba5d46f1 100644
--- a/util/config.c
+++ b/util/config.c
@@ -62,10 +62,93 @@ static bool set_string(char *dst, size_t cap, const char *val)
return strscpy(dst, val, cap) >= 0;
}
+static bool numeric_dns_label(const char *label, size_t len)
+{
+ size_t i = 0;
+ bool hex = len > 2 && label[0] == '0' &&
+ (label[1] == 'x' || label[1] == 'X');
+
+ if (!len)
+ return false;
+ if (hex)
+ i = 2;
+ for (; i < len; i++) {
+ __u8 c = label[i];
+
+ if (c >= '0' && c <= '9')
+ continue;
+ if (hex && ((c >= 'a' && c <= 'f') ||
+ (c >= 'A' && c <= 'F')))
+ continue;
+ return false;
+ }
+ return !hex || i > 2;
+}
+
+static bool tls_dns_name_valid(const char *name)
+{
+ size_t len = strlen(name), label_len = 0, label_start = 0;
+ bool numeric_address = true;
+ size_t i;
+
+ if (!len || len > 253)
+ return false;
+ for (i = 0; i < len; i++) {
+ __u8 c = name[i];
+
+ if (c == '.') {
+ if (!label_len || label_len > 63 || name[i - 1] == '-')
+ return false;
+ if (!numeric_dns_label(name + label_start, label_len))
+ numeric_address = false;
+ label_start = i + 1;
+ label_len = 0;
+ continue;
+ }
+ if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || c == '-') ||
+ (!label_len && c == '-'))
+ return false;
+ label_len++;
+ }
+ if (!label_len || label_len > 63 || name[len - 1] == '-')
+ return false;
+ if (!numeric_dns_label(name + label_start, label_len))
+ numeric_address = false;
+ return !numeric_address;
+}
+
+static bool tls_classical_hosts_valid(const char *value)
+{
+ const char *host = value;
+
+ if (!*value)
+ return true;
+ while (*host) {
+ const char *end = strchr(host, ',');
+ size_t len = end ? (size_t)(end - host) : strlen(host);
+ char name[254];
+
+ if (!len || len >= sizeof(name))
+ return false;
+ memcpy(name, host, len);
+ name[len] = '\0';
+ if (!tls_dns_name_valid(name))
+ return false;
+ if (!end)
+ break;
+ host = end + 1;
+ if (!*host)
+ return false;
+ }
+ return true;
+}
+
static void config_defaults(struct shirudo_config *cfg)
{
*cfg = (struct shirudo_config){};
cfg->map_export_valid = true;
+ cfg->tls_classical_hosts_valid = true;
cfg->map_export_otel_retries = 3;
cfg->map_export_log_record_max_bytes = SHIRUDO_MAP_EXPORT_LOG_RECORD_MAX_DEFAULT;
cfg->map_export_otlp_max_bytes = SHIRUDO_MAP_EXPORT_OTLP_MAX_DEFAULT;
@@ -173,6 +256,14 @@ int config_load_path(struct shirudo_config *cfg, const char *path)
else
strscpy(cfg->tpm_tcti, val,
sizeof(cfg->tpm_tcti));
+ } else if (strcmp(key, "tls.classical_hosts") == 0) {
+ if (!set_string(cfg->tls_classical_hosts,
+ sizeof(cfg->tls_classical_hosts), val) ||
+ !tls_classical_hosts_valid(val)) {
+ cfg->tls_classical_hosts_valid = false;
+ pr_warn("config: tls.classical_hosts: invalid exact "
+ "DNS host list");
+ }
} else if (strcmp(key, "map_export.json_path") == 0) {
if (!set_string(cfg->map_export_json_path,
sizeof(cfg->map_export_json_path), val))
@@ -228,9 +319,13 @@ int config_load_path(struct shirudo_config *cfg, const char *path)
} else {
if (strncmp(key, "map_export.", 11) == 0)
map_export_bad(cfg, key, val, "unknown key");
- else
+ else if (strncmp(key, "tls.", 4) == 0) {
+ cfg->tls_classical_hosts_valid = false;
+ pr_warn("config: %s: unknown TLS setting", key);
+ } else {
pr_warn("config: unknown key '%s' (ignored)",
key);
+ }
}
}
if (ferror(f) && !rc)
diff --git a/util/config.h b/util/config.h
index 974ca8e7..f5638651 100644
--- a/util/config.h
+++ b/util/config.h
@@ -17,6 +17,7 @@
#define SHIRUDO_OWNER_AUTH_MAX 256
#define SHIRUDO_TPM_TCTI_MAX 256
+#define SHIRUDO_TLS_HOSTS_MAX 1024
#define SHIRUDO_MAP_EXPORT_PATH_MAX 4096
#define SHIRUDO_MAP_EXPORT_ENDPOINT_MAX 2048
#define SHIRUDO_MAP_EXPORT_URI_MAX 2048
@@ -36,6 +37,9 @@ struct shirudo_config {
* overrides it.
*/
char tpm_tcti[SHIRUDO_TPM_TCTI_MAX];
+ /* Exact DNS names that may negotiate classical TLS key exchange. */
+ bool tls_classical_hosts_valid;
+ char tls_classical_hosts[SHIRUDO_TLS_HOSTS_MAX];
/* Empty sinks are idle. */
bool map_export_valid;
char map_export_json_path[SHIRUDO_MAP_EXPORT_PATH_MAX];
diff --git a/util/crypto.h b/util/crypto.h
index 7d4aa1ea..7f25fc5c 100644
--- a/util/crypto.h
+++ b/util/crypto.h
@@ -70,11 +70,13 @@ void tls_ca_cleanup(struct shirudo_tls_ca *ca);
/*
* shirudo's TLS policy for every libcurl handle it opens: TLS 1.3 only
- * and hybrid ML-KEM key exchange only (X25519MLKEM768, with the P-256
- * hybrid as fallback), so neither a version downgrade nor a classical
- * group can be negotiated. ca may be NULL; otherwise it is the extra
- * trust anchor fed to the SSL_CTX callback. Returns 0 or a negative
- * errno; callers must not connect when it fails.
+ * and hybrid ML-KEM key exchange by default. Exact hosts in
+ * tls.classical_hosts may also negotiate classical groups, from the
+ * immutable runtime config on targets or root-managed host config on
+ * operator commands. This setting does not change certificate
+ * verification. ca may be NULL; otherwise it
+ * is the extra trust anchor fed to the SSL_CTX callback. Returns 0 or a
+ * negative errno; callers must not connect when it fails.
*/
int tls_curl_policy(CURL *curl, struct shirudo_tls_ca *ca);
diff --git a/util/image_config.c b/util/image_config.c
index 1b64d900..fcf73c2a 100644
--- a/util/image_config.c
+++ b/util/image_config.c
@@ -210,7 +210,8 @@ int shirudo_image_config_validate(int root_fd)
rc = -ENAMETOOLONG;
if (!rc) {
rc = config_load_path(&candidate, path);
- if (!rc && !candidate.map_export_valid)
+ if (!rc && (!candidate.map_export_valid ||
+ !candidate.tls_classical_hosts_valid))
rc = -EINVAL;
explicit_bzero(&candidate, sizeof(candidate));
}
@@ -239,7 +240,8 @@ int shirudo_image_config_set(const struct shirudo_config *bootstrap,
return -ENAMETOOLONG;
}
rc = config_load_path(&candidate, path);
- if (rc || !candidate.map_export_valid) {
+ if (rc || !candidate.map_export_valid ||
+ !candidate.tls_classical_hosts_valid) {
close(fd);
return rc ? rc : -EINVAL;
}
@@ -248,6 +250,11 @@ int shirudo_image_config_set(const struct shirudo_config *bootstrap,
candidate.tpm_owner_auth_len = bootstrap->tpm_owner_auth_len;
memcpy(candidate.tpm_tcti, bootstrap->tpm_tcti,
sizeof(candidate.tpm_tcti));
+ memcpy(candidate.tls_classical_hosts,
+ bootstrap->tls_classical_hosts,
+ sizeof(candidate.tls_classical_hosts));
+ candidate.tls_classical_hosts_valid =
+ bootstrap->tls_classical_hosts_valid;
}
if (config_fd >= 0)
close(config_fd);
diff --git a/util/tls_openssl.c b/util/tls_openssl.c
index 4c9d8e7c..c0dc3840 100644
--- a/util/tls_openssl.c
+++ b/util/tls_openssl.c
@@ -7,24 +7,170 @@
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
+#include <string.h>
+#include <strings.h>
#include <unistd.h>
+#include <curl/curl.h>
+
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
+#include <shirudo/misc.h>
+
+#include "config.h"
#include "crypto.h"
+#include "image_config.h"
#include "io.h"
+#include "log.h"
+
+/* Hybrid-first exception list; default policy below remains hybrid-only. */
+#define SHIRUDO_TLS_GROUPS "*X25519MLKEM768:SecP256r1MLKEM768"
+#define SHIRUDO_TLS_CLASSICAL_GROUPS \
+ "*X25519MLKEM768:SecP256r1MLKEM768:X25519:secp256r1"
+
+static bool numeric_dns_label(const char *label, size_t len)
+{
+ size_t i = 0;
+ bool hex = len > 2 && label[0] == '0' &&
+ (label[1] == 'x' || label[1] == 'X');
+
+ if (!len)
+ return false;
+ if (hex)
+ i = 2;
+ for (; i < len; i++) {
+ __u8 c = label[i];
+
+ if (c >= '0' && c <= '9')
+ continue;
+ if (hex && ((c >= 'a' && c <= 'f') ||
+ (c >= 'A' && c <= 'F')))
+ continue;
+ return false;
+ }
+ return !hex || i > 2;
+}
+
+static bool valid_dns_name(const char *name)
+{
+ size_t len = strlen(name), label_len = 0, label_start = 0;
+ bool numeric_address = true;
+ size_t i;
+
+ if (!len || len > 253)
+ return false;
+ for (i = 0; i < len; i++) {
+ __u8 c = name[i];
+
+ if (c == '.') {
+ if (!label_len || label_len > 63 || name[i - 1] == '-')
+ return false;
+ if (!numeric_dns_label(name + label_start, label_len))
+ numeric_address = false;
+ label_start = i + 1;
+ label_len = 0;
+ continue;
+ }
+ if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') || c == '-') ||
+ (!label_len && c == '-'))
+ return false;
+ label_len++;
+ }
+ if (!label_len || label_len > 63 || name[len - 1] == '-')
+ return false;
+ if (!numeric_dns_label(name + label_start, label_len))
+ numeric_address = false;
+ return !numeric_address;
+}
/*
- * Hybrid ML-KEM only: X25519MLKEM768 with a key share, the P-256 hybrid
- * as the HelloRetryRequest fallback, and no classical group at all, so
- * a server without ML-KEM gets a handshake failure rather than a
- * classical key exchange. Both names exist in OpenSSL 3.5+.
+ * Exceptions are exact DNS names from the active HTTPS URL. This also
+ * checks redirected URLs, so each registry host must be opted in itself.
*/
-#define SHIRUDO_TLS_GROUPS "*X25519MLKEM768:SecP256r1MLKEM768"
+static bool tls_classical_host_allowed(CURL *curl)
+{
+ struct shirudo_config cfg = {};
+ const char *allowlist, *effective_url;
+ CURLU *url = NULL;
+ char *scheme = NULL, *host = NULL;
+ size_t host_len;
+ bool allowed = false;
+
+ if (!shirudo_image_config_get(&cfg) && config_load(&cfg))
+ return false;
+ if (!cfg.tls_classical_hosts_valid ||
+ !cfg.tls_classical_hosts[0])
+ return false;
+ allowlist = cfg.tls_classical_hosts;
+ if (curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url) !=
+ CURLE_OK ||
+ !effective_url)
+ return false;
+ url = curl_url();
+ if (!url || curl_url_set(url, CURLUPART_URL, effective_url, 0) !=
+ CURLUE_OK ||
+ curl_url_get(url, CURLUPART_SCHEME, &scheme, 0) != CURLUE_OK ||
+ strcasecmp(scheme, "https") ||
+ curl_url_get(url, CURLUPART_HOST, &host, 0) != CURLUE_OK)
+ goto out;
+ host_len = strlen(host);
+ if (host_len && host[host_len - 1] == '.')
+ host[--host_len] = '\0';
+ if (!valid_dns_name(host))
+ goto out;
+
+ while (*allowlist) {
+ const char *end = strchr(allowlist, ',');
+ size_t len = end ? (size_t)(end - allowlist) : strlen(allowlist);
+ char entry[254];
+
+ if (len < sizeof(entry)) {
+ memcpy(entry, allowlist, len);
+ entry[len] = '\0';
+ if (valid_dns_name(entry) && !strncasecmp(host, entry, len) &&
+ host_len == len) {
+ allowed = true;
+ break;
+ }
+ }
+ if (!end)
+ break;
+ allowlist = end + 1;
+ }
+out:
+ if (host)
+ curl_free(host);
+ if (scheme)
+ curl_free(scheme);
+ if (url)
+ curl_url_cleanup(url);
+ return allowed;
+}
+
+static void shirudo_tls_info_callback(const SSL *ssl, int where, int ret)
+{
+ const char *group, *host;
+ int group_id;
+
+ (void)ret;
+ if (!(where & SSL_CB_HANDSHAKE_DONE))
+ return;
+ group_id = SSL_get_negotiated_group((SSL *)ssl);
+ group = group_id == NID_undef ? NULL :
+ SSL_group_to_name((SSL *)ssl, group_id);
+ if (group && (!strcasecmp(group, "X25519MLKEM768") ||
+ !strcasecmp(group, "SecP256r1MLKEM768")))
+ return;
+ host = SSL_get_servername((SSL *)ssl, TLSEXT_NAMETYPE_host_name);
+ pr_warn("TLS non-hybrid key exchange with %s: %s",
+ host ? host : "unknown host", group ? group : "unknown group");
+}
void tls_ca_cleanup(struct shirudo_tls_ca *ca)
{
@@ -39,11 +185,20 @@ static CURLcode shirudo_sslctx_callback(CURL *curl, void *sslctx, void *userptr)
SSL_CTX *ctx = sslctx;
X509 *cert;
BIO *bio;
+ const char *groups = SHIRUDO_TLS_GROUPS;
int fd;
- (void)curl;
+ if (tls_classical_host_allowed(curl)) {
+ /* Keep this per-host policy from leaking through libcurl reuse. */
+ if (curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L) != CURLE_OK ||
+ curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L) !=
+ CURLE_OK)
+ return CURLE_SSL_CONNECT_ERROR;
+ groups = SHIRUDO_TLS_CLASSICAL_GROUPS;
+ SSL_CTX_set_info_callback(ctx, shirudo_tls_info_callback);
+ }
if (SSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION) != 1 ||
- SSL_CTX_set1_groups_list(ctx, SHIRUDO_TLS_GROUPS) != 1) {
+ SSL_CTX_set1_groups_list(ctx, groups) != 1) {
ERR_clear_error();
return CURLE_SSL_CIPHER;
}