From 0f1698f9068b0ffd2b09692c2d22bc2ddbd243b6 Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Tue, 2 Jun 2015 04:01:04 +0000 Subject: [PATCH] 8043758: Datagram Transport Layer Security (DTLS) Reviewed-by: jnimeh, weijun, mullan, wetmore --- .../javax/net/ssl/ExtendedSSLSession.java | 14 +- .../classes/javax/net/ssl/SNIServerName.java | 4 +- .../classes/javax/net/ssl/SSLContext.java | 64 +- .../classes/javax/net/ssl/SSLContextSpi.java | 40 +- .../classes/javax/net/ssl/SSLEngine.java | 314 ++-- .../javax/net/ssl/SSLEngineResult.java | 145 +- .../classes/javax/net/ssl/SSLParameters.java | 146 +- .../classes/javax/net/ssl/SSLSession.java | 36 +- .../net/ssl/X509ExtendedTrustManager.java | 73 +- .../sun/security/ssl/AppInputStream.java | 105 +- .../sun/security/ssl/AppOutputStream.java | 79 +- .../sun/security/ssl/Authenticator.java | 154 +- .../classes/sun/security/ssl/CipherBox.java | 146 +- .../classes/sun/security/ssl/CipherSuite.java | 81 +- .../classes/sun/security/ssl/Ciphertext.java | 145 ++ .../sun/security/ssl/ClientAuthType.java | 36 + .../sun/security/ssl/ClientHandshaker.java | 251 +++- .../sun/security/ssl/DTLSInputRecord.java | 1265 +++++++++++++++++ .../sun/security/ssl/DTLSOutputRecord.java | 597 ++++++++ .../classes/sun/security/ssl/DTLSRecord.java | 87 ++ .../share/classes/sun/security/ssl/Debug.java | 46 + .../classes/sun/security/ssl/EngineArgs.java | 238 ---- .../sun/security/ssl/EngineInputRecord.java | 427 ------ .../sun/security/ssl/EngineOutputRecord.java | 329 ----- .../sun/security/ssl/EngineWriter.java | 244 ---- .../sun/security/ssl/HandshakeHash.java | 113 +- .../sun/security/ssl/HandshakeInStream.java | 171 +-- .../sun/security/ssl/HandshakeMessage.java | 272 +++- .../sun/security/ssl/HandshakeOutStream.java | 183 +-- .../security/ssl/HandshakeStateManager.java | 925 ++++++++++++ .../classes/sun/security/ssl/Handshaker.java | 303 ++-- .../sun/security/ssl/HelloCookieManager.java | 144 ++ .../sun/security/ssl/HelloExtensions.java | 2 + .../classes/sun/security/ssl/InputRecord.java | 1059 ++++++-------- .../share/classes/sun/security/ssl/MAC.java | 54 +- .../ssl/MaxFragmentLengthExtension.java | 139 ++ .../sun/security/ssl/OutputRecord.java | 755 +++++----- .../classes/sun/security/ssl/Plaintext.java | 77 + .../sun/security/ssl/ProtocolList.java | 7 +- .../sun/security/ssl/ProtocolVersion.java | 131 +- .../security/ssl/RSAClientKeyExchange.java | 10 +- .../sun/security/ssl/RandomCookie.java | 10 +- .../classes/sun/security/ssl/Record.java | 103 +- .../classes/sun/security/ssl/RecordType.java | 122 ++ .../sun/security/ssl/SSLContextImpl.java | 496 +++++-- .../sun/security/ssl/SSLEngineImpl.java | 1255 ++++++++-------- .../security/ssl/SSLEngineInputRecord.java | 409 ++++++ .../security/ssl/SSLEngineOutputRecord.java | 570 ++++++++ .../classes/sun/security/ssl/SSLRecord.java | 117 ++ .../sun/security/ssl/SSLServerSocketImpl.java | 16 +- .../sun/security/ssl/SSLSessionImpl.java | 88 +- .../sun/security/ssl/SSLSocketImpl.java | 1220 ++++++++-------- .../security/ssl/SSLSocketInputRecord.java | 441 ++++++ .../security/ssl/SSLSocketOutputRecord.java | 383 +++++ .../sun/security/ssl/ServerHandshaker.java | 258 ++-- .../classes/sun/security/ssl/SunJSSE.java | 9 +- .../sun/security/ssl/X509KeyManagerImpl.java | 4 +- .../security/ssl/X509TrustManagerImpl.java | 4 +- .../share/conf/security/java.security | 6 +- jdk/test/javax/net/ssl/DTLS/CipherSuite.java | 75 + jdk/test/javax/net/ssl/DTLS/ClientAuth.java | 57 + .../javax/net/ssl/DTLS/DTLSOverDatagram.java | 602 ++++++++ .../javax/net/ssl/DTLS/InvalidCookie.java | 66 + .../javax/net/ssl/DTLS/InvalidRecords.java | 78 + .../net/ssl/DTLS/NoMacInitialClientHello.java | 65 + jdk/test/javax/net/ssl/DTLS/Reordered.java | 65 + .../javax/net/ssl/DTLS/Retransmission.java | 79 + .../javax/net/ssl/DTLS/WeakCipherSuite.java | 69 + .../javax/net/ssl/SSLEngine/CheckStatus.java | 18 +- .../javax/net/ssl/SSLEngine/LargeBufs.java | 2 +- .../javax/net/ssl/TLS/CipherTestUtils.java | 1 + .../net/ssl/TLSv11/ExportableBlockCipher.java | 11 +- .../ssl/TLSv11/ExportableStreamCipher.java | 11 +- .../templates/SSLSocketSSLEngineTemplate.java | 14 + .../ssl/AppInputStream/ReadHandshake.java | 13 +- .../ssl/ClientHandshaker/LengthCheckTest.java | 4 +- 76 files changed, 11196 insertions(+), 4956 deletions(-) create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/Ciphertext.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/ClientAuthType.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/DTLSInputRecord.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/DTLSOutputRecord.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/DTLSRecord.java delete mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/EngineArgs.java delete mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/EngineInputRecord.java delete mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/EngineOutputRecord.java delete mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/EngineWriter.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/HandshakeStateManager.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/HelloCookieManager.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/MaxFragmentLengthExtension.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/Plaintext.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/RecordType.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/SSLEngineInputRecord.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/SSLEngineOutputRecord.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/SSLRecord.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/SSLSocketInputRecord.java create mode 100644 jdk/src/java.base/share/classes/sun/security/ssl/SSLSocketOutputRecord.java create mode 100644 jdk/test/javax/net/ssl/DTLS/CipherSuite.java create mode 100644 jdk/test/javax/net/ssl/DTLS/ClientAuth.java create mode 100644 jdk/test/javax/net/ssl/DTLS/DTLSOverDatagram.java create mode 100644 jdk/test/javax/net/ssl/DTLS/InvalidCookie.java create mode 100644 jdk/test/javax/net/ssl/DTLS/InvalidRecords.java create mode 100644 jdk/test/javax/net/ssl/DTLS/NoMacInitialClientHello.java create mode 100644 jdk/test/javax/net/ssl/DTLS/Reordered.java create mode 100644 jdk/test/javax/net/ssl/DTLS/Retransmission.java create mode 100644 jdk/test/javax/net/ssl/DTLS/WeakCipherSuite.java diff --git a/jdk/src/java.base/share/classes/javax/net/ssl/ExtendedSSLSession.java b/jdk/src/java.base/share/classes/javax/net/ssl/ExtendedSSLSession.java index 70f98ce221d..bc9b012db8c 100644 --- a/jdk/src/java.base/share/classes/javax/net/ssl/ExtendedSSLSession.java +++ b/jdk/src/java.base/share/classes/javax/net/ssl/ExtendedSSLSession.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,7 @@ package javax.net.ssl; import java.util.List; /** - * Extends the SSLSession interface to support additional + * Extends the {@code SSLSession} interface to support additional * session attributes. * * @since 1.7 @@ -39,8 +39,8 @@ public abstract class ExtendedSSLSession implements SSLSession { * is willing to use. *

* Note: this method is used to indicate to the peer which signature - * algorithms may be used for digital signatures in TLS 1.2. It is - * not meaningful for TLS versions prior to 1.2. + * algorithms may be used for digital signatures in TLS/DTLS 1.2. It is + * not meaningful for TLS/DTLS versions prior to 1.2. *

* The signature algorithm name must be a standard Java Security * name (such as "SHA1withRSA", "SHA256withECDSA", and so on). @@ -52,7 +52,7 @@ public abstract class ExtendedSSLSession implements SSLSession { * Note: the local supported signature algorithms should conform to * the algorithm constraints specified by * {@link SSLParameters#getAlgorithmConstraints getAlgorithmConstraints()} - * method in SSLParameters. + * method in {@code SSLParameters}. * * @return An array of supported signature algorithms, in descending * order of preference. The return value is an empty array if @@ -67,8 +67,8 @@ public abstract class ExtendedSSLSession implements SSLSession { * able to use. *

* Note: this method is used to indicate to the local side which signature - * algorithms may be used for digital signatures in TLS 1.2. It is - * not meaningful for TLS versions prior to 1.2. + * algorithms may be used for digital signatures in TLS/DTLS 1.2. It is + * not meaningful for TLS/DTLS versions prior to 1.2. *

* The signature algorithm name must be a standard Java Security * name (such as "SHA1withRSA", "SHA256withECDSA", and so on). diff --git a/jdk/src/java.base/share/classes/javax/net/ssl/SNIServerName.java b/jdk/src/java.base/share/classes/javax/net/ssl/SNIServerName.java index 1ef9d05c21e..9df92d75db8 100644 --- a/jdk/src/java.base/share/classes/javax/net/ssl/SNIServerName.java +++ b/jdk/src/java.base/share/classes/javax/net/ssl/SNIServerName.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,7 @@ import java.util.Arrays; * Instances of this class represent a server name in a Server Name * Indication (SNI) extension. *

- * The SNI extension is a feature that extends the SSL/TLS protocols to + * The SNI extension is a feature that extends the SSL/TLS/DTLS protocols to * indicate what server name the client is attempting to connect to during * handshaking. See section 3, "Server Name Indication", of TLS Extensions (RFC 6066). diff --git a/jdk/src/java.base/share/classes/javax/net/ssl/SSLContext.java b/jdk/src/java.base/share/classes/javax/net/ssl/SSLContext.java index c40d7060c39..ebdae178fd8 100644 --- a/jdk/src/java.base/share/classes/javax/net/ssl/SSLContext.java +++ b/jdk/src/java.base/share/classes/javax/net/ssl/SSLContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,12 +32,12 @@ import sun.security.jca.GetInstance; /** * Instances of this class represent a secure socket protocol * implementation which acts as a factory for secure socket - * factories or SSLEngines. This class is initialized + * factories or {@code SSLEngine}s. This class is initialized * with an optional set of key and trust managers and source of * secure random bytes. * *

Every implementation of the Java platform is required to support the - * following standard SSLContext protocol: + * following standard {@code SSLContext} protocol: *

@@ -79,7 +79,7 @@ public class SSLContext { *

If a default context was set using the {@link #setDefault * SSLContext.setDefault()} method, it is returned. Otherwise, the first * call of this method triggers the call - * SSLContext.getInstance("Default"). + * {@code SSLContext.getInstance("Default")}. * If successful, that object is made the default SSL context and returned. * *

The default context is immediately @@ -106,8 +106,8 @@ public class SSLContext { * @param context the SSLContext * @throws NullPointerException if context is null * @throws SecurityException if a security manager exists and its - * checkPermission method does not allow - * SSLPermission("setDefaultSSLContext") + * {@code checkPermission} method does not allow + * {@code SSLPermission("setDefaultSSLContext")} * @since 1.6 */ public static synchronized void setDefault(SSLContext context) { @@ -122,7 +122,7 @@ public class SSLContext { } /** - * Returns a SSLContext object that implements the + * Returns a {@code SSLContext} object that implements the * specified secure socket protocol. * *

This method traverses the list of registered security Providers, @@ -141,7 +141,7 @@ public class SSLContext { * Documentation * for information about standard protocol names. * - * @return the new SSLContext object. + * @return the new {@code SSLContext} object. * * @exception NoSuchAlgorithmException if no Provider supports a * SSLContextSpi implementation for the @@ -159,7 +159,7 @@ public class SSLContext { } /** - * Returns a SSLContext object that implements the + * Returns a {@code SSLContext} object that implements the * specified secure socket protocol. * *

A new SSLContext object encapsulating the @@ -179,7 +179,7 @@ public class SSLContext { * * @param provider the name of the provider. * - * @return the new SSLContext object. + * @return the new {@code SSLContext} object. * * @throws NoSuchAlgorithmException if a SSLContextSpi * implementation for the specified protocol is not @@ -202,7 +202,7 @@ public class SSLContext { } /** - * Returns a SSLContext object that implements the + * Returns a {@code SSLContext} object that implements the * specified secure socket protocol. * *

A new SSLContext object encapsulating the @@ -219,7 +219,7 @@ public class SSLContext { * * @param provider an instance of the provider. * - * @return the new SSLContext object. + * @return the new {@code SSLContext} object. * * @throws NoSuchAlgorithmException if a SSLContextSpi * implementation for the specified protocol is not available @@ -239,22 +239,22 @@ public class SSLContext { } /** - * Returns the protocol name of this SSLContext object. + * Returns the protocol name of this {@code SSLContext} object. * *

This is the same name that was specified in one of the - * getInstance calls that created this - * SSLContext object. + * {@code getInstance} calls that created this + * {@code SSLContext} object. * - * @return the protocol name of this SSLContext object. + * @return the protocol name of this {@code SSLContext} object. */ public final String getProtocol() { return this.protocol; } /** - * Returns the provider of this SSLContext object. + * Returns the provider of this {@code SSLContext} object. * - * @return the provider of this SSLContext object + * @return the provider of this {@code SSLContext} object */ public final Provider getProvider() { return this.provider; @@ -283,31 +283,35 @@ public class SSLContext { } /** - * Returns a SocketFactory object for this + * Returns a {@code SocketFactory} object for this * context. * - * @return the SocketFactory object + * @return the {@code SocketFactory} object + * @throws UnsupportedOperationException if the underlying provider + * does not implement the operation. * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the init() has not been called + * initialization and the {@code init()} has not been called */ public final SSLSocketFactory getSocketFactory() { return contextSpi.engineGetSocketFactory(); } /** - * Returns a ServerSocketFactory object for + * Returns a {@code ServerSocketFactory} object for * this context. * - * @return the ServerSocketFactory object + * @return the {@code ServerSocketFactory} object + * @throws UnsupportedOperationException if the underlying provider + * does not implement the operation. * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the init() has not been called + * initialization and the {@code init()} has not been called */ public final SSLServerSocketFactory getServerSocketFactory() { return contextSpi.engineGetServerSocketFactory(); } /** - * Creates a new SSLEngine using this context. + * Creates a new {@code SSLEngine} using this context. *

* Applications using this factory method are providing no hints * for an internal session reuse strategy. If hints are desired, @@ -317,11 +321,11 @@ public class SSLContext { * Some cipher suites (such as Kerberos) require remote hostname * information, in which case this factory method should not be used. * - * @return the SSLEngine object + * @return the {@code SSLEngine} object * @throws UnsupportedOperationException if the underlying provider * does not implement the operation. * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the init() has not been called + * initialization and the {@code init()} has not been called * @since 1.5 */ public final SSLEngine createSSLEngine() { @@ -338,7 +342,7 @@ public class SSLContext { } /** - * Creates a new SSLEngine using this context using + * Creates a new {@code SSLEngine} using this context using * advisory peer information. *

* Applications using this factory method are providing hints @@ -349,11 +353,11 @@ public class SSLContext { * * @param peerHost the non-authoritative name of the host * @param peerPort the non-authoritative port - * @return the new SSLEngine object + * @return the new {@code SSLEngine} object * @throws UnsupportedOperationException if the underlying provider * does not implement the operation. * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the init() has not been called + * initialization and the {@code init()} has not been called * @since 1.5 */ public final SSLEngine createSSLEngine(String peerHost, int peerPort) { diff --git a/jdk/src/java.base/share/classes/javax/net/ssl/SSLContextSpi.java b/jdk/src/java.base/share/classes/javax/net/ssl/SSLContextSpi.java index 269ed8502e6..966524da9fb 100644 --- a/jdk/src/java.base/share/classes/javax/net/ssl/SSLContextSpi.java +++ b/jdk/src/java.base/share/classes/javax/net/ssl/SSLContextSpi.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,7 +29,7 @@ import java.security.*; /** * This class defines the Service Provider Interface (SPI) - * for the SSLContext class. + * for the {@code SSLContext} class. * *

All the abstract methods in this class must be implemented by each * cryptographic service provider who wishes to supply the implementation @@ -52,31 +52,35 @@ public abstract class SSLContextSpi { SecureRandom sr) throws KeyManagementException; /** - * Returns a SocketFactory object for this + * Returns a {@code SocketFactory} object for this * context. * - * @return the SocketFactory object + * @return the {@code SocketFactory} object + * @throws UnsupportedOperationException if the underlying provider + * does not implement the operation. * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the engineInit() + * initialization and the {@code engineInit()} * has not been called * @see javax.net.ssl.SSLContext#getSocketFactory() */ protected abstract SSLSocketFactory engineGetSocketFactory(); /** - * Returns a ServerSocketFactory object for + * Returns a {@code ServerSocketFactory} object for * this context. * - * @return the ServerSocketFactory object + * @return the {@code ServerSocketFactory} object + * @throws UnsupportedOperationException if the underlying provider + * does not implement the operation. * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the engineInit() + * initialization and the {@code engineInit()} * has not been called * @see javax.net.ssl.SSLContext#getServerSocketFactory() */ protected abstract SSLServerSocketFactory engineGetServerSocketFactory(); /** - * Creates a new SSLEngine using this context. + * Creates a new {@code SSLEngine} using this context. *

* Applications using this factory method are providing no hints * for an internal session reuse strategy. If hints are desired, @@ -86,9 +90,9 @@ public abstract class SSLContextSpi { * Some cipher suites (such as Kerberos) require remote hostname * information, in which case this factory method should not be used. * - * @return the SSLEngine Object + * @return the {@code SSLEngine} Object * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the engineInit() + * initialization and the {@code engineInit()} * has not been called * * @see SSLContext#createSSLEngine() @@ -98,7 +102,7 @@ public abstract class SSLContextSpi { protected abstract SSLEngine engineCreateSSLEngine(); /** - * Creates a SSLEngine using this context. + * Creates a {@code SSLEngine} using this context. *

* Applications using this factory method are providing hints * for an internal session reuse strategy. @@ -108,9 +112,9 @@ public abstract class SSLContextSpi { * * @param host the non-authoritative name of the host * @param port the non-authoritative port - * @return the SSLEngine Object + * @return the {@code SSLEngine} Object * @throws IllegalStateException if the SSLContextImpl requires - * initialization and the engineInit() + * initialization and the {@code engineInit()} * has not been called * * @see SSLContext#createSSLEngine(String, int) @@ -120,19 +124,19 @@ public abstract class SSLContextSpi { protected abstract SSLEngine engineCreateSSLEngine(String host, int port); /** - * Returns a server SSLSessionContext object for + * Returns a server {@code SSLSessionContext} object for * this context. * - * @return the SSLSessionContext object + * @return the {@code SSLSessionContext} object * @see javax.net.ssl.SSLContext#getServerSessionContext() */ protected abstract SSLSessionContext engineGetServerSessionContext(); /** - * Returns a client SSLSessionContext object for + * Returns a client {@code SSLSessionContext} object for * this context. * - * @return the SSLSessionContext object + * @return the {@code SSLSessionContext} object * @see javax.net.ssl.SSLContext#getClientSessionContext() */ protected abstract SSLSessionContext engineGetClientSessionContext(); diff --git a/jdk/src/java.base/share/classes/javax/net/ssl/SSLEngine.java b/jdk/src/java.base/share/classes/javax/net/ssl/SSLEngine.java index 64110880258..4539513c74b 100644 --- a/jdk/src/java.base/share/classes/javax/net/ssl/SSLEngine.java +++ b/jdk/src/java.base/share/classes/javax/net/ssl/SSLEngine.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,15 +37,15 @@ import java.nio.ReadOnlyBufferException; *

* The secure communications modes include: