Skip to content
Permalink
Browse files
8229733: TLS message handling improvements
Reviewed-by: jnimeh, rhalade, ahgross
  • Loading branch information
XueleiFan committed Oct 20, 2019
1 parent 9efd3d7 commit 123febeb9899ff2d84a26aee8ab89d9f977f8103
Showing 3 changed files with 37 additions and 11 deletions.
@@ -209,7 +209,7 @@ protected HandshakeContext(SSLContextImpl sslContext,
/**
* Constructor for PostHandshakeContext
*/
HandshakeContext(TransportContext conContext) {
protected HandshakeContext(TransportContext conContext) {
this.sslContext = conContext.sslContext;
this.conContext = conContext;
this.sslConfig = conContext.sslConfig;
@@ -219,6 +219,7 @@ protected HandshakeContext(SSLContextImpl sslContext,
this.handshakeOutput = new HandshakeOutStream(conContext.outputRecord);
this.delegatedActions = new LinkedList<>();

this.handshakeConsumers = new LinkedHashMap<>();
this.handshakeProducers = null;
this.handshakeHash = null;
this.activeProtocols = null;
@@ -30,17 +30,11 @@
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* A compact implementation of HandshakeContext for post-handshake messages
*/
final class PostHandshakeContext extends HandshakeContext {
private final static Map<Byte, SSLConsumer> consumers = Map.of(
SSLHandshake.KEY_UPDATE.id, SSLHandshake.KEY_UPDATE,
SSLHandshake.NEW_SESSION_TICKET.id, SSLHandshake.NEW_SESSION_TICKET);

PostHandshakeContext(TransportContext context) throws IOException {
super(context);

@@ -49,10 +43,23 @@ final class PostHandshakeContext extends HandshakeContext {
"Post-handshake not supported in " + negotiatedProtocol.name);
}

this.localSupportedSignAlgs = new ArrayList<SignatureScheme>(
this.localSupportedSignAlgs = new ArrayList<>(
context.conSession.getLocalSupportedSignatureSchemes());

handshakeConsumers = new LinkedHashMap<>(consumers);
// Add the potential post-handshake consumers.
if (context.sslConfig.isClientMode) {
handshakeConsumers.putIfAbsent(
SSLHandshake.KEY_UPDATE.id,
SSLHandshake.KEY_UPDATE);
handshakeConsumers.putIfAbsent(
SSLHandshake.NEW_SESSION_TICKET.id,
SSLHandshake.NEW_SESSION_TICKET);
} else {
handshakeConsumers.putIfAbsent(
SSLHandshake.KEY_UPDATE.id,
SSLHandshake.KEY_UPDATE);
}

handshakeFinished = true;
handshakeSession = context.conSession;
}
@@ -83,4 +90,21 @@ void dispatch(byte handshakeType, ByteBuffer fragment) throws IOException {
SSLHandshake.nameOf(handshakeType), be);
}
}

static boolean isConsumable(TransportContext context, byte handshakeType) {
if (handshakeType == SSLHandshake.KEY_UPDATE.id) {
// The KeyUpdate handshake message does not apply to TLS 1.2 and
// previous protocols.
return context.protocolVersion.useTLS13PlusSpec();
}

if (handshakeType == SSLHandshake.NEW_SESSION_TICKET.id) {
// The new session ticket handshake message could be consumer in
// client side only.
return context.sslConfig.isClientMode;
}

// No more post-handshake message supported currently.
return false;
}
}
@@ -164,12 +164,13 @@ void dispatch(Plaintext plaintext) throws IOException {
" message: " +
SSLHandshake.nameOf(type));
}
if (type == SSLHandshake.KEY_UPDATE.id &&
!protocolVersion.useTLS13PlusSpec()) {

if (!PostHandshakeContext.isConsumable(this, type)) {
throw fatal(Alert.UNEXPECTED_MESSAGE,
"Unexpected post-handshake message: " +
SSLHandshake.nameOf(type));
}

handshakeContext = new PostHandshakeContext(this);
} else {
handshakeContext = sslConfig.isClientMode ?

0 comments on commit 123febe

Please sign in to comment.