提交 0a8d223a 编写于 作者: I igerasim

8202613: Improve TLS connections stability

Reviewed-by: xuelei, wetmore
上级 cd794d1a
/* /*
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -711,7 +711,8 @@ final class ClientHandshaker extends Handshaker { ...@@ -711,7 +711,8 @@ final class ClientHandshaker extends Handshaker {
session = new SSLSessionImpl(protocolVersion, cipherSuite, session = new SSLSessionImpl(protocolVersion, cipherSuite,
getLocalSupportedSignAlgs(), getLocalSupportedSignAlgs(),
mesg.sessionId, getHostSE(), getPortSE(), mesg.sessionId, getHostSE(), getPortSE(),
(extendedMasterSecretExt != null)); (extendedMasterSecretExt != null),
getEndpointIdentificationAlgorithmSE());
session.setRequestedServerNames(requestedServerNames); session.setRequestedServerNames(requestedServerNames);
setHandshakeSessionSE(session); setHandshakeSessionSE(session);
if (debug != null && Debug.isOn("handshake")) { if (debug != null && Debug.isOn("handshake")) {
...@@ -1385,6 +1386,24 @@ final class ClientHandshaker extends Handshaker { ...@@ -1385,6 +1386,24 @@ final class ClientHandshaker extends Handshaker {
} }
} }
// ensure that the endpoint identification algorithm matches the
// one in the session
String identityAlg = getEndpointIdentificationAlgorithmSE();
if (session != null && identityAlg != null) {
String sessionIdentityAlg =
session.getEndpointIdentificationAlgorithm();
if (!Objects.equals(identityAlg, sessionIdentityAlg)) {
if (debug != null && Debug.isOn("session")) {
System.out.println("%% can't resume, endpoint id" +
" algorithm does not match, requested: " +
identityAlg + ", cached: " + sessionIdentityAlg);
}
session = null;
}
}
if (session != null) { if (session != null) {
if (debug != null) { if (debug != null) {
if (Debug.isOn("handshake") || Debug.isOn("session")) { if (Debug.isOn("handshake") || Debug.isOn("session")) {
......
/* /*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -115,6 +115,10 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -115,6 +115,10 @@ final class SSLSessionImpl extends ExtendedSSLSession {
private Principal peerPrincipal; private Principal peerPrincipal;
private Principal localPrincipal; private Principal localPrincipal;
// The endpoint identification algorithm used to check certificates
// in this session.
private final String endpointIdentificationAlgorithm;
/* /*
* Is the session currently re-established with a session-resumption * Is the session currently re-established with a session-resumption
* abbreviated initial handshake? * abbreviated initial handshake?
...@@ -146,7 +150,7 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -146,7 +150,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
*/ */
private SSLSessionImpl() { private SSLSessionImpl() {
this(ProtocolVersion.NONE, CipherSuite.C_NULL, null, this(ProtocolVersion.NONE, CipherSuite.C_NULL, null,
new SessionId(false, null), null, -1, false); new SessionId(false, null), null, -1, false, null);
} }
/* /*
...@@ -157,10 +161,10 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -157,10 +161,10 @@ final class SSLSessionImpl extends ExtendedSSLSession {
SSLSessionImpl(ProtocolVersion protocolVersion, CipherSuite cipherSuite, SSLSessionImpl(ProtocolVersion protocolVersion, CipherSuite cipherSuite,
Collection<SignatureAndHashAlgorithm> algorithms, Collection<SignatureAndHashAlgorithm> algorithms,
SecureRandom generator, String host, int port, SecureRandom generator, String host, int port,
boolean useExtendedMasterSecret) { boolean useExtendedMasterSecret, String endpointIdAlgorithm) {
this(protocolVersion, cipherSuite, algorithms, this(protocolVersion, cipherSuite, algorithms,
new SessionId(defaultRejoinable, generator), host, port, new SessionId(defaultRejoinable, generator), host, port,
useExtendedMasterSecret); useExtendedMasterSecret, endpointIdAlgorithm);
} }
/* /*
...@@ -169,7 +173,8 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -169,7 +173,8 @@ final class SSLSessionImpl extends ExtendedSSLSession {
SSLSessionImpl(ProtocolVersion protocolVersion, CipherSuite cipherSuite, SSLSessionImpl(ProtocolVersion protocolVersion, CipherSuite cipherSuite,
Collection<SignatureAndHashAlgorithm> algorithms, Collection<SignatureAndHashAlgorithm> algorithms,
SessionId id, String host, int port, SessionId id, String host, int port,
boolean useExtendedMasterSecret) { boolean useExtendedMasterSecret,
String endpointIdAlgorithm){
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
sessionId = id; sessionId = id;
peerCerts = null; peerCerts = null;
...@@ -182,6 +187,7 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -182,6 +187,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
localSupportedSignAlgs = localSupportedSignAlgs =
SignatureAndHashAlgorithm.getAlgorithmNames(algorithms); SignatureAndHashAlgorithm.getAlgorithmNames(algorithms);
this.useExtendedMasterSecret = useExtendedMasterSecret; this.useExtendedMasterSecret = useExtendedMasterSecret;
this.endpointIdentificationAlgorithm = endpointIdAlgorithm;
if (debug != null && Debug.isOn("session")) { if (debug != null && Debug.isOn("session")) {
System.out.println("%% Initialized: " + this); System.out.println("%% Initialized: " + this);
...@@ -247,6 +253,10 @@ final class SSLSessionImpl extends ExtendedSSLSession { ...@@ -247,6 +253,10 @@ final class SSLSessionImpl extends ExtendedSSLSession {
localPrincipal = principal; localPrincipal = principal;
} }
String getEndpointIdentificationAlgorithm() {
return this.endpointIdentificationAlgorithm;
}
/** /**
* Returns true iff this session may be resumed ... sessions are * Returns true iff this session may be resumed ... sessions are
* usually resumable. Security policies may suggest otherwise, * usually resumable. Security policies may suggest otherwise,
......
/* /*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -711,6 +711,25 @@ final class ServerHandshaker extends Handshaker { ...@@ -711,6 +711,25 @@ final class ServerHandshaker extends Handshaker {
} }
} }
// ensure that the endpoint identification algorithm matches the
// one in the session
String identityAlg = getEndpointIdentificationAlgorithmSE();
if (resumingSession && identityAlg != null) {
String sessionIdentityAlg =
previous.getEndpointIdentificationAlgorithm();
if (!Objects.equals(identityAlg, sessionIdentityAlg)) {
if (debug != null && Debug.isOn("session")) {
System.out.println("%% can't resume, endpoint id"
+ " algorithm does not match, requested: " +
identityAlg + ", cached: " +
sessionIdentityAlg);
}
resumingSession = false;
}
}
if (resumingSession) { if (resumingSession) {
CipherSuite suite = previous.getSuite(); CipherSuite suite = previous.getSuite();
// verify that the ciphersuite from the cached session // verify that the ciphersuite from the cached session
...@@ -782,7 +801,8 @@ final class ServerHandshaker extends Handshaker { ...@@ -782,7 +801,8 @@ final class ServerHandshaker extends Handshaker {
sslContext.getSecureRandom(), sslContext.getSecureRandom(),
getHostAddressSE(), getPortSE(), getHostAddressSE(), getPortSE(),
(requestedToUseEMS && (requestedToUseEMS &&
(protocolVersion.v >= ProtocolVersion.TLS10.v))); (protocolVersion.v >= ProtocolVersion.TLS10.v)),
getEndpointIdentificationAlgorithmSE());
if (protocolVersion.v >= ProtocolVersion.TLS12.v) { if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
if (peerSupportedSignAlgs != null) { if (peerSupportedSignAlgs != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册