Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
30766537
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看板
提交
30766537
编写于
1月 03, 2020
作者:
A
andrew
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8231139: Improved keystore support
Reviewed-by: mbalao
上级
ab3130ac
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
63 addition
and
104 deletion
+63
-104
src/share/classes/com/sun/crypto/provider/JceKeyStore.java
src/share/classes/com/sun/crypto/provider/JceKeyStore.java
+19
-42
src/share/classes/java/security/CodeSource.java
src/share/classes/java/security/CodeSource.java
+1
-1
src/share/classes/java/security/UnresolvedPermission.java
src/share/classes/java/security/UnresolvedPermission.java
+1
-1
src/share/classes/java/security/cert/CertificateRevokedException.java
...asses/java/security/cert/CertificateRevokedException.java
+1
-1
src/share/classes/sun/misc/IOUtils.java
src/share/classes/sun/misc/IOUtils.java
+18
-33
src/share/classes/sun/security/krb5/internal/NetClient.java
src/share/classes/sun/security/krb5/internal/NetClient.java
+2
-2
src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
.../sun/security/krb5/internal/ccache/CCacheInputStream.java
+4
-4
src/share/classes/sun/security/provider/JavaKeyStore.java
src/share/classes/sun/security/provider/JavaKeyStore.java
+8
-11
src/share/classes/sun/security/util/DerValue.java
src/share/classes/sun/security/util/DerValue.java
+1
-1
test/sun/security/util/DerValue/BadValue.java
test/sun/security/util/DerValue/BadValue.java
+8
-8
未找到文件。
src/share/classes/com/sun/crypto/provider/JceKeyStore.java
浏览文件 @
30766537
...
...
@@ -43,6 +43,7 @@ import java.security.cert.CertificateFactory;
import
java.security.cert.CertificateException
;
import
javax.crypto.SealedObject
;
import
sun.misc.IOUtils
;
import
sun.misc.ObjectInputFilter
;
/**
...
...
@@ -70,7 +71,7 @@ public final class JceKeyStore extends KeyStoreSpi {
private
static
final
class
PrivateKeyEntry
{
Date
date
;
// the creation date of this entry
byte
[]
protectedKey
;
Certificate
chain
[]
;
Certificate
[]
chain
;
};
// Secret key
...
...
@@ -738,23 +739,11 @@ public final class JceKeyStore extends KeyStoreSpi {
entry
.
date
=
new
Date
(
dis
.
readLong
());
// read the private key
try
{
entry
.
protectedKey
=
new
byte
[
dis
.
readInt
()];
}
catch
(
OutOfMemoryError
e
)
{
throw
new
IOException
(
"Keysize too big"
);
}
dis
.
readFully
(
entry
.
protectedKey
);
entry
.
protectedKey
=
IOUtils
.
readExactlyNBytes
(
dis
,
dis
.
readInt
());
// read the certificate chain
int
numOfCerts
=
dis
.
readInt
();
try
{
if
(
numOfCerts
>
0
)
{
entry
.
chain
=
new
Certificate
[
numOfCerts
];
}
}
catch
(
OutOfMemoryError
e
)
{
throw
new
IOException
(
"Too many certificates in "
+
"chain"
);
}
List
<
Certificate
>
tmpCerts
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
numOfCerts
;
j
++)
{
if
(
xVersion
==
2
)
{
// read the certificate type, and instantiate a
...
...
@@ -774,15 +763,12 @@ public final class JceKeyStore extends KeyStoreSpi {
}
}
// instantiate the certificate
try
{
encoded
=
new
byte
[
dis
.
readInt
()];
}
catch
(
OutOfMemoryError
e
)
{
throw
new
IOException
(
"Certificate too big"
);
}
dis
.
readFully
(
encoded
);
encoded
=
IOUtils
.
readExactlyNBytes
(
dis
,
dis
.
readInt
());
bais
=
new
ByteArrayInputStream
(
encoded
);
entry
.
chain
[
j
]
=
cf
.
generateCertificate
(
bais
);
tmpCerts
.
add
(
cf
.
generateCertificate
(
bais
)
);
}
entry
.
chain
=
tmpCerts
.
toArray
(
new
Certificate
[
numOfCerts
]);
// Add the entry to the list
entries
.
put
(
alias
,
entry
);
...
...
@@ -814,12 +800,7 @@ public final class JceKeyStore extends KeyStoreSpi {
cfs
.
put
(
certType
,
cf
);
}
}
try
{
encoded
=
new
byte
[
dis
.
readInt
()];
}
catch
(
OutOfMemoryError
e
)
{
throw
new
IOException
(
"Certificate too big"
);
}
dis
.
readFully
(
encoded
);
encoded
=
IOUtils
.
readExactlyNBytes
(
dis
,
dis
.
readInt
());
bais
=
new
ByteArrayInputStream
(
encoded
);
entry
.
cert
=
cf
.
generateCertificate
(
bais
);
...
...
@@ -870,12 +851,9 @@ public final class JceKeyStore extends KeyStoreSpi {
* with
*/
if
(
password
!=
null
)
{
byte
computed
[],
actual
[];
computed
=
md
.
digest
();
actual
=
new
byte
[
computed
.
length
];
dis
.
readFully
(
actual
);
for
(
int
i
=
0
;
i
<
computed
.
length
;
i
++)
{
if
(
computed
[
i
]
!=
actual
[
i
])
{
byte
[]
computed
=
md
.
digest
();
byte
[]
actual
=
IOUtils
.
readExactlyNBytes
(
dis
,
computed
.
length
);
if
(!
MessageDigest
.
isEqual
(
computed
,
actual
))
{
throw
new
IOException
(
"Keystore was tampered with, or "
+
"password was incorrect"
,
...
...
@@ -883,7 +861,6 @@ public final class JceKeyStore extends KeyStoreSpi {
"Password verification failed"
));
}
}
}
}
finally
{
if
(
ois
!=
null
)
{
ois
.
close
();
...
...
src/share/classes/java/security/CodeSource.java
浏览文件 @
30766537
...
...
@@ -570,7 +570,7 @@ public class CodeSource implements java.io.Serializable {
cfs
.
put
(
certType
,
cf
);
}
// parse the certificate
byte
[]
encoded
=
IOUtils
.
readNBytes
(
ois
,
ois
.
readInt
());
byte
[]
encoded
=
IOUtils
.
read
Exactly
NBytes
(
ois
,
ois
.
readInt
());
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
encoded
);
try
{
certList
.
add
(
cf
.
generateCertificate
(
bais
));
...
...
src/share/classes/java/security/UnresolvedPermission.java
浏览文件 @
30766537
...
...
@@ -590,7 +590,7 @@ implements java.io.Serializable
cfs
.
put
(
certType
,
cf
);
}
// parse the certificate
byte
[]
encoded
=
IOUtils
.
readNBytes
(
ois
,
ois
.
readInt
());
byte
[]
encoded
=
IOUtils
.
read
Exactly
NBytes
(
ois
,
ois
.
readInt
());
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
encoded
);
try
{
certList
.
add
(
cf
.
generateCertificate
(
bais
));
...
...
src/share/classes/java/security/cert/CertificateRevokedException.java
浏览文件 @
30766537
...
...
@@ -239,7 +239,7 @@ public class CertificateRevokedException extends CertificateException {
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
String
oid
=
(
String
)
ois
.
readObject
();
boolean
critical
=
ois
.
readBoolean
();
byte
[]
extVal
=
IOUtils
.
readNBytes
(
ois
,
ois
.
readInt
());
byte
[]
extVal
=
IOUtils
.
read
Exactly
NBytes
(
ois
,
ois
.
readInt
());
Extension
ext
=
sun
.
security
.
x509
.
Extension
.
newExtension
(
new
ObjectIdentifier
(
oid
),
critical
,
extVal
);
extensions
.
put
(
oid
,
ext
);
...
...
src/share/classes/sun/misc/IOUtils.java
浏览文件 @
30766537
/*
* Copyright (c) 2009, 201
7
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 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
...
...
@@ -51,46 +51,31 @@ public class IOUtils {
private
static
final
int
MAX_BUFFER_SIZE
=
Integer
.
MAX_VALUE
-
8
;
/**
* Read up to {@code length} of bytes from {@code in}
* until EOF is detected.
* Read exactly {@code length} of bytes from {@code in}.
*
* <p> Note that this method is safe to be called with unknown large
* {@code length} argument. The memory used is proportional to the
* actual bytes available. An exception is thrown if there are not
* enough bytes in the stream.
*
* @param is input stream, must not be null
* @param length number of bytes to read
* @param readAll if true, an EOFException will be thrown if not enough
* bytes are read.
* @return bytes read
* @throws IOException Any IO error or a premature EOF is detected
* @throws EOFException if there are not enough bytes in the stream
* @throws IOException if an I/O error occurs or {@code length} is negative
* @throws OutOfMemoryError if an array of the required size cannot be
* allocated.
*/
public
static
byte
[]
read
Fully
(
InputStream
is
,
int
length
,
boolean
readAll
)
public
static
byte
[]
read
ExactlyNBytes
(
InputStream
is
,
int
length
)
throws
IOException
{
if
(
length
<
0
)
{
throw
new
IOException
(
"Invalid length"
);
}
byte
[]
output
=
{};
int
pos
=
0
;
while
(
pos
<
length
)
{
int
bytesToRead
;
if
(
pos
>=
output
.
length
)
{
// Only expand when there's no room
bytesToRead
=
Math
.
min
(
length
-
pos
,
output
.
length
+
1024
);
if
(
output
.
length
<
pos
+
bytesToRead
)
{
output
=
Arrays
.
copyOf
(
output
,
pos
+
bytesToRead
);
}
}
else
{
bytesToRead
=
output
.
length
-
pos
;
}
int
cc
=
is
.
read
(
output
,
pos
,
bytesToRead
);
if
(
cc
<
0
)
{
if
(
readAll
)
{
throw
new
EOFException
(
"Detect premature EOF"
);
}
else
{
if
(
output
.
length
!=
pos
)
{
output
=
Arrays
.
copyOf
(
output
,
pos
);
}
break
;
}
throw
new
IOException
(
"length cannot be negative: "
+
length
);
}
pos
+=
cc
;
byte
[]
data
=
readNBytes
(
is
,
length
);
if
(
data
.
length
<
length
)
{
throw
new
EOFException
();
}
return
output
;
return
data
;
}
/**
...
...
src/share/classes/sun/security/krb5/internal/NetClient.java
浏览文件 @
30766537
/*
* Copyright (c) 2000, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
...
...
@@ -103,7 +103,7 @@ class TCPClient extends NetClient {
}
try
{
return
IOUtils
.
read
Fully
(
in
,
len
,
true
);
return
IOUtils
.
read
ExactlyNBytes
(
in
,
len
);
}
catch
(
IOException
ioe
)
{
if
(
Krb5
.
DEBUG
)
{
System
.
out
.
println
(
...
...
src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
浏览文件 @
30766537
...
...
@@ -128,7 +128,7 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
length
--;
for
(
int
i
=
0
;
i
<=
length
;
i
++)
{
namelength
=
readLength4
();
byte
[]
bytes
=
IOUtils
.
read
Fully
(
this
,
namelength
,
true
);
byte
[]
bytes
=
IOUtils
.
read
ExactlyNBytes
(
this
,
namelength
);
result
.
add
(
new
String
(
bytes
));
}
if
(
result
.
isEmpty
())
{
...
...
@@ -186,7 +186,7 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
if
(
version
==
KRB5_FCC_FVNO_3
)
read
(
2
);
/* keytype recorded twice in fvno 3 */
keyLen
=
readLength4
();
byte
[]
bytes
=
IOUtils
.
read
Fully
(
this
,
keyLen
,
true
);
byte
[]
bytes
=
IOUtils
.
read
ExactlyNBytes
(
this
,
keyLen
);
return
new
EncryptionKey
(
bytes
,
keyType
,
new
Integer
(
version
));
}
...
...
@@ -239,7 +239,7 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
for
(
int
i
=
0
;
i
<
num
;
i
++)
{
adtype
=
read
(
2
);
adlength
=
readLength4
();
data
=
IOUtils
.
read
Fully
(
this
,
adlength
,
true
);
data
=
IOUtils
.
read
ExactlyNBytes
(
this
,
adlength
);
auData
.
add
(
new
AuthorizationDataEntry
(
adtype
,
data
));
}
return
auData
.
toArray
(
new
AuthorizationDataEntry
[
auData
.
size
()]);
...
...
@@ -253,7 +253,7 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
if
(
length
==
0
)
{
return
null
;
}
else
{
return
IOUtils
.
read
Fully
(
this
,
length
,
true
);
return
IOUtils
.
read
ExactlyNBytes
(
this
,
length
);
}
}
...
...
src/share/classes/sun/security/provider/JavaKeyStore.java
浏览文件 @
30766537
...
...
@@ -691,7 +691,7 @@ abstract class JavaKeyStore extends KeyStoreSpi {
// Read the private key
entry
.
protectedPrivKey
=
IOUtils
.
read
Fully
(
dis
,
dis
.
readInt
(),
true
);
IOUtils
.
read
ExactlyNBytes
(
dis
,
dis
.
readInt
()
);
// Read the certificate chain
int
numOfCerts
=
dis
.
readInt
();
...
...
@@ -716,7 +716,7 @@ abstract class JavaKeyStore extends KeyStoreSpi {
}
}
// instantiate the certificate
encoded
=
IOUtils
.
read
Fully
(
dis
,
dis
.
readInt
(),
true
);
encoded
=
IOUtils
.
read
ExactlyNBytes
(
dis
,
dis
.
readInt
()
);
bais
=
new
ByteArrayInputStream
(
encoded
);
certs
.
add
(
cf
.
generateCertificate
(
bais
));
bais
.
close
();
...
...
@@ -755,7 +755,7 @@ abstract class JavaKeyStore extends KeyStoreSpi {
cfs
.
put
(
certType
,
cf
);
}
}
encoded
=
IOUtils
.
read
Fully
(
dis
,
dis
.
readInt
(),
true
);
encoded
=
IOUtils
.
read
ExactlyNBytes
(
dis
,
dis
.
readInt
()
);
bais
=
new
ByteArrayInputStream
(
encoded
);
entry
.
cert
=
cf
.
generateCertificate
(
bais
);
bais
.
close
();
...
...
@@ -776,20 +776,17 @@ abstract class JavaKeyStore extends KeyStoreSpi {
if
(
password
!=
null
)
{
byte
computed
[],
actual
[];
computed
=
md
.
digest
();
actual
=
new
byte
[
computed
.
length
];
dis
.
readFully
(
actual
);
for
(
int
i
=
0
;
i
<
computed
.
length
;
i
++)
{
if
(
computed
[
i
]
!=
actual
[
i
])
{
actual
=
IOUtils
.
readExactlyNBytes
(
dis
,
computed
.
length
);
if
(!
MessageDigest
.
isEqual
(
computed
,
actual
))
{
Throwable
t
=
new
UnrecoverableKeyException
(
"Password verification failed"
);
throw
(
IOException
)
new
IOException
throw
(
IOException
)
new
IOException
(
"Keystore was tampered with, or "
+
"password was incorrect"
).
initCause
(
t
);
}
}
}
}
}
/**
* To guard against tampering with the keystore, we append a keyed
...
...
src/share/classes/sun/security/util/DerValue.java
浏览文件 @
30766537
...
...
@@ -409,7 +409,7 @@ public class DerValue {
if
(
fullyBuffered
&&
in
.
available
()
!=
length
)
throw
new
IOException
(
"extra data given to DerValue constructor"
);
byte
[]
bytes
=
IOUtils
.
read
Fully
(
in
,
length
,
true
);
byte
[]
bytes
=
IOUtils
.
read
ExactlyNBytes
(
in
,
length
);
buffer
=
new
DerInputBuffer
(
bytes
,
allowBER
);
return
new
DerInputStream
(
buffer
);
...
...
test/sun/security/util/DerValue/BadValue.java
浏览文件 @
30766537
/*
* Copyright (c) 2009, 201
7
Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 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
...
...
@@ -35,23 +35,23 @@ public class BadValue {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// Test IOUtils.
readFully
// Test IOUtils.
// We have 4 bytes
InputStream
in
=
new
ByteArrayInputStream
(
new
byte
[
10
]);
byte
[]
bs
=
IOUtils
.
read
Fully
(
in
,
4
,
true
);
byte
[]
bs
=
IOUtils
.
read
ExactlyNBytes
(
in
,
4
);
if
(
bs
.
length
!=
4
||
in
.
available
()
!=
6
)
{
throw
new
Exception
(
"First read error"
);
}
// But only 6 left
bs
=
IOUtils
.
read
Fully
(
in
,
10
,
false
);
bs
=
IOUtils
.
read
NBytes
(
in
,
10
);
if
(
bs
.
length
!=
6
||
in
.
available
()
!=
0
)
{
throw
new
Exception
(
"Second read error"
);
}
// MAX length results in exception
in
=
new
ByteArrayInputStream
(
new
byte
[
10
]);
try
{
bs
=
IOUtils
.
read
Fully
(
in
,
Integer
.
MAX_VALUE
,
true
);
bs
=
IOUtils
.
read
ExactlyNBytes
(
in
,
Integer
.
MAX_VALUE
);
throw
new
Exception
(
"No exception on MAX_VALUE length"
);
}
catch
(
EOFException
ex
)
{
// this is expected
...
...
@@ -59,7 +59,7 @@ public class BadValue {
// -1 length results in exception
in
=
new
ByteArrayInputStream
(
new
byte
[
10
]);
try
{
bs
=
IOUtils
.
read
Fully
(
in
,
-
1
,
true
);
bs
=
IOUtils
.
read
ExactlyNBytes
(
in
,
-
1
);
throw
new
Exception
(
"No exception on -1 length"
);
}
catch
(
IOException
ex
)
{
// this is expected
...
...
@@ -68,13 +68,13 @@ public class BadValue {
// 20>10, readAll means failure
in
=
new
ByteArrayInputStream
(
new
byte
[
10
]);
try
{
bs
=
IOUtils
.
read
Fully
(
in
,
20
,
true
);
bs
=
IOUtils
.
read
ExactlyNBytes
(
in
,
20
);
throw
new
Exception
(
"No exception on EOF"
);
}
catch
(
EOFException
e
)
{
// OK
}
int
bignum
=
10
*
1024
*
1024
;
bs
=
IOUtils
.
read
Fully
(
new
SuperSlowStream
(
bignum
),
bignum
,
true
);
bs
=
IOUtils
.
read
ExactlyNBytes
(
new
SuperSlowStream
(
bignum
),
bignum
);
if
(
bs
.
length
!=
bignum
)
{
throw
new
Exception
(
"Read returned small array"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录