Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
3d8c4fbc
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看板
提交
3d8c4fbc
编写于
8年前
作者:
I
igerasim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8163896: Finalizing one key of a KeyPair invalidates the other key
Reviewed-by: coffeys, vinnie
上级
702718aa
无相关合并请求
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
158 addition
and
45 deletion
+158
-45
src/windows/classes/sun/security/mscapi/Key.java
src/windows/classes/sun/security/mscapi/Key.java
+35
-29
src/windows/classes/sun/security/mscapi/KeyStore.java
src/windows/classes/sun/security/mscapi/KeyStore.java
+3
-3
src/windows/classes/sun/security/mscapi/RSAKeyPair.java
src/windows/classes/sun/security/mscapi/RSAKeyPair.java
+4
-3
src/windows/classes/sun/security/mscapi/RSAPrivateKey.java
src/windows/classes/sun/security/mscapi/RSAPrivateKey.java
+12
-4
src/windows/classes/sun/security/mscapi/RSAPublicKey.java
src/windows/classes/sun/security/mscapi/RSAPublicKey.java
+14
-6
test/java/security/KeyPairGenerator/FinalizeHalf.java
test/java/security/KeyPairGenerator/FinalizeHalf.java
+90
-0
未找到文件。
src/windows/classes/sun/security/mscapi/Key.java
浏览文件 @
3d8c4fbc
/*
* Copyright (c) 2005, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 201
6
, 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
...
...
@@ -30,7 +30,6 @@ import sun.security.util.Length;
/**
* The handle for an RSA or DSA key using the Microsoft Crypto API.
*
* @see DSAPrivateKey
* @see RSAPrivateKey
* @see RSAPublicKey
*
...
...
@@ -41,9 +40,35 @@ abstract class Key implements java.security.Key, Length
{
private
static
final
long
serialVersionUID
=
-
1088859394025049194L
;
// Native handle
protected
long
hCryptProv
=
0
;
protected
long
hCryptKey
=
0
;
static
class
NativeHandles
{
long
hCryptProv
=
0
;
long
hCryptKey
=
0
;
public
NativeHandles
(
long
hCryptProv
,
long
hCryptKey
)
{
this
.
hCryptProv
=
hCryptProv
;
this
.
hCryptKey
=
hCryptKey
;
}
/**
* Finalization method
*/
protected
void
finalize
()
throws
Throwable
{
try
{
synchronized
(
this
)
{
cleanUp
(
hCryptProv
,
hCryptKey
);
hCryptProv
=
0
;
hCryptKey
=
0
;
}
}
finally
{
super
.
finalize
();
}
}
}
protected
NativeHandles
handles
;
// Key length
protected
int
keyLength
=
0
;
...
...
@@ -51,31 +76,12 @@ abstract class Key implements java.security.Key, Length
/**
* Construct a Key object.
*/
protected
Key
(
long
hCryptProv
,
long
hCryptKey
,
int
keyLength
)
protected
Key
(
NativeHandles
handles
,
int
keyLength
)
{
this
.
hCryptProv
=
hCryptProv
;
this
.
hCryptKey
=
hCryptKey
;
this
.
handles
=
handles
;
this
.
keyLength
=
keyLength
;
}
/**
* Finalization method
*/
protected
void
finalize
()
throws
Throwable
{
try
{
synchronized
(
this
)
{
cleanUp
(
hCryptProv
,
hCryptKey
);
hCryptProv
=
0
;
hCryptKey
=
0
;
}
}
finally
{
super
.
finalize
();
}
}
/**
* Native method to cleanup the key handle.
*/
...
...
@@ -96,7 +102,7 @@ abstract class Key implements java.security.Key, Length
*/
public
long
getHCryptKey
()
{
return
hCryptKey
;
return
h
andles
.
h
CryptKey
;
}
/**
...
...
@@ -104,12 +110,12 @@ abstract class Key implements java.security.Key, Length
*/
public
long
getHCryptProvider
()
{
return
hCryptProv
;
return
h
andles
.
h
CryptProv
;
}
/**
* Returns the standard algorithm name for this key. For
* example, "
DSA" would indicate that this key is a D
SA key.
* example, "
RSA" would indicate that this key is a R
SA key.
* See Appendix A in the <a href=
* "../../../guide/security/CryptoSpec.html#AppA">
* Java Cryptography Architecture API Specification & Reference </a>
...
...
This diff is collapsed.
Click to expand it.
src/windows/classes/sun/security/mscapi/KeyStore.java
浏览文件 @
3d8c4fbc
...
...
@@ -169,7 +169,7 @@ abstract class KeyStore extends KeyStoreSpi {
}
certChain
=
chain
;
}
}
;
}
/*
* An X.509 certificate factory.
...
...
@@ -800,7 +800,8 @@ abstract class KeyStore extends KeyStoreSpi {
}
storeWithUniqueAlias
(
alias
,
new
KeyEntry
(
alias
,
new
RSAPrivateKey
(
hCryptProv
,
hCryptKey
,
keyLength
),
new
RSAPrivateKey
(
new
Key
.
NativeHandles
(
hCryptProv
,
hCryptKey
),
keyLength
),
certChain
));
}
catch
(
Throwable
e
)
...
...
@@ -856,7 +857,6 @@ abstract class KeyStore extends KeyStoreSpi {
* Load keys and/or certificates from keystore into Collection.
*
* @param name Name of keystore.
* @param entries Collection of key/certificate.
*/
private
native
void
loadKeysOrCertificateChains
(
String
name
)
throws
KeyStoreException
;
...
...
This diff is collapsed.
Click to expand it.
src/windows/classes/sun/security/mscapi/RSAKeyPair.java
浏览文件 @
3d8c4fbc
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005,
2016,
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
...
...
@@ -41,8 +41,9 @@ class RSAKeyPair {
*/
RSAKeyPair
(
long
hCryptProv
,
long
hCryptKey
,
int
keyLength
)
{
privateKey
=
new
RSAPrivateKey
(
hCryptProv
,
hCryptKey
,
keyLength
);
publicKey
=
new
RSAPublicKey
(
hCryptProv
,
hCryptKey
,
keyLength
);
Key
.
NativeHandles
handles
=
new
Key
.
NativeHandles
(
hCryptProv
,
hCryptKey
);
privateKey
=
new
RSAPrivateKey
(
handles
,
keyLength
);
publicKey
=
new
RSAPublicKey
(
handles
,
keyLength
);
}
public
RSAPrivateKey
getPrivate
()
{
...
...
This diff is collapsed.
Click to expand it.
src/windows/classes/sun/security/mscapi/RSAPrivateKey.java
浏览文件 @
3d8c4fbc
/*
* Copyright (c) 2005, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 201
6
, 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
...
...
@@ -42,7 +42,15 @@ class RSAPrivateKey extends Key implements PrivateKey
*/
RSAPrivateKey
(
long
hCryptProv
,
long
hCryptKey
,
int
keyLength
)
{
super
(
hCryptProv
,
hCryptKey
,
keyLength
);
super
(
new
NativeHandles
(
hCryptProv
,
hCryptKey
),
keyLength
);
}
/**
* Construct an RSAPrivateKey object.
*/
RSAPrivateKey
(
NativeHandles
handles
,
int
keyLength
)
{
super
(
handles
,
keyLength
);
}
/**
...
...
@@ -63,8 +71,8 @@ class RSAPrivateKey extends Key implements PrivateKey
public
String
toString
()
{
return
"RSAPrivateKey [size="
+
keyLength
+
" bits, type="
+
getKeyType
(
hCryptKey
)
+
", container="
+
getContainerName
(
hCryptProv
)
+
"]"
;
getKeyType
(
h
andles
.
h
CryptKey
)
+
", container="
+
getContainerName
(
h
andles
.
h
CryptProv
)
+
"]"
;
}
// This class is not serializable
...
...
This diff is collapsed.
Click to expand it.
src/windows/classes/sun/security/mscapi/RSAPublicKey.java
浏览文件 @
3d8c4fbc
/*
* Copyright (c) 2005, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 201
6
, 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
...
...
@@ -51,7 +51,15 @@ class RSAPublicKey extends Key implements java.security.interfaces.RSAPublicKey
*/
RSAPublicKey
(
long
hCryptProv
,
long
hCryptKey
,
int
keyLength
)
{
super
(
hCryptProv
,
hCryptKey
,
keyLength
);
super
(
new
NativeHandles
(
hCryptProv
,
hCryptKey
),
keyLength
);
}
/**
* Construct an RSAPublicKey object.
*/
RSAPublicKey
(
NativeHandles
handles
,
int
keyLength
)
{
super
(
handles
,
keyLength
);
}
/**
...
...
@@ -77,8 +85,8 @@ class RSAPublicKey extends Key implements java.security.interfaces.RSAPublicKey
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"RSAPublicKey [size="
).
append
(
keyLength
)
.
append
(
" bits, type="
).
append
(
getKeyType
(
hCryptKey
))
.
append
(
", container="
).
append
(
getContainerName
(
hCryptProv
))
.
append
(
" bits, type="
).
append
(
getKeyType
(
h
andles
.
h
CryptKey
))
.
append
(
", container="
).
append
(
getContainerName
(
h
andles
.
h
CryptProv
))
.
append
(
"]\n modulus: "
).
append
(
getModulus
())
.
append
(
"\n public exponent: "
).
append
(
getPublicExponent
());
...
...
@@ -93,7 +101,7 @@ class RSAPublicKey extends Key implements java.security.interfaces.RSAPublicKey
if
(
exponent
==
null
)
{
try
{
publicKeyBlob
=
getPublicKeyBlob
(
hCryptKey
);
publicKeyBlob
=
getPublicKeyBlob
(
h
andles
.
h
CryptKey
);
exponent
=
new
BigInteger
(
1
,
getExponent
(
publicKeyBlob
));
}
catch
(
KeyException
e
)
{
...
...
@@ -112,7 +120,7 @@ class RSAPublicKey extends Key implements java.security.interfaces.RSAPublicKey
if
(
modulus
==
null
)
{
try
{
publicKeyBlob
=
getPublicKeyBlob
(
hCryptKey
);
publicKeyBlob
=
getPublicKeyBlob
(
h
andles
.
h
CryptKey
);
modulus
=
new
BigInteger
(
1
,
getModulus
(
publicKeyBlob
));
}
catch
(
KeyException
e
)
{
...
...
This diff is collapsed.
Click to expand it.
test/java/security/KeyPairGenerator/FinalizeHalf.java
0 → 100644
浏览文件 @
3d8c4fbc
/*
* Copyright (c) 2016, 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.
*/
/**
* @test
* @bug 8163896
* @summary Finalizing one key of a KeyPair invalidates the other key
*/
import
java.security.Key
;
import
java.security.KeyPair
;
import
java.security.KeyPairGenerator
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.Provider
;
import
java.security.ProviderException
;
import
java.security.Security
;
import
java.util.function.Consumer
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
FinalizeHalf
{
static
int
failures
=
0
;
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
List
<
Consumer
<
Key
>>
methods
=
new
ArrayList
<>();
methods
.
add
((
Key
k
)
->
k
.
getEncoded
());
methods
.
add
((
Key
k
)
->
k
.
toString
());
for
(
String
algo
:
new
String
[]
{
"DiffieHellman"
,
"DSA"
,
"RSA"
})
{
for
(
Provider
provider
:
Security
.
getProviders
())
{
for
(
boolean
priv
:
new
boolean
[]
{
true
,
false
})
{
for
(
Consumer
<
Key
>
method
:
methods
)
{
test
(
algo
,
provider
,
priv
,
method
);
}
}
}
}
if
(
failures
>
0
)
{
throw
new
RuntimeException
(
failures
+
" test(s) failed."
);
}
}
static
void
test
(
String
algo
,
Provider
provider
,
boolean
priv
,
Consumer
<
Key
>
method
)
throws
Exception
{
KeyPairGenerator
generator
;
try
{
generator
=
KeyPairGenerator
.
getInstance
(
algo
,
provider
);
}
catch
(
NoSuchAlgorithmException
nsae
)
{
return
;
}
System
.
out
.
println
(
"Checking "
+
provider
.
getName
()
+
", "
+
algo
);
KeyPair
pair
=
generator
.
generateKeyPair
();
Key
key
=
priv
?
pair
.
getPrivate
()
:
pair
.
getPublic
();
pair
=
null
;
for
(
int
i
=
0
;
i
<
32
;
++
i
)
{
System
.
gc
();
}
try
{
method
.
accept
(
key
);
}
catch
(
ProviderException
pe
)
{
failures
++;
}
}
}
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
反馈
建议
客服
返回
顶部