Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
7e7b76aa
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看板
提交
7e7b76aa
编写于
4月 06, 2020
作者:
Y
yan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8234027: Better JCEKS key support
Reviewed-by: andrew
上级
1503a09b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
47 addition
and
16 deletion
+47
-16
src/share/classes/com/sun/crypto/provider/JceKeyStore.java
src/share/classes/com/sun/crypto/provider/JceKeyStore.java
+25
-3
src/share/classes/com/sun/crypto/provider/KeyProtector.java
src/share/classes/com/sun/crypto/provider/KeyProtector.java
+6
-3
src/share/classes/com/sun/crypto/provider/SealedObjectForKeyProtector.java
.../com/sun/crypto/provider/SealedObjectForKeyProtector.java
+16
-10
未找到文件。
src/share/classes/com/sun/crypto/provider/JceKeyStore.java
浏览文件 @
7e7b76aa
...
...
@@ -81,6 +81,12 @@ public final class JceKeyStore extends KeyStoreSpi {
private
static
final
class
SecretKeyEntry
{
Date
date
;
// the creation date of this entry
SealedObject
sealedKey
;
// Maximum possible length of sealedKey. Used to detect malicious
// input data. This field is set to the file length of the keystore
// at loading. It is useless when creating a new SecretKeyEntry
// to be store in a keystore.
int
maxLength
;
}
// Trusted certificate
...
...
@@ -136,8 +142,8 @@ public final class JceKeyStore extends KeyStoreSpi {
}
key
=
keyProtector
.
recover
(
encrInfo
);
}
else
{
key
=
keyProtector
.
unseal
(((
SecretKeyEntry
)
entry
).
sealedKey
);
SecretKeyEntry
ske
=
((
SecretKeyEntry
)
entry
);
key
=
keyProtector
.
unseal
(
ske
.
sealedKey
,
ske
.
maxLength
);
}
return
key
;
...
...
@@ -282,6 +288,7 @@ public final class JceKeyStore extends KeyStoreSpi {
// seal and store the key
entry
.
sealedKey
=
keyProtector
.
seal
(
key
);
entry
.
maxLength
=
Integer
.
MAX_VALUE
;
entries
.
put
(
alias
.
toLowerCase
(
Locale
.
ENGLISH
),
entry
);
}
...
...
@@ -691,6 +698,10 @@ public final class JceKeyStore extends KeyStoreSpi {
if
(
stream
==
null
)
return
;
byte
[]
allData
=
IOUtils
.
readAllBytes
(
stream
);
int
fullLength
=
allData
.
length
;
stream
=
new
ByteArrayInputStream
(
allData
);
if
(
password
!=
null
)
{
md
=
getPreKeyedHash
(
password
);
dis
=
new
DataInputStream
(
new
DigestInputStream
(
stream
,
md
));
...
...
@@ -829,10 +840,11 @@ public final class JceKeyStore extends KeyStoreSpi {
AccessController
.
doPrivileged
(
(
PrivilegedAction
<
Void
>)()
->
{
ObjectInputFilter
.
Config
.
setObjectInputFilter
(
ois2
,
new
DeserializationChecker
());
ois2
,
new
DeserializationChecker
(
fullLength
));
return
null
;
});
entry
.
sealedKey
=
(
SealedObject
)
ois
.
readObject
();
entry
.
maxLength
=
fullLength
;
// NOTE: don't close ois here since we are still
// using dis!!!
}
catch
(
ClassNotFoundException
cnfe
)
{
...
...
@@ -909,8 +921,17 @@ public final class JceKeyStore extends KeyStoreSpi {
* deserialized.
*/
private
static
class
DeserializationChecker
implements
ObjectInputFilter
{
private
static
final
int
MAX_NESTED_DEPTH
=
2
;
// Full length of keystore, anything inside a SecretKeyEntry should not
// be bigger. Otherwise, must be illegal.
private
final
int
fullLength
;
public
DeserializationChecker
(
int
fullLength
)
{
this
.
fullLength
=
fullLength
;
}
@Override
public
ObjectInputFilter
.
Status
checkInput
(
ObjectInputFilter
.
FilterInfo
info
)
{
...
...
@@ -919,6 +940,7 @@ public final class JceKeyStore extends KeyStoreSpi {
long
nestedDepth
=
info
.
depth
();
if
((
nestedDepth
==
1
&&
info
.
serialClass
()
!=
SealedObjectForKeyProtector
.
class
)
||
info
.
arrayLength
()
>
fullLength
||
(
nestedDepth
>
MAX_NESTED_DEPTH
&&
info
.
serialClass
()
!=
null
&&
info
.
serialClass
()
!=
Object
.
class
))
{
...
...
src/share/classes/com/sun/crypto/provider/KeyProtector.java
浏览文件 @
7e7b76aa
/*
* Copyright (c) 1998, 201
8
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 201
9
, 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
...
...
@@ -352,8 +352,11 @@ final class KeyProtector {
/**
* Unseals the sealed key.
*
* @param maxLength Maximum possible length of so.
* If bigger, must be illegal.
*/
Key
unseal
(
SealedObject
so
)
Key
unseal
(
SealedObject
so
,
int
maxLength
)
throws
NoSuchAlgorithmException
,
UnrecoverableKeyException
{
SecretKey
sKey
=
null
;
try
{
...
...
@@ -388,7 +391,7 @@ final class KeyProtector {
SunJCE
.
getInstance
(),
"PBEWithMD5AndTripleDES"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
sKey
,
params
);
return
soForKeyProtector
.
getKey
(
cipher
);
return
soForKeyProtector
.
getKey
(
cipher
,
maxLength
);
}
catch
(
NoSuchAlgorithmException
ex
)
{
// Note: this catch needed to be here because of the
// later catch of GeneralSecurityException
...
...
src/share/classes/com/sun/crypto/provider/SealedObjectForKeyProtector.java
浏览文件 @
7e7b76aa
...
...
@@ -73,7 +73,7 @@ final class SealedObjectForKeyProtector extends SealedObject {
return
params
;
}
final
Key
getKey
(
Cipher
c
)
final
Key
getKey
(
Cipher
c
,
int
maxLength
)
throws
IOException
,
ClassNotFoundException
,
IllegalBlockSizeException
,
BadPaddingException
{
...
...
@@ -82,7 +82,7 @@ final class SealedObjectForKeyProtector extends SealedObject {
AccessController
.
doPrivileged
(
(
PrivilegedAction
<
Void
>)
()
->
{
ObjectInputFilter
.
Config
.
setObjectInputFilter
(
ois
,
DeserializationChecker
.
ONE_FILTER
);
new
DeserializationChecker
(
maxLength
)
);
return
null
;
});
try
{
...
...
@@ -110,7 +110,7 @@ final class SealedObjectForKeyProtector extends SealedObject {
*/
private
static
class
DeserializationChecker
implements
ObjectInputFilter
{
private
static
final
ObjectInputFilter
O
NE
_FILTER
;
private
static
final
ObjectInputFilter
O
WN
_FILTER
;
static
{
String
prop
=
AccessController
.
doPrivileged
(
...
...
@@ -122,26 +122,32 @@ final class SealedObjectForKeyProtector extends SealedObject {
return
Security
.
getProperty
(
KEY_SERIAL_FILTER
);
}
});
ONE_FILTER
=
new
DeserializationChecker
(
prop
==
null
?
null
:
ObjectInputFilter
.
Config
.
createFilter
(
prop
));
OWN_FILTER
=
prop
==
null
?
null
:
ObjectInputFilter
.
Config
.
createFilter
(
prop
);
}
private
final
ObjectInputFilter
base
;
// Maximum possible length of anything inside
private
final
int
maxLength
;
private
DeserializationChecker
(
ObjectInputFilter
base
)
{
this
.
base
=
base
;
private
DeserializationChecker
(
int
maxLength
)
{
this
.
maxLength
=
maxLength
;
}
@Override
public
ObjectInputFilter
.
Status
checkInput
(
ObjectInputFilter
.
FilterInfo
info
)
{
if
(
info
.
arrayLength
()
>
maxLength
)
{
return
Status
.
REJECTED
;
}
if
(
info
.
serialClass
()
==
Object
.
class
)
{
return
Status
.
UNDECIDED
;
}
if
(
base
!=
null
)
{
Status
result
=
base
.
checkInput
(
info
);
if
(
OWN_FILTER
!=
null
)
{
Status
result
=
OWN_FILTER
.
checkInput
(
info
);
if
(
result
!=
Status
.
UNDECIDED
)
{
return
result
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录