Use @SuppressJava6Requirement for animal sniffer plugin to ensure we always guard correctly (#9655)
Motivation: We can use the `@SuppressJava6Requirement` annotation to be more precise about when we use Java6+ APIs. This helps us to ensure we always protect these places. Modifications: Make use of `@SuppressJava6Requirement` explicit Result: Fixes https://github.com/netty/netty/issues/2509.
This commit is contained in:
parent
833f11be75
commit
6c05d16967
@ -18,6 +18,8 @@ package io.netty.handler.codec.spdy;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufAllocator;
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
|
|
||||||
@ -70,11 +72,17 @@ class SpdyHeaderBlockZlibEncoder extends SpdyHeaderBlockRawEncoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Guarded by java version check")
|
||||||
private boolean compressInto(ByteBuf compressed) {
|
private boolean compressInto(ByteBuf compressed) {
|
||||||
byte[] out = compressed.array();
|
byte[] out = compressed.array();
|
||||||
int off = compressed.arrayOffset() + compressed.writerIndex();
|
int off = compressed.arrayOffset() + compressed.writerIndex();
|
||||||
int toWrite = compressed.writableBytes();
|
int toWrite = compressed.writableBytes();
|
||||||
int numBytes = compressor.deflate(out, off, toWrite, Deflater.SYNC_FLUSH);
|
final int numBytes;
|
||||||
|
if (PlatformDependent.javaVersion() >= 7) {
|
||||||
|
numBytes = compressor.deflate(out, off, toWrite, Deflater.SYNC_FLUSH);
|
||||||
|
} else {
|
||||||
|
numBytes = compressor.deflate(out, off, toWrite);
|
||||||
|
}
|
||||||
compressed.writerIndex(compressed.writerIndex() + numBytes);
|
compressed.writerIndex(compressed.writerIndex() + numBytes);
|
||||||
return numBytes == toWrite;
|
return numBytes == toWrite;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ChannelPromise;
|
import io.netty.channel.ChannelPromise;
|
||||||
import io.netty.channel.ChannelPromiseNotifier;
|
import io.netty.channel.ChannelPromiseNotifier;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
@ -320,7 +322,11 @@ public class JdkZlibEncoder extends ZlibEncoder {
|
|||||||
return ctx.writeAndFlush(footer, promise);
|
return ctx.writeAndFlush(footer, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
private void deflate(ByteBuf out) {
|
private void deflate(ByteBuf out) {
|
||||||
|
if (PlatformDependent.javaVersion() < 7) {
|
||||||
|
deflateJdk6(out);
|
||||||
|
}
|
||||||
int numBytes;
|
int numBytes;
|
||||||
do {
|
do {
|
||||||
int writerIndex = out.writerIndex();
|
int writerIndex = out.writerIndex();
|
||||||
@ -330,6 +336,16 @@ public class JdkZlibEncoder extends ZlibEncoder {
|
|||||||
} while (numBytes > 0);
|
} while (numBytes > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deflateJdk6(ByteBuf out) {
|
||||||
|
int numBytes;
|
||||||
|
do {
|
||||||
|
int writerIndex = out.writerIndex();
|
||||||
|
numBytes = deflater.deflate(
|
||||||
|
out.array(), out.arrayOffset() + writerIndex, out.writableBytes());
|
||||||
|
out.writerIndex(writerIndex + numBytes);
|
||||||
|
} while (numBytes > 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
|
@ -17,6 +17,7 @@ package io.netty.util.internal;
|
|||||||
|
|
||||||
import java.util.concurrent.atomic.LongAdder;
|
import java.util.concurrent.atomic.LongAdder;
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
final class LongAdderCounter extends LongAdder implements LongCounter {
|
final class LongAdderCounter extends LongAdder implements LongCounter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -482,6 +482,7 @@ public final class NativeLibraryLoader {
|
|||||||
|
|
||||||
private static final class NoexecVolumeDetector {
|
private static final class NoexecVolumeDetector {
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
private static boolean canExecuteExecutable(File file) throws IOException {
|
private static boolean canExecuteExecutable(File file) throws IOException {
|
||||||
if (PlatformDependent.javaVersion() < 7) {
|
if (PlatformDependent.javaVersion() < 7) {
|
||||||
// Pre-JDK7, the Java API did not directly support POSIX permissions; instead of implementing a custom
|
// Pre-JDK7, the Java API did not directly support POSIX permissions; instead of implementing a custom
|
||||||
|
@ -132,6 +132,7 @@ public final class PlatformDependent {
|
|||||||
if (javaVersion() >= 7) {
|
if (javaVersion() >= 7) {
|
||||||
RANDOM_PROVIDER = new ThreadLocalRandomProvider() {
|
RANDOM_PROVIDER = new ThreadLocalRandomProvider() {
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
public Random current() {
|
public Random current() {
|
||||||
return java.util.concurrent.ThreadLocalRandom.current();
|
return java.util.concurrent.ThreadLocalRandom.current();
|
||||||
}
|
}
|
||||||
@ -964,6 +965,7 @@ public final class PlatformDependent {
|
|||||||
/**
|
/**
|
||||||
* Returns a new concurrent {@link Deque}.
|
* Returns a new concurrent {@link Deque}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
public static <C> Deque<C> newConcurrentDeque() {
|
public static <C> Deque<C> newConcurrentDeque() {
|
||||||
if (javaVersion() < 7) {
|
if (javaVersion() < 7) {
|
||||||
return new LinkedBlockingDeque<C>();
|
return new LinkedBlockingDeque<C>();
|
||||||
|
@ -33,6 +33,7 @@ import static io.netty.util.internal.ObjectUtil.checkNotNull;
|
|||||||
/**
|
/**
|
||||||
* The {@link PlatformDependent} operations which requires access to {@code sun.misc.*}.
|
* The {@link PlatformDependent} operations which requires access to {@code sun.misc.*}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Unsafe access is guarded")
|
||||||
final class PlatformDependent0 {
|
final class PlatformDependent0 {
|
||||||
|
|
||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(PlatformDependent0.class);
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(PlatformDependent0.class);
|
||||||
|
@ -88,6 +88,7 @@ public final class SocketUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
public static void bind(final SocketChannel socketChannel, final SocketAddress address) throws IOException {
|
public static void bind(final SocketChannel socketChannel, final SocketAddress address) throws IOException {
|
||||||
try {
|
try {
|
||||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
|
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
|
||||||
@ -115,6 +116,7 @@ public final class SocketUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
public static void bind(final DatagramChannel networkChannel, final SocketAddress address) throws IOException {
|
public static void bind(final DatagramChannel networkChannel, final SocketAddress address) throws IOException {
|
||||||
try {
|
try {
|
||||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
|
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
|
||||||
@ -182,6 +184,7 @@ public final class SocketUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
public static InetAddress loopbackAddress() {
|
public static InetAddress loopbackAddress() {
|
||||||
return AccessController.doPrivileged(new PrivilegedAction<InetAddress>() {
|
return AccessController.doPrivileged(new PrivilegedAction<InetAddress>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
|||||||
* Annotation to suppress the Java 6 source code requirement checks for a method.
|
* Annotation to suppress the Java 6 source code requirement checks for a method.
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.CLASS)
|
@Retention(RetentionPolicy.CLASS)
|
||||||
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
|
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE })
|
||||||
public @interface SuppressJava6Requirement {
|
public @interface SuppressJava6Requirement {
|
||||||
|
|
||||||
String reason();
|
String reason();
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.net.ssl.ExtendedSSLSession;
|
import javax.net.ssl.ExtendedSSLSession;
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
@ -29,6 +31,7 @@ import java.util.List;
|
|||||||
* Delegates all operations to a wrapped {@link OpenSslSession} except the methods defined by {@link ExtendedSSLSession}
|
* Delegates all operations to a wrapped {@link OpenSslSession} except the methods defined by {@link ExtendedSSLSession}
|
||||||
* itself.
|
* itself.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
abstract class ExtendedOpenSslSession extends ExtendedSSLSession implements OpenSslSession {
|
abstract class ExtendedOpenSslSession extends ExtendedSSLSession implements OpenSslSession {
|
||||||
|
|
||||||
// TODO: use OpenSSL API to actually fetch the real data but for now just do what Conscrypt does:
|
// TODO: use OpenSSL API to actually fetch the real data but for now just do what Conscrypt does:
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.net.ssl.SSLParameters;
|
import javax.net.ssl.SSLParameters;
|
||||||
import java.security.AlgorithmConstraints;
|
import java.security.AlgorithmConstraints;
|
||||||
|
|
||||||
@ -29,6 +31,7 @@ final class Java7SslParametersUtils {
|
|||||||
* {@link AlgorithmConstraints} in the code. This helps us to not get into trouble when using it in java
|
* {@link AlgorithmConstraints} in the code. This helps us to not get into trouble when using it in java
|
||||||
* version < 7 and especially when using on android.
|
* version < 7 and especially when using on android.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
static void setAlgorithmConstraints(SSLParameters sslParameters, Object algorithmConstraints) {
|
static void setAlgorithmConstraints(SSLParameters sslParameters, Object algorithmConstraints) {
|
||||||
sslParameters.setAlgorithmConstraints((AlgorithmConstraints) algorithmConstraints);
|
sslParameters.setAlgorithmConstraints((AlgorithmConstraints) algorithmConstraints);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.net.ssl.SNIHostName;
|
import javax.net.ssl.SNIHostName;
|
||||||
import javax.net.ssl.SNIMatcher;
|
import javax.net.ssl.SNIMatcher;
|
||||||
import javax.net.ssl.SNIServerName;
|
import javax.net.ssl.SNIServerName;
|
||||||
@ -25,6 +27,7 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
final class Java8SslUtils {
|
final class Java8SslUtils {
|
||||||
|
|
||||||
private Java8SslUtils() { }
|
private Java8SslUtils() { }
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.net.ssl.SSLEngine;
|
import javax.net.ssl.SSLEngine;
|
||||||
import javax.net.ssl.SSLEngineResult;
|
import javax.net.ssl.SSLEngineResult;
|
||||||
@ -30,6 +31,7 @@ import static io.netty.handler.ssl.SslUtils.toSSLHandshakeException;
|
|||||||
import static io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectionListener;
|
import static io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectionListener;
|
||||||
import static io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector;
|
import static io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector;
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
final class Java9SslEngine extends JdkSslEngine {
|
final class Java9SslEngine extends JdkSslEngine {
|
||||||
private final ProtocolSelectionListener selectionListener;
|
private final ProtocolSelectionListener selectionListener;
|
||||||
private final AlpnSelector alpnSelector;
|
private final AlpnSelector alpnSelector;
|
||||||
|
@ -27,9 +27,11 @@ import java.util.function.BiFunction;
|
|||||||
|
|
||||||
import io.netty.util.internal.EmptyArrays;
|
import io.netty.util.internal.EmptyArrays;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
final class Java9SslUtils {
|
final class Java9SslUtils {
|
||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Java9SslUtils.class);
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Java9SslUtils.class);
|
||||||
private static final Method SET_APPLICATION_PROTOCOLS;
|
private static final Method SET_APPLICATION_PROTOCOLS;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import javax.net.ssl.SSLEngine;
|
import javax.net.ssl.SSLEngine;
|
||||||
@ -145,6 +147,7 @@ class JdkSslEngine extends SSLEngine implements ApplicationProtocolAccessor {
|
|||||||
engine.setEnabledProtocols(strings);
|
engine.setEnabledProtocols(strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Can only be called when running on JDK7+")
|
||||||
@Override
|
@Override
|
||||||
public SSLSession getHandshakeSession() {
|
public SSLSession getHandshakeSession() {
|
||||||
return engine.getHandshakeSession();
|
return engine.getHandshakeSession();
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.net.ssl.SSLEngine;
|
import javax.net.ssl.SSLEngine;
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
@ -35,6 +36,7 @@ import java.util.List;
|
|||||||
* default {@link X509ExtendedTrustManager} implementations provided by the JDK that can not handle a protocol version
|
* default {@link X509ExtendedTrustManager} implementations provided by the JDK that can not handle a protocol version
|
||||||
* of {@code TLSv1.3}.
|
* of {@code TLSv1.3}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
final class OpenSslTlsv13X509ExtendedTrustManager extends X509ExtendedTrustManager {
|
final class OpenSslTlsv13X509ExtendedTrustManager extends X509ExtendedTrustManager {
|
||||||
|
|
||||||
private final X509ExtendedTrustManager tm;
|
private final X509ExtendedTrustManager tm;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.security.auth.x500.X500Principal;
|
import javax.security.auth.x500.X500Principal;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@ -81,7 +83,7 @@ final class OpenSslX509Certificate extends X509Certificate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No @Override annotation as it was only introduced in Java8.
|
// No @Override annotation as it was only introduced in Java8.
|
||||||
@Override
|
@SuppressJava6Requirement(reason = "Can only be called from Java8 as class is package-private")
|
||||||
public void verify(PublicKey key, Provider sigProvider)
|
public void verify(PublicKey key, Provider sigProvider)
|
||||||
throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
|
throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
|
||||||
unwrap().verify(key, sigProvider);
|
unwrap().verify(key, sigProvider);
|
||||||
|
@ -17,6 +17,7 @@ package io.netty.handler.ssl;
|
|||||||
|
|
||||||
import io.netty.util.internal.EmptyArrays;
|
import io.netty.util.internal.EmptyArrays;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ import java.security.cert.X509Certificate;
|
|||||||
* This is really a "hack" until there is an official API as requested on the in
|
* This is really a "hack" until there is an official API as requested on the in
|
||||||
* <a href="https://bugs.openjdk.java.net/projects/JDK/issues/JDK-8210843">JDK-8210843</a>.
|
* <a href="https://bugs.openjdk.java.net/projects/JDK/issues/JDK-8210843">JDK-8210843</a>.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
final class OpenSslX509TrustManagerWrapper {
|
final class OpenSslX509TrustManagerWrapper {
|
||||||
private static final InternalLogger LOGGER = InternalLoggerFactory
|
private static final InternalLogger LOGGER = InternalLoggerFactory
|
||||||
.getInstance(OpenSslX509TrustManagerWrapper.class);
|
.getInstance(OpenSslX509TrustManagerWrapper.class);
|
||||||
@ -163,6 +165,7 @@ final class OpenSslX509TrustManagerWrapper {
|
|||||||
this.tmOffset = tmOffset;
|
this.tmOffset = tmOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@Override
|
@Override
|
||||||
public X509TrustManager wrapIfNeeded(X509TrustManager manager) {
|
public X509TrustManager wrapIfNeeded(X509TrustManager manager) {
|
||||||
if (!(manager instanceof X509ExtendedTrustManager)) {
|
if (!(manager instanceof X509ExtendedTrustManager)) {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
import io.netty.internal.tcnative.CertificateCallback;
|
import io.netty.internal.tcnative.CertificateCallback;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
import io.netty.internal.tcnative.SSL;
|
import io.netty.internal.tcnative.SSL;
|
||||||
@ -155,13 +156,7 @@ public final class ReferenceCountedOpenSslClientContext extends ReferenceCounted
|
|||||||
//
|
//
|
||||||
// See https://github.com/netty/netty/issues/5372
|
// See https://github.com/netty/netty/issues/5372
|
||||||
|
|
||||||
// Use this to prevent an error when running on java < 7
|
setVerifyCallback(ctx, engineMap, manager);
|
||||||
if (useExtendedTrustManager(manager)) {
|
|
||||||
SSLContext.setCertVerifyCallback(ctx,
|
|
||||||
new ExtendedTrustManagerVerifyCallback(engineMap, (X509ExtendedTrustManager) manager));
|
|
||||||
} else {
|
|
||||||
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (keyMaterialProvider != null) {
|
if (keyMaterialProvider != null) {
|
||||||
keyMaterialProvider.destroy();
|
keyMaterialProvider.destroy();
|
||||||
@ -178,6 +173,17 @@ public final class ReferenceCountedOpenSslClientContext extends ReferenceCounted
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Guarded by java version check")
|
||||||
|
private static void setVerifyCallback(long ctx, OpenSslEngineMap engineMap, X509TrustManager manager) {
|
||||||
|
// Use this to prevent an error when running on java < 7
|
||||||
|
if (useExtendedTrustManager(manager)) {
|
||||||
|
SSLContext.setCertVerifyCallback(ctx,
|
||||||
|
new ExtendedTrustManagerVerifyCallback(engineMap, (X509ExtendedTrustManager) manager));
|
||||||
|
} else {
|
||||||
|
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// No cache is currently supported for client side mode.
|
// No cache is currently supported for client side mode.
|
||||||
static final class OpenSslClientSessionContext extends OpenSslSessionContext {
|
static final class OpenSslClientSessionContext extends OpenSslSessionContext {
|
||||||
OpenSslClientSessionContext(ReferenceCountedOpenSslContext context, OpenSslKeyMaterialProvider provider) {
|
OpenSslClientSessionContext(ReferenceCountedOpenSslContext context, OpenSslKeyMaterialProvider provider) {
|
||||||
@ -234,6 +240,7 @@ public final class ReferenceCountedOpenSslClientContext extends ReferenceCounted
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier {
|
private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier {
|
||||||
private final X509ExtendedTrustManager manager;
|
private final X509ExtendedTrustManager manager;
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import io.netty.util.ResourceLeakTracker;
|
|||||||
import io.netty.util.internal.ObjectUtil;
|
import io.netty.util.internal.ObjectUtil;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.SystemPropertyUtil;
|
import io.netty.util.internal.SystemPropertyUtil;
|
||||||
import io.netty.util.internal.UnstableApi;
|
import io.netty.util.internal.UnstableApi;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
@ -637,6 +638,7 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Guarded by java version check")
|
||||||
static boolean useExtendedTrustManager(X509TrustManager trustManager) {
|
static boolean useExtendedTrustManager(X509TrustManager trustManager) {
|
||||||
return PlatformDependent.javaVersion() >= 7 && trustManager instanceof X509ExtendedTrustManager;
|
return PlatformDependent.javaVersion() >= 7 && trustManager instanceof X509ExtendedTrustManager;
|
||||||
}
|
}
|
||||||
@ -715,6 +717,16 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
|
|||||||
return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
|
return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
|
||||||
}
|
}
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
if (PlatformDependent.javaVersion() >= 7) {
|
||||||
|
return translateToError(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Could not detect a specific error code to use, so fallback to a default code.
|
||||||
|
return CertificateVerifier.X509_V_ERR_UNSPECIFIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
|
private static int translateToError(Throwable cause) {
|
||||||
if (cause instanceof CertificateRevokedException) {
|
if (cause instanceof CertificateRevokedException) {
|
||||||
return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
|
return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
|
||||||
}
|
}
|
||||||
@ -739,12 +751,8 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
|
|||||||
}
|
}
|
||||||
wrapped = wrapped.getCause();
|
wrapped = wrapped.getCause();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Could not detect a specific error code to use, so fallback to a default code.
|
|
||||||
return CertificateVerifier.X509_V_ERR_UNSPECIFIED;
|
return CertificateVerifier.X509_V_ERR_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
abstract void verify(ReferenceCountedOpenSslEngine engine, X509Certificate[] peerCerts,
|
abstract void verify(ReferenceCountedOpenSslEngine engine, X509Certificate[] peerCerts,
|
||||||
String auth) throws Exception;
|
String auth) throws Exception;
|
||||||
|
@ -28,6 +28,7 @@ import io.netty.util.ResourceLeakTracker;
|
|||||||
import io.netty.util.internal.EmptyArrays;
|
import io.netty.util.internal.EmptyArrays;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.UnstableApi;
|
import io.netty.util.internal.UnstableApi;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
@ -1952,6 +1953,7 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@Override
|
@Override
|
||||||
public final synchronized SSLParameters getSSLParameters() {
|
public final synchronized SSLParameters getSSLParameters() {
|
||||||
SSLParameters sslParameters = super.getSSLParameters();
|
SSLParameters sslParameters = super.getSSLParameters();
|
||||||
@ -1975,6 +1977,7 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
|||||||
return sslParameters;
|
return sslParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@Override
|
@Override
|
||||||
public final synchronized void setSSLParameters(SSLParameters sslParameters) {
|
public final synchronized void setSSLParameters(SSLParameters sslParameters) {
|
||||||
int version = PlatformDependent.javaVersion();
|
int version = PlatformDependent.javaVersion();
|
||||||
|
@ -22,6 +22,7 @@ import io.netty.internal.tcnative.SSLContext;
|
|||||||
import io.netty.internal.tcnative.SniHostNameMatcher;
|
import io.netty.internal.tcnative.SniHostNameMatcher;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
@ -147,13 +148,7 @@ public final class ReferenceCountedOpenSslServerContext extends ReferenceCounted
|
|||||||
//
|
//
|
||||||
// See https://github.com/netty/netty/issues/5372
|
// See https://github.com/netty/netty/issues/5372
|
||||||
|
|
||||||
// Use this to prevent an error when running on java < 7
|
setVerifyCallback(ctx, engineMap, manager);
|
||||||
if (useExtendedTrustManager(manager)) {
|
|
||||||
SSLContext.setCertVerifyCallback(ctx, new ExtendedTrustManagerVerifyCallback(
|
|
||||||
engineMap, (X509ExtendedTrustManager) manager));
|
|
||||||
} else {
|
|
||||||
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
|
|
||||||
}
|
|
||||||
|
|
||||||
X509Certificate[] issuers = manager.getAcceptedIssuers();
|
X509Certificate[] issuers = manager.getAcceptedIssuers();
|
||||||
if (issuers != null && issuers.length > 0) {
|
if (issuers != null && issuers.length > 0) {
|
||||||
@ -194,6 +189,17 @@ public final class ReferenceCountedOpenSslServerContext extends ReferenceCounted
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Guarded by java version check")
|
||||||
|
private static void setVerifyCallback(long ctx, OpenSslEngineMap engineMap, X509TrustManager manager) {
|
||||||
|
// Use this to prevent an error when running on java < 7
|
||||||
|
if (useExtendedTrustManager(manager)) {
|
||||||
|
SSLContext.setCertVerifyCallback(ctx, new ExtendedTrustManagerVerifyCallback(
|
||||||
|
engineMap, (X509ExtendedTrustManager) manager));
|
||||||
|
} else {
|
||||||
|
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final class OpenSslServerCertificateCallback implements CertificateCallback {
|
private static final class OpenSslServerCertificateCallback implements CertificateCallback {
|
||||||
private final OpenSslEngineMap engineMap;
|
private final OpenSslEngineMap engineMap;
|
||||||
private final OpenSslKeyMaterialManager keyManagerHolder;
|
private final OpenSslKeyMaterialManager keyManagerHolder;
|
||||||
@ -236,6 +242,7 @@ public final class ReferenceCountedOpenSslServerContext extends ReferenceCounted
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier {
|
private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier {
|
||||||
private final X509ExtendedTrustManager manager;
|
private final X509ExtendedTrustManager manager;
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package io.netty.handler.ssl.util;
|
package io.netty.handler.ssl.util;
|
||||||
|
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import sun.security.x509.AlgorithmId;
|
import sun.security.x509.AlgorithmId;
|
||||||
import sun.security.x509.CertificateAlgorithmId;
|
import sun.security.x509.CertificateAlgorithmId;
|
||||||
import sun.security.x509.CertificateIssuerName;
|
import sun.security.x509.CertificateIssuerName;
|
||||||
@ -42,6 +43,7 @@ import static io.netty.handler.ssl.util.SelfSignedCertificate.*;
|
|||||||
*/
|
*/
|
||||||
final class OpenJdkSelfSignedCertGenerator {
|
final class OpenJdkSelfSignedCertGenerator {
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by dependency check")
|
||||||
static String[] generate(String fqdn, KeyPair keypair, SecureRandom random, Date notBefore, Date notAfter)
|
static String[] generate(String fqdn, KeyPair keypair, SecureRandom random, Date notBefore, Date notAfter)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
PrivateKey key = keypair.getPrivate();
|
PrivateKey key = keypair.getPrivate();
|
||||||
|
@ -18,6 +18,7 @@ package io.netty.handler.ssl.util;
|
|||||||
|
|
||||||
import io.netty.util.concurrent.FastThreadLocal;
|
import io.netty.util.concurrent.FastThreadLocal;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.net.ssl.ManagerFactoryParameters;
|
import javax.net.ssl.ManagerFactoryParameters;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
@ -136,6 +137,15 @@ public abstract class SimpleTrustManagerFactory extends TrustManagerFactory {
|
|||||||
if (trustManagers == null) {
|
if (trustManagers == null) {
|
||||||
trustManagers = parent.engineGetTrustManagers();
|
trustManagers = parent.engineGetTrustManagers();
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
if (PlatformDependent.javaVersion() >= 7) {
|
||||||
|
wrapIfNeeded(trustManagers);
|
||||||
|
}
|
||||||
|
this.trustManagers = trustManagers;
|
||||||
|
}
|
||||||
|
return trustManagers.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
|
private static void wrapIfNeeded(TrustManager[] trustManagers) {
|
||||||
for (int i = 0; i < trustManagers.length; i++) {
|
for (int i = 0; i < trustManagers.length; i++) {
|
||||||
final TrustManager tm = trustManagers[i];
|
final TrustManager tm = trustManagers[i];
|
||||||
if (tm instanceof X509TrustManager && !(tm instanceof X509ExtendedTrustManager)) {
|
if (tm instanceof X509TrustManager && !(tm instanceof X509ExtendedTrustManager)) {
|
||||||
@ -143,9 +153,5 @@ public abstract class SimpleTrustManagerFactory extends TrustManagerFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.trustManagers = trustManagers;
|
|
||||||
}
|
|
||||||
return trustManagers.clone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.ssl.util;
|
package io.netty.handler.ssl.util;
|
||||||
|
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import javax.net.ssl.SSLEngine;
|
import javax.net.ssl.SSLEngine;
|
||||||
import javax.net.ssl.X509ExtendedTrustManager;
|
import javax.net.ssl.X509ExtendedTrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
@ -24,6 +26,7 @@ import java.security.cert.X509Certificate;
|
|||||||
|
|
||||||
import static io.netty.util.internal.ObjectUtil.*;
|
import static io.netty.util.internal.ObjectUtil.*;
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
final class X509TrustManagerWrapper extends X509ExtendedTrustManager {
|
final class X509TrustManagerWrapper extends X509ExtendedTrustManager {
|
||||||
|
|
||||||
private final X509TrustManager delegate;
|
private final X509TrustManager delegate;
|
||||||
|
71
pom.xml
71
pom.xml
@ -819,78 +819,7 @@
|
|||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
</signature>
|
</signature>
|
||||||
<ignores>
|
<ignores>
|
||||||
<ignore>sun.misc.Unsafe</ignore>
|
|
||||||
<ignore>sun.misc.Cleaner</ignore>
|
|
||||||
<ignore>sun.nio.ch.DirectBuffer</ignore>
|
|
||||||
|
|
||||||
<ignore>java.util.zip.Deflater</ignore>
|
|
||||||
|
|
||||||
<!-- Used for NIO -->
|
|
||||||
<ignore>java.nio.channels.DatagramChannel</ignore>
|
|
||||||
<ignore>java.nio.channels.MembershipKey</ignore>
|
|
||||||
<ignore>java.nio.channels.ServerSocketChannel</ignore>
|
|
||||||
<ignore>java.nio.channels.SocketChannel</ignore>
|
|
||||||
<ignore>java.net.StandardProtocolFamily</ignore>
|
|
||||||
<ignore>java.nio.channels.spi.SelectorProvider</ignore>
|
|
||||||
<ignore>java.net.SocketOption</ignore>
|
|
||||||
<ignore>java.net.StandardSocketOptions</ignore>
|
|
||||||
<ignore>java.nio.channels.NetworkChannel</ignore>
|
|
||||||
|
|
||||||
<!-- Self-signed certificate generation -->
|
|
||||||
<ignore>sun.security.x509.AlgorithmId</ignore>
|
|
||||||
<ignore>sun.security.x509.CertificateAlgorithmId</ignore>
|
|
||||||
<ignore>sun.security.x509.CertificateIssuerName</ignore>
|
|
||||||
<ignore>sun.security.x509.CertificateSerialNumber</ignore>
|
|
||||||
<ignore>sun.security.x509.CertificateSubjectName</ignore>
|
|
||||||
<ignore>sun.security.x509.CertificateValidity</ignore>
|
|
||||||
<ignore>sun.security.x509.CertificateVersion</ignore>
|
|
||||||
<ignore>sun.security.x509.CertificateX509Key</ignore>
|
|
||||||
<ignore>sun.security.x509.X500Name</ignore>
|
|
||||||
<ignore>sun.security.x509.X509CertInfo</ignore>
|
|
||||||
<ignore>sun.security.x509.X509CertImpl</ignore>
|
|
||||||
|
|
||||||
<!-- SSLSession implementation -->
|
|
||||||
<ignore>javax.net.ssl.SSLEngine</ignore>
|
|
||||||
<ignore>javax.net.ssl.ExtendedSSLSession</ignore>
|
|
||||||
<ignore>javax.net.ssl.X509ExtendedTrustManager</ignore>
|
|
||||||
<ignore>javax.net.ssl.SSLParameters</ignore>
|
|
||||||
<ignore>javax.net.ssl.SNIServerName</ignore>
|
|
||||||
<ignore>javax.net.ssl.SNIHostName</ignore>
|
|
||||||
<ignore>javax.net.ssl.SNIMatcher</ignore>
|
|
||||||
<ignore>java.security.AlgorithmConstraints</ignore>
|
|
||||||
<ignore>java.security.cert.CertificateRevokedException</ignore>
|
|
||||||
<ignore>java.security.cert.CertPathValidatorException</ignore>
|
|
||||||
<ignore>java.security.cert.CertPathValidatorException$Reason</ignore>
|
|
||||||
<ignore>java.security.cert.CertPathValidatorException$BasicReason</ignore>
|
|
||||||
|
|
||||||
<ignore>java.util.concurrent.ConcurrentLinkedDeque</ignore>
|
|
||||||
<ignore>java.util.concurrent.ThreadLocalRandom</ignore>
|
|
||||||
|
|
||||||
<!-- Compression -->
|
|
||||||
<ignore>java.util.zip.CRC32</ignore>
|
|
||||||
<ignore>java.util.zip.Adler32</ignore>
|
|
||||||
|
|
||||||
<!-- NioDatagramChannel implementation -->
|
|
||||||
<ignore>java.net.ProtocolFamily</ignore>
|
|
||||||
|
|
||||||
<!-- JDK 9 -->
|
|
||||||
<ignore>java.nio.ByteBuffer</ignore>
|
<ignore>java.nio.ByteBuffer</ignore>
|
||||||
<ignore>java.nio.CharBuffer</ignore>
|
|
||||||
|
|
||||||
<!-- JDK 8 -->
|
|
||||||
<ignore>java.util.concurrent.atomic.LongAdder</ignore>
|
|
||||||
<ignore>java.util.function.BiFunction</ignore>
|
|
||||||
<ignore>java.security.cert.X509Certificate</ignore>
|
|
||||||
|
|
||||||
<!-- Resolver -->
|
|
||||||
<ignore>java.net.InetAddress</ignore>
|
|
||||||
|
|
||||||
<!-- NoexecVolumeDetector -->
|
|
||||||
<ignore>java.nio.file.attribute.PosixFilePermission</ignore>
|
|
||||||
<ignore>java.nio.file.Files</ignore>
|
|
||||||
<ignore>java.nio.file.LinkOption</ignore>
|
|
||||||
<ignore>java.nio.file.Path</ignore>
|
|
||||||
<ignore>java.io.File</ignore>
|
|
||||||
</ignores>
|
</ignores>
|
||||||
<annotations>
|
<annotations>
|
||||||
<annotation>io.netty.util.internal.SuppressJava6Requirement</annotation>
|
<annotation>io.netty.util.internal.SuppressJava6Requirement</annotation>
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import io.netty.channel.socket.InternetProtocolFamily;
|
import io.netty.channel.socket.InternetProtocolFamily;
|
||||||
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
@ -26,9 +28,13 @@ import java.nio.channels.spi.SelectorProvider;
|
|||||||
|
|
||||||
public class DatagramUnicastIPv6Test extends DatagramUnicastTest {
|
public class DatagramUnicastIPv6Test extends DatagramUnicastTest {
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Guarded by java version check")
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void assumeIpv6Supported() {
|
public static void assumeIpv6Supported() {
|
||||||
try {
|
try {
|
||||||
|
if (PlatformDependent.javaVersion() < 7) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
Channel channel = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET6);
|
Channel channel = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET6);
|
||||||
channel.close();
|
channel.close();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
|
@ -17,6 +17,7 @@ package io.netty.channel.socket.nio;
|
|||||||
|
|
||||||
import io.netty.channel.ChannelException;
|
import io.netty.channel.ChannelException;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.Channel;
|
import java.nio.channels.Channel;
|
||||||
@ -29,6 +30,7 @@ import java.util.Set;
|
|||||||
* Provides {@link ChannelOption} over a given {@link java.net.SocketOption} which is then passed through the underlying
|
* Provides {@link ChannelOption} over a given {@link java.net.SocketOption} which is then passed through the underlying
|
||||||
* {@link java.nio.channels.NetworkChannel}.
|
* {@link java.nio.channels.NetworkChannel}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage explicit by the user")
|
||||||
public final class NioChannelOption<T> extends ChannelOption<T> {
|
public final class NioChannelOption<T> extends ChannelOption<T> {
|
||||||
|
|
||||||
private final java.net.SocketOption<T> option;
|
private final java.net.SocketOption<T> option;
|
||||||
@ -53,6 +55,7 @@ public final class NioChannelOption<T> extends ChannelOption<T> {
|
|||||||
// See https://github.com/netty/netty/issues/8166
|
// See https://github.com/netty/netty/issues/8166
|
||||||
|
|
||||||
// Internal helper methods to remove code duplication between Nio*Channel implementations.
|
// Internal helper methods to remove code duplication between Nio*Channel implementations.
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
static <T> boolean setOption(Channel jdkChannel, NioChannelOption<T> option, T value) {
|
static <T> boolean setOption(Channel jdkChannel, NioChannelOption<T> option, T value) {
|
||||||
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
|
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
|
||||||
if (!channel.supportedOptions().contains(option.option)) {
|
if (!channel.supportedOptions().contains(option.option)) {
|
||||||
@ -71,6 +74,7 @@ public final class NioChannelOption<T> extends ChannelOption<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
static <T> T getOption(Channel jdkChannel, NioChannelOption<T> option) {
|
static <T> T getOption(Channel jdkChannel, NioChannelOption<T> option) {
|
||||||
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
|
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
|
||||||
|
|
||||||
@ -89,6 +93,7 @@ public final class NioChannelOption<T> extends ChannelOption<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static ChannelOption[] getOptions(Channel jdkChannel) {
|
static ChannelOption[] getOptions(Channel jdkChannel) {
|
||||||
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
|
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
|
||||||
|
@ -33,6 +33,7 @@ import io.netty.channel.socket.InternetProtocolFamily;
|
|||||||
import io.netty.util.internal.SocketUtils;
|
import io.netty.util.internal.SocketUtils;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -88,6 +89,7 @@ public final class NioDatagramChannel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
private static DatagramChannel newSocket(SelectorProvider provider, InternetProtocolFamily ipFamily) {
|
private static DatagramChannel newSocket(SelectorProvider provider, InternetProtocolFamily ipFamily) {
|
||||||
if (ipFamily == null) {
|
if (ipFamily == null) {
|
||||||
return newSocket(provider);
|
return newSocket(provider);
|
||||||
@ -394,6 +396,7 @@ public final class NioDatagramChannel
|
|||||||
return joinGroup(multicastAddress, networkInterface, source, newPromise());
|
return joinGroup(multicastAddress, networkInterface, source, newPromise());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture joinGroup(
|
public ChannelFuture joinGroup(
|
||||||
InetAddress multicastAddress, NetworkInterface networkInterface,
|
InetAddress multicastAddress, NetworkInterface networkInterface,
|
||||||
@ -474,6 +477,7 @@ public final class NioDatagramChannel
|
|||||||
return leaveGroup(multicastAddress, networkInterface, source, newPromise());
|
return leaveGroup(multicastAddress, networkInterface, source, newPromise());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture leaveGroup(
|
public ChannelFuture leaveGroup(
|
||||||
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source,
|
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source,
|
||||||
@ -527,6 +531,7 @@ public final class NioDatagramChannel
|
|||||||
/**
|
/**
|
||||||
* Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
|
* Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture block(
|
public ChannelFuture block(
|
||||||
InetAddress multicastAddress, NetworkInterface networkInterface,
|
InetAddress multicastAddress, NetworkInterface networkInterface,
|
||||||
|
@ -24,6 +24,7 @@ import io.netty.channel.nio.AbstractNioMessageChannel;
|
|||||||
import io.netty.channel.socket.DefaultServerSocketChannelConfig;
|
import io.netty.channel.socket.DefaultServerSocketChannelConfig;
|
||||||
import io.netty.channel.socket.ServerSocketChannelConfig;
|
import io.netty.channel.socket.ServerSocketChannelConfig;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
@ -126,6 +127,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
|||||||
return SocketUtils.localSocketAddress(javaChannel().socket());
|
return SocketUtils.localSocketAddress(javaChannel().socket());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@Override
|
@Override
|
||||||
protected void doBind(SocketAddress localAddress) throws Exception {
|
protected void doBind(SocketAddress localAddress) throws Exception {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
if (PlatformDependent.javaVersion() >= 7) {
|
||||||
@ -220,7 +222,6 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
|||||||
return super.getOption(option);
|
return super.getOption(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ChannelOption<?>, Object> getOptions() {
|
public Map<ChannelOption<?>, Object> getOptions() {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
if (PlatformDependent.javaVersion() >= 7) {
|
||||||
|
@ -33,6 +33,7 @@ import io.netty.channel.socket.SocketChannelConfig;
|
|||||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import io.netty.util.internal.SocketUtils;
|
import io.netty.util.internal.SocketUtils;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
import io.netty.util.internal.UnstableApi;
|
import io.netty.util.internal.UnstableApi;
|
||||||
import io.netty.util.internal.logging.InternalLogger;
|
import io.netty.util.internal.logging.InternalLogger;
|
||||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||||
@ -152,6 +153,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
return (InetSocketAddress) super.remoteAddress();
|
return (InetSocketAddress) super.remoteAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
@Override
|
@Override
|
||||||
protected final void doShutdownOutput() throws Exception {
|
protected final void doShutdownOutput() throws Exception {
|
||||||
@ -270,6 +272,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
private void shutdownInput0() throws Exception {
|
private void shutdownInput0() throws Exception {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
if (PlatformDependent.javaVersion() >= 7) {
|
||||||
javaChannel().shutdownInput();
|
javaChannel().shutdownInput();
|
||||||
@ -496,7 +499,6 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
return super.getOption(option);
|
return super.getOption(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ChannelOption<?>, Object> getOptions() {
|
public Map<ChannelOption<?>, Object> getOptions() {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
if (PlatformDependent.javaVersion() >= 7) {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package io.netty.channel.socket.nio;
|
package io.netty.channel.socket.nio;
|
||||||
|
|
||||||
import io.netty.channel.socket.InternetProtocolFamily;
|
import io.netty.channel.socket.InternetProtocolFamily;
|
||||||
|
import io.netty.util.internal.SuppressJava6Requirement;
|
||||||
|
|
||||||
import java.net.ProtocolFamily;
|
import java.net.ProtocolFamily;
|
||||||
import java.net.StandardProtocolFamily;
|
import java.net.StandardProtocolFamily;
|
||||||
@ -32,6 +33,7 @@ final class ProtocolFamilyConverter {
|
|||||||
/**
|
/**
|
||||||
* Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
|
* Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
|
||||||
*/
|
*/
|
||||||
|
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
|
||||||
public static ProtocolFamily convert(InternetProtocolFamily family) {
|
public static ProtocolFamily convert(InternetProtocolFamily family) {
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case IPv4:
|
case IPv4:
|
||||||
|
Loading…
Reference in New Issue
Block a user