This is an automated email from the ASF dual-hosted git repository.

anton-vinogradov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new c2e3b5687ec IGNITE-29310 Support automatic TLS certificate reload in 
custom SSL context factories (#13847)
c2e3b5687ec is described below

commit c2e3b5687ec96df27c56df4c01637271b022288b
Author: Anton Vinogradov <[email protected]>
AuthorDate: Wed Nov 18 14:04:14 2026 +0300

    IGNITE-29310 Support automatic TLS certificate reload in custom SSL context 
factories (#13847)
---
 docs/_docs/security/ssl-tls.adoc                   |  10 +-
 .../ignite/ssl/AbstractSslContextFactory.java      | 139 ++++++++++++++++++++-
 .../org/apache/ignite/ssl/SslContextFactory.java   | 122 +-----------------
 modules/core/pom.xml                               |   2 +-
 .../processors/ssl/SslFactoryRegistry.java         |  11 +-
 .../processors/ssl/SslFactoryRegistryTest.java     | 105 ++++++++++++++++
 .../ignite/ssl/TestCertificateAuthority.java       |   7 +-
 parent/pom.xml                                     |   1 +
 8 files changed, 263 insertions(+), 134 deletions(-)

diff --git a/docs/_docs/security/ssl-tls.adoc b/docs/_docs/security/ssl-tls.adoc
index 56531d4cecc..56d809c4f9d 100644
--- a/docs/_docs/security/ssl-tls.adoc
+++ b/docs/_docs/security/ssl-tls.adoc
@@ -197,7 +197,7 @@ It does not update the HTTP REST endpoint or external 
client applications.
 
 === Enable Hot Reload
 
-Enable hot reload on each configured `SslContextFactory` before starting the 
node:
+Enable hot reload on each configured factory before starting the node:
 
 [source,java]
 ----
@@ -229,7 +229,7 @@ This includes issuing certificates. The default lead time 
is 7 days.
 The first check at or after that date attempts a reload, including the startup 
check.
 Allow enough time before expiry to supply the replacements, wait through the 
one-hour interval and load the stores.
 Keep the lead time shorter than the lifetime of the replacement certificates, 
or they will already be due when loaded.
-See 
link:{javadoc_base_url}/org/apache/ignite/ssl/SslContextFactory.html#getHotReloadTime()[getHotReloadTime(),
 window=_blank] for the calculation.
+See 
link:{javadoc_base_url}/org/apache/ignite/ssl/AbstractSslContextFactory.html#getHotReloadTime()[getHotReloadTime(),
 window=_blank] for the calculation.
 
 If the loaded certificates are still due for hot reload, Ignite records a 
failed hot reload attempt even though it installed them.
 This can happen when the certificates have not changed, only the trust store 
changed, or the replacements expire within `hotReloadBeforeExpiryMs`.
@@ -270,8 +270,10 @@ Otherwise, or to load the corrected stores without 
waiting, restart the affected
 
 === Custom Certificate Sources
 
-For automatic hot reload, custom sources require a subclass of 
javadoc:org.apache.ignite.ssl.SslContextFactory[].
-Factories extending only `AbstractSslContextFactory` support manual reload 
only.
+For automatic hot reload, a custom factory creates its key managers with 
`createKeyManagers(KeyManagerFactory, KeyStore, char[])` of 
javadoc:org.apache.ignite.ssl.AbstractSslContextFactory[].
+On each load, call this method once with the key store and the key password 
that your source returned.
+Ignite takes the hot reload date from that key store.
+A factory that does not call this method has no hot reload date, and the node 
logs a warning.
 Limit request duration in custom sources: a blocked load delays other hot 
reloads and manual reload.
 
 == SslContextFactory Properties
diff --git 
a/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
 
b/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
index 6babf0267f3..5f0b0447a4f 100644
--- 
a/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
+++ 
b/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
@@ -17,11 +17,18 @@
 
 package org.apache.ignite.ssl;
 
+import java.security.GeneralSecurityException;
 import java.security.KeyManagementException;
+import java.security.KeyStore;
 import java.security.NoSuchAlgorithmException;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Enumeration;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.cache.configuration.Factory;
 import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLParameters;
@@ -39,6 +46,9 @@ public abstract class AbstractSslContextFactory implements 
Factory<SSLContext> {
     /** Default SSL protocol. */
     public static final String DFLT_SSL_PROTOCOL = "TLS";
 
+    /** Default lead time for certificate hot reload: 7 days. */
+    public static final long DFLT_HOT_RELOAD_BEFORE_EXPIRY_MS = 
TimeUnit.DAYS.toMillis(7);
+
     /** SSL protocol. */
     protected String proto = DFLT_SSL_PROTOCOL;
 
@@ -51,6 +61,68 @@ public abstract class AbstractSslContextFactory implements 
Factory<SSLContext> {
     /** Cached instance of an {@link SSLContext}. */
     protected final AtomicReference<SSLContext> sslCtx = new 
AtomicReference<>();
 
+    /** */
+    private boolean hotReloadEnabled;
+
+    /** */
+    private volatile long hotReloadBeforeExpiryMs = 
DFLT_HOT_RELOAD_BEFORE_EXPIRY_MS;
+
+    /** */
+    private transient volatile long earliestExpiry;
+
+    /** */
+    private transient long pendingExpiry;
+
+    /**
+     * Automatic hot reload takes its date from the key store that the factory 
passes to
+     * {@link #createKeyManagers(KeyManagerFactory, KeyStore, char[])}.
+     *
+     * @return Whether automatic certificate hot reload is enabled. Defaults 
to {@code false}.
+     */
+    public boolean isHotReloadEnabled() {
+        return hotReloadEnabled;
+    }
+
+    /**
+     * @param enabled Whether automatic certificate hot reload is enabled. 
Changes require a node restart.
+     */
+    public void setHotReloadEnabled(boolean enabled) {
+        hotReloadEnabled = enabled;
+    }
+
+    /**
+     * @return How long before the certificates expire hot reload becomes due, 
in milliseconds.
+     *     Defaults to {@link #DFLT_HOT_RELOAD_BEFORE_EXPIRY_MS}.
+     */
+    public long getHotReloadBeforeExpiryMs() {
+        return hotReloadBeforeExpiryMs;
+    }
+
+    /**
+     * @param millis How long before the certificates expire hot reload 
becomes due, in milliseconds. Must be positive.
+     */
+    public void setHotReloadBeforeExpiryMs(long millis) {
+        A.ensure(millis > 0, "millis > 0");
+
+        hotReloadBeforeExpiryMs = millis;
+    }
+
+    /**
+     * The hot reload time is calculated from the key store passed to
+     * {@link #createKeyManagers(KeyManagerFactory, KeyStore, char[])} during 
the last successful load.
+     * It comes {@link #getHotReloadBeforeExpiryMs()} before the earliest 
expiry among the chains of the private keys.
+     * A chain expires when any certificate in it expires.
+     * Keys without an X.509 certificate chain are ignored, as TLS cannot use 
them.
+     *
+     * @return Hot reload time in milliseconds since the epoch, or {@code 0} 
if the certificates have not been loaded yet
+     *     or the last successful load supplied no key store or no private key 
with an X.509 chain.
+     */
+    public long getHotReloadTime() {
+        long expiry = earliestExpiry;
+
+        return expiry == 0 ? 0 : expiry - hotReloadBeforeExpiryMs;
+    }
+
     /**
      * Gets protocol for secure transport.
      *
@@ -113,9 +185,11 @@ public abstract class AbstractSslContextFactory implements 
Factory<SSLContext> {
      * @return Initialized SSL context.
      * @throws SSLException If SSL context could not be created.
      */
-    SSLContext createSslContext() throws SSLException {
+    private SSLContext createSslContext() throws SSLException {
         checkParameters();
 
+        pendingExpiry = 0;
+
         KeyManager[] keyMgrs = createKeyManagers();
 
         TrustManager[] trustMgrs = createTrustManagers();
@@ -137,6 +211,8 @@ public abstract class AbstractSslContextFactory implements 
Factory<SSLContext> {
 
             ctx.init(keyMgrs, trustMgrs, null);
 
+            earliestExpiry = pendingExpiry;
+
             return ctx;
         }
         catch (NoSuchAlgorithmException e) {
@@ -170,6 +246,67 @@ public abstract class AbstractSslContextFactory implements 
Factory<SSLContext> {
      */
     protected abstract KeyManager[] createKeyManagers() throws SSLException;
 
+    /**
+     * Creates key managers from the key store. For the hot reload date, call 
it once per load with the key store that
+     * supplies the key managers.
+     *
+     * @param keyMgrFactory Key manager factory.
+     * @param store Key store with the private keys and their certificate 
chains.
+     * @param pwd Password of the private keys.
+     * @return Key managers of the key store.
+     * @throws GeneralSecurityException If the key managers cannot be created.
+     */
+    protected final synchronized KeyManager[] 
createKeyManagers(KeyManagerFactory keyMgrFactory, KeyStore store, char[] pwd)
+        throws GeneralSecurityException {
+        keyMgrFactory.init(store, pwd);
+
+        pendingExpiry = keyChainsExpiry(store);
+
+        return keyMgrFactory.getKeyManagers();
+    }
+
+    /**
+     * @param store Loaded key store.
+     * @return Earliest certificate expiry in the private key chains, or 
{@code 0} if the store has no private key
+     *     with an X.509 certificate chain.
+     * @throws GeneralSecurityException If the key store cannot be read.
+     */
+    private static long keyChainsExpiry(KeyStore store) throws 
GeneralSecurityException {
+        long earliest = Long.MAX_VALUE;
+
+        for (Enumeration<String> aliases = store.aliases(); 
aliases.hasMoreElements(); ) {
+            String alias = aliases.nextElement();
+
+            if (!store.isKeyEntry(alias))
+                continue;
+
+            earliest = Math.min(earliest, 
chainExpiry(store.getCertificateChain(alias)));
+        }
+
+        return earliest == Long.MAX_VALUE ? 0 : earliest;
+    }
+
+    /**
+     * @param chain Certificate chain of a key entry, or {@code null} if the 
entry has none.
+     * @return Earliest expiry in the chain, or {@link Long#MAX_VALUE} if 
there is no chain or it holds a certificate other
+     *     than X.509, as TLS ignores such keys.
+     */
+    private static long chainExpiry(Certificate[] chain) {
+        long expiry = Long.MAX_VALUE;
+
+        if (chain == null)
+            return expiry;
+
+        for (Certificate cert : chain) {
+            if (!(cert instanceof X509Certificate x509))
+                return Long.MAX_VALUE;
+
+            expiry = Math.min(expiry, x509.getNotAfter().getTime());
+        }
+
+        return expiry;
+    }
+
     /**
      * @return Created Trust Managers.
      * @throws SSLException If Trust Managers could not be created.
diff --git 
a/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java 
b/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java
index f3116d2e658..149c44330eb 100644
--- a/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java
+++ b/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java
@@ -24,15 +24,11 @@ import java.io.InputStream;
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
 import java.security.NoSuchAlgorithmException;
-import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.concurrent.TimeUnit;
 import javax.net.ssl.KeyManager;
 import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
@@ -65,9 +61,6 @@ public class SslContextFactory extends 
AbstractSslContextFactory {
     /** Default key manager / trust manager algorithm. Specifying different 
trust manager algorithm is not supported. */
     public static final String DFLT_KEY_ALGORITHM = 
System.getProperty("ssl.KeyManagerFactory.algorithm", "SunX509");
 
-    /** Default lead time for certificate hot reload: 7 days. */
-    public static final long DFLT_HOT_RELOAD_BEFORE_EXPIRY_MS = 
TimeUnit.DAYS.toMillis(7);
-
     /** Key manager algorithm. */
     protected String keyAlgorithm = DFLT_KEY_ALGORITHM;
 
@@ -92,73 +85,6 @@ public class SslContextFactory extends 
AbstractSslContextFactory {
     /** Trust managers. */
     protected TrustManager[] trustMgrs;
 
-    /** */
-    private boolean hotReloadEnabled;
-
-    /** */
-    private volatile long hotReloadBeforeExpiryMs = 
DFLT_HOT_RELOAD_BEFORE_EXPIRY_MS;
-
-    /** */
-    private transient volatile long earliestExpiry;
-
-    /** */
-    private transient long pendingExpiry;
-
-    /**
-     * @return Whether automatic certificate hot reload is enabled. Defaults 
to {@code false}.
-     */
-    public boolean isHotReloadEnabled() {
-        return hotReloadEnabled;
-    }
-
-    /**
-     * @param enabled Whether automatic certificate hot reload is enabled. 
Changes require a node restart.
-     */
-    public void setHotReloadEnabled(boolean enabled) {
-        hotReloadEnabled = enabled;
-    }
-
-    /**
-     * @return How long before the certificates expire hot reload becomes due, 
in milliseconds.
-     *     Defaults to {@link #DFLT_HOT_RELOAD_BEFORE_EXPIRY_MS}.
-     */
-    public long getHotReloadBeforeExpiryMs() {
-        return hotReloadBeforeExpiryMs;
-    }
-
-    /**
-     * @param millis How long before the certificates expire hot reload 
becomes due, in milliseconds. Must be positive.
-     */
-    public void setHotReloadBeforeExpiryMs(long millis) {
-        A.ensure(millis > 0, "millis > 0");
-
-        hotReloadBeforeExpiryMs = millis;
-    }
-
-    /**
-     * The hot reload time is calculated from the loaded certificates.
-     * It comes {@link #getHotReloadBeforeExpiryMs()} before the earliest 
expiry among the chains of the private keys.
-     * A chain expires when any certificate in it expires.
-     * Keys without an X.509 certificate chain are ignored, as TLS cannot use 
them.
-     *
-     * @return Hot reload time in milliseconds since the epoch, or {@code 0} 
if the certificates have not been loaded yet
-     *     or have no private key with an X.509 chain.
-     */
-    public long getHotReloadTime() {
-        long expiry = earliestExpiry;
-
-        return expiry == 0 ? 0 : expiry - hotReloadBeforeExpiryMs;
-    }
-
-    /** {@inheritDoc} */
-    @Override SSLContext createSslContext() throws SSLException {
-        SSLContext ctx = super.createSslContext();
-
-        earliestExpiry = pendingExpiry;
-
-        return ctx;
-    }
-
     /**
      * Gets key store type used for context creation.
      *
@@ -338,11 +264,7 @@ public class SslContextFactory extends 
AbstractSslContextFactory {
 
             KeyStore keyStore = loadKeyStore(keyStoreType, keyStoreFilePath, 
keyStorePwd);
 
-            keyMgrFactory.init(keyStore, keyStorePwd);
-
-            pendingExpiry = keyChainsExpiry(keyStore);
-
-            return keyMgrFactory.getKeyManagers();
+            return createKeyManagers(keyMgrFactory, keyStore, keyStorePwd);
         }
         catch (NoSuchAlgorithmException e) {
             throw new SSLException("Unsupported key algorithm: " + 
keyAlgorithm, e);
@@ -353,48 +275,6 @@ public class SslContextFactory extends 
AbstractSslContextFactory {
         }
     }
 
-    /**
-     * @param store Loaded key store.
-     * @return Earliest certificate expiry in the private key chains, or 
{@code 0} if the store has no private key
-     *     with an X.509 certificate chain.
-     * @throws GeneralSecurityException If the key store cannot be read.
-     */
-    private static long keyChainsExpiry(KeyStore store) throws 
GeneralSecurityException {
-        long earliest = Long.MAX_VALUE;
-
-        for (Enumeration<String> aliases = store.aliases(); 
aliases.hasMoreElements(); ) {
-            String alias = aliases.nextElement();
-
-            if (!store.isKeyEntry(alias))
-                continue;
-
-            earliest = Math.min(earliest, 
chainExpiry(store.getCertificateChain(alias)));
-        }
-
-        return earliest == Long.MAX_VALUE ? 0 : earliest;
-    }
-
-    /**
-     * @param chain Certificate chain of a key entry, or {@code null} if the 
entry has none.
-     * @return Earliest expiry in the chain, or {@link Long#MAX_VALUE} if 
there is no chain or it holds a certificate other
-     *     than X.509, as TLS ignores such keys.
-     */
-    private static long chainExpiry(Certificate[] chain) {
-        long expiry = Long.MAX_VALUE;
-
-        if (chain == null)
-            return expiry;
-
-        for (Certificate cert : chain) {
-            if (!(cert instanceof X509Certificate x509))
-                return Long.MAX_VALUE;
-
-            expiry = Math.min(expiry, x509.getNotAfter().getTime());
-        }
-
-        return expiry;
-    }
-
     /** {@inheritDoc} */
     @Override protected final TrustManager[] createTrustManagers() throws 
SSLException {
         if (trustMgrs != null)
diff --git a/modules/core/pom.xml b/modules/core/pom.xml
index 47fd6cc45de..f2b464d91bd 100644
--- a/modules/core/pom.xml
+++ b/modules/core/pom.xml
@@ -161,7 +161,7 @@
         <dependency>
             <groupId>org.bouncycastle</groupId>
             <artifactId>bcpkix-jdk18on</artifactId>
-            <version>1.86</version>
+            <version>${bouncycastle.version}</version>
             <scope>test</scope>
         </dependency>
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
index 9f1b5b2acbf..aa6b489f5a8 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
@@ -35,7 +35,6 @@ import 
org.apache.ignite.internal.processors.metric.MetricRegistryImpl;
 import 
org.apache.ignite.internal.thread.context.function.OperationContextAwareRunnable;
 import org.apache.ignite.logger.NullLogger;
 import org.apache.ignite.ssl.AbstractSslContextFactory;
-import org.apache.ignite.ssl.SslContextFactory;
 import org.jetbrains.annotations.Nullable;
 
 import static java.util.concurrent.TimeUnit.HOURS;
@@ -102,7 +101,7 @@ public class SslFactoryRegistry {
         boolean hotReload = false;
 
         for (RegisteredFactory registered : factories) {
-            SslContextFactory sslFactory = registered.hotReloadFactory();
+            AbstractSslContextFactory sslFactory = 
registered.hotReloadFactory();
 
             if (sslFactory != null) {
                 registered.logHotReloadTime(sslFactory.getHotReloadTime());
@@ -178,8 +177,8 @@ public class SslFactoryRegistry {
         }
 
         /** @return The factory if hot reload is enabled for it, {@code null} 
otherwise. */
-        @Nullable private SslContextFactory hotReloadFactory() {
-            return factory instanceof SslContextFactory sslFactory && 
sslFactory.isHotReloadEnabled() ? sslFactory : null;
+        @Nullable private AbstractSslContextFactory hotReloadFactory() {
+            return factory instanceof AbstractSslContextFactory sslFactory && 
sslFactory.isHotReloadEnabled() ? sslFactory : null;
         }
 
         /**
@@ -212,7 +211,7 @@ public class SslFactoryRegistry {
          * @throws IgniteException If the reload fails or leaves certificates 
that are still due.
          */
         private void reloadIfDue() {
-            SslContextFactory sslFactory = (SslContextFactory)factory;
+            AbstractSslContextFactory sslFactory = 
(AbstractSslContextFactory)factory;
 
             if (!due(sslFactory.getHotReloadTime())) {
                 failures.set(0);
@@ -253,7 +252,7 @@ public class SslFactoryRegistry {
 
             ((AbstractSslContextFactory)factory).init();
 
-            SslContextFactory sslFactory = hotReloadFactory();
+            AbstractSslContextFactory sslFactory = hotReloadFactory();
 
             if (sslFactory != null) {
                 failures.set(0);
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
index 4cd7b66ddd8..4bf12cde354 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
@@ -19,6 +19,9 @@ package org.apache.ignite.internal.processors.ssl;
 
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -28,7 +31,11 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.atomic.AtomicInteger;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
+import javax.net.ssl.TrustManager;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
@@ -59,6 +66,7 @@ import static 
org.apache.ignite.ssl.TestCertificateAuthority.PASSWORD;
 import static org.apache.ignite.ssl.TestCertificateAuthority.save;
 import static org.apache.ignite.testframework.GridTestUtils.runAsync;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
@@ -487,6 +495,62 @@ public class SslFactoryRegistryTest {
         assertEquals(0, metric("AutomaticHotReloadAttempts"));
     }
 
+    /**
+     * Given: a custom factory has loaded a certificate that is due for hot 
reload.
+     * When: the source supplies a new key store and password and the 
scheduled check runs.
+     * Then: the factory installs the replacement context and schedules its 
next reload from the new certificate.
+     */
+    @Test
+    public void testScheduledReloadUsesCustomFactoryKeyStoreAndPassword() 
throws Exception {
+        SourceSslContextFactory custom = new SourceSslContextFactory();
+
+        custom.setKeys(authority.keyStore("node", at(-1), at(10)), PASSWORD);
+        custom.setHotReloadEnabled(true);
+
+        SSLContext initCtx = custom.create();
+
+        registry.register("communication", custom);
+        registry.start(ctx);
+
+        char[] replacementPwd = "replacement".toCharArray();
+        KeyStore replacement = authority.keyStore("node", at(-1), 
at(DAYS.toHours(30)), replacementPwd);
+
+        custom.setKeys(replacement, replacementPwd);
+        check.run();
+
+        assertNotSame(initCtx, custom.create());
+
+        long expiry = 
((X509Certificate)replacement.getCertificate("node")).getNotAfter().getTime();
+
+        assertEquals(expiry - custom.getHotReloadBeforeExpiryMs(), 
custom.getHotReloadTime());
+    }
+
+    /**
+     * Given: hot reload is enabled for a custom factory that has loaded a key 
store with due certificates.
+     * When: a manual reload creates the context without a key store, and the 
scheduled check runs.
+     * Then: the factory has no hot reload date, and the check makes no 
attempt.
+     */
+    @Test
+    public void testLoadWithoutKeyStoreClearsHotReloadDate() throws Exception {
+        SourceSslContextFactory custom = new SourceSslContextFactory();
+
+        custom.setKeys(authority.keyStore("node", at(-1), at(10)), PASSWORD);
+        custom.setHotReloadEnabled(true);
+        custom.create();
+
+        assertTrue(custom.getHotReloadTime() > 0);
+
+        registry.register("communication", custom);
+        registry.start(ctx);
+
+        custom.setKeys(null, null);
+        registry.reload(custom);
+        check.run();
+
+        assertEquals(0, custom.getHotReloadTime());
+        assertEquals(0, metric("AutomaticHotReloadAttempts"));
+    }
+
     /**
      * Given: a registered factory that is not an {@link SslContextFactory}.
      * When: a manual reload runs.
@@ -883,4 +947,45 @@ public class SslFactoryRegistryTest {
             return getKeyStoreFilePath().hashCode();
         }
     }
+
+    /** Creates key managers from the key store and password supplied by the 
test, or none without a key store. */
+    private static class SourceSslContextFactory extends 
AbstractSslContextFactory {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private KeyStore store;
+
+        /** */
+        private char[] pwd;
+
+        /** */
+        private void setKeys(KeyStore store, char[] pwd) {
+            this.store = store;
+            this.pwd = pwd;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected void checkParameters() {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override protected KeyManager[] createKeyManagers() throws 
SSLException {
+            if (store == null)
+                return null;
+
+            try {
+                return 
createKeyManagers(KeyManagerFactory.getInstance("SunX509"), store, pwd);
+            }
+            catch (GeneralSecurityException e) {
+                throw new SSLException(e);
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override protected TrustManager[] createTrustManagers() {
+            return null;
+        }
+    }
 }
diff --git 
a/modules/core/src/test/java/org/apache/ignite/ssl/TestCertificateAuthority.java
 
b/modules/core/src/test/java/org/apache/ignite/ssl/TestCertificateAuthority.java
index a8d5205edc0..232f4711139 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/ssl/TestCertificateAuthority.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/ssl/TestCertificateAuthority.java
@@ -70,11 +70,16 @@ public class TestCertificateAuthority {
      * The chain holds a leaf certificate with the given dates, signed by this 
CA, followed by the CA certificate.
      */
     public KeyStore keyStore(String alias, long notBefore, long notAfter) 
throws Exception {
+        return keyStore(alias, notBefore, notAfter, PASSWORD);
+    }
+
+    /** Creates the key store with the given password for its private key. */
+    public KeyStore keyStore(String alias, long notBefore, long notAfter, 
char[] pwd) throws Exception {
         KeyPair leafKeys = keyPair();
         X509Certificate leaf = certificate(new X500Principal("CN=" + alias), 
leafKeys, notBefore, notAfter, false);
         KeyStore store = emptyStore();
 
-        store.setKeyEntry(alias, leafKeys.getPrivate(), PASSWORD, new 
X509Certificate[] {leaf, cert});
+        store.setKeyEntry(alias, leafKeys.getPrivate(), pwd, new 
X509Certificate[] {leaf, cert});
 
         return store;
     }
diff --git a/parent/pom.xml b/parent/pom.xml
index dcfd2021796..04629ecb634 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -68,6 +68,7 @@
         <failIfNoTests>false</failIfNoTests>
 
         <!-- Dependency versions -->
+        <bouncycastle.version>1.86</bouncycastle.version>
         <commons.codec.version>1.23.0</commons.codec.version>
         <commons.collections.version>3.2.2</commons.collections.version>
         <commons.io.version>2.22.0</commons.io.version>

Reply via email to