zstan commented on code in PR #13874: URL: https://github.com/apache/ignite/pull/13874#discussion_r4737683020
########## modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/JettySslFactoryAdapter.java: ########## @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.rest.protocols.http.jetty; + +import java.security.GeneralSecurityException; +import java.security.KeyStore; +import java.util.function.Consumer; +import javax.cache.configuration.Factory; +import javax.net.ssl.SSLContext; +import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.processors.ssl.ReloadableSslFactory; +import org.apache.ignite.ssl.AbstractSslContextFactory; +import org.apache.ignite.ssl.jetty.AutoReloadJettySslFactory; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.ssl.AbstractSslContextFactory.DFLT_AUTO_RELOAD_BEFORE_EXPIRY_MS; + +/** + * Adapter through which the SSL factory registry reloads the TLS factory of the Jetty HTTPS connector. A failed reload + * leaves the previous keys and trust settings in use. + * Automatic reload follows the settings of the Jetty factory if it implements {@link AutoReloadJettySslFactory}. Otherwise + * automatic reload is enabled with the lead time {@link AbstractSslContextFactory#DFLT_AUTO_RELOAD_BEFORE_EXPIRY_MS}. + * <p> + * Jetty's factory guards its TLS state with an internal lock: it loads the state under this lock, and new connections + * take the state under it too. Before loading a replacement, Jetty clears the state. So that new connections never see + * a factory without keys, the reload and, if loading fails, the restore of the previous state run under this lock. + * Jetty lets callers hold the lock only inside {@link SslContextFactory#unload(Consumer)} and + * {@link SslContextFactory#reload(Consumer)}, so the work runs inside {@code unload(...)} and ends with {@link SkipUnload}. + * Jetty selects certificates for SNI host names from the key store of the state, so the restore keeps SNI selection. + * If the restore fails too, the factory has no state until the next successful reload, and the reload error carries + * that failure as a suppressed exception. A failed reload outside Ignite, such as one by Jetty's {@code KeyStoreScanner}, + * can also leave the factory without state. Such a factory is due for automatic reload right away, and the reload has nothing + * to restore: it loads the configured sources. + * <p> + * After a failed reload, the factory gets back the context and stores set in {@code jetty.xml}, and the next reload + * reads its configured sources again. Once the factory has started, its getters return the loaded state rather than + * these settings. So the adapter cannot keep a context or store that code sets on the running factory: a failed reload + * drops it. + */ +class JettySslFactoryAdapter implements ReloadableSslFactory { + /** The adapter is serializable only because {@link Factory} is. Serializing it fails, as Jetty's factory is not serializable. */ + private static final long serialVersionUID = 0L; + + /** */ + private final SslContextFactory factory; + + /** State set in {@code jetty.xml}. The factory loads a {@code null} part from its configured source. */ + private final TlsState configured; + + /** + * @param factory TLS factory of the HTTPS connector before startup, when its getters return the state set in {@code jetty.xml}. + */ + JettySslFactoryAdapter(SslContextFactory factory) { + assert !factory.isStarted(); Review Comment: i.e. without -ea it can goes through this check ? probably : throw new IllegalStateException ? -- 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]
