Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
9b713a3a
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看板
提交
9b713a3a
编写于
10月 09, 2018
作者:
I
igerasim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8210870: Libsunmscapi improved interactions
Reviewed-by: valeriep, mschoene, rhalade
上级
439cc5ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
100 addition
and
33 deletion
+100
-33
src/windows/classes/sun/security/mscapi/KeyStore.java
src/windows/classes/sun/security/mscapi/KeyStore.java
+11
-4
src/windows/native/sun/security/mscapi/security.cpp
src/windows/native/sun/security/mscapi/security.cpp
+89
-29
未找到文件。
src/windows/classes/sun/security/mscapi/KeyStore.java
浏览文件 @
9b713a3a
...
...
@@ -753,6 +753,7 @@ abstract class KeyStore extends KeyStoreSpi {
/**
* Generates a certificate chain from the collection of
* certificates and stores the result into a key entry.
* This method is called by native code in libsunmscapi.
*/
private
void
generateCertificateChain
(
String
alias
,
Collection
<?
extends
Certificate
>
certCollection
)
...
...
@@ -775,13 +776,15 @@ abstract class KeyStore extends KeyStoreSpi {
catch
(
Throwable
e
)
{
// Ignore the exception and skip this entry
// TODO - throw CertificateException?
// If e is thrown, remember to deal with it in
// native code.
}
}
/**
* Generates RSA key and certificate chain from the private key handle,
* collection of certificates and stores the result into key entries.
* This method is called by native code in libsunmscapi.
*/
private
void
generateRSAKeyAndCertificateChain
(
String
alias
,
long
hCryptProv
,
long
hCryptKey
,
int
keyLength
,
...
...
@@ -807,12 +810,14 @@ abstract class KeyStore extends KeyStoreSpi {
catch
(
Throwable
e
)
{
// Ignore the exception and skip this entry
// TODO - throw CertificateException?
// If e is thrown, remember to deal with it in
// native code.
}
}
/**
* Generates certificates from byte data and stores into cert collection.
* This method is called by native code in libsunmscapi.
*
* @param data Byte data.
* @param certCollection Collection of certificates.
...
...
@@ -836,12 +841,14 @@ abstract class KeyStore extends KeyStoreSpi {
catch
(
CertificateException
e
)
{
// Ignore the exception and skip this certificate
// TODO - throw CertificateException?
// If e is thrown, remember to deal with it in
// native code.
}
catch
(
Throwable
te
)
{
// Ignore the exception and skip this certificate
// TODO - throw CertificateException?
// If e is thrown, remember to deal with it in
// native code.
}
}
...
...
src/windows/native/sun/security/mscapi/security.cpp
浏览文件 @
9b713a3a
...
...
@@ -425,6 +425,15 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_loadKeysOrCertificateCh
// Create ArrayList to store certs in each chain
jobject
jArrayList
=
env
->
NewObject
(
clazzArrayList
,
mNewArrayList
);
if
(
jArrayList
==
NULL
)
{
__leave
;
}
// Cleanup the previous allocated name
if
(
pszNameString
)
{
delete
[]
pszNameString
;
pszNameString
=
NULL
;
}
for
(
unsigned
int
j
=
0
;
j
<
rgpChain
->
cElement
;
j
++
)
{
...
...
@@ -463,6 +472,9 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_loadKeysOrCertificateCh
// Allocate and populate byte array
jbyteArray
byteArray
=
env
->
NewByteArray
(
cbCertEncoded
);
if
(
byteArray
==
NULL
)
{
__leave
;
}
env
->
SetByteArrayRegion
(
byteArray
,
0
,
cbCertEncoded
,
(
jbyte
*
)
pbCertEncoded
);
...
...
@@ -471,30 +483,44 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_loadKeysOrCertificateCh
env
->
CallVoidMethod
(
obj
,
mGenCert
,
byteArray
,
jArrayList
);
}
if
(
bHasNoPrivateKey
)
{
// Generate certificate chain and store into cert chain
// collection
env
->
CallVoidMethod
(
obj
,
mGenCertChain
,
env
->
NewStringUTF
(
pszNameString
),
jArrayList
);
}
else
// Usually pszNameString should be non-NULL. It's either
// the friendly name or an element from the subject name
// or SAN.
if
(
pszNameString
)
{
// Determine key type: RSA or DSA
DWORD
dwData
=
CALG_RSA_KEYX
;
DWORD
dwSize
=
sizeof
(
DWORD
);
::
CryptGetKeyParam
(
hUserKey
,
KP_ALGID
,
(
BYTE
*
)
&
dwData
,
&
dwSize
,
NULL
);
if
((
dwData
&
ALG_TYPE_RSA
)
==
ALG_TYPE_RSA
)
if
(
bHasNoPrivateKey
)
{
// Generate RSA certificate chain and store into cert
// chain collection
env
->
CallVoidMethod
(
obj
,
mGenRSAKeyAndCertChain
,
env
->
NewStringUTF
(
pszNameString
),
(
jlong
)
hCryptProv
,
(
jlong
)
hUserKey
,
dwPublicKeyLength
,
jArrayList
);
// Generate certificate chain and store into cert chain
// collection
jstring
name
=
env
->
NewStringUTF
(
pszNameString
);
if
(
name
==
NULL
)
{
__leave
;
}
env
->
CallVoidMethod
(
obj
,
mGenCertChain
,
name
,
jArrayList
);
}
else
{
// Determine key type: RSA or DSA
DWORD
dwData
=
CALG_RSA_KEYX
;
DWORD
dwSize
=
sizeof
(
DWORD
);
::
CryptGetKeyParam
(
hUserKey
,
KP_ALGID
,
(
BYTE
*
)
&
dwData
,
&
dwSize
,
NULL
);
if
((
dwData
&
ALG_TYPE_RSA
)
==
ALG_TYPE_RSA
)
{
// Generate RSA certificate chain and store into cert
// chain collection
jstring
name
=
env
->
NewStringUTF
(
pszNameString
);
if
(
name
==
NULL
)
{
__leave
;
}
env
->
CallVoidMethod
(
obj
,
mGenRSAKeyAndCertChain
,
name
,
(
jlong
)
hCryptProv
,
(
jlong
)
hUserKey
,
dwPublicKeyLength
,
jArrayList
);
}
}
}
}
...
...
@@ -641,6 +667,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSASignature_signHash
// Create new byte array
jbyteArray
temp
=
env
->
NewByteArray
(
dwBufLen
);
if
(
temp
==
NULL
)
{
__leave
;
}
// Copy data from native buffer
env
->
SetByteArrayRegion
(
temp
,
0
,
dwBufLen
,
pSignedHashBuffer
);
...
...
@@ -964,6 +993,9 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_KeyStore_storeCertificate
}
jCertAliasChars
=
env
->
GetStringChars
(
jCertAliasName
,
NULL
);
if
(
jCertAliasChars
==
NULL
)
{
__leave
;
}
memcpy
(
pszCertAliasName
,
jCertAliasChars
,
size
*
sizeof
(
WCHAR
));
pszCertAliasName
[
size
]
=
0
;
// append the string terminator
...
...
@@ -1600,7 +1632,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSACipher_encryptDecrypt
}
// Create new byte array
result
=
env
->
NewByteArray
(
dwBufLen
);
if
((
result
=
env
->
NewByteArray
(
dwBufLen
))
==
NULL
)
{
__leave
;
}
// Copy data from native buffer to Java buffer
env
->
SetByteArrayRegion
(
result
,
0
,
dwBufLen
,
(
jbyte
*
)
pData
);
...
...
@@ -1651,7 +1685,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getPublicKeyB
}
// Create new byte array
blob
=
env
->
NewByteArray
(
dwBlobLen
);
if
((
blob
=
env
->
NewByteArray
(
dwBlobLen
))
==
NULL
)
{
__leave
;
}
// Copy data from native buffer to Java buffer
env
->
SetByteArrayRegion
(
blob
,
0
,
dwBlobLen
,
(
jbyte
*
)
pbKeyBlob
);
...
...
@@ -1680,6 +1716,13 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getExponent
__try
{
jsize
length
=
env
->
GetArrayLength
(
jKeyBlob
);
jsize
headerLength
=
sizeof
(
PUBLICKEYSTRUC
)
+
sizeof
(
RSAPUBKEY
);
if
(
length
<
headerLength
)
{
ThrowExceptionWithMessage
(
env
,
KEY_EXCEPTION
,
"Invalid BLOB"
);
__leave
;
}
if
((
keyBlob
=
env
->
GetByteArrayElements
(
jKeyBlob
,
0
))
==
NULL
)
{
__leave
;
}
...
...
@@ -1706,7 +1749,9 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getExponent
exponentBytes
[
i
]
=
((
BYTE
*
)
&
pRsaPubKey
->
pubexp
)[
j
];
}
exponent
=
env
->
NewByteArray
(
len
);
if
((
exponent
=
env
->
NewByteArray
(
len
))
==
NULL
)
{
__leave
;
}
env
->
SetByteArrayRegion
(
exponent
,
0
,
len
,
exponentBytes
);
}
__finally
...
...
@@ -1736,6 +1781,13 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getModulus
__try
{
jsize
length
=
env
->
GetArrayLength
(
jKeyBlob
);
jsize
headerLength
=
sizeof
(
PUBLICKEYSTRUC
)
+
sizeof
(
RSAPUBKEY
);
if
(
length
<
headerLength
)
{
ThrowExceptionWithMessage
(
env
,
KEY_EXCEPTION
,
"Invalid BLOB"
);
__leave
;
}
if
((
keyBlob
=
env
->
GetByteArrayElements
(
jKeyBlob
,
0
))
==
NULL
)
{
__leave
;
}
...
...
@@ -1752,19 +1804,25 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_mscapi_RSAPublicKey_getModulus
(
RSAPUBKEY
*
)
(
keyBlob
+
sizeof
(
PUBLICKEYSTRUC
));
int
len
=
pRsaPubKey
->
bitlen
/
8
;
if
(
len
<
0
||
len
>
length
-
headerLength
)
{
ThrowExceptionWithMessage
(
env
,
KEY_EXCEPTION
,
"Invalid key length"
);
__leave
;
}
modulusBytes
=
new
(
env
)
jbyte
[
len
];
if
(
modulusBytes
==
NULL
)
{
__leave
;
}
BYTE
*
pbModulus
=
(
BYTE
*
)
(
keyBlob
+
sizeof
(
PUBLICKEYSTRUC
)
+
sizeof
(
RSAPUBKEY
));
BYTE
*
pbModulus
=
(
BYTE
*
)
(
keyBlob
+
headerLength
);
// convert from little-endian while copying from blob
for
(
int
i
=
0
,
j
=
len
-
1
;
i
<
len
;
i
++
,
j
--
)
{
modulusBytes
[
i
]
=
pbModulus
[
j
];
}
modulus
=
env
->
NewByteArray
(
len
);
if
((
modulus
=
env
->
NewByteArray
(
len
))
==
NULL
)
{
__leave
;
}
env
->
SetByteArrayRegion
(
modulus
,
0
,
len
,
modulusBytes
);
}
__finally
...
...
@@ -1972,7 +2030,9 @@ jbyteArray generateKeyBlob(
}
}
jBlob
=
env
->
NewByteArray
(
jBlobLength
);
if
((
jBlob
=
env
->
NewByteArray
(
jBlobLength
))
==
NULL
)
{
__leave
;
}
env
->
SetByteArrayRegion
(
jBlob
,
0
,
jBlobLength
,
jBlobBytes
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录