|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.security.ssl; |
|
|
|
import java.io.IOException; |
|
import java.nio.ByteBuffer; |
|
import javax.net.ssl.SSLProtocolException; |
|
import static sun.security.ssl.SSLExtension.CH_EXTENDED_MASTER_SECRET; |
|
import sun.security.ssl.SSLExtension.ExtensionConsumer; |
|
import static sun.security.ssl.SSLExtension.SH_EXTENDED_MASTER_SECRET; |
|
import sun.security.ssl.SSLExtension.SSLExtensionSpec; |
|
import sun.security.ssl.SSLHandshake.HandshakeMessage; |
|
|
|
|
|
|
|
*/ |
|
final class ExtendedMasterSecretExtension { |
|
static final HandshakeProducer chNetworkProducer = |
|
new CHExtendedMasterSecretProducer(); |
|
static final ExtensionConsumer chOnLoadConsumer = |
|
new CHExtendedMasterSecretConsumer(); |
|
static final HandshakeAbsence chOnLoadAbsence = |
|
new CHExtendedMasterSecretAbsence(); |
|
|
|
static final HandshakeProducer shNetworkProducer = |
|
new SHExtendedMasterSecretProducer(); |
|
static final ExtensionConsumer shOnLoadConsumer = |
|
new SHExtendedMasterSecretConsumer(); |
|
static final HandshakeAbsence shOnLoadAbsence = |
|
new SHExtendedMasterSecretAbsence(); |
|
|
|
static final SSLStringizer emsStringizer = |
|
new ExtendedMasterSecretStringizer(); |
|
|
|
|
|
|
|
*/ |
|
static final class ExtendedMasterSecretSpec implements SSLExtensionSpec { |
|
|
|
static final ExtendedMasterSecretSpec NOMINAL = |
|
new ExtendedMasterSecretSpec(); |
|
|
|
private ExtendedMasterSecretSpec() { |
|
// blank |
|
} |
|
|
|
private ExtendedMasterSecretSpec(HandshakeContext hc, |
|
ByteBuffer m) throws IOException { |
|
|
|
if (m.hasRemaining()) { |
|
throw hc.conContext.fatal(Alert.DECODE_ERROR, |
|
new SSLProtocolException( |
|
"Invalid extended_master_secret extension data: " + |
|
"not empty")); |
|
} |
|
} |
|
|
|
@Override |
|
public String toString() { |
|
return "<empty>"; |
|
} |
|
} |
|
|
|
private static final |
|
class ExtendedMasterSecretStringizer implements SSLStringizer { |
|
@Override |
|
public String toString(HandshakeContext hc, ByteBuffer buffer) { |
|
try { |
|
return (new ExtendedMasterSecretSpec(hc, buffer)).toString(); |
|
} catch (IOException ioe) { |
|
|
|
return ioe.getMessage(); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final |
|
class CHExtendedMasterSecretProducer implements HandshakeProducer { |
|
|
|
private CHExtendedMasterSecretProducer() { |
|
// blank |
|
} |
|
|
|
@Override |
|
public byte[] produce(ConnectionContext context, |
|
HandshakeMessage message) throws IOException { |
|
|
|
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
|
|
|
|
if (!chc.sslConfig.isAvailable(CH_EXTENDED_MASTER_SECRET) || |
|
!SSLConfiguration.useExtendedMasterSecret || |
|
!chc.conContext.protocolVersion.useTLS10PlusSpec()) { |
|
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
SSLLogger.fine( |
|
"Ignore unavailable extended_master_secret extension"); |
|
} |
|
|
|
return null; |
|
} |
|
|
|
if (chc.handshakeSession == null || |
|
chc.handshakeSession.useExtendedMasterSecret) { |
|
byte[] extData = new byte[0]; |
|
chc.handshakeExtensions.put(CH_EXTENDED_MASTER_SECRET, |
|
ExtendedMasterSecretSpec.NOMINAL); |
|
|
|
return extData; |
|
} |
|
|
|
return null; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final |
|
class CHExtendedMasterSecretConsumer implements ExtensionConsumer { |
|
|
|
private CHExtendedMasterSecretConsumer() { |
|
// blank |
|
} |
|
|
|
@Override |
|
public void consume(ConnectionContext context, |
|
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
|
|
|
|
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
|
|
|
|
if (!shc.sslConfig.isAvailable(CH_EXTENDED_MASTER_SECRET) || |
|
!SSLConfiguration.useExtendedMasterSecret || |
|
!shc.negotiatedProtocol.useTLS10PlusSpec()) { |
|
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
SSLLogger.fine("Ignore unavailable extension: " + |
|
CH_EXTENDED_MASTER_SECRET.name); |
|
} |
|
return; |
|
} |
|
|
|
|
|
ExtendedMasterSecretSpec spec = |
|
new ExtendedMasterSecretSpec(shc, buffer); |
|
if (shc.isResumption && shc.resumingSession != null && |
|
!shc.resumingSession.useExtendedMasterSecret) { |
|
// For abbreviated handshake request, If the original |
|
// session did not use the "extended_master_secret" |
|
// extension but the new ClientHello contains the |
|
// extension, then the server MUST NOT perform the |
|
// abbreviated handshake. Instead, it SHOULD continue |
|
|
|
shc.isResumption = false; |
|
shc.resumingSession = null; |
|
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
SSLLogger.fine( |
|
"abort session resumption which did not use " + |
|
"Extended Master Secret extension"); |
|
} |
|
} |
|
|
|
// Update the context. |
|
|
|
shc.handshakeExtensions.put( |
|
CH_EXTENDED_MASTER_SECRET, ExtendedMasterSecretSpec.NOMINAL); |
|
|
|
// No impact on session resumption. |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final |
|
class CHExtendedMasterSecretAbsence implements HandshakeAbsence { |
|
@Override |
|
public void absent(ConnectionContext context, |
|
HandshakeMessage message) throws IOException { |
|
|
|
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
|
|
|
|
if (!shc.sslConfig.isAvailable(CH_EXTENDED_MASTER_SECRET) || |
|
!SSLConfiguration.useExtendedMasterSecret) { |
|
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
SSLLogger.fine("Ignore unavailable extension: " + |
|
CH_EXTENDED_MASTER_SECRET.name); |
|
} |
|
return; |
|
} |
|
|
|
if (shc.negotiatedProtocol.useTLS10PlusSpec() && |
|
!SSLConfiguration.allowLegacyMasterSecret) { |
|
// For full handshake, if the server receives a ClientHello |
|
// without the extension, it SHOULD abort the handshake if |
|
// it does not wish to interoperate with legacy clients. |
|
// |
|
// As if extended master extension is required for full |
|
|
|
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
|
"Extended Master Secret extension is required"); |
|
} |
|
|
|
if (shc.isResumption && shc.resumingSession != null) { |
|
if (shc.resumingSession.useExtendedMasterSecret) { |
|
// For abbreviated handshake request, if the original |
|
// session used the "extended_master_secret" extension |
|
// but the new ClientHello does not contain it, the |
|
|
|
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
|
"Missing Extended Master Secret extension " + |
|
"on session resumption"); |
|
} else { |
|
// For abbreviated handshake request, if neither the |
|
// original session nor the new ClientHello uses the |
|
|
|
if (!SSLConfiguration.allowLegacyResumption) { |
|
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
|
"Missing Extended Master Secret extension " + |
|
"on session resumption"); |
|
} else { |
|
shc.isResumption = false; |
|
shc.resumingSession = null; |
|
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
SSLLogger.fine( |
|
"abort session resumption, " + |
|
"missing Extended Master Secret extension"); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final |
|
class SHExtendedMasterSecretProducer implements HandshakeProducer { |
|
|
|
private SHExtendedMasterSecretProducer() { |
|
// blank |
|
} |
|
|
|
@Override |
|
public byte[] produce(ConnectionContext context, |
|
HandshakeMessage message) throws IOException { |
|
|
|
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
|
|
if (shc.handshakeSession.useExtendedMasterSecret) { |
|
byte[] extData = new byte[0]; |
|
shc.handshakeExtensions.put(SH_EXTENDED_MASTER_SECRET, |
|
ExtendedMasterSecretSpec.NOMINAL); |
|
|
|
return extData; |
|
} |
|
|
|
return null; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final |
|
class SHExtendedMasterSecretConsumer implements ExtensionConsumer { |
|
|
|
private SHExtendedMasterSecretConsumer() { |
|
// blank |
|
} |
|
|
|
@Override |
|
public void consume(ConnectionContext context, |
|
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
|
|
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
|
|
// In response to the client extended_master_secret extension |
|
|
|
ExtendedMasterSecretSpec requstedSpec = (ExtendedMasterSecretSpec) |
|
chc.handshakeExtensions.get(CH_EXTENDED_MASTER_SECRET); |
|
if (requstedSpec == null) { |
|
throw chc.conContext.fatal(Alert.UNSUPPORTED_EXTENSION, |
|
"Server sent the extended_master_secret " + |
|
"extension improperly"); |
|
} |
|
|
|
|
|
ExtendedMasterSecretSpec spec = |
|
new ExtendedMasterSecretSpec(chc, buffer); |
|
if (chc.isResumption && chc.resumingSession != null && |
|
!chc.resumingSession.useExtendedMasterSecret) { |
|
throw chc.conContext.fatal(Alert.UNSUPPORTED_EXTENSION, |
|
"Server sent an unexpected extended_master_secret " + |
|
"extension on session resumption"); |
|
} |
|
|
|
|
|
chc.handshakeExtensions.put( |
|
SH_EXTENDED_MASTER_SECRET, ExtendedMasterSecretSpec.NOMINAL); |
|
|
|
// No impact on session resumption. |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private static final |
|
class SHExtendedMasterSecretAbsence implements HandshakeAbsence { |
|
@Override |
|
public void absent(ConnectionContext context, |
|
HandshakeMessage message) throws IOException { |
|
|
|
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
|
|
if (SSLConfiguration.useExtendedMasterSecret && |
|
!SSLConfiguration.allowLegacyMasterSecret) { |
|
// For full handshake, if a client receives a ServerHello |
|
// without the extension, it SHOULD abort the handshake if |
|
|
|
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
|
"Extended Master Secret extension is required"); |
|
} |
|
|
|
if (chc.isResumption && chc.resumingSession != null) { |
|
if (chc.resumingSession.useExtendedMasterSecret) { |
|
// For abbreviated handshake, if the original session used |
|
// the "extended_master_secret" extension but the new |
|
// ServerHello does not contain the extension, the client |
|
|
|
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
|
"Missing Extended Master Secret extension " + |
|
"on session resumption"); |
|
} else if (SSLConfiguration.useExtendedMasterSecret && |
|
!SSLConfiguration.allowLegacyResumption && |
|
chc.negotiatedProtocol.useTLS10PlusSpec()) { |
|
|
|
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
|
"Extended Master Secret extension is required"); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|