Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
797f2cae
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
797f2cae
编写于
12月 21, 2010
作者:
W
weijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6996367: improve HandshakeHash
Reviewed-by: xuelei
上级
741c9607
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
102 deletion
+16
-102
src/share/classes/sun/security/ssl/ClientHandshaker.java
src/share/classes/sun/security/ssl/ClientHandshaker.java
+2
-3
src/share/classes/sun/security/ssl/HandshakeHash.java
src/share/classes/sun/security/ssl/HandshakeHash.java
+13
-97
src/share/classes/sun/security/ssl/ServerHandshaker.java
src/share/classes/sun/security/ssl/ServerHandshaker.java
+1
-2
未找到文件。
src/share/classes/sun/security/ssl/ClientHandshaker.java
浏览文件 @
797f2cae
...
...
@@ -381,8 +381,7 @@ final class ClientHandshaker extends Handshaker {
mesgVersion
);
}
handshakeHash
.
protocolDetermined
(
mesgVersion
.
v
>=
ProtocolVersion
.
TLS12
.
v
);
handshakeHash
.
protocolDetermined
(
mesgVersion
);
// Set protocolVersion and propagate to SSLSocket and the
// Handshake streams
...
...
@@ -1223,7 +1222,7 @@ final class ClientHandshaker extends Handshaker {
// not follow the spec that HandshakeHash.reset() can be only be
// called before protocolDetermined.
// if (maxProtocolVersion.v < ProtocolVersion.TLS12.v) {
// handshakeHash.protocolDetermined(
false
);
// handshakeHash.protocolDetermined(
maxProtocolVersion
);
// }
// create the ClientHello message
...
...
src/share/classes/sun/security/ssl/HandshakeHash.java
浏览文件 @
797f2cae
...
...
@@ -49,27 +49,27 @@ import java.util.Set;
*
* You need to obey these conventions when using this class:
*
* 1. protocolDetermined(
boolean isTLS12
) should be called when the negotiated
* 1. protocolDetermined(
version
) should be called when the negotiated
* protocol version is determined.
*
* 2. Before protocolDetermined() is called, only update(), reset(),
* restrictCertificateVerifyAlgs(), setFinishedAlg(), and
* setCertificateVerifyAlg() can be called.
*
* 3. After protocolDetermined(
*) is called.
reset() cannot be called.
* 3. After protocolDetermined(
) is called,
reset() cannot be called.
*
* 4. After protocolDetermined(
false) is called, getFinishedHash() and
* get
CertificateVerifyHash() cannot be called. After protocolDetermined(true)
*
is called,
getMD5Clone() and getSHAClone() cannot be called.
* 4. After protocolDetermined(
) is called, if the version is pre-TLS 1.2,
* get
FinishedHash() and getCertificateVerifyHash() cannot be called. Otherwise,
* getMD5Clone() and getSHAClone() cannot be called.
*
* 5. getMD5Clone() and getSHAClone() can only be called after
* protocolDetermined(
false) is called
.
* protocolDetermined(
) is called and version is pre-TLS 1.2
.
*
* 6. getFinishedHash() and getCertificateVerifyHash() can only be called after
* all protocolDetermined(
true
), setCertificateVerifyAlg() and setFinishedAlg()
* have been called
. If a CertificateVerify message is to be used, call
*
setCertificateVerifyAlg() with the hash algorithm as the argument.
* Otherwise, you still must call setCertificateVerifyAlg(null) before
* all protocolDetermined(), setCertificateVerifyAlg() and setFinishedAlg()
* have been called
and the version is TLS 1.2. If a CertificateVerify message
*
is to be used, call setCertificateVerifyAlg() with the hash algorithm as the
*
argument.
Otherwise, you still must call setCertificateVerifyAlg(null) before
* calculating any hash value.
*
* Suggestions: Call protocolDetermined(), restrictCertificateVerifyAlgs(),
...
...
@@ -78,6 +78,7 @@ import java.util.Set;
* Example:
* <pre>
* HandshakeHash hh = new HandshakeHash(...)
* hh.protocolDetermined(ProtocolVersion.TLS12);
* hh.update(clientHelloBytes);
* hh.setFinishedAlg("SHA-256");
* hh.update(serverHelloBytes);
...
...
@@ -161,12 +162,12 @@ final class HandshakeHash {
}
void
protocolDetermined
(
boolean
isTLS12
)
{
void
protocolDetermined
(
ProtocolVersion
pv
)
{
// Do not set again, will ignore
if
(
version
!=
-
1
)
return
;
version
=
isTLS12
?
2
:
1
;
version
=
pv
.
compareTo
(
ProtocolVersion
.
TLS12
)
>=
0
?
2
:
1
;
switch
(
version
)
{
case
1
:
// initiate md5, sha and call update on saved array
...
...
@@ -310,91 +311,6 @@ final class HandshakeHash {
throw
new
Error
(
"BAD"
);
}
}
////////////////////////////////////////////////////////////////
// TEST
////////////////////////////////////////////////////////////////
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Test
t
=
new
Test
();
t
.
test
(
null
,
"SHA-256"
);
t
.
test
(
""
,
"SHA-256"
);
t
.
test
(
"SHA-1"
,
"SHA-256"
);
t
.
test
(
"SHA-256"
,
"SHA-256"
);
t
.
test
(
"SHA-384"
,
"SHA-256"
);
t
.
test
(
"SHA-512"
,
"SHA-256"
);
t
.
testSame
(
"sha"
,
"SHA-1"
);
t
.
testSame
(
"SHA"
,
"SHA-1"
);
t
.
testSame
(
"SHA1"
,
"SHA-1"
);
t
.
testSame
(
"SHA-1"
,
"SHA-1"
);
t
.
testSame
(
"SHA256"
,
"SHA-256"
);
t
.
testSame
(
"SHA-256"
,
"SHA-256"
);
}
static
class
Test
{
void
update
(
HandshakeHash
hh
,
String
s
)
{
hh
.
update
(
s
.
getBytes
(),
0
,
s
.
length
());
}
static
byte
[]
digest
(
String
alg
,
String
data
)
throws
Exception
{
return
MessageDigest
.
getInstance
(
alg
).
digest
(
data
.
getBytes
());
}
static
void
equals
(
byte
[]
b1
,
byte
[]
b2
)
{
if
(!
Arrays
.
equals
(
b1
,
b2
))
{
throw
new
RuntimeException
(
"Bad"
);
}
}
void
testSame
(
String
a
,
String
a2
)
{
System
.
out
.
println
(
"testSame: "
+
a
+
" "
+
a2
);
if
(!
HandshakeHash
.
normalizeAlgName
(
a
).
equals
(
a2
))
{
throw
new
RuntimeException
(
"Bad"
);
}
}
/**
* Special convention: when it's certain that CV will not be used at the
* very beginning, use null as cvAlg. If known at a late stage, use "".
*/
void
test
(
String
cvAlg
,
String
finAlg
)
throws
Exception
{
System
.
out
.
println
(
"test: "
+
cvAlg
+
" "
+
finAlg
);
byte
[]
cv
=
null
,
f1
,
f2
;
HandshakeHash
hh
=
new
HandshakeHash
(
true
,
true
,
null
);
if
(
cvAlg
==
null
)
{
hh
.
setCertificateVerifyAlg
(
cvAlg
);
}
update
(
hh
,
"ClientHello,"
);
hh
.
reset
();
update
(
hh
,
"ClientHellov2,"
);
hh
.
setFinishedAlg
(
finAlg
);
// Useless calls
hh
.
setFinishedAlg
(
"SHA-1"
);
hh
.
setFinishedAlg
(
"SHA-512"
);
update
(
hh
,
"More,"
);
if
(
cvAlg
!=
null
)
{
if
(
cvAlg
.
isEmpty
())
cvAlg
=
null
;
hh
.
setCertificateVerifyAlg
(
cvAlg
);
}
// Useless calls
hh
.
setCertificateVerifyAlg
(
"SHA-1"
);
hh
.
setCertificateVerifyAlg
(
null
);
hh
.
protocolDetermined
(
true
);
if
(
cvAlg
!=
null
)
{
cv
=
hh
.
getAllHandshakeMessages
();
equals
(
cv
,
"ClientHellov2,More,"
.
getBytes
());
}
update
(
hh
,
"FIN1,"
);
f1
=
hh
.
getFinishedHash
();
equals
(
f1
,
digest
(
finAlg
,
"ClientHellov2,More,FIN1,"
));
update
(
hh
,
"FIN2,"
);
f2
=
hh
.
getFinishedHash
();
equals
(
f2
,
digest
(
finAlg
,
"ClientHellov2,More,FIN1,FIN2,"
));
}
}
}
/**
...
...
src/share/classes/sun/security/ssl/ServerHandshaker.java
浏览文件 @
797f2cae
...
...
@@ -424,8 +424,7 @@ final class ServerHandshaker extends Handshaker {
" not enabled or not supported"
);
}
handshakeHash
.
protocolDetermined
(
selectedVersion
.
v
>=
ProtocolVersion
.
TLS12
.
v
);
handshakeHash
.
protocolDetermined
(
selectedVersion
);
setVersion
(
selectedVersion
);
m1
.
protocolVersion
=
protocolVersion
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录