author | xuelei |
Wed, 20 Feb 2019 10:20:48 -0800 | |
changeset 53852 | 25002c4f0145 |
parent 53064 | 103ed9569fc8 |
child 57485 | af4b0fc25bc4 |
permissions | -rw-r--r-- |
50768 | 1 |
/* |
53852
25002c4f0145
8219389: Delegated task created by SSLEngine throws BufferUnderflowException
xuelei
parents:
53064
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
50768 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.security.ssl; |
|
27 |
||
28 |
import java.io.IOException; |
|
53852
25002c4f0145
8219389: Delegated task created by SSLEngine throws BufferUnderflowException
xuelei
parents:
53064
diff
changeset
|
29 |
import java.nio.BufferOverflowException; |
25002c4f0145
8219389: Delegated task created by SSLEngine throws BufferUnderflowException
xuelei
parents:
53064
diff
changeset
|
30 |
import java.nio.BufferUnderflowException; |
50768 | 31 |
import java.nio.ByteBuffer; |
51134
a0de9a3a6766
8206929: Check session context for TLS 1.3 session resumption
apetcher
parents:
50768
diff
changeset
|
32 |
import java.util.ArrayList; |
50768 | 33 |
import java.util.LinkedHashMap; |
34 |
import java.util.Map; |
|
35 |
||
36 |
/** |
|
37 |
* A compact implementation of HandshakeContext for post-handshake messages |
|
38 |
*/ |
|
39 |
final class PostHandshakeContext extends HandshakeContext { |
|
40 |
private final static Map<Byte, SSLConsumer> consumers = Map.of( |
|
41 |
SSLHandshake.KEY_UPDATE.id, SSLHandshake.KEY_UPDATE, |
|
42 |
SSLHandshake.NEW_SESSION_TICKET.id, SSLHandshake.NEW_SESSION_TICKET); |
|
43 |
||
44 |
PostHandshakeContext(TransportContext context) throws IOException { |
|
45 |
super(context); |
|
46 |
||
47 |
if (!negotiatedProtocol.useTLS13PlusSpec()) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
52512
diff
changeset
|
48 |
throw conContext.fatal(Alert.UNEXPECTED_MESSAGE, |
50768 | 49 |
"Post-handshake not supported in " + negotiatedProtocol.name); |
50 |
} |
|
51 |
||
51134
a0de9a3a6766
8206929: Check session context for TLS 1.3 session resumption
apetcher
parents:
50768
diff
changeset
|
52 |
this.localSupportedSignAlgs = new ArrayList<SignatureScheme>( |
a0de9a3a6766
8206929: Check session context for TLS 1.3 session resumption
apetcher
parents:
50768
diff
changeset
|
53 |
context.conSession.getLocalSupportedSignatureSchemes()); |
a0de9a3a6766
8206929: Check session context for TLS 1.3 session resumption
apetcher
parents:
50768
diff
changeset
|
54 |
|
50768 | 55 |
handshakeConsumers = new LinkedHashMap<>(consumers); |
56 |
handshakeFinished = true; |
|
57 |
} |
|
58 |
||
59 |
@Override |
|
60 |
void kickstart() throws IOException { |
|
61 |
SSLHandshake.kickstart(this); |
|
62 |
} |
|
63 |
||
64 |
@Override |
|
65 |
void dispatch(byte handshakeType, ByteBuffer fragment) throws IOException { |
|
66 |
SSLConsumer consumer = handshakeConsumers.get(handshakeType); |
|
67 |
if (consumer == null) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
52512
diff
changeset
|
68 |
throw conContext.fatal(Alert.UNEXPECTED_MESSAGE, |
50768 | 69 |
"Unexpected post-handshake message: " + |
70 |
SSLHandshake.nameOf(handshakeType)); |
|
71 |
} |
|
72 |
||
73 |
try { |
|
74 |
consumer.consume(this, fragment); |
|
75 |
} catch (UnsupportedOperationException unsoe) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
52512
diff
changeset
|
76 |
throw conContext.fatal(Alert.UNEXPECTED_MESSAGE, |
50768 | 77 |
"Unsupported post-handshake message: " + |
78 |
SSLHandshake.nameOf(handshakeType), unsoe); |
|
53852
25002c4f0145
8219389: Delegated task created by SSLEngine throws BufferUnderflowException
xuelei
parents:
53064
diff
changeset
|
79 |
} catch (BufferUnderflowException | BufferOverflowException be) { |
25002c4f0145
8219389: Delegated task created by SSLEngine throws BufferUnderflowException
xuelei
parents:
53064
diff
changeset
|
80 |
throw conContext.fatal(Alert.DECODE_ERROR, |
25002c4f0145
8219389: Delegated task created by SSLEngine throws BufferUnderflowException
xuelei
parents:
53064
diff
changeset
|
81 |
"Illegal handshake message: " + |
25002c4f0145
8219389: Delegated task created by SSLEngine throws BufferUnderflowException
xuelei
parents:
53064
diff
changeset
|
82 |
SSLHandshake.nameOf(handshakeType), be); |
50768 | 83 |
} |
84 |
} |
|
85 |
} |