Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
493194dd
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看板
提交
493194dd
编写于
7月 21, 2012
作者:
W
weijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
Reviewed-by: xuelei
上级
9e61768c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
99 addition
and
39 deletion
+99
-39
src/share/classes/com/sun/crypto/provider/OAEPParameters.java
...share/classes/com/sun/crypto/provider/OAEPParameters.java
+3
-19
src/share/classes/sun/security/pkcs/PKCS7.java
src/share/classes/sun/security/pkcs/PKCS7.java
+1
-1
src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
+3
-5
src/share/classes/sun/security/x509/AlgorithmId.java
src/share/classes/sun/security/x509/AlgorithmId.java
+8
-14
test/sun/security/x509/AlgorithmId/NonStandardNames.java
test/sun/security/x509/AlgorithmId/NonStandardNames.java
+84
-0
未找到文件。
src/share/classes/com/sun/crypto/provider/OAEPParameters.java
浏览文件 @
493194dd
...
...
@@ -105,22 +105,6 @@ public final class OAEPParameters extends AlgorithmParametersSpi {
}
}
private
static
String
convertToStandardName
(
String
internalName
)
{
if
(
internalName
.
equals
(
"SHA"
))
{
return
"SHA-1"
;
}
else
if
(
internalName
.
equals
(
"SHA224"
))
{
return
"SHA-224"
;
}
else
if
(
internalName
.
equals
(
"SHA256"
))
{
return
"SHA-256"
;
}
else
if
(
internalName
.
equals
(
"SHA384"
))
{
return
"SHA-384"
;
}
else
if
(
internalName
.
equals
(
"SHA512"
))
{
return
"SHA-512"
;
}
else
{
return
internalName
;
}
}
protected
void
engineInit
(
byte
[]
encoded
)
throws
IOException
{
DerInputStream
der
=
new
DerInputStream
(
encoded
);
...
...
@@ -132,8 +116,8 @@ public final class OAEPParameters extends AlgorithmParametersSpi {
DerValue
data
=
datum
[
i
];
if
(
data
.
isContextSpecific
((
byte
)
0x00
))
{
// hash algid
mdName
=
convertToStandardName
(
AlgorithmId
.
parse
(
data
.
data
.
getDerValue
()).
getName
()
)
;
mdName
=
AlgorithmId
.
parse
(
data
.
data
.
getDerValue
()).
getName
();
}
else
if
(
data
.
isContextSpecific
((
byte
)
0x01
))
{
// mgf algid
AlgorithmId
val
=
AlgorithmId
.
parse
(
data
.
data
.
getDerValue
());
...
...
@@ -142,7 +126,7 @@ public final class OAEPParameters extends AlgorithmParametersSpi {
}
AlgorithmId
params
=
AlgorithmId
.
parse
(
new
DerValue
(
val
.
getEncodedParams
()));
String
mgfDigestName
=
convertToStandardName
(
params
.
getName
()
);
String
mgfDigestName
=
params
.
getName
(
);
if
(
mgfDigestName
.
equals
(
"SHA-1"
))
{
mgfSpec
=
MGF1ParameterSpec
.
SHA1
;
}
else
if
(
mgfDigestName
.
equals
(
"SHA-224"
))
{
...
...
src/share/classes/sun/security/pkcs/PKCS7.java
浏览文件 @
493194dd
...
...
@@ -882,7 +882,7 @@ public class PKCS7 {
PKCS7
tsToken
=
tsReply
.
getToken
();
TimestampToken
tst
=
tsReply
.
getTimestampToken
();
if
(!
tst
.
getHashAlgorithm
().
getName
().
equals
(
"SHA"
))
{
if
(!
tst
.
getHashAlgorithm
().
getName
().
equals
(
"SHA
-1
"
))
{
throw
new
IOException
(
"Digest algorithm not SHA-1 in "
+
"timestamp token"
);
}
...
...
src/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
浏览文件 @
493194dd
...
...
@@ -1298,11 +1298,9 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
try
{
String
algName
=
macData
.
getDigestAlgName
().
toUpperCase
(
Locale
.
ENGLISH
);
if
(
algName
.
equals
(
"SHA"
)
||
algName
.
equals
(
"SHA1"
)
||
algName
.
equals
(
"SHA-1"
))
{
algName
=
"SHA1"
;
}
// Change SHA-1 to SHA1
algName
=
algName
.
replace
(
"-"
,
""
);
// generate MAC (MAC key is created within JCE)
Mac
m
=
Mac
.
getInstance
(
"HmacPBE"
+
algName
);
...
...
src/share/classes/sun/security/x509/AlgorithmId.java
浏览文件 @
493194dd
...
...
@@ -242,10 +242,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
AlgorithmId
paramsId
=
AlgorithmId
.
parse
(
new
DerValue
(
getEncodedParams
()));
String
paramsName
=
paramsId
.
getName
();
if
(
paramsName
.
equals
(
"SHA"
))
{
paramsName
=
"SHA1"
;
}
algName
=
paramsName
+
"withECDSA"
;
algName
=
makeSigAlg
(
paramsName
,
"EC"
);
}
catch
(
IOException
e
)
{
// ignore
}
...
...
@@ -876,11 +873,11 @@ public class AlgorithmId implements Serializable, DerEncoder {
nameTable
=
new
HashMap
<
ObjectIdentifier
,
String
>();
nameTable
.
put
(
MD5_oid
,
"MD5"
);
nameTable
.
put
(
MD2_oid
,
"MD2"
);
nameTable
.
put
(
SHA_oid
,
"SHA"
);
nameTable
.
put
(
SHA224_oid
,
"SHA224"
);
nameTable
.
put
(
SHA256_oid
,
"SHA256"
);
nameTable
.
put
(
SHA384_oid
,
"SHA384"
);
nameTable
.
put
(
SHA512_oid
,
"SHA512"
);
nameTable
.
put
(
SHA_oid
,
"SHA
-1
"
);
nameTable
.
put
(
SHA224_oid
,
"SHA
-
224"
);
nameTable
.
put
(
SHA256_oid
,
"SHA
-
256"
);
nameTable
.
put
(
SHA384_oid
,
"SHA
-
384"
);
nameTable
.
put
(
SHA512_oid
,
"SHA
-
512"
);
nameTable
.
put
(
RSAEncryption_oid
,
"RSA"
);
nameTable
.
put
(
RSA_oid
,
"RSA"
);
nameTable
.
put
(
DH_oid
,
"Diffie-Hellman"
);
...
...
@@ -917,11 +914,8 @@ public class AlgorithmId implements Serializable, DerEncoder {
* name and a encryption algorithm name.
*/
public
static
String
makeSigAlg
(
String
digAlg
,
String
encAlg
)
{
digAlg
=
digAlg
.
replace
(
"-"
,
""
).
toUpperCase
(
Locale
.
ENGLISH
);
if
(
digAlg
.
equalsIgnoreCase
(
"SHA"
))
digAlg
=
"SHA1"
;
encAlg
=
encAlg
.
toUpperCase
(
Locale
.
ENGLISH
);
if
(
encAlg
.
equals
(
"EC"
))
encAlg
=
"ECDSA"
;
digAlg
=
digAlg
.
replace
(
"-"
,
""
);
if
(
encAlg
.
equalsIgnoreCase
(
"EC"
))
encAlg
=
"ECDSA"
;
return
digAlg
+
"with"
+
encAlg
;
}
...
...
test/sun/security/x509/AlgorithmId/NonStandardNames.java
0 → 100644
浏览文件 @
493194dd
/*
* Copyright (c) 2012, 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 7180907
* @summary Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
*/
import
java.security.MessageDigest
;
import
java.security.Signature
;
import
java.security.cert.X509Certificate
;
import
sun.security.pkcs.ContentInfo
;
import
sun.security.pkcs.PKCS7
;
import
sun.security.pkcs.PKCS9Attribute
;
import
sun.security.pkcs.PKCS9Attributes
;
import
sun.security.pkcs.SignerInfo
;
import
sun.security.tools.CertAndKeyGen
;
import
sun.security.x509.AlgorithmId
;
import
sun.security.x509.X500Name
;
public
class
NonStandardNames
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
byte
[]
data
=
"Hello"
.
getBytes
();
X500Name
n
=
new
X500Name
(
"cn=Me"
);
CertAndKeyGen
cakg
=
new
CertAndKeyGen
(
"RSA"
,
"SHA256withRSA"
);
cakg
.
generate
(
1024
);
X509Certificate
cert
=
cakg
.
getSelfCertificate
(
n
,
1000
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-256"
);
PKCS9Attributes
authed
=
new
PKCS9Attributes
(
new
PKCS9Attribute
[]{
new
PKCS9Attribute
(
PKCS9Attribute
.
CONTENT_TYPE_OID
,
ContentInfo
.
DATA_OID
),
new
PKCS9Attribute
(
PKCS9Attribute
.
MESSAGE_DIGEST_OID
,
md
.
digest
(
data
)),
});
Signature
s
=
Signature
.
getInstance
(
"SHA256withRSA"
);
s
.
initSign
(
cakg
.
getPrivateKey
());
s
.
update
(
authed
.
getDerEncoding
());
byte
[]
sig
=
s
.
sign
();
SignerInfo
signerInfo
=
new
SignerInfo
(
n
,
cert
.
getSerialNumber
(),
AlgorithmId
.
get
(
"SHA-256"
),
authed
,
AlgorithmId
.
get
(
"SHA256withRSA"
),
sig
,
null
);
PKCS7
pkcs7
=
new
PKCS7
(
new
AlgorithmId
[]
{
signerInfo
.
getDigestAlgorithmId
()},
new
ContentInfo
(
data
),
new
X509Certificate
[]
{
cert
},
new
SignerInfo
[]
{
signerInfo
});
if
(
pkcs7
.
verify
(
signerInfo
,
data
)
==
null
)
{
throw
new
Exception
(
"Not verified"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录