|
112 | 112 | "Reads network TLS configuration from the config `network` section |
113 | 113 | (when available) and falls back to well-known environment variables. |
114 | 114 |
|
115 | | - Config values (camelCase as from JSON): |
116 | | - :caCertFile - path to a PEM CA certificate bundle |
117 | | - :clientCert - path to a PEM client certificate for mTLS |
118 | | - :clientKey - path to a PEM client private key for mTLS |
119 | | - :clientKeyPassphrase - passphrase for an encrypted client key |
| 115 | + The JSON config uses camelCase (`caCertFile`, `clientCert`, ...), but |
| 116 | + `eca.config` normalizes keys under `:network` to kebab-case before |
| 117 | + this function is called, so we look up kebab-cased keys here. |
| 118 | +
|
| 119 | + Config values (kebab-case after normalization): |
| 120 | + :ca-cert-file - path to a PEM CA certificate bundle |
| 121 | + :client-cert - path to a PEM client certificate for mTLS |
| 122 | + :client-key - path to a PEM client private key for mTLS |
| 123 | + :client-key-passphrase - passphrase for an encrypted client key |
120 | 124 |
|
121 | 125 | Environment variable fallbacks (lowest priority): |
122 | 126 | SSL_CERT_FILE / NODE_EXTRA_CA_CERTS -> :ca-cert-file |
|
125 | 129 | ECA_CLIENT_KEY_PASSPHRASE -> :client-key-passphrase" |
126 | 130 | [file-config] |
127 | 131 | (let [net (:network file-config)] |
128 | | - {:ca-cert-file (or (non-blank (:caCertFile net)) |
| 132 | + {:ca-cert-file (or (non-blank (:ca-cert-file net)) |
129 | 133 | (non-blank (config/get-env "SSL_CERT_FILE")) |
130 | 134 | (non-blank (config/get-env "NODE_EXTRA_CA_CERTS"))) |
131 | | - :client-cert (or (non-blank (:clientCert net)) |
| 135 | + :client-cert (or (non-blank (:client-cert net)) |
132 | 136 | (non-blank (config/get-env "ECA_CLIENT_CERT"))) |
133 | | - :client-key (or (non-blank (:clientKey net)) |
| 137 | + :client-key (or (non-blank (:client-key net)) |
134 | 138 | (non-blank (config/get-env "ECA_CLIENT_KEY"))) |
135 | | - :client-key-passphrase (or (non-blank (:clientKeyPassphrase net)) |
| 139 | + :client-key-passphrase (or (non-blank (:client-key-passphrase net)) |
136 | 140 | (non-blank (config/get-env "ECA_CLIENT_KEY_PASSPHRASE")))})) |
137 | 141 |
|
138 | 142 | (defn load-pem-certificates |
|
279 | 283 | custom CA or mTLS settings are present, and stores it in |
280 | 284 | `*ssl-context*`." |
281 | 285 | [file-config] |
282 | | - (let [net-cfg (read-network-config file-config)] |
| 286 | + (let [net-cfg (read-network-config file-config) |
| 287 | + configured? (boolean (:network file-config))] |
| 288 | + (logger/debug logger-tag "Resolved network config:" net-cfg) |
283 | 289 | (try |
284 | | - (when-let [ctx (build-ssl-context net-cfg)] |
285 | | - (logger/info logger-tag "Custom SSL context configured" |
286 | | - (cond-> {} |
287 | | - (:ca-cert-file net-cfg) (assoc :ca-cert-file (:ca-cert-file net-cfg)) |
288 | | - (:client-cert net-cfg) (assoc :client-cert (:client-cert net-cfg)))) |
289 | | - (alter-var-root #'*ssl-context* (constantly ctx))) |
| 290 | + (if-let [ctx (build-ssl-context net-cfg)] |
| 291 | + (do |
| 292 | + (logger/info logger-tag "Custom SSL context configured" |
| 293 | + (cond-> {} |
| 294 | + (:ca-cert-file net-cfg) (assoc :ca-cert-file (:ca-cert-file net-cfg)) |
| 295 | + (:client-cert net-cfg) (assoc :client-cert (:client-cert net-cfg)))) |
| 296 | + (alter-var-root #'*ssl-context* (constantly ctx))) |
| 297 | + (when configured? |
| 298 | + (logger/warn logger-tag |
| 299 | + (str "`network` config present but no TLS settings were resolved; " |
| 300 | + "using JVM defaults. Check caCertFile/clientCert/clientKey paths.")))) |
290 | 301 | (catch Exception e |
291 | 302 | (logger/error logger-tag "Failed to build SSL context:" (.getMessage e)))))) |
0 commit comments