Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
5bd7c570
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5bd7c570
编写于
8月 03, 2017
作者:
X
xuelei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8180643: Illegal handshake message
Reviewed-by: weijun
上级
6488a271
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
137 addition
and
0 deletion
+137
-0
jdk/src/java.base/share/classes/sun/security/ssl/HandshakeMessage.java
...base/share/classes/sun/security/ssl/HandshakeMessage.java
+21
-0
jdk/src/java.base/share/classes/sun/security/ssl/Handshaker.java
.../java.base/share/classes/sun/security/ssl/Handshaker.java
+6
-0
jdk/test/javax/net/ssl/SSLEngine/IllegalHandshakeMessage.java
...test/javax/net/ssl/SSLEngine/IllegalHandshakeMessage.java
+110
-0
未找到文件。
jdk/src/java.base/share/classes/sun/security/ssl/HandshakeMessage.java
浏览文件 @
5bd7c570
...
@@ -79,6 +79,9 @@ public abstract class HandshakeMessage {
...
@@ -79,6 +79,9 @@ public abstract class HandshakeMessage {
public
static
final
Debug
debug
=
Debug
.
getInstance
(
"ssl"
);
public
static
final
Debug
debug
=
Debug
.
getInstance
(
"ssl"
);
// enum HandshakeType:
// enum HandshakeType:
//
// Please update the isUnsupported() method accordingly if the handshake
// types get updated in the future.
static
final
byte
ht_hello_request
=
0
;
// RFC 5246
static
final
byte
ht_hello_request
=
0
;
// RFC 5246
static
final
byte
ht_client_hello
=
1
;
// RFC 5246
static
final
byte
ht_client_hello
=
1
;
// RFC 5246
static
final
byte
ht_server_hello
=
2
;
// RFC 5246
static
final
byte
ht_server_hello
=
2
;
// RFC 5246
...
@@ -130,6 +133,24 @@ public abstract class HandshakeMessage {
...
@@ -130,6 +133,24 @@ public abstract class HandshakeMessage {
return
b
;
return
b
;
}
}
static
boolean
isUnsupported
(
byte
handshakeType
)
{
return
(
handshakeType
!=
ht_hello_request
)
&&
(
handshakeType
!=
ht_client_hello
)
&&
(
handshakeType
!=
ht_server_hello
)
&&
(
handshakeType
!=
ht_hello_verify_request
)
&&
(
handshakeType
!=
ht_new_session_ticket
)
&&
(
handshakeType
!=
ht_certificate
)
&&
(
handshakeType
!=
ht_server_key_exchange
)
&&
(
handshakeType
!=
ht_certificate_request
)
&&
(
handshakeType
!=
ht_server_hello_done
)
&&
(
handshakeType
!=
ht_certificate_verify
)
&&
(
handshakeType
!=
ht_client_key_exchange
)
&&
(
handshakeType
!=
ht_finished
)
&&
(
handshakeType
!=
ht_certificate_url
)
&&
(
handshakeType
!=
ht_certificate_status
)
&&
(
handshakeType
!=
ht_supplemental_data
);
}
private
static
byte
[]
genPad
(
int
b
,
int
count
)
{
private
static
byte
[]
genPad
(
int
b
,
int
count
)
{
byte
[]
padding
=
new
byte
[
count
];
byte
[]
padding
=
new
byte
[
count
];
Arrays
.
fill
(
padding
,
(
byte
)
b
);
Arrays
.
fill
(
padding
,
(
byte
)
b
);
...
...
jdk/src/java.base/share/classes/sun/security/ssl/Handshaker.java
浏览文件 @
5bd7c570
...
@@ -1034,6 +1034,12 @@ abstract class Handshaker {
...
@@ -1034,6 +1034,12 @@ abstract class Handshaker {
input
.
mark
(
4
);
input
.
mark
(
4
);
messageType
=
(
byte
)
input
.
getInt8
();
messageType
=
(
byte
)
input
.
getInt8
();
if
(
HandshakeMessage
.
isUnsupported
(
messageType
))
{
throw
new
SSLProtocolException
(
"Received unsupported or unknown handshake message: "
+
messageType
);
}
messageLen
=
input
.
getInt24
();
messageLen
=
input
.
getInt24
();
if
(
input
.
available
()
<
messageLen
)
{
if
(
input
.
available
()
<
messageLen
)
{
...
...
jdk/test/javax/net/ssl/SSLEngine/IllegalHandshakeMessage.java
0 → 100644
浏览文件 @
5bd7c570
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
//
// This test case relies on updated static security property, no way to re-use
// security property in samevm/agentvm mode.
//
/*
* @test
* @bug 8180643
* @summary Illegal handshake message
*
* @run main/othervm IllegalHandshakeMessage
*/
import
javax.net.ssl.*
;
import
javax.net.ssl.SSLEngineResult.*
;
import
java.io.*
;
import
java.security.*
;
import
java.nio.*
;
public
class
IllegalHandshakeMessage
{
public
static
void
main
(
String
args
[])
throws
Exception
{
SSLContext
context
=
SSLContext
.
getDefault
();
SSLEngine
cliEngine
=
context
.
createSSLEngine
();
cliEngine
.
setUseClientMode
(
true
);
SSLEngine
srvEngine
=
context
.
createSSLEngine
();
srvEngine
.
setUseClientMode
(
false
);
SSLSession
session
=
cliEngine
.
getSession
();
int
netBufferMax
=
session
.
getPacketBufferSize
();
int
appBufferMax
=
session
.
getApplicationBufferSize
();
ByteBuffer
cliToSrv
=
ByteBuffer
.
allocateDirect
(
netBufferMax
);
ByteBuffer
srvToCli
=
ByteBuffer
.
allocateDirect
(
netBufferMax
);
ByteBuffer
srvIBuff
=
ByteBuffer
.
allocateDirect
(
appBufferMax
+
50
);
ByteBuffer
cliOBuff
=
ByteBuffer
.
wrap
(
"I'm client"
.
getBytes
());
ByteBuffer
srvOBuff
=
ByteBuffer
.
wrap
(
"I'm server"
.
getBytes
());
System
.
out
.
println
(
"client hello (handshake type(0xAB))"
);
SSLEngineResult
cliRes
=
cliEngine
.
wrap
(
cliOBuff
,
cliToSrv
);
System
.
out
.
println
(
"Client wrap result: "
+
cliRes
);
cliToSrv
.
flip
();
if
(
cliToSrv
.
limit
()
>
7
)
{
cliToSrv
.
put
(
5
,
(
byte
)
0xAB
);
// use illegal handshake type
cliToSrv
.
put
(
7
,
(
byte
)
0x80
);
// use illegal message length
}
else
{
// unlikely
throw
new
Exception
(
"No handshage message generated."
);
}
try
{
SSLEngineResult
srvRes
=
srvEngine
.
unwrap
(
cliToSrv
,
srvIBuff
);
System
.
out
.
println
(
"Server unwrap result: "
+
srvRes
);
runDelegatedTasks
(
srvRes
,
srvEngine
);
srvRes
=
srvEngine
.
wrap
(
srvOBuff
,
srvToCli
);
System
.
out
.
println
(
"Server wrap result: "
+
srvRes
);
throw
new
Exception
(
"Unsupported handshake message is not handled properly."
);
}
catch
(
SSLException
e
)
{
// get the expected exception
System
.
out
.
println
(
"Expected exception: "
+
e
);
}
}
private
static
void
runDelegatedTasks
(
SSLEngineResult
result
,
SSLEngine
engine
)
throws
Exception
{
if
(
result
.
getHandshakeStatus
()
==
HandshakeStatus
.
NEED_TASK
)
{
Runnable
runnable
;
while
((
runnable
=
engine
.
getDelegatedTask
())
!=
null
)
{
System
.
out
.
println
(
"\trunning delegated task..."
);
runnable
.
run
();
}
HandshakeStatus
hsStatus
=
engine
.
getHandshakeStatus
();
if
(
hsStatus
==
HandshakeStatus
.
NEED_TASK
)
{
throw
new
Exception
(
"handshake shouldn't need additional tasks"
);
}
System
.
out
.
println
(
"\tnew HandshakeStatus: "
+
hsStatus
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录