Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
b5d84e6a
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看板
提交
b5d84e6a
编写于
9月 28, 2017
作者:
K
kevinw
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
2a65095c
9231b55d
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
794 addition
and
315 deletion
+794
-315
src/share/classes/javax/crypto/JceSecurity.java
src/share/classes/javax/crypto/JceSecurity.java
+6
-6
src/share/classes/sun/security/ssl/SSLSocketImpl.java
src/share/classes/sun/security/ssl/SSLSocketImpl.java
+6
-1
src/share/lib/security/java.security-aix
src/share/lib/security/java.security-aix
+44
-42
src/share/lib/security/java.security-linux
src/share/lib/security/java.security-linux
+44
-41
src/share/lib/security/java.security-macosx
src/share/lib/security/java.security-macosx
+44
-41
src/share/lib/security/java.security-solaris
src/share/lib/security/java.security-solaris
+44
-41
src/share/lib/security/java.security-windows
src/share/lib/security/java.security-windows
+44
-41
test/com/sun/crypto/provider/Cipher/AES/TestAESCiphers/Dynamic.java
...un/crypto/provider/Cipher/AES/TestAESCiphers/Dynamic.java
+6
-15
test/com/sun/crypto/provider/Cipher/Blowfish/TestCipherBlowfish.java
...n/crypto/provider/Cipher/Blowfish/TestCipherBlowfish.java
+2
-2
test/com/sun/crypto/provider/Cipher/PBE/PBESameBuffer/AESPBEWrapper.java
...ypto/provider/Cipher/PBE/PBESameBuffer/AESPBEWrapper.java
+22
-17
test/com/sun/crypto/provider/Cipher/PBE/PBESameBuffer/PBECipherWrapper.java
...o/provider/Cipher/PBE/PBESameBuffer/PBECipherWrapper.java
+28
-20
test/com/sun/crypto/provider/Cipher/PBE/TestCipherKeyWrapperPBEKey.java
...rypto/provider/Cipher/PBE/TestCipherKeyWrapperPBEKey.java
+10
-7
test/com/sun/crypto/provider/Cipher/PBE/TestCipherPBE.java
test/com/sun/crypto/provider/Cipher/PBE/TestCipherPBE.java
+8
-5
test/com/sun/crypto/provider/Cipher/TestCipher.java
test/com/sun/crypto/provider/Cipher/TestCipher.java
+22
-18
test/javax/crypto/CryptoPermission/CryptoPolicyFallback.java
test/javax/crypto/CryptoPermission/CryptoPolicyFallback.java
+123
-0
test/javax/crypto/CryptoPermission/TestUnlimited.java
test/javax/crypto/CryptoPermission/TestUnlimited.java
+70
-18
test/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java
test/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java
+271
-0
未找到文件。
src/share/classes/javax/crypto/JceSecurity.java
浏览文件 @
b5d84e6a
/*
/*
* Copyright (c) 1997, 201
6
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 201
7
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -257,12 +257,12 @@ final class JceSecurity {
...
@@ -257,12 +257,12 @@ final class JceSecurity {
* user edit or an application call is required.
* user edit or an application call is required.
*
*
* Otherwise, if user has policy jar files installed in the legacy
* Otherwise, if user has policy jar files installed in the legacy
*
jre
/lib/security/ directory, the JDK will honor whatever
*
<java-home>
/lib/security/ directory, the JDK will honor whatever
* setting is set by those policy files. (legacy/current behavior)
* setting is set by those policy files. (legacy/current behavior)
*
*
* If none of the above 2 conditions are met, the JDK will default
* If none of the above 2 conditions are met, the JDK will default
* to using the limited crypto policy files found in the
* to using the
un
limited crypto policy files found in the
*
jre/lib/security/policy/
limited/ directory
*
<java-home>/lib/security/policy/un
limited/ directory
*/
*/
private
static
void
setupJurisdictionPolicies
()
throws
Exception
{
private
static
void
setupJurisdictionPolicies
()
throws
Exception
{
// Sanity check the crypto.policy Security property. Single
// Sanity check the crypto.policy Security property. Single
...
@@ -300,9 +300,9 @@ final class JceSecurity {
...
@@ -300,9 +300,9 @@ final class JceSecurity {
!
importJar
.
exists
()))
{
!
importJar
.
exists
()))
{
// Compatibility set up. If crypto.policy is not defined.
// Compatibility set up. If crypto.policy is not defined.
// check to see if legacy jars exist in lib directory. If
// check to see if legacy jars exist in lib directory. If
// they don't exist, we default to limited policy mode.
// they don't exist, we default to
un
limited policy mode.
cpPath
=
Paths
.
get
(
cpPath
=
Paths
.
get
(
javaHomeProperty
,
"lib"
,
"security"
,
"policy"
,
"limited"
);
javaHomeProperty
,
"lib"
,
"security"
,
"policy"
,
"
un
limited"
);
// point to the new jar files in limited directory
// point to the new jar files in limited directory
exportJar
=
new
File
(
cpPath
.
toFile
(),
"US_export_policy.jar"
);
exportJar
=
new
File
(
cpPath
.
toFile
(),
"US_export_policy.jar"
);
importJar
=
new
File
(
cpPath
.
toFile
(),
"local_policy.jar"
);
importJar
=
new
File
(
cpPath
.
toFile
(),
"local_policy.jar"
);
...
...
src/share/classes/sun/security/ssl/SSLSocketImpl.java
浏览文件 @
b5d84e6a
...
@@ -1778,7 +1778,12 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
...
@@ -1778,7 +1778,12 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
try
{
try
{
readRecord
(
inrec
,
true
);
readRecord
(
inrec
,
true
);
}
catch
(
SocketTimeoutException
e
)
{
}
catch
(
SocketTimeoutException
e
)
{
// if time out, ignore the exception and continue
if
((
debug
!=
null
)
&&
Debug
.
isOn
(
"ssl"
))
{
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
", received Exception: "
+
e
);
}
fatal
((
byte
)(-
1
),
"Did not receive close_notify from peer"
,
e
);
}
}
}
}
inrec
=
null
;
inrec
=
null
;
...
...
src/share/lib/security/java.security-aix
浏览文件 @
b5d84e6a
...
@@ -737,69 +737,71 @@ jdk.tls.legacyAlgorithms= \
...
@@ -737,69 +737,71 @@ jdk.tls.legacyAlgorithms= \
# Cryptographic Jurisdiction Policy defaults
# Cryptographic Jurisdiction Policy defaults
#
#
# Due to the import control restrictions of some countries, the default
# Import and export control rules on cryptographic software vary from
# JCE policy files allow for strong but "limited" cryptographic key
# country to country. By default, the JDK provides two different sets of
# lengths to be used. If your country's cryptographic regulations allow,
# cryptographic policy files:
# the "unlimited" strength policy files can be used instead, which contain
# no restrictions on cryptographic strengths.
#
#
#
YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
#
unlimited: These policy files contain no restrictions on cryptographic
#
TO DETERMINE THE EXACT REQUIREMENTS
.
#
strengths or algorithms
.
#
#
# <java-home> (below) refers to the directory where the JRE was
# limited: These policy files contain more restricted cryptographic
# installed. It is determined based on whether you are running JCE
# strengths, and are still available if your country or
# on a JRE or a JRE contained within the Java Development Kit, or
# usage requires the traditional restrictive policy.
# JDK(TM). The JDK contains the JRE, but at a different level in the
# file hierarchy. For example, if the JDK is installed in
# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then
# <java-home> is:
#
#
# /home/user1/jdk1.8.0/jre [Unix]
# The JDK JCE framework uses the unlimited policy files by default.
# C:\jdk1.8.0\jre [Windows]
# However the user may explicitly choose a set either by defining the
# "crypto.policy" Security property or by installing valid JCE policy
# jar files into the traditional JDK installation location. To better
# support older JDK Update releases, the "crypto.policy" property is not
# defined by default. See below for more information.
#
#
# If on the other hand the JRE is installed in /home/user1/jre1.8.0
# The following logic determines which policy files are used:
# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not
# installed, then <java-home> is:
#
#
# /home/user1/jre1.8.0 [Unix]
# <java-home> refers to the directory where the JRE was
# C:\jre1.8.0 [Windows]
# installed and may be determined using the "java.home"
# System property.
#
#
# On Windows, for each JDK installation, there may be additional
# 1. If the Security property "crypto.policy" has been defined,
# JREs installed under the "Program Files" directory. Please make
# then the following mechanism is used:
# sure that you install the unlimited strength policy JAR files
# for all JREs that you plan to use.
#
#
#
The policy files are jar files organized into
subdirectories of
#
The policy files are stored as jar files in
subdirectories of
# <java-home>/lib/security/policy. Each directory contains a complete
# <java-home>/lib/security/policy. Each directory contains a complete
# set of policy files.
# set of policy files.
#
#
#
The "crypto.policy" Security property controls the directory selection,
#
The "crypto.policy" Security property controls the directory
# and thus the effective cryptographic policy.
#
selection,
and thus the effective cryptographic policy.
#
#
# The default set of directories is:
# The default set of directories is:
#
#
# limited | unlimited
# limited | unlimited
#
#
# however other directories can be created and configured.
# 2. If the "crypto.policy" property is not set and the traditional
#
# US_export_policy.jar and local_policy.jar files
# To support older JDK Update releases, the crypto.policy property
# (e.g. limited/unlimited) are found in the legacy
# is not defined by default. When the property is not defined, an
# <java-home>/lib/security directory, then the rules embedded within
# update release binary aware of the new property will use the following
# those jar files will be used. This helps preserve compatibility
# logic to decide what crypto policy files get used :
#
# * If the US_export_policy.jar and local_policy.jar files are located
# in the (legacy) <java-home>/lib/security directory, then the rules
# embedded in those jar files will be used. This helps preserve compatibility
# for users upgrading from an older installation.
# for users upgrading from an older installation.
#
#
# * If crypto.policy is not defined and no such jar files are present in
# 3. If the jar files are not present in the legacy location
# the legacy locations, then the JDK will use the limited settings
# and the "crypto.policy" Security property is not defined,
# (equivalent to crypto.policy=limited)
# then the JDK will use the unlimited settings (equivalent to
# crypto.policy=unlimited)
#
#
# Please see the JCA documentation for additional information on these
# Please see the JCA documentation for additional information on these
# files and formats.
# files and formats.
#crypto.policy=unlimited
#
#
# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
# TO DETERMINE THE EXACT REQUIREMENTS.
#
# Please note that the JCE for Java SE, including the JCE framework,
# cryptographic policy files, and standard JCE providers provided with
# the Java SE, have been reviewed and approved for export as mass market
# encryption item by the US Bureau of Industry and Security.
#
# Note: This property is currently used by the JDK Reference implementation.
# It is not guaranteed to be examined and used by other implementations.
#
#crypto.policy=unlimited
# The policy for the XML Signature secure validation mode. The mode is
# The policy for the XML Signature secure validation mode. The mode is
# enabled by setting the property "org.jcp.xml.dsig.secureValidation" to
# enabled by setting the property "org.jcp.xml.dsig.secureValidation" to
...
...
src/share/lib/security/java.security-linux
浏览文件 @
b5d84e6a
...
@@ -737,67 +737,70 @@ jdk.tls.legacyAlgorithms= \
...
@@ -737,67 +737,70 @@ jdk.tls.legacyAlgorithms= \
# Cryptographic Jurisdiction Policy defaults
# Cryptographic Jurisdiction Policy defaults
#
#
# Due to the import control restrictions of some countries, the default
# Import and export control rules on cryptographic software vary from
# JCE policy files allow for strong but "limited" cryptographic key
# country to country. By default, the JDK provides two different sets of
# lengths to be used. If your country's cryptographic regulations allow,
# cryptographic policy files:
# the "unlimited" strength policy files can be used instead, which contain
# no restrictions on cryptographic strengths.
#
#
#
YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
#
unlimited: These policy files contain no restrictions on cryptographic
#
TO DETERMINE THE EXACT REQUIREMENTS
.
#
strengths or algorithms
.
#
#
# <java-home> (below) refers to the directory where the JRE was
# limited: These policy files contain more restricted cryptographic
# installed. It is determined based on whether you are running JCE
# strengths, and are still available if your country or
# on a JRE or a JRE contained within the Java Development Kit, or
# usage requires the traditional restrictive policy.
# JDK(TM). The JDK contains the JRE, but at a different level in the
# file hierarchy. For example, if the JDK is installed in
# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then
# <java-home> is:
#
#
# /home/user1/jdk1.8.0/jre [Unix]
# The JDK JCE framework uses the unlimited policy files by default.
# C:\jdk1.8.0\jre [Windows]
# However the user may explicitly choose a set either by defining the
# "crypto.policy" Security property or by installing valid JCE policy
# jar files into the traditional JDK installation location. To better
# support older JDK Update releases, the "crypto.policy" property is not
# defined by default. See below for more information.
#
#
# If on the other hand the JRE is installed in /home/user1/jre1.8.0
# The following logic determines which policy files are used:
# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not
# installed, then <java-home> is:
#
#
# /home/user1/jre1.8.0 [Unix]
# <java-home> refers to the directory where the JRE was
# C:\jre1.8.0 [Windows]
# installed and may be determined using the "java.home"
# System property.
#
#
# On Windows, for each JDK installation, there may be additional
# 1. If the Security property "crypto.policy" has been defined,
# JREs installed under the "Program Files" directory. Please make
# then the following mechanism is used:
# sure that you install the unlimited strength policy JAR files
# for all JREs that you plan to use.
#
#
#
The policy files are jar files organized into
subdirectories of
#
The policy files are stored as jar files in
subdirectories of
# <java-home>/lib/security/policy. Each directory contains a complete
# <java-home>/lib/security/policy. Each directory contains a complete
# set of policy files.
# set of policy files.
#
#
#
The "crypto.policy" Security property controls the directory selection,
#
The "crypto.policy" Security property controls the directory
# and thus the effective cryptographic policy.
#
selection,
and thus the effective cryptographic policy.
#
#
# The default set of directories is:
# The default set of directories is:
#
#
# limited | unlimited
# limited | unlimited
#
#
# however other directories can be created and configured.
# 2. If the "crypto.policy" property is not set and the traditional
#
# US_export_policy.jar and local_policy.jar files
# To support older JDK Update releases, the crypto.policy property
# (e.g. limited/unlimited) are found in the legacy
# is not defined by default. When the property is not defined, an
# <java-home>/lib/security directory, then the rules embedded within
# update release binary aware of the new property will use the following
# those jar files will be used. This helps preserve compatibility
# logic to decide what crypto policy files get used :
#
# * If the US_export_policy.jar and local_policy.jar files are located
# in the (legacy) <java-home>/lib/security directory, then the rules
# embedded in those jar files will be used. This helps preserve compatibility
# for users upgrading from an older installation.
# for users upgrading from an older installation.
#
#
# * If crypto.policy is not defined and no such jar files are present in
# 3. If the jar files are not present in the legacy location
# the legacy locations, then the JDK will use the limited settings
# and the "crypto.policy" Security property is not defined,
# (equivalent to crypto.policy=limited)
# then the JDK will use the unlimited settings (equivalent to
# crypto.policy=unlimited)
#
#
# Please see the JCA documentation for additional information on these
# Please see the JCA documentation for additional information on these
# files and formats.
# files and formats.
#
# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
# TO DETERMINE THE EXACT REQUIREMENTS.
#
# Please note that the JCE for Java SE, including the JCE framework,
# cryptographic policy files, and standard JCE providers provided with
# the Java SE, have been reviewed and approved for export as mass market
# encryption item by the US Bureau of Industry and Security.
#
# Note: This property is currently used by the JDK Reference implementation.
# It is not guaranteed to be examined and used by other implementations.
#
#crypto.policy=unlimited
#crypto.policy=unlimited
#
#
...
...
src/share/lib/security/java.security-macosx
浏览文件 @
b5d84e6a
...
@@ -740,67 +740,70 @@ jdk.tls.legacyAlgorithms= \
...
@@ -740,67 +740,70 @@ jdk.tls.legacyAlgorithms= \
# Cryptographic Jurisdiction Policy defaults
# Cryptographic Jurisdiction Policy defaults
#
#
# Due to the import control restrictions of some countries, the default
# Import and export control rules on cryptographic software vary from
# JCE policy files allow for strong but "limited" cryptographic key
# country to country. By default, the JDK provides two different sets of
# lengths to be used. If your country's cryptographic regulations allow,
# cryptographic policy files:
# the "unlimited" strength policy files can be used instead, which contain
# no restrictions on cryptographic strengths.
#
#
#
YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
#
unlimited: These policy files contain no restrictions on cryptographic
#
TO DETERMINE THE EXACT REQUIREMENTS
.
#
strengths or algorithms
.
#
#
# <java-home> (below) refers to the directory where the JRE was
# limited: These policy files contain more restricted cryptographic
# installed. It is determined based on whether you are running JCE
# strengths, and are still available if your country or
# on a JRE or a JRE contained within the Java Development Kit, or
# usage requires the traditional restrictive policy.
# JDK(TM). The JDK contains the JRE, but at a different level in the
# file hierarchy. For example, if the JDK is installed in
# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then
# <java-home> is:
#
#
# /home/user1/jdk1.8.0/jre [Unix]
# The JDK JCE framework uses the unlimited policy files by default.
# C:\jdk1.8.0\jre [Windows]
# However the user may explicitly choose a set either by defining the
# "crypto.policy" Security property or by installing valid JCE policy
# jar files into the traditional JDK installation location. To better
# support older JDK Update releases, the "crypto.policy" property is not
# defined by default. See below for more information.
#
#
# If on the other hand the JRE is installed in /home/user1/jre1.8.0
# The following logic determines which policy files are used:
# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not
# installed, then <java-home> is:
#
#
# /home/user1/jre1.8.0 [Unix]
# <java-home> refers to the directory where the JRE was
# C:\jre1.8.0 [Windows]
# installed and may be determined using the "java.home"
# System property.
#
#
# On Windows, for each JDK installation, there may be additional
# 1. If the Security property "crypto.policy" has been defined,
# JREs installed under the "Program Files" directory. Please make
# then the following mechanism is used:
# sure that you install the unlimited strength policy JAR files
# for all JREs that you plan to use.
#
#
#
The policy files are jar files organized into
subdirectories of
#
The policy files are stored as jar files in
subdirectories of
# <java-home>/lib/security/policy. Each directory contains a complete
# <java-home>/lib/security/policy. Each directory contains a complete
# set of policy files.
# set of policy files.
#
#
#
The "crypto.policy" Security property controls the directory selection,
#
The "crypto.policy" Security property controls the directory
# and thus the effective cryptographic policy.
#
selection,
and thus the effective cryptographic policy.
#
#
# The default set of directories is:
# The default set of directories is:
#
#
# limited | unlimited
# limited | unlimited
#
#
# however other directories can be created and configured.
# 2. If the "crypto.policy" property is not set and the traditional
#
# US_export_policy.jar and local_policy.jar files
# To support older JDK Update releases, the crypto.policy property
# (e.g. limited/unlimited) are found in the legacy
# is not defined by default. When the property is not defined, an
# <java-home>/lib/security directory, then the rules embedded within
# update release binary aware of the new property will use the following
# those jar files will be used. This helps preserve compatibility
# logic to decide what crypto policy files get used :
#
# * If the US_export_policy.jar and local_policy.jar files are located
# in the (legacy) <java-home>/lib/security directory, then the rules
# embedded in those jar files will be used. This helps preserve compatibility
# for users upgrading from an older installation.
# for users upgrading from an older installation.
#
#
# * If crypto.policy is not defined and no such jar files are present in
# 3. If the jar files are not present in the legacy location
# the legacy locations, then the JDK will use the limited settings
# and the "crypto.policy" Security property is not defined,
# (equivalent to crypto.policy=limited)
# then the JDK will use the unlimited settings (equivalent to
# crypto.policy=unlimited)
#
#
# Please see the JCA documentation for additional information on these
# Please see the JCA documentation for additional information on these
# files and formats.
# files and formats.
#
# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
# TO DETERMINE THE EXACT REQUIREMENTS.
#
# Please note that the JCE for Java SE, including the JCE framework,
# cryptographic policy files, and standard JCE providers provided with
# the Java SE, have been reviewed and approved for export as mass market
# encryption item by the US Bureau of Industry and Security.
#
# Note: This property is currently used by the JDK Reference implementation.
# It is not guaranteed to be examined and used by other implementations.
#
#crypto.policy=unlimited
#crypto.policy=unlimited
#
#
...
...
src/share/lib/security/java.security-solaris
浏览文件 @
b5d84e6a
...
@@ -739,67 +739,70 @@ jdk.tls.legacyAlgorithms= \
...
@@ -739,67 +739,70 @@ jdk.tls.legacyAlgorithms= \
# Cryptographic Jurisdiction Policy defaults
# Cryptographic Jurisdiction Policy defaults
#
#
# Due to the import control restrictions of some countries, the default
# Import and export control rules on cryptographic software vary from
# JCE policy files allow for strong but "limited" cryptographic key
# country to country. By default, the JDK provides two different sets of
# lengths to be used. If your country's cryptographic regulations allow,
# cryptographic policy files:
# the "unlimited" strength policy files can be used instead, which contain
# no restrictions on cryptographic strengths.
#
#
#
YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
#
unlimited: These policy files contain no restrictions on cryptographic
#
TO DETERMINE THE EXACT REQUIREMENTS
.
#
strengths or algorithms
.
#
#
# <java-home> (below) refers to the directory where the JRE was
# limited: These policy files contain more restricted cryptographic
# installed. It is determined based on whether you are running JCE
# strengths, and are still available if your country or
# on a JRE or a JRE contained within the Java Development Kit, or
# usage requires the traditional restrictive policy.
# JDK(TM). The JDK contains the JRE, but at a different level in the
# file hierarchy. For example, if the JDK is installed in
# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then
# <java-home> is:
#
#
# /home/user1/jdk1.8.0/jre [Unix]
# The JDK JCE framework uses the unlimited policy files by default.
# C:\jdk1.8.0\jre [Windows]
# However the user may explicitly choose a set either by defining the
# "crypto.policy" Security property or by installing valid JCE policy
# jar files into the traditional JDK installation location. To better
# support older JDK Update releases, the "crypto.policy" property is not
# defined by default. See below for more information.
#
#
# If on the other hand the JRE is installed in /home/user1/jre1.8.0
# The following logic determines which policy files are used:
# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not
# installed, then <java-home> is:
#
#
# /home/user1/jre1.8.0 [Unix]
# <java-home> refers to the directory where the JRE was
# C:\jre1.8.0 [Windows]
# installed and may be determined using the "java.home"
# System property.
#
#
# On Windows, for each JDK installation, there may be additional
# 1. If the Security property "crypto.policy" has been defined,
# JREs installed under the "Program Files" directory. Please make
# then the following mechanism is used:
# sure that you install the unlimited strength policy JAR files
# for all JREs that you plan to use.
#
#
#
The policy files are jar files organized into
subdirectories of
#
The policy files are stored as jar files in
subdirectories of
# <java-home>/lib/security/policy. Each directory contains a complete
# <java-home>/lib/security/policy. Each directory contains a complete
# set of policy files.
# set of policy files.
#
#
#
The "crypto.policy" Security property controls the directory selection,
#
The "crypto.policy" Security property controls the directory
# and thus the effective cryptographic policy.
#
selection,
and thus the effective cryptographic policy.
#
#
# The default set of directories is:
# The default set of directories is:
#
#
# limited | unlimited
# limited | unlimited
#
#
# however other directories can be created and configured.
# 2. If the "crypto.policy" property is not set and the traditional
#
# US_export_policy.jar and local_policy.jar files
# To support older JDK Update releases, the crypto.policy property
# (e.g. limited/unlimited) are found in the legacy
# is not defined by default. When the property is not defined, an
# <java-home>/lib/security directory, then the rules embedded within
# update release binary aware of the new property will use the following
# those jar files will be used. This helps preserve compatibility
# logic to decide what crypto policy files get used :
#
# * If the US_export_policy.jar and local_policy.jar files are located
# in the (legacy) <java-home>/lib/security directory, then the rules
# embedded in those jar files will be used. This helps preserve compatibility
# for users upgrading from an older installation.
# for users upgrading from an older installation.
#
#
# * If crypto.policy is not defined and no such jar files are present in
# 3. If the jar files are not present in the legacy location
# the legacy locations, then the JDK will use the limited settings
# and the "crypto.policy" Security property is not defined,
# (equivalent to crypto.policy=limited)
# then the JDK will use the unlimited settings (equivalent to
# crypto.policy=unlimited)
#
#
# Please see the JCA documentation for additional information on these
# Please see the JCA documentation for additional information on these
# files and formats.
# files and formats.
#
# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
# TO DETERMINE THE EXACT REQUIREMENTS.
#
# Please note that the JCE for Java SE, including the JCE framework,
# cryptographic policy files, and standard JCE providers provided with
# the Java SE, have been reviewed and approved for export as mass market
# encryption item by the US Bureau of Industry and Security.
#
# Note: This property is currently used by the JDK Reference implementation.
# It is not guaranteed to be examined and used by other implementations.
#
#crypto.policy=unlimited
#crypto.policy=unlimited
#
#
...
...
src/share/lib/security/java.security-windows
浏览文件 @
b5d84e6a
...
@@ -740,67 +740,70 @@ jdk.tls.legacyAlgorithms= \
...
@@ -740,67 +740,70 @@ jdk.tls.legacyAlgorithms= \
# Cryptographic Jurisdiction Policy defaults
# Cryptographic Jurisdiction Policy defaults
#
#
# Due to the import control restrictions of some countries, the default
# Import and export control rules on cryptographic software vary from
# JCE policy files allow for strong but "limited" cryptographic key
# country to country. By default, the JDK provides two different sets of
# lengths to be used. If your country's cryptographic regulations allow,
# cryptographic policy files:
# the "unlimited" strength policy files can be used instead, which contain
# no restrictions on cryptographic strengths.
#
#
#
YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
#
unlimited: These policy files contain no restrictions on cryptographic
#
TO DETERMINE THE EXACT REQUIREMENTS
.
#
strengths or algorithms
.
#
#
# <java-home> (below) refers to the directory where the JRE was
# limited: These policy files contain more restricted cryptographic
# installed. It is determined based on whether you are running JCE
# strengths, and are still available if your country or
# on a JRE or a JRE contained within the Java Development Kit, or
# usage requires the traditional restrictive policy.
# JDK(TM). The JDK contains the JRE, but at a different level in the
# file hierarchy. For example, if the JDK is installed in
# /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then
# <java-home> is:
#
#
# /home/user1/jdk1.8.0/jre [Unix]
# The JDK JCE framework uses the unlimited policy files by default.
# C:\jdk1.8.0\jre [Windows]
# However the user may explicitly choose a set either by defining the
# "crypto.policy" Security property or by installing valid JCE policy
# jar files into the traditional JDK installation location. To better
# support older JDK Update releases, the "crypto.policy" property is not
# defined by default. See below for more information.
#
#
# If on the other hand the JRE is installed in /home/user1/jre1.8.0
# The following logic determines which policy files are used:
# on Unix or in C:\jre1.8.0 on Windows, and the JDK is not
# installed, then <java-home> is:
#
#
# /home/user1/jre1.8.0 [Unix]
# <java-home> refers to the directory where the JRE was
# C:\jre1.8.0 [Windows]
# installed and may be determined using the "java.home"
# System property.
#
#
# On Windows, for each JDK installation, there may be additional
# 1. If the Security property "crypto.policy" has been defined,
# JREs installed under the "Program Files" directory. Please make
# then the following mechanism is used:
# sure that you install the unlimited strength policy JAR files
# for all JREs that you plan to use.
#
#
#
The policy files are jar files organized into
subdirectories of
#
The policy files are stored as jar files in
subdirectories of
# <java-home>/lib/security/policy. Each directory contains a complete
# <java-home>/lib/security/policy. Each directory contains a complete
# set of policy files.
# set of policy files.
#
#
#
The "crypto.policy" Security property controls the directory selection,
#
The "crypto.policy" Security property controls the directory
# and thus the effective cryptographic policy.
#
selection,
and thus the effective cryptographic policy.
#
#
# The default set of directories is:
# The default set of directories is:
#
#
# limited | unlimited
# limited | unlimited
#
#
# however other directories can be created and configured.
# 2. If the "crypto.policy" property is not set and the traditional
#
# US_export_policy.jar and local_policy.jar files
# To support older JDK Update releases, the crypto.policy property
# (e.g. limited/unlimited) are found in the legacy
# is not defined by default. When the property is not defined, an
# <java-home>/lib/security directory, then the rules embedded within
# update release binary aware of the new property will use the following
# those jar files will be used. This helps preserve compatibility
# logic to decide what crypto policy files get used :
#
# * If the US_export_policy.jar and local_policy.jar files are located
# in the (legacy) <java-home>/lib/security directory, then the rules
# embedded in those jar files will be used. This helps preserve compatibility
# for users upgrading from an older installation.
# for users upgrading from an older installation.
#
#
# * If crypto.policy is not defined and no such jar files are present in
# 3. If the jar files are not present in the legacy location
# the legacy locations, then the JDK will use the limited settings
# and the "crypto.policy" Security property is not defined,
# (equivalent to crypto.policy=limited)
# then the JDK will use the unlimited settings (equivalent to
# crypto.policy=unlimited)
#
#
# Please see the JCA documentation for additional information on these
# Please see the JCA documentation for additional information on these
# files and formats.
# files and formats.
#
# YOU ARE ADVISED TO CONSULT YOUR EXPORT/IMPORT CONTROL COUNSEL OR ATTORNEY
# TO DETERMINE THE EXACT REQUIREMENTS.
#
# Please note that the JCE for Java SE, including the JCE framework,
# cryptographic policy files, and standard JCE providers provided with
# the Java SE, have been reviewed and approved for export as mass market
# encryption item by the US Bureau of Industry and Security.
#
# Note: This property is currently used by the JDK Reference implementation.
# It is not guaranteed to be examined and used by other implementations.
#
#crypto.policy=unlimited
#crypto.policy=unlimited
#
#
...
...
test/com/sun/crypto/provider/Cipher/AES/TestAESCiphers/Dynamic.java
浏览文件 @
b5d84e6a
/*
/*
* Copyright (c) 2012, 201
5
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 201
6
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -150,19 +150,8 @@ public class Dynamic {
...
@@ -150,19 +150,8 @@ public class Dynamic {
int
offset
=
ci
.
update
(
plainText
,
0
,
plainText
.
length
,
cipherText
,
int
offset
=
ci
.
update
(
plainText
,
0
,
plainText
.
length
,
cipherText
,
0
);
0
);
ci
.
doFinal
(
cipherText
,
offset
);
ci
.
doFinal
(
cipherText
,
offset
);
ci
.
init
(
Cipher
.
DECRYPT_MODE
,
key
,
ci
.
getParameters
());
if
(!
mo
.
equalsIgnoreCase
(
"ECB"
))
{
iv
=
ci
.
getIV
();
aps
=
new
IvParameterSpec
(
iv
);
}
else
{
aps
=
null
;
}
if
(!
mo
.
equalsIgnoreCase
(
"GCM"
))
{
ci
.
init
(
Cipher
.
DECRYPT_MODE
,
key
,
aps
);
}
else
{
ci
.
init
(
Cipher
.
DECRYPT_MODE
,
key
,
ci
.
getParameters
());
}
byte
[]
recoveredText
=
new
byte
[
ci
.
getOutputSize
(
cipherText
.
length
)];
byte
[]
recoveredText
=
new
byte
[
ci
.
getOutputSize
(
cipherText
.
length
)];
int
len
=
ci
.
doFinal
(
cipherText
,
0
,
cipherText
.
length
,
int
len
=
ci
.
doFinal
(
cipherText
,
0
,
cipherText
.
length
,
recoveredText
);
recoveredText
);
...
@@ -174,12 +163,14 @@ public class Dynamic {
...
@@ -174,12 +163,14 @@ public class Dynamic {
result
=
Arrays
.
equals
(
plainText
,
tmp
);
result
=
Arrays
.
equals
(
plainText
,
tmp
);
}
catch
(
NoSuchAlgorithmException
nsaEx
)
{
}
catch
(
NoSuchAlgorithmException
nsaEx
)
{
nsaEx
.
printStackTrace
();
// CFB7 and OFB150 are negative test,SunJCE not support this
// CFB7 and OFB150 are negative test,SunJCE not support this
// algorithm
// algorithm
result
=
mo
.
equalsIgnoreCase
(
"CFB7"
)
result
=
mo
.
equalsIgnoreCase
(
"CFB7"
)
||
mo
.
equalsIgnoreCase
(
"OFB150"
);
||
mo
.
equalsIgnoreCase
(
"OFB150"
);
if
(!
result
)
{
// only report unexpected exception
nsaEx
.
printStackTrace
();
}
}
}
return
result
;
return
result
;
}
}
...
...
test/com/sun/crypto/provider/Cipher/Blowfish/TestCipherBlowfish.java
浏览文件 @
b5d84e6a
/*
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015,
2016,
Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -42,7 +42,7 @@ public class TestCipherBlowfish extends TestCipher {
...
@@ -42,7 +42,7 @@ public class TestCipherBlowfish extends TestCipher {
"OFB"
,
"OFB8"
,
"OFB16"
,
"OFB24"
,
"OFB32"
,
"OFB40"
,
"OFB48"
,
"OFB56"
,
"OFB"
,
"OFB8"
,
"OFB16"
,
"OFB24"
,
"OFB32"
,
"OFB40"
,
"OFB48"
,
"OFB56"
,
"OFB64"
},
"OFB64"
},
new
String
[]{
"NoPaDDing"
,
"PKCS5Padding"
},
new
String
[]{
"NoPaDDing"
,
"PKCS5Padding"
},
true
);
32
,
448
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
test/com/sun/crypto/provider/Cipher/PBE/PBESameBuffer/AESPBEWrapper.java
浏览文件 @
b5d84e6a
/*
/*
* Copyright (c) 2012, 201
4
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 201
6
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
import
java.io.PrintStream
;
import
java.io.PrintStream
;
import
java.security.AlgorithmParameters
;
import
java.security.AlgorithmParameters
;
import
java.security.InvalidKeyException
;
import
java.security.InvalidKeyException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.Provider
;
import
java.security.Provider
;
import
javax.crypto.Cipher
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKeyFactory
;
import
javax.crypto.SecretKeyFactory
;
...
@@ -69,6 +70,15 @@ public class AESPBEWrapper extends PBEWrapper {
...
@@ -69,6 +70,15 @@ public class AESPBEWrapper extends PBEWrapper {
*/
*/
@Override
@Override
public
boolean
execute
(
int
edMode
,
byte
[]
inputText
,
int
offset
,
int
len
)
{
public
boolean
execute
(
int
edMode
,
byte
[]
inputText
,
int
offset
,
int
len
)
{
boolean
isUnlimited
;
try
{
isUnlimited
=
(
Cipher
.
getMaxAllowedKeyLength
(
this
.
algo
)
==
Integer
.
MAX_VALUE
);
}
catch
(
NoSuchAlgorithmException
nsae
)
{
out
.
println
(
"Got unexpected exception for "
+
this
.
algo
);
nsae
.
printStackTrace
(
out
);
return
false
;
}
try
{
try
{
// init Cipher
// init Cipher
if
(
Cipher
.
ENCRYPT_MODE
==
edMode
)
{
if
(
Cipher
.
ENCRYPT_MODE
==
edMode
)
{
...
@@ -78,6 +88,11 @@ public class AESPBEWrapper extends PBEWrapper {
...
@@ -78,6 +88,11 @@ public class AESPBEWrapper extends PBEWrapper {
ci
.
init
(
Cipher
.
DECRYPT_MODE
,
this
.
key
,
pbeParams
);
ci
.
init
(
Cipher
.
DECRYPT_MODE
,
this
.
key
,
pbeParams
);
}
}
if
(
this
.
algo
.
endsWith
(
"AES_256"
)
&&
!
isUnlimited
)
{
out
.
print
(
"Expected exception not thrown for "
+
this
.
algo
);
return
false
;
}
// First, generate the cipherText at an allocated buffer
// First, generate the cipherText at an allocated buffer
byte
[]
outputText
=
ci
.
doFinal
(
inputText
,
offset
,
len
);
byte
[]
outputText
=
ci
.
doFinal
(
inputText
,
offset
,
len
);
...
@@ -86,29 +101,19 @@ public class AESPBEWrapper extends PBEWrapper {
...
@@ -86,29 +101,19 @@ public class AESPBEWrapper extends PBEWrapper {
int
off
=
ci
.
update
(
inputText
,
offset
,
len
,
inputText
,
myoff
);
int
off
=
ci
.
update
(
inputText
,
offset
,
len
,
inputText
,
myoff
);
ci
.
doFinal
(
inputText
,
myoff
+
off
);
ci
.
doFinal
(
inputText
,
myoff
+
off
);
if
(
this
.
algo
.
endsWith
(
"AES_256"
))
{
out
.
print
(
"Expected exception uncaught, "
+
"keyStrength > 128 within "
+
this
.
algo
);
return
false
;
}
// Compare to see whether the two results are the same or not
// Compare to see whether the two results are the same or not
return
equalsBlock
(
inputText
,
myoff
,
outputText
,
0
,
return
equalsBlock
(
inputText
,
myoff
,
outputText
,
0
,
outputText
.
length
);
outputText
.
length
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
if
((
ex
instanceof
InvalidKeyException
)
if
((
ex
instanceof
InvalidKeyException
)
&&
this
.
algo
.
endsWith
(
"AES_256"
))
{
&&
this
.
algo
.
endsWith
(
"AES_256"
)
&&
!
isUnlimited
)
{
out
.
println
(
"Expected InvalidKeyException exception: "
out
.
println
(
"Expected InvalidKeyException thrown"
);
+
ex
.
getMessage
());
return
true
;
return
true
;
}
else
{
out
.
println
(
"Got unexpected exception for "
+
algo
);
ex
.
printStackTrace
(
out
);
return
false
;
}
}
out
.
println
(
"Catch unexpected exception within "
+
algo
);
ex
.
printStackTrace
(
out
);
return
false
;
}
}
}
}
}
}
test/com/sun/crypto/provider/Cipher/PBE/PBESameBuffer/PBECipherWrapper.java
浏览文件 @
b5d84e6a
/*
/*
* Copyright (c) 2012, 201
4
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 201
6
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -32,6 +32,7 @@ import java.security.spec.AlgorithmParameterSpec;
...
@@ -32,6 +32,7 @@ import java.security.spec.AlgorithmParameterSpec;
import
java.util.StringTokenizer
;
import
java.util.StringTokenizer
;
import
java.security.InvalidKeyException
;
import
java.security.InvalidKeyException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.Provider
;
import
java.security.Provider
;
import
java.io.PrintStream
;
import
java.io.PrintStream
;
...
@@ -64,9 +65,25 @@ public class PBECipherWrapper extends PBEWrapper {
...
@@ -64,9 +65,25 @@ public class PBECipherWrapper extends PBEWrapper {
StringTokenizer
st
=
new
StringTokenizer
(
algo
,
"/"
);
StringTokenizer
st
=
new
StringTokenizer
(
algo
,
"/"
);
String
baseAlgo
=
st
.
nextToken
().
toUpperCase
();
String
baseAlgo
=
st
.
nextToken
().
toUpperCase
();
boolean
isUnlimited
;
try
{
isUnlimited
=
(
Cipher
.
getMaxAllowedKeyLength
(
this
.
algo
)
==
Integer
.
MAX_VALUE
);
}
catch
(
NoSuchAlgorithmException
nsae
)
{
out
.
println
(
"Got unexpected exception for "
+
this
.
algo
);
nsae
.
printStackTrace
(
out
);
return
false
;
}
// Perform encryption or decryption depends on the specified edMode
// Perform encryption or decryption depends on the specified edMode
try
{
try
{
ci
.
init
(
edMode
,
key
,
aps
);
ci
.
init
(
edMode
,
key
,
aps
);
if
((
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
||
baseAlgo
.
endsWith
(
"AES_256"
))
&&
!
isUnlimited
)
{
out
.
print
(
"Expected InvalidKeyException not thrown: "
+
this
.
algo
);
return
false
;
}
// First, generate the cipherText at an allocated buffer
// First, generate the cipherText at an allocated buffer
byte
[]
outputText
=
ci
.
doFinal
(
inputText
,
offset
,
len
);
byte
[]
outputText
=
ci
.
doFinal
(
inputText
,
offset
,
len
);
...
@@ -78,33 +95,24 @@ public class PBECipherWrapper extends PBEWrapper {
...
@@ -78,33 +95,24 @@ public class PBECipherWrapper extends PBEWrapper {
ci
.
doFinal
(
inputText
,
myoff
+
off
);
ci
.
doFinal
(
inputText
,
myoff
+
off
);
if
(
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
||
baseAlgo
.
endsWith
(
"AES_256"
))
{
out
.
print
(
"Expected exception uncaught,"
+
"keyStrength > 128 within "
+
this
.
algo
);
return
false
;
}
// Compare to see whether the two results are the same or not
// Compare to see whether the two results are the same or not
boolean
result
=
equalsBlock
(
inputText
,
myoff
,
outputText
,
0
,
boolean
result
=
equalsBlock
(
inputText
,
myoff
,
outputText
,
0
,
outputText
.
length
);
outputText
.
length
);
return
result
;
return
result
;
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
if
((
ex
instanceof
InvalidKeyException
)
if
((
ex
instanceof
InvalidKeyException
)
&&
&&
(
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
(
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
||
baseAlgo
.
endsWith
(
"AES_256"
)))
{
||
baseAlgo
.
endsWith
(
"AES_256"
))
&&
out
.
println
(
"Expected InvalidKeyException exception: "
!
isUnlimited
)
{
+
ex
.
getMessage
());
out
.
println
(
"Expected InvalidKeyException thrown for "
+
algo
);
return
true
;
return
true
;
}
else
{
out
.
println
(
"Got unexpected exception for "
+
algo
);
ex
.
printStackTrace
(
out
);
return
false
;
}
}
out
.
println
(
"Catch unexpected exception within "
+
algo
);
ex
.
printStackTrace
(
out
);
return
false
;
}
}
}
}
}
}
test/com/sun/crypto/provider/Cipher/PBE/TestCipherKeyWrapperPBEKey.java
浏览文件 @
b5d84e6a
/*
/*
* Copyright (c) 2012, 201
4
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 201
6
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -119,6 +119,9 @@ public class TestCipherKeyWrapperPBEKey {
...
@@ -119,6 +119,9 @@ public class TestCipherKeyWrapperPBEKey {
=
new
StringTokenizer
(
algo
,
"/"
).
nextToken
().
toUpperCase
();
=
new
StringTokenizer
(
algo
,
"/"
).
nextToken
().
toUpperCase
();
boolean
isAES
=
baseAlgo
.
contains
(
"AES"
);
boolean
isAES
=
baseAlgo
.
contains
(
"AES"
);
boolean
isUnlimited
=
(
Cipher
.
getMaxAllowedKeyLength
(
algo
)
==
Integer
.
MAX_VALUE
);
try
{
try
{
// Initialization
// Initialization
new
Random
().
nextBytes
(
salt
);
new
Random
().
nextBytes
(
salt
);
...
@@ -128,7 +131,6 @@ public class TestCipherKeyWrapperPBEKey {
...
@@ -128,7 +131,6 @@ public class TestCipherKeyWrapperPBEKey {
SecretKey
key
=
skf
.
generateSecret
(
new
PBEKeySpec
(
SecretKey
key
=
skf
.
generateSecret
(
new
PBEKeySpec
(
"Secret Key"
.
toCharArray
()));
"Secret Key"
.
toCharArray
()));
Cipher
ci
=
Cipher
.
getInstance
(
algo
);
Cipher
ci
=
Cipher
.
getInstance
(
algo
);
if
(
isAES
)
{
if
(
isAES
)
{
ci
.
init
(
Cipher
.
WRAP_MODE
,
key
);
ci
.
init
(
Cipher
.
WRAP_MODE
,
key
);
pbeParams
=
ci
.
getParameters
();
pbeParams
=
ci
.
getParameters
();
...
@@ -145,10 +147,10 @@ public class TestCipherKeyWrapperPBEKey {
...
@@ -145,10 +147,10 @@ public class TestCipherKeyWrapperPBEKey {
Key
unwrappedKey
=
ci
.
unwrap
(
keyWrapper
,
algo
,
Cipher
.
SECRET_KEY
);
Key
unwrappedKey
=
ci
.
unwrap
(
keyWrapper
,
algo
,
Cipher
.
SECRET_KEY
);
if
(
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
if
(
(
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
||
baseAlgo
.
endsWith
(
"AES_256"
))
{
||
baseAlgo
.
endsWith
(
"AES_256"
))
&&
!
isUnlimited
)
{
out
.
print
(
out
.
print
(
"
InvalidKeyException not thrown when keyStrength > 128
"
);
"
Expected InvalidKeyException not thrown
"
);
return
false
;
return
false
;
}
}
...
@@ -157,8 +159,9 @@ public class TestCipherKeyWrapperPBEKey {
...
@@ -157,8 +159,9 @@ public class TestCipherKeyWrapperPBEKey {
}
catch
(
InvalidKeyException
ex
)
{
}
catch
(
InvalidKeyException
ex
)
{
if
((
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
if
((
baseAlgo
.
endsWith
(
"TRIPLEDES"
)
||
baseAlgo
.
endsWith
(
"AES_256"
)))
{
||
baseAlgo
.
endsWith
(
"AES_256"
))
&&
!
isUnlimited
)
{
out
.
println
(
"Expected InvalidKeyException, keyStrength > 128"
);
out
.
print
(
"Expected InvalidKeyException thrown"
);
return
true
;
return
true
;
}
else
{
}
else
{
throw
ex
;
throw
ex
;
...
...
test/com/sun/crypto/provider/Cipher/PBE/TestCipherPBE.java
浏览文件 @
b5d84e6a
/*
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015,
2016,
Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -79,6 +79,9 @@ public class TestCipherPBE {
...
@@ -79,6 +79,9 @@ public class TestCipherPBE {
out
.
println
(
"=> Testing: "
+
algorithm
);
out
.
println
(
"=> Testing: "
+
algorithm
);
boolean
isUnlimited
=
(
Cipher
.
getMaxAllowedKeyLength
(
algorithm
)
==
Integer
.
MAX_VALUE
);
try
{
try
{
// Initialization
// Initialization
AlgorithmParameterSpec
algoParamSpec
AlgorithmParameterSpec
algoParamSpec
...
@@ -98,9 +101,9 @@ public class TestCipherPBE {
...
@@ -98,9 +101,9 @@ public class TestCipherPBE {
ci
.
init
(
Cipher
.
DECRYPT_MODE
,
secretKey
,
algoParamSpec
);
ci
.
init
(
Cipher
.
DECRYPT_MODE
,
secretKey
,
algoParamSpec
);
byte
[]
recoveredText
=
ci
.
doFinal
(
cipherText
);
byte
[]
recoveredText
=
ci
.
doFinal
(
cipherText
);
if
(
algorithm
.
contains
(
"TripleDES"
))
{
if
(
algorithm
.
contains
(
"TripleDES"
)
&&
!
isUnlimited
)
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
"Expected InvalidKeyException
exception uncaugh
"
);
"Expected InvalidKeyException
not thrown
"
);
}
}
// Comparison
// Comparison
...
@@ -110,8 +113,8 @@ public class TestCipherPBE {
...
@@ -110,8 +113,8 @@ public class TestCipherPBE {
}
}
out
.
println
(
"Test Passed."
);
out
.
println
(
"Test Passed."
);
}
catch
(
InvalidKeyException
ex
)
{
}
catch
(
InvalidKeyException
ex
)
{
if
(
algorithm
.
contains
(
"TripleDES"
))
{
if
(
algorithm
.
contains
(
"TripleDES"
)
&&
!
isUnlimited
)
{
out
.
println
(
"Expected InvalidKeyException
raised
"
);
out
.
println
(
"Expected InvalidKeyException
thrown
"
);
}
else
{
}
else
{
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
}
}
...
...
test/com/sun/crypto/provider/Cipher/TestCipher.java
浏览文件 @
b5d84e6a
...
@@ -49,14 +49,13 @@ public abstract class TestCipher {
...
@@ -49,14 +49,13 @@ public abstract class TestCipher {
private
final
String
[]
MODES
;
private
final
String
[]
MODES
;
private
final
String
[]
PADDINGS
;
private
final
String
[]
PADDINGS
;
/* Used to test cipher with different key strengths
/* Used to test variable-key-length ciphers:
Key size tested is increment of KEYCUTTER from MINIMUM_KEY_SIZE to
Key size tested is increment of KEYCUTTER from minKeySize
maximum allowed keysize.
to min(maxKeySize, Cipher.getMaxAllowedKeyLength(algo)).
DES/DESede/Blowfish work with currently selected key sizes.
*/
*/
private
final
int
variousKeySize
;
private
final
int
KEYCUTTER
=
8
;
private
final
int
KEYCUTTER
=
8
;
private
final
int
MINIMUM_KEY_SIZE
=
32
;
private
final
int
minKeySize
;
private
final
int
maxKeySize
;
// Used to assert that Encryption/Decryption works with same buffer
// Used to assert that Encryption/Decryption works with same buffer
// TEXT_LEN is multiple of blocks in order to work against ciphers w/ NoPadding
// TEXT_LEN is multiple of blocks in order to work against ciphers w/ NoPadding
...
@@ -68,23 +67,28 @@ public abstract class TestCipher {
...
@@ -68,23 +67,28 @@ public abstract class TestCipher {
private
final
byte
[]
IV
;
private
final
byte
[]
IV
;
private
final
byte
[]
INPUT_TEXT
;
private
final
byte
[]
INPUT_TEXT
;
// for variable-key-length ciphers
TestCipher
(
String
algo
,
String
[]
modes
,
String
[]
paddings
,
TestCipher
(
String
algo
,
String
[]
modes
,
String
[]
paddings
,
boolean
keyStrength
)
throws
NoSuchAlgorithmException
{
int
minKeySize
,
int
maxKeySize
)
throws
NoSuchAlgorithmException
{
ALGORITHM
=
algo
;
ALGORITHM
=
algo
;
MODES
=
modes
;
MODES
=
modes
;
PADDINGS
=
paddings
;
PADDINGS
=
paddings
;
this
.
variousKeySize
this
.
minKeySize
=
minKeySize
;
=
keyStrength
?
Cipher
.
getMaxAllowedKeyLength
(
ALGORITHM
)
:
0
;
int
maxAllowedKeySize
=
Cipher
.
getMaxAllowedKeyLength
(
ALGORITHM
);
if
(
maxKeySize
>
maxAllowedKeySize
)
{
maxKeySize
=
maxAllowedKeySize
;
}
this
.
maxKeySize
=
maxKeySize
;
IV
=
generateBytes
(
8
);
IV
=
generateBytes
(
8
);
INPUT_TEXT
=
generateBytes
(
TEXT_LEN
+
PAD_BYTES
+
ENC_OFFSET
);
INPUT_TEXT
=
generateBytes
(
TEXT_LEN
+
PAD_BYTES
+
ENC_OFFSET
);
}
}
// for fixed-key-length ciphers
TestCipher
(
String
algo
,
String
[]
modes
,
String
[]
paddings
)
{
TestCipher
(
String
algo
,
String
[]
modes
,
String
[]
paddings
)
{
ALGORITHM
=
algo
;
ALGORITHM
=
algo
;
MODES
=
modes
;
MODES
=
modes
;
PADDINGS
=
paddings
;
PADDINGS
=
paddings
;
various
KeySize
=
0
;
this
.
minKeySize
=
this
.
max
KeySize
=
0
;
IV
=
generateBytes
(
8
);
IV
=
generateBytes
(
8
);
INPUT_TEXT
=
generateBytes
(
TEXT_LEN
+
PAD_BYTES
+
ENC_OFFSET
);
INPUT_TEXT
=
generateBytes
(
TEXT_LEN
+
PAD_BYTES
+
ENC_OFFSET
);
...
@@ -98,8 +102,8 @@ public abstract class TestCipher {
...
@@ -98,8 +102,8 @@ public abstract class TestCipher {
return
bytes
;
return
bytes
;
}
}
private
boolean
is
KeyStren
thSupported
()
{
private
boolean
is
MultipleKeyLeng
thSupported
()
{
return
(
variousKeySize
!=
0
);
return
(
maxKeySize
!=
minKeySize
);
}
}
public
void
runAll
()
throws
InvalidKeyException
,
public
void
runAll
()
throws
InvalidKeyException
,
...
@@ -110,11 +114,11 @@ public abstract class TestCipher {
...
@@ -110,11 +114,11 @@ public abstract class TestCipher {
for
(
String
mode
:
MODES
)
{
for
(
String
mode
:
MODES
)
{
for
(
String
padding
:
PADDINGS
)
{
for
(
String
padding
:
PADDINGS
)
{
if
(!
is
KeyStren
thSupported
())
{
if
(!
is
MultipleKeyLeng
thSupported
())
{
runTest
(
mode
,
padding
,
0
);
runTest
(
mode
,
padding
,
minKeySize
);
}
else
{
}
else
{
int
keySize
=
various
KeySize
;
int
keySize
=
max
KeySize
;
while
(
keySize
>=
MINIMUM_KEY_SIZE
)
{
while
(
keySize
>=
minKeySize
)
{
out
.
println
(
"With Key Strength: "
+
keySize
);
out
.
println
(
"With Key Strength: "
+
keySize
);
runTest
(
mode
,
padding
,
keySize
);
runTest
(
mode
,
padding
,
keySize
);
keySize
-=
KEYCUTTER
;
keySize
-=
KEYCUTTER
;
...
@@ -139,6 +143,7 @@ public abstract class TestCipher {
...
@@ -139,6 +143,7 @@ public abstract class TestCipher {
if
(
keySize
!=
0
)
{
if
(
keySize
!=
0
)
{
kg
.
init
(
keySize
);
kg
.
init
(
keySize
);
}
}
SecretKey
key
=
kg
.
generateKey
();
SecretKey
key
=
kg
.
generateKey
();
SecretKeySpec
skeySpec
=
new
SecretKeySpec
(
key
.
getEncoded
(),
ALGORITHM
);
SecretKeySpec
skeySpec
=
new
SecretKeySpec
(
key
.
getEncoded
(),
ALGORITHM
);
...
@@ -150,7 +155,6 @@ public abstract class TestCipher {
...
@@ -150,7 +155,6 @@ public abstract class TestCipher {
}
}
// Encryption
// Encryption
byte
[]
plainText
=
INPUT_TEXT
.
clone
();
byte
[]
plainText
=
INPUT_TEXT
.
clone
();
// Generate cipher and save to separate buffer
// Generate cipher and save to separate buffer
...
...
test/javax/crypto/CryptoPermission/CryptoPolicyFallback.java
0 → 100644
浏览文件 @
b5d84e6a
/*
* 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 8169335
* @summary Add a crypto policy fallback in case Security Property
* 'crypto.policy' does not exist.
* @run main/othervm CryptoPolicyFallback
*/
import
java.io.*
;
import
java.nio.file.*
;
import
java.util.stream.*
;
import
javax.crypto.*
;
/*
* Take the current java.security file, strip out the 'crypto.policy' entry,
* write to a new file in the current directory, then use that file as the
* replacement java.security file. This test will fail if the crypto.policy
* entry doesn't match the compiled in value.
*/
public
class
CryptoPolicyFallback
{
private
static
final
String
FILENAME
=
"java.security"
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
javaHome
=
System
.
getProperty
(
"java.home"
);
Path
path
=
Paths
.
get
(
javaHome
,
"lib"
,
"security"
,
FILENAME
);
/*
* Get the default value.
*/
String
defaultPolicy
;
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
path
))
{
/*
* If the input java.security file is malformed
* (missing crypto.policy, attribute/no value, etc), throw
* exception. split() might throw AIOOB which
* is ok behavior.
*/
String
s
=
lines
.
filter
(
x
->
x
.
startsWith
(
"crypto.policy="
))
.
findFirst
().
orElse
(
""
);
if
(!
s
.
isEmpty
())
{
defaultPolicy
=
s
.
split
(
"="
)[
1
].
trim
();
}
else
{
defaultPolicy
=
s
;
}
}
/*
* We know there is at least one crypto.policy entry, strip
* all of them out of the java.security file.
*/
try
(
PrintWriter
out
=
new
PrintWriter
(
FILENAME
);
Stream
<
String
>
lines
=
Files
.
lines
(
path
))
{
lines
.
filter
(
x
->
!
x
.
trim
().
startsWith
(
"crypto.policy="
))
.
forEach
(
out:
:
println
);
}
/*
* "-Djava.security.properties==file" does a complete replacement
* of the system java.security file. i.e. value must be "=file"
*/
System
.
setProperty
(
"java.security.properties"
,
"="
+
FILENAME
);
/*
* Find out expected value.
*/
int
expected
;
switch
(
defaultPolicy
)
{
case
"limited"
:
expected
=
128
;
break
;
case
""
:
case
"unlimited"
:
expected
=
Integer
.
MAX_VALUE
;
break
;
default
:
throw
new
Exception
(
"Unexpected Default Policy Value: "
+
defaultPolicy
);
}
/*
* Do the actual check. If the JCE Framework can't initialize
* an Exception is normally thrown here.
*/
int
maxKeyLen
=
Cipher
.
getMaxAllowedKeyLength
(
"AES"
);
System
.
out
.
println
(
"Default Policy: "
+
defaultPolicy
+
"\nExpected max AES key length: "
+
expected
+
", received : "
+
maxKeyLen
);
if
(
expected
!=
maxKeyLen
)
{
throw
new
Exception
(
"Wrong Key Length size!"
);
}
System
.
out
.
println
(
"PASSED!"
);
}
}
test/javax/crypto/CryptoPermission/TestUnlimited.java
浏览文件 @
b5d84e6a
...
@@ -25,12 +25,13 @@
...
@@ -25,12 +25,13 @@
/**
/**
* @test
* @test
* @bug 8157561
* @bug 8061842
* @summary Ship the unlimited policy files in JDK Updates
* @summary Package jurisdiction policy files as something other than JAR
* @run main/othervm TestUnlimited use_default default
* @run main/othervm TestUnlimited "" exception
* @run main/othervm TestUnlimited "" exception
* @run main/othervm TestUnlimited limited
fail
* @run main/othervm TestUnlimited limited
limited
* @run main/othervm TestUnlimited unlimited
pass
* @run main/othervm TestUnlimited unlimited
unlimited
* @run main/othervm TestUnlimited unlimited/
pass
* @run main/othervm TestUnlimited unlimited/
unlimited
* @run main/othervm TestUnlimited NosuchDir exception
* @run main/othervm TestUnlimited NosuchDir exception
* @run main/othervm TestUnlimited . exception
* @run main/othervm TestUnlimited . exception
* @run main/othervm TestUnlimited /tmp/unlimited exception
* @run main/othervm TestUnlimited /tmp/unlimited exception
...
@@ -40,9 +41,39 @@
...
@@ -40,9 +41,39 @@
*/
*/
import
javax.crypto.*
;
import
javax.crypto.*
;
import
java.security.Security
;
import
java.security.Security
;
import
java.nio.file.*
;
import
java.util.stream.*
;
public
class
TestUnlimited
{
public
class
TestUnlimited
{
private
enum
Result
{
UNLIMITED
,
LIMITED
,
EXCEPTION
,
UNKNOWN
};
/*
* Grab the default policy entry from java.security.
*
* If the input java.security file is malformed
* (missing crypto.policy, attribute/no value, etc), throw
* exception. split() might throw AIOOB which
* is ok behavior.
*/
private
static
String
getDefaultPolicy
()
throws
Exception
{
String
javaHome
=
System
.
getProperty
(
"java.home"
);
Path
path
=
Paths
.
get
(
javaHome
,
"lib"
,
"security"
,
"java.security"
);
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
path
))
{
String
s
=
lines
.
filter
(
x
->
x
.
startsWith
(
"crypto.policy="
))
.
findFirst
().
orElse
(
""
);
if
(!
s
.
isEmpty
())
return
s
.
split
(
"="
)[
1
].
trim
();
return
s
;
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
/*
/*
* Override the Security property to allow for unlimited policy.
* Override the Security property to allow for unlimited policy.
...
@@ -53,16 +84,38 @@ public class TestUnlimited {
...
@@ -53,16 +84,38 @@ public class TestUnlimited {
throw
new
Exception
(
"Two args required"
);
throw
new
Exception
(
"Two args required"
);
}
}
boolean
expected
=
args
[
1
].
equals
(
"pass"
);
String
testStr
=
args
[
0
];
boolean
exception
=
args
[
1
].
equals
(
"exception"
);
String
expectedStr
=
args
[
1
];
boolean
result
=
false
;
if
(
testStr
.
equals
(
"use_default"
))
{
expectedStr
=
getDefaultPolicy
();
}
Result
expected
=
Result
.
UNKNOWN
;
// avoid NPE warnings
Result
result
;
System
.
out
.
println
(
"Testing: "
+
args
[
0
]);
switch
(
expectedStr
)
{
case
""
:
case
"unlimited"
:
expected
=
Result
.
UNLIMITED
;
break
;
case
"limited"
:
expected
=
Result
.
LIMITED
;
break
;
case
"exception"
:
expected
=
Result
.
EXCEPTION
;
break
;
default
:
throw
new
Exception
(
"Unexpected argument"
);
}
if
(
args
[
0
].
equals
(
"\"\""
))
{
System
.
out
.
println
(
"Testing: "
+
testStr
);
if
(
testStr
.
equals
(
"\"\""
))
{
Security
.
setProperty
(
"crypto.policy"
,
""
);
Security
.
setProperty
(
"crypto.policy"
,
""
);
}
else
{
}
else
{
Security
.
setProperty
(
"crypto.policy"
,
args
[
0
]);
// skip default case.
if
(!
testStr
.
equals
(
"use_default"
))
{
Security
.
setProperty
(
"crypto.policy"
,
testStr
);
}
}
}
/*
/*
...
@@ -74,21 +127,20 @@ public class TestUnlimited {
...
@@ -74,21 +127,20 @@ public class TestUnlimited {
System
.
out
.
println
(
"max AES key len:"
+
maxKeyLen
);
System
.
out
.
println
(
"max AES key len:"
+
maxKeyLen
);
if
(
maxKeyLen
>
128
)
{
if
(
maxKeyLen
>
128
)
{
System
.
out
.
println
(
"Unlimited policy is active"
);
System
.
out
.
println
(
"Unlimited policy is active"
);
result
=
true
;
result
=
Result
.
UNLIMITED
;
}
else
{
}
else
{
System
.
out
.
println
(
"Unlimited policy is NOT active"
);
System
.
out
.
println
(
"Unlimited policy is NOT active"
);
result
=
false
;
result
=
Result
.
LIMITED
;
}
}
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
if
(!
exception
)
{
//ExceptionInInitializerError's
throw
new
Exception
();
result
=
Result
.
EXCEPTION
;
}
}
}
System
.
out
.
println
(
System
.
out
.
println
(
"Expected:\t"
+
expected
+
"\nResult:\t\t"
+
result
);
"Expected:\t"
+
expected
+
"\nResult:\t\t"
+
result
);
if
(
expected
!=
result
)
{
if
(
!
expected
.
equals
(
result
)
)
{
throw
new
Exception
();
throw
new
Exception
(
"Didn't match"
);
}
}
System
.
out
.
println
(
"DONE!"
);
System
.
out
.
println
(
"DONE!"
);
...
...
test/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java
0 → 100644
浏览文件 @
b5d84e6a
/*
* Copyright (c) 2017, 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 8184328
* @summary JDK8u131-b34-socketRead0 hang at SSL read
* @run main/othervm SSLSocketCloseHang
*/
import
java.io.*
;
import
java.net.*
;
import
java.util.*
;
import
java.security.*
;
import
javax.net.ssl.*
;
public
class
SSLSocketCloseHang
{
/*
* =============================================================
* Set the various variables needed for the tests, then
* specify what tests to run on each side.
*/
/*
* Should we run the client or server in a separate thread?
* Both sides can throw exceptions, but do you have a preference
* as to which side should be the main thread.
*/
static
boolean
separateServerThread
=
true
;
/*
* Where do we find the keystores?
*/
static
String
pathToStores
=
"../../../../sun/security/ssl/etc"
;
static
String
keyStoreFile
=
"keystore"
;
static
String
trustStoreFile
=
"truststore"
;
static
String
passwd
=
"passphrase"
;
/*
* Is the server ready to serve?
*/
volatile
static
boolean
serverReady
=
false
;
/*
* Was the client responsible for closing the socket
*/
volatile
static
boolean
clientClosed
=
false
;
/*
* Turn on SSL debugging?
*/
static
boolean
debug
=
false
;
/*
* If the client or server is doing some kind of object creation
* that the other side depends on, and that thread prematurely
* exits, you may experience a hang. The test harness will
* terminate all hung threads after its timeout has expired,
* currently 3 minutes by default, but you might try to be
* smart about it....
*/
/*
* Define the server side of the test.
*
* If the server prematurely exits, serverReady will be set to true
* to avoid infinite hangs.
*/
void
doServerSide
()
throws
Exception
{
SSLServerSocketFactory
sslssf
=
(
SSLServerSocketFactory
)
SSLServerSocketFactory
.
getDefault
();
SSLServerSocket
sslServerSocket
=
(
SSLServerSocket
)
sslssf
.
createServerSocket
(
serverPort
);
serverPort
=
sslServerSocket
.
getLocalPort
();
/*
* Signal Client, we're ready for his connect.
*/
serverReady
=
true
;
SSLSocket
sslSocket
=
(
SSLSocket
)
sslServerSocket
.
accept
();
sslSocket
.
startHandshake
();
while
(!
clientClosed
)
{
Thread
.
sleep
(
500
);
}
}
/*
* Define the client side of the test.
*
* If the server prematurely exits, serverReady will be set to true
* to avoid infinite hangs.
*/
void
doClientSide
()
throws
Exception
{
boolean
caught
=
false
;
/*
* Wait for server to get started.
*/
System
.
out
.
println
(
"waiting on server"
);
while
(!
serverReady
)
{
Thread
.
sleep
(
50
);
}
System
.
out
.
println
(
"server ready"
);
Socket
baseSocket
=
new
Socket
(
"localhost"
,
serverPort
);
baseSocket
.
setSoTimeout
(
100
);
SSLSocketFactory
sslsf
=
(
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
();
SSLSocket
sslSocket
=
(
SSLSocket
)
sslsf
.
createSocket
(
baseSocket
,
"localhost"
,
serverPort
,
false
);
// handshaking
sslSocket
.
startHandshake
();
System
.
out
.
println
(
"handshake done"
);
Thread
.
sleep
(
500
);
System
.
out
.
println
(
"client closing"
);
sslSocket
.
close
();
clientClosed
=
true
;
System
.
out
.
println
(
"client closed"
);
}
/*
* =============================================================
* The remainder is just support stuff
*/
// use any free port by default
volatile
int
serverPort
=
0
;
volatile
Exception
serverException
=
null
;
volatile
Exception
clientException
=
null
;
volatile
byte
[]
serverDigest
=
null
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
keyFilename
=
System
.
getProperty
(
"test.src"
,
"./"
)
+
"/"
+
pathToStores
+
"/"
+
keyStoreFile
;
String
trustFilename
=
System
.
getProperty
(
"test.src"
,
"./"
)
+
"/"
+
pathToStores
+
"/"
+
trustStoreFile
;
System
.
setProperty
(
"javax.net.ssl.keyStore"
,
keyFilename
);
System
.
setProperty
(
"javax.net.ssl.keyStorePassword"
,
passwd
);
System
.
setProperty
(
"javax.net.ssl.trustStore"
,
trustFilename
);
System
.
setProperty
(
"javax.net.ssl.trustStorePassword"
,
passwd
);
if
(
debug
)
System
.
setProperty
(
"javax.net.debug"
,
"all"
);
/*
* Start the tests.
*/
new
SSLSocketCloseHang
();
}
Thread
clientThread
=
null
;
Thread
serverThread
=
null
;
/*
* Primary constructor, used to drive remainder of the test.
*
* Fork off the other side, then do your work.
*/
SSLSocketCloseHang
()
throws
Exception
{
if
(
separateServerThread
)
{
startServer
(
true
);
startClient
(
false
);
}
else
{
startClient
(
true
);
startServer
(
false
);
}
/*
* Wait for other side to close down.
*/
if
(
separateServerThread
)
{
serverThread
.
join
();
}
else
{
clientThread
.
join
();
}
/*
* When we get here, the test is pretty much over.
*
* If the main thread excepted, that propagates back
* immediately. If the other thread threw an exception, we
* should report back.
*/
if
(
serverException
!=
null
)
{
System
.
out
.
print
(
"Server Exception:"
);
throw
serverException
;
}
if
(
clientException
!=
null
)
{
System
.
out
.
print
(
"Client Exception:"
);
throw
clientException
;
}
}
void
startServer
(
boolean
newThread
)
throws
Exception
{
if
(
newThread
)
{
serverThread
=
new
Thread
()
{
public
void
run
()
{
try
{
doServerSide
();
}
catch
(
Exception
e
)
{
/*
* Our server thread just died.
*
* Release the client, if not active already...
*/
System
.
err
.
println
(
"Server died..."
);
System
.
err
.
println
(
e
);
serverReady
=
true
;
serverException
=
e
;
}
}
};
serverThread
.
start
();
}
else
{
doServerSide
();
}
}
void
startClient
(
boolean
newThread
)
throws
Exception
{
if
(
newThread
)
{
clientThread
=
new
Thread
()
{
public
void
run
()
{
try
{
doClientSide
();
}
catch
(
Exception
e
)
{
/*
* Our client thread just died.
*/
System
.
err
.
println
(
"Client died..."
);
clientException
=
e
;
}
}
};
clientThread
.
start
();
}
else
{
doClientSide
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录