|
42 | 42 | #include "tscore/ink_config.h" |
43 | 43 | #include "tscore/Layout.h" |
44 | 44 | #include "records/RecHttp.h" |
| 45 | +#include "records/RecCore.h" |
45 | 46 |
|
46 | 47 | #include <openssl/pem.h> |
| 48 | +#include <array> |
47 | 49 | #include <cstring> |
48 | 50 | #include <cmath> |
| 51 | +#include <unordered_map> |
49 | 52 |
|
50 | 53 | int SSLConfig::config_index = 0; |
51 | 54 | int SSLConfig::configids[] = {0, 0}; |
@@ -89,6 +92,80 @@ DbgCtl dbg_ctl_ssl_client_ctx{"ssl_client_ctx"}; |
89 | 92 |
|
90 | 93 | } // end anonymous namespace |
91 | 94 |
|
| 95 | +/** Determines the SSL session cache configuration value using a priority-based selection scheme. |
| 96 | + * |
| 97 | + * This function resolves the SSL session cache configuration by evaluating multiple potential |
| 98 | + * configuration sources and selecting the one with the highest priority. The priority calculation |
| 99 | + * combines two factors: |
| 100 | + * |
| 101 | + * Configuration Name Priority (base priority): |
| 102 | + * - `proxy.config.ssl.session_cache.mode`: 3 (highest preference) |
| 103 | + * - `proxy.config.ssl.session_cache.value`: 2 (medium preference) |
| 104 | + * - `proxy.config.ssl.session_cache.enabled`: 1 (lowest preference) |
| 105 | + * |
| 106 | + * Configuration Source Priority (added to base priority): |
| 107 | + * - Environment variable (`REC_SOURCE_ENV`): +0x30 (highest precedence) |
| 108 | + * - Explicit configuration (`REC_SOURCE_EXPLICIT`): +0x20 (config file, API) |
| 109 | + * - Plugin default (`REC_SOURCE_PLUGIN`): +0x10 (plugin-supplied) |
| 110 | + * - Built-in default (`REC_SOURCE_DEFAULT`): +0x00 (lowest precedence) |
| 111 | + * |
| 112 | + * Priority Calculation: |
| 113 | + * `total_priority = base_priority + source_priority` |
| 114 | + * |
| 115 | + * Examples: |
| 116 | + * - `mode` set via environment variable: 3 + 0x30 = 0x33 (highest possible) |
| 117 | + * - `mode` set explicitly in config: 3 + 0x20 = 0x23 |
| 118 | + * - `value` set via environment variable: 2 + 0x30 = 0x32 |
| 119 | + * - `enabled` set explicitly in config: 1 + 0x20 = 0x21 |
| 120 | + * |
| 121 | + * The configuration with the highest total priority is selected. This ensures that: |
| 122 | + * 1. Environment variables always override other sources. |
| 123 | + * 2. Among configurations from the same source, `mode` > `value` > `enabled`. |
| 124 | + * 3. Explicit configuration overrides plugin defaults and built-in defaults. |
| 125 | + * |
| 126 | + * @return The SSL session cache mode value. |
| 127 | + */ |
| 128 | +static int |
| 129 | +get_ssl_session_cache_config() |
| 130 | +{ |
| 131 | + struct ConfigOption { |
| 132 | + const char *name; ///< Configuration parameter name (e.g., "proxy.config.ssl.session_cache.mode"). |
| 133 | + int value; ///< The configured value if explicitly set. |
| 134 | + int priority; ///< The inherit priority of the config name, higher is more preferred. |
| 135 | + }; |
| 136 | + |
| 137 | + /// The priority of the source. Higher is more preferred. |
| 138 | + std::unordered_map<int, int> source_priorities = { |
| 139 | + {REC_SOURCE_ENV, 0x30}, |
| 140 | + {REC_SOURCE_EXPLICIT, 0x20}, |
| 141 | + {REC_SOURCE_PLUGIN, 0x10}, |
| 142 | + {REC_SOURCE_DEFAULT, 0x0 }, |
| 143 | + {REC_SOURCE_NULL, 0x0 }, // For completeness, no record should have this set. |
| 144 | + }; |
| 145 | + |
| 146 | + std::array<ConfigOption, 3> configs = { |
| 147 | + { |
| 148 | + {"proxy.config.ssl.session_cache.mode", 0, 0x3}, |
| 149 | + {"proxy.config.ssl.session_cache.value", 0, 0x2}, |
| 150 | + {"proxy.config.ssl.session_cache.enabled", 0, 0x1}, |
| 151 | + } |
| 152 | + }; |
| 153 | + |
| 154 | + // Loop over the config names, updating their priority score per their source. |
| 155 | + auto *highest_priority_config = &configs[0]; |
| 156 | + for (auto &config : configs) { |
| 157 | + RecSourceT source; |
| 158 | + if (RecGetRecordSource(config.name, &source) == REC_ERR_OKAY) { |
| 159 | + config.priority += source_priorities[source]; |
| 160 | + config.value = RecGetRecordInt(config.name).value_or(0); |
| 161 | + if (config.priority > highest_priority_config->priority) { |
| 162 | + highest_priority_config = &config; |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + return highest_priority_config->value; |
| 167 | +} |
| 168 | + |
92 | 169 | SSLConfigParams::SSLConfigParams() |
93 | 170 | { |
94 | 171 | ink_mutex_init(&ctxMapLock); |
@@ -452,7 +529,8 @@ SSLConfigParams::initialize() |
452 | 529 | // SSL session cache configurations |
453 | 530 | ssl_origin_session_cache = RecGetRecordInt("proxy.config.ssl.origin_session_cache.enabled").value_or(0); |
454 | 531 | ssl_origin_session_cache_size = RecGetRecordInt("proxy.config.ssl.origin_session_cache.size").value_or(0); |
455 | | - ssl_session_cache = RecGetRecordInt("proxy.config.ssl.session_cache.value").value_or(0); |
| 532 | + ssl_session_cache = get_ssl_session_cache_config(); |
| 533 | + |
456 | 534 | ssl_session_cache_size = RecGetRecordInt("proxy.config.ssl.session_cache.size").value_or(0); |
457 | 535 | ssl_session_cache_num_buckets = RecGetRecordInt("proxy.config.ssl.session_cache.num_buckets").value_or(0); |
458 | 536 | ssl_session_cache_skip_on_contention = |
|
0 commit comments