24 */ |
24 */ |
25 |
25 |
26 package sun.security.ssl; |
26 package sun.security.ssl; |
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
|
29 import java.nio.ByteBuffer; |
|
30 import java.util.LinkedHashMap; |
29 |
31 |
30 /** |
32 /** |
31 * A clean implementation of HandshakeContext for post-handshake messages |
33 * A compact implementation of HandshakeContext for post-handshake messages |
32 */ |
34 */ |
33 |
35 |
34 public class PostHandshakeContext extends HandshakeContext { |
36 public class PostHandshakeContext extends HandshakeContext { |
35 |
37 |
|
38 final static LinkedHashMap<Byte, SSLConsumer> consumers; |
|
39 static { |
|
40 consumers = new LinkedHashMap<>() {{ |
|
41 put(SSLHandshake.KEY_UPDATE.id, |
|
42 SSLHandshake.KEY_UPDATE); |
|
43 }}; |
|
44 } |
|
45 |
|
46 |
36 PostHandshakeContext(TransportContext context) throws IOException { |
47 PostHandshakeContext(TransportContext context) throws IOException { |
37 super(context.sslContext, context); |
48 super(context); |
|
49 |
|
50 if (!negotiatedProtocol.useTLS13PlusSpec()) { |
|
51 conContext.fatal(Alert.UNEXPECTED_MESSAGE, "Post-handshake not " + |
|
52 "supported in " + negotiatedProtocol.name); |
|
53 } |
|
54 |
|
55 handshakeConsumers = consumers; |
|
56 handshakeFinished = true; |
38 } |
57 } |
39 |
58 |
40 @Override |
59 @Override |
41 void kickstart() throws IOException { |
60 void kickstart() throws IOException { |
|
61 SSLHandshake.kickstart(this); |
|
62 } |
|
63 |
|
64 @Override |
|
65 void dispatch(byte handshakeType, ByteBuffer fragment) throws IOException { |
|
66 |
|
67 SSLConsumer consumer = handshakeConsumers.get(handshakeType); |
|
68 if (consumer == null) { |
|
69 conContext.fatal(Alert.UNEXPECTED_MESSAGE, |
|
70 "Unexpected post-handshake message: " + |
|
71 SSLHandshake.nameOf(handshakeType)); |
|
72 return; |
|
73 } |
|
74 |
|
75 try { |
|
76 consumer.consume(this, fragment); |
|
77 } catch (UnsupportedOperationException unsoe) { |
|
78 conContext.fatal(Alert.UNEXPECTED_MESSAGE, |
|
79 "Unsupported post-handshake message: " + |
|
80 SSLHandshake.nameOf(handshakeType), unsoe); |
|
81 } |
|
82 } |
|
83 |
|
84 void free() { |
|
85 if (delegatedActions.isEmpty()) { |
|
86 conContext.handshakeContext = null; |
|
87 } |
42 } |
88 } |
43 } |
89 } |