Path: blob/master/src/java.base/share/classes/sun/security/ssl/ClientHandshakeContext.java
41159 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.ssl;2627import java.io.IOException;28import java.security.cert.X509Certificate;2930import sun.security.ssl.ClientHello.ClientHelloMessage;3132class ClientHandshakeContext extends HandshakeContext {33/*34* Allow unsafe server certificate change?35*36* Server certificate change during SSL/TLS renegotiation may be considered37* unsafe, as described in the Triple Handshake attacks:38*39* https://secure-resumption.com/tlsauth.pdf40*41* Endpoint identification (See42* SSLParameters.getEndpointIdentificationAlgorithm()) is a pretty nice43* guarantee that the server certificate change in renegotiation is legal.44* However, endpoint identification is only enabled for HTTPS and LDAP45* over SSL/TLS by default. It is not enough to protect SSL/TLS46* connections other than HTTPS and LDAP.47*48* The renegotiation indication extension (See RFC 5746) is a pretty49* strong guarantee that the endpoints on both client and server sides50* are identical on the same connection. However, the Triple Handshake51* attacks can bypass this guarantee if there is a session-resumption52* handshake between the initial full handshake and the renegotiation53* full handshake.54*55* Server certificate change may be unsafe and should be restricted if56* endpoint identification is not enabled and the previous handshake is57* a session-resumption abbreviated initial handshake, unless the58* identities represented by both certificates can be regraded as the59* same (See isIdentityEquivalent()).60*61* Considering the compatibility impact and the actual requirements to62* support server certificate change in practice, the system property,63* jdk.tls.allowUnsafeServerCertChange, is used to define whether unsafe64* server certificate change in renegotiation is allowed or not. The65* default value of the system property is "false". To mitigate the66* compatibility impact, applications may want to set the system67* property to "true" at their own risk.68*69* If the value of the system property is "false", server certificate70* change in renegotiation after a session-resumption abbreviated initial71* handshake is restricted (See isIdentityEquivalent()).72*73* If the system property is set to "true" explicitly, the restriction on74* server certificate change in renegotiation is disabled.75*/76static final boolean allowUnsafeServerCertChange =77Utilities.getBooleanProperty(78"jdk.tls.allowUnsafeServerCertChange", false);7980/*81* the reserved server certificate chain in previous handshaking82*83* The server certificate chain is only reserved if the previous84* handshake is a session-resumption abbreviated initial handshake.85*/86X509Certificate[] reservedServerCerts = null;8788X509Certificate[] deferredCerts;8990ClientHelloMessage initialClientHelloMsg = null;9192// PSK identity is selected in first Hello and used again after HRR93byte[] pskIdentity;9495ClientHandshakeContext(SSLContextImpl sslContext,96TransportContext conContext) throws IOException {97super(sslContext, conContext);98}99100@Override101void kickstart() throws IOException {102if (kickstartMessageDelivered) {103return;104}105106SSLHandshake.kickstart(this);107kickstartMessageDelivered = true;108}109}110111112