nizhikov commented on code in PR #13786:
URL: https://github.com/apache/ignite/pull/13786#discussion_r4583385787
##########
modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java:
##########
@@ -259,24 +330,80 @@ public static TrustManager getDisabledTrustManager() {
/** {@inheritDoc} */
@Override protected final KeyManager[] createKeyManagers() throws
SSLException {
+ KeyManagerFactory keyMgrFactory;
+
try {
- KeyManagerFactory keyMgrFactory =
KeyManagerFactory.getInstance(keyAlgorithm);
+ keyMgrFactory = KeyManagerFactory.getInstance(keyAlgorithm);
+ }
+ catch (NoSuchAlgorithmException e) {
+ throw new SSLException("Unsupported key algorithm: " +
keyAlgorithm, e);
+ }
- KeyStore keyStore = loadKeyStore(keyStoreType, keyStoreFilePath,
keyStorePwd);
+ KeyStore keyStore = loadKeyStore(keyStoreType, keyStoreFilePath,
keyStorePwd);
+ try {
keyMgrFactory.init(keyStore, keyStorePwd);
+ pendingHotReloadTime = hotReloadEnabled ? hotReloadTime(keyStore)
: 0;
+
return keyMgrFactory.getKeyManagers();
}
- catch (NoSuchAlgorithmException e) {
- throw new SSLException("Unsupported key algorithm: " +
keyAlgorithm, e);
- }
catch (GeneralSecurityException e) {
throw new SSLException("Failed to initialize Key Manager (security
exception occurred) [type=" +
keyStoreType + ", keyStorePath=" + keyStoreFilePath + ']', e);
}
}
+ /**
+ * @param store Loaded key store.
+ * @return Start of the hot reload window of the chain that expires first.
+ * @throws GeneralSecurityException If a key or certificate cannot be read.
+ * @throws SSLException If there are no private keys or a private key has
no X.509 certificate chain.
+ */
+ private long hotReloadTime(KeyStore store) throws
GeneralSecurityException, SSLException {
+ long earliestExpiry = Long.MAX_VALUE;
+ long selectedStart = Long.MAX_VALUE;
+ boolean hasPrivateKeys = false;
+
+ for (Enumeration<String> aliases = store.aliases();
aliases.hasMoreElements(); ) {
+ String alias = aliases.nextElement();
+
+ if (!store.isKeyEntry(alias) || !(store.getKey(alias, keyStorePwd)
instanceof PrivateKey))
+ continue;
+
+ hasPrivateKeys = true;
+
+ Certificate[] chain = store.getCertificateChain(alias);
+
+ if (chain == null || chain.length == 0)
+ throw new SSLException("Certificate chain is unavailable
[alias=" + alias + "]. Remove the key or add its X.509 chain.");
+
+ long chainExpiry = Long.MAX_VALUE;
+
+ for (Certificate certificate : chain) {
+ if (!(certificate instanceof X509Certificate cert))
Review Comment:
Why do we need to throw here? Can we just ignore?
--
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]