From 8f3904f6dca6ad00a56fac329e0ef8fe90561e6d Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 31 Oct 2014 13:00:05 +0900 Subject: [PATCH] Code clean-up - Fix the inspector warnings - Fix the infinite recursion in SslContext.newClientContext() - Fix Javadoc errors --- .../netty/handler/ssl/CipherSuiteFilter.java | 1 + .../ssl/JdkApplicationProtocolNegotiator.java | 13 ++++--- .../io/netty/handler/ssl/JdkSslContext.java | 34 +++++++++---------- .../handler/ssl/OpenSslServerContext.java | 16 ++++----- .../java/io/netty/handler/ssl/SslContext.java | 7 ++-- .../ssl/SupportedCipherSuiteFilter.java | 1 + 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/CipherSuiteFilter.java b/handler/src/main/java/io/netty/handler/ssl/CipherSuiteFilter.java index 13c539cd32..c115b775a7 100644 --- a/handler/src/main/java/io/netty/handler/ssl/CipherSuiteFilter.java +++ b/handler/src/main/java/io/netty/handler/ssl/CipherSuiteFilter.java @@ -15,6 +15,7 @@ */ package io.netty.handler.ssl; +import javax.net.ssl.SSLEngine; import java.util.List; import java.util.Set; diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkApplicationProtocolNegotiator.java b/handler/src/main/java/io/netty/handler/ssl/JdkApplicationProtocolNegotiator.java index cd7bf71404..1a14331128 100644 --- a/handler/src/main/java/io/netty/handler/ssl/JdkApplicationProtocolNegotiator.java +++ b/handler/src/main/java/io/netty/handler/ssl/JdkApplicationProtocolNegotiator.java @@ -15,11 +15,10 @@ */ package io.netty.handler.ssl; +import javax.net.ssl.SSLEngine; import java.util.List; import java.util.Set; -import javax.net.ssl.SSLEngine; - /** * JDK extension methods to support {@link ApplicationProtocolNegotiator} */ @@ -27,7 +26,7 @@ public interface JdkApplicationProtocolNegotiator extends ApplicationProtocolNeg /** * Abstract factory pattern for wrapping an {@link SSLEngine} object. This is useful for NPN/APLN JDK support. */ - public interface SslEngineWrapperFactory { + interface SslEngineWrapperFactory { /** * Abstract factory pattern for wrapping an {@link SSLEngine} object. This is useful for NPN/APLN support. * @@ -48,7 +47,7 @@ public interface JdkApplicationProtocolNegotiator extends ApplicationProtocolNeg * {@link ProtocolSelector#unsupported()} OR {@link ProtocolSelector#select(List)} will be called for each SSL * handshake. */ - public interface ProtocolSelector { + interface ProtocolSelector { /** * Callback invoked to let the application know that the peer does not support this * {@link ApplicationProtocolNegotiator}. @@ -72,7 +71,7 @@ public interface JdkApplicationProtocolNegotiator extends ApplicationProtocolNeg * {@link ProtocolSelectionListener#unsupported()} OR the {@link ProtocolSelectionListener#selected(String)} method * will be called for each SSL handshake. */ - public interface ProtocolSelectionListener { + interface ProtocolSelectionListener { /** * Callback invoked to let the application know that the peer does not support this * {@link ApplicationProtocolNegotiator}. @@ -93,7 +92,7 @@ public interface JdkApplicationProtocolNegotiator extends ApplicationProtocolNeg /** * Factory interface for {@link ProtocolSelector} objects. */ - public interface ProtocolSelectorFactory { + interface ProtocolSelectorFactory { /** * Generate a new instance of {@link ProtocolSelector}. * @param engine The {@link SSLEngine} that the returned {@link ProtocolSelector} will be used to create an @@ -107,7 +106,7 @@ public interface JdkApplicationProtocolNegotiator extends ApplicationProtocolNeg /** * Factory interface for {@link ProtocolSelectionListener} objects. */ - public interface ProtocolSelectionListenerFactory { + interface ProtocolSelectionListenerFactory { /** * Generate a new instance of {@link ProtocolSelectionListener}. * @param engine The {@link SSLEngine} that the returned {@link ProtocolSelectionListener} will be used to diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java b/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java index 08ae41b112..9af91b3b57 100644 --- a/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java +++ b/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java @@ -16,13 +16,25 @@ package io.netty.handler.ssl; -import static io.netty.util.internal.ObjectUtil.checkNotNull; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufInputStream; +import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; +import javax.crypto.Cipher; +import javax.crypto.EncryptedPrivateKeyInfo; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLSessionContext; +import javax.net.ssl.TrustManagerFactory; +import javax.security.auth.x500.X500Principal; import java.io.File; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; @@ -48,18 +60,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.crypto.Cipher; -import javax.crypto.EncryptedPrivateKeyInfo; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKey; -import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.PBEKeySpec; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLSessionContext; -import javax.net.ssl.TrustManagerFactory; -import javax.security.auth.x500.X500Principal; +import static io.netty.util.internal.ObjectUtil.*; /** * An {@link SslContext} which uses JDK's SSL/TLS implementation. @@ -141,8 +142,7 @@ public abstract class JdkSslContext extends SslContext { } private static void addIfSupported(Set supported, List enabled, String... names) { - for (int i = 0; i < names.length; ++i) { - String n = names[i]; + for (String n: names) { if (supported.contains(n)) { enabled.add(n); } @@ -224,7 +224,7 @@ public abstract class JdkSslContext extends SslContext { } /** - * Translate a {@link ApplicationProtocolConfiguration} object to a {@link JdkApplicationProtocolNegotiator} object. + * Translate a {@link ApplicationProtocolConfig} object to a {@link JdkApplicationProtocolNegotiator} object. * @param config The configuration which defines the translation * @param isServer {@code true} if a server {@code false} otherwise. * @return The results of the translation @@ -336,7 +336,7 @@ public abstract class JdkSslContext extends SslContext { byte[] encodedKey = new byte[encodedKeyBuf.readableBytes()]; encodedKeyBuf.readBytes(encodedKey).release(); - char[] keyPasswordChars = keyPassword == null ? new char[0] : keyPassword.toCharArray(); + char[] keyPasswordChars = keyPassword == null ? EmptyArrays.EMPTY_CHARS : keyPassword.toCharArray(); PKCS8EncodedKeySpec encodedKeySpec = generateKeySpec(keyPasswordChars, encodedKey); PrivateKey key; diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSslServerContext.java b/handler/src/main/java/io/netty/handler/ssl/OpenSslServerContext.java index 5295a81883..ff0d1e0e53 100644 --- a/handler/src/main/java/io/netty/handler/ssl/OpenSslServerContext.java +++ b/handler/src/main/java/io/netty/handler/ssl/OpenSslServerContext.java @@ -15,22 +15,21 @@ */ package io.netty.handler.ssl; -import static io.netty.util.internal.ObjectUtil.checkNotNull; import io.netty.buffer.ByteBufAllocator; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; +import org.apache.tomcat.jni.Pool; +import org.apache.tomcat.jni.SSL; +import org.apache.tomcat.jni.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLException; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLException; - -import org.apache.tomcat.jni.Pool; -import org.apache.tomcat.jni.SSL; -import org.apache.tomcat.jni.SSLContext; +import static io.netty.util.internal.ObjectUtil.*; /** * A server-side {@link SslContext} which uses OpenSSL's SSL/TLS implementation. @@ -293,6 +292,7 @@ public final class OpenSslServerContext extends SslContext { return sessionTimeout; } + @Override public ApplicationProtocolNegotiator applicationProtocolNegotiator() { return apn; } @@ -359,7 +359,7 @@ public final class OpenSslServerContext extends SslContext { } /** - * Translate a {@link ApplicationProtocolConfiguration} object to a + * Translate a {@link ApplicationProtocolConfig} object to a * {@link OpenSslApplicationProtocolNegotiator} object. * @param config The configuration which defines the translation * @param isServer {@code true} if a server {@code false} otherwise. diff --git a/handler/src/main/java/io/netty/handler/ssl/SslContext.java b/handler/src/main/java/io/netty/handler/ssl/SslContext.java index da8c4f57f0..202acca0e7 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslContext.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslContext.java @@ -20,9 +20,6 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; -import java.io.File; -import java.util.List; - import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; @@ -30,6 +27,8 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; +import java.io.File; +import java.util.List; /** * A secure socket protocol implementation which acts as a factory for {@link SSLEngine} and {@link SslHandler}. @@ -360,7 +359,7 @@ public abstract class SslContext { */ public static SslContext newClientContext( SslProvider provider, TrustManagerFactory trustManagerFactory) throws SSLException { - return newClientContext(provider, trustManagerFactory); + return newClientContext(provider, null, trustManagerFactory); } /** diff --git a/handler/src/main/java/io/netty/handler/ssl/SupportedCipherSuiteFilter.java b/handler/src/main/java/io/netty/handler/ssl/SupportedCipherSuiteFilter.java index 7c904327c3..132f1a0e5e 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SupportedCipherSuiteFilter.java +++ b/handler/src/main/java/io/netty/handler/ssl/SupportedCipherSuiteFilter.java @@ -15,6 +15,7 @@ */ package io.netty.handler.ssl; +import javax.net.ssl.SSLEngine; import java.util.ArrayList; import java.util.List; import java.util.Set;