Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
37150460
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看板
提交
37150460
编写于
12月 05, 2018
作者:
C
coffeys
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8213952: Relax DNSName restriction as per RFC 1123
Reviewed-by: weijun, mullan, chegar
上级
03461177
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
138 addition
and
41 deletion
+138
-41
src/share/classes/sun/security/x509/DNSName.java
src/share/classes/sun/security/x509/DNSName.java
+40
-35
src/share/classes/sun/security/x509/GeneralName.java
src/share/classes/sun/security/x509/GeneralName.java
+1
-1
src/share/classes/sun/security/x509/RFC822Name.java
src/share/classes/sun/security/x509/RFC822Name.java
+1
-1
src/share/classes/sun/security/x509/URIName.java
src/share/classes/sun/security/x509/URIName.java
+3
-3
src/share/classes/sun/security/x509/X500Name.java
src/share/classes/sun/security/x509/X500Name.java
+1
-1
test/sun/security/tools/keytool/KeyToolTest.java
test/sun/security/tools/keytool/KeyToolTest.java
+1
-0
test/sun/security/x509/GeneralName/DNSNameTest.java
test/sun/security/x509/GeneralName/DNSNameTest.java
+91
-0
未找到文件。
src/share/classes/sun/security/x509/DNSName.java
浏览文件 @
37150460
/*
* Copyright (c) 1997, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 201
8
, 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
...
...
@@ -34,16 +34,17 @@ import sun.security.util.*;
* This class implements the DNSName as required by the GeneralNames
* ASN.1 object.
* <p>
* [RFC
2459] When the subjectAltName extension contains a domain name service
* [RFC
5280] When the subjectAltName extension contains a domain name system
* label, the domain name MUST be stored in the dNSName (an IA5String).
* The name MUST be in the "preferred name syntax," as specified by RFC
* 1034 [RFC 1034]. Note that while upper and lower case letters are
* allowed in domain names, no signifigance is attached to the case. In
* The name MUST be in the "preferred name syntax", as specified by
* Section 3.5 of [RFC1034] and as modified by Section 2.1 of
* [RFC1123]. Note that while uppercase and lowercase letters are
* allowed in domain names, no significance is attached to the case. In
* addition, while the string " " is a legal domain name, subjectAltName
* extensions with a dNSName
" " are not permitted. Finally, the use of
*
the DNS representation for Internet mail addresses (wpolk.nist.gov
*
instead of wpolk@nist.gov) is not permitted; such identities are to
* be encoded as rfc822Name.
* extensions with a dNSName
of " " MUST NOT be used. Finally, the use
*
of the DNS representation for Internet mail addresses
*
(subscriber.example.com instead of subscriber@example.com) MUST NOT
* be
used; such identities are to be
encoded as rfc822Name.
* <p>
* @author Amit Kapoor
* @author Hemma Prafullchandra
...
...
@@ -51,9 +52,8 @@ import sun.security.util.*;
public
class
DNSName
implements
GeneralNameInterface
{
private
String
name
;
private
static
final
String
alpha
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
;
private
static
final
String
digitsAndHyphen
=
"0123456789-"
;
private
static
final
String
alphaDigitsAndHyphen
=
alpha
+
digitsAndHyphen
;
private
static
final
String
alphaDigits
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;
/**
* Create the DNSName object from the passed encoded Der value.
...
...
@@ -73,35 +73,38 @@ public class DNSName implements GeneralNameInterface {
*/
public
DNSName
(
String
name
)
throws
IOException
{
if
(
name
==
null
||
name
.
length
()
==
0
)
throw
new
IOException
(
"DNS name must not be null"
);
if
(
name
.
indexOf
(
' '
)
!=
-
1
)
throw
new
IOException
(
"DNS names or NameConstraints with blank components are not permitted"
);
if
(
name
.
charAt
(
0
)
==
'.'
||
name
.
charAt
(
name
.
length
()
-
1
)
==
'.'
)
throw
new
IOException
(
"DNS names or NameConstraints may not begin or end with a ."
);
//Name will consist of label components separated by "."
//startIndex is the index of the first character of a component
//endIndex is the index of the last character of a component plus 1
for
(
int
endIndex
,
startIndex
=
0
;
startIndex
<
name
.
length
();
startIndex
=
endIndex
+
1
)
{
throw
new
IOException
(
"DNSName must not be null or empty"
);
if
(
name
.
contains
(
" "
))
throw
new
IOException
(
"DNSName with blank components is not permitted"
);
if
(
name
.
startsWith
(
"."
)
||
name
.
endsWith
(
"."
))
throw
new
IOException
(
"DNSName may not begin or end with a ."
);
/*
* Name will consist of label components separated by "."
* startIndex is the index of the first character of a component
* endIndex is the index of the last character of a component plus 1
*/
for
(
int
endIndex
,
startIndex
=
0
;
startIndex
<
name
.
length
();
startIndex
=
endIndex
+
1
)
{
endIndex
=
name
.
indexOf
(
'.'
,
startIndex
);
if
(
endIndex
<
0
)
{
endIndex
=
name
.
length
();
}
if
(
(
endIndex
-
startIndex
)
<
1
)
throw
new
IOException
(
"DNSName
SubjectAltNames
with empty components are not permitted"
);
if
(
endIndex
-
startIndex
<
1
)
throw
new
IOException
(
"DNSName with empty components are not permitted"
);
//
DNSName components must begin with a letter A-Z or a-z
if
(
alpha
.
indexOf
(
name
.
charAt
(
startIndex
))
<
0
)
throw
new
IOException
(
"DNSName components must begin with a letter"
);
//
RFC 1123: DNSName components must begin with a letter or digit
if
(
alpha
Digits
.
indexOf
(
name
.
charAt
(
startIndex
))
<
0
)
throw
new
IOException
(
"DNSName components must begin with a letter
or digit
"
);
//nonStartIndex: index for characters in the component beyond the first one
for
(
int
nonStartIndex
=
startIndex
+
1
;
nonStartIndex
<
endIndex
;
nonStartIndex
++)
{
char
x
=
name
.
charAt
(
nonStartIndex
);
if
((
alphaDigits
AndHyphen
).
indexOf
(
x
)
<
0
)
if
((
alphaDigits
).
indexOf
(
x
)
<
0
&&
x
!=
'-'
)
throw
new
IOException
(
"DNSName components must consist of letters, digits, and hyphens"
);
}
}
this
.
name
=
name
;
}
/**
* Return the type of the GeneralName.
*/
...
...
@@ -117,7 +120,7 @@ public class DNSName implements GeneralNameInterface {
}
/**
* Encode the DNS
n
ame into the DerOutputStream.
* Encode the DNS
N
ame into the DerOutputStream.
*
* @param out the DER stream to encode the DNSName to.
* @exception IOException on encoding errors.
...
...
@@ -137,7 +140,7 @@ public class DNSName implements GeneralNameInterface {
* Compares this name with another, for equality.
*
* @return true iff the names are equivalent
* according to RFC
2459
.
* according to RFC
5280
.
*/
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
...
...
@@ -148,7 +151,7 @@ public class DNSName implements GeneralNameInterface {
DNSName
other
=
(
DNSName
)
obj
;
// RFC
2459
mandates that these names are
// RFC
5280
mandates that these names are
// not case-sensitive
return
name
.
equalsIgnoreCase
(
other
.
name
);
}
...
...
@@ -172,12 +175,14 @@ public class DNSName implements GeneralNameInterface {
* </ul>. These results are used in checking NameConstraints during
* certification path verification.
* <p>
* RFC2459: DNS name restrictions are expressed as foo.bar.com. Any subdomain
* satisfies the name constraint. For example, www.foo.bar.com would
* satisfy the constraint but bigfoo.bar.com would not.
* RFC5280: DNS name restrictions are expressed as host.example.com.
* Any DNS name that can be constructed by simply adding zero or more
* labels to the left-hand side of the name satisfies the name constraint.
* For example, www.host.example.com would satisfy the constraint but
* host1.example.com would not.
* <p>
* draft-ietf-pkix-new-part1-00.txt: DNS
n
ame restrictions are expressed as foo.bar.com.
* Any DNS
n
ame that
* draft-ietf-pkix-new-part1-00.txt: DNS
N
ame restrictions are expressed as foo.bar.com.
* Any DNS
N
ame that
* can be constructed by simply adding to the left hand side of the name
* satisfies the name constraint. For example, www.foo.bar.com would
* satisfy the constraint but foo1.bar.com would not.
...
...
src/share/classes/sun/security/x509/GeneralName.java
浏览文件 @
37150460
...
...
@@ -112,7 +112,7 @@ public class GeneralName {
encName
.
resetTag
(
DerValue
.
tag_IA5String
);
name
=
new
DNSName
(
encName
);
}
else
{
throw
new
IOException
(
"Invalid encoding of DNS
n
ame"
);
throw
new
IOException
(
"Invalid encoding of DNS
N
ame"
);
}
break
;
...
...
src/share/classes/sun/security/x509/RFC822Name.java
浏览文件 @
37150460
...
...
@@ -246,7 +246,7 @@ public class RFC822Name implements GeneralNameInterface
subtree
=
subtree
.
substring
(
atNdx
+
1
);
}
/* count dots in
dnsname, adding one if dnsn
ame preceded by @ */
/* count dots in
DNSName, adding one if DNSN
ame preceded by @ */
for
(;
subtree
.
lastIndexOf
(
'.'
)
>=
0
;
i
++)
{
subtree
=
subtree
.
substring
(
0
,
subtree
.
lastIndexOf
(
'.'
));
}
...
...
src/share/classes/sun/security/x509/URIName.java
浏览文件 @
37150460
...
...
@@ -131,13 +131,13 @@ public class URIName implements GeneralNameInterface {
try
{
hostDNS
=
new
DNSName
(
host
);
}
catch
(
IOException
ioe
)
{
// Not a valid DNS
Name; see if it is a valid IPv4
// Not a valid DNSName; see if it is a valid IPv4
// IPAddressName
try
{
hostIP
=
new
IPAddressName
(
host
);
}
catch
(
Exception
ioe2
)
{
throw
new
IOException
(
"invalid URI name (host "
+
"portion is not a valid DNS
n
ame, IPv4 address,"
+
"portion is not a valid DNS
N
ame, IPv4 address,"
+
" or IPv6 address):"
+
name
);
}
}
...
...
@@ -339,7 +339,7 @@ public class URIName implements GeneralNameInterface {
// If one (or both) is an IP address, only same type
constraintType
=
NAME_SAME_TYPE
;
}
else
{
// Both host portions are DNS
n
ames. Are they domains?
// Both host portions are DNS
N
ames. Are they domains?
boolean
thisDomain
=
(
host
.
charAt
(
0
)
==
'.'
);
boolean
otherDomain
=
(
otherHost
.
charAt
(
0
)
==
'.'
);
DNSName
otherDNS
=
(
DNSName
)
otherHostObject
;
...
...
src/share/classes/sun/security/x509/X500Name.java
浏览文件 @
37150460
...
...
@@ -1219,7 +1219,7 @@ public class X500Name implements GeneralNameInterface, Principal {
*/
/*
* OID for "DC=" domain component attributes, used with DNS
n
ames in DN
* OID for "DC=" domain component attributes, used with DNS
N
ames in DN
* format
*/
DOMAIN_COMPONENT_OID
=
...
...
test/sun/security/tools/keytool/KeyToolTest.java
浏览文件 @
37150460
...
...
@@ -1028,6 +1028,7 @@ public class KeyToolTest {
testOK
(
""
,
pre
+
"san3 -ext san=dns:me.org"
);
testOK
(
""
,
pre
+
"san4 -ext san=ip:192.168.0.1"
);
testOK
(
""
,
pre
+
"san5 -ext san=oid:1.2.3.4"
);
testOK
(
""
,
pre
+
"san6 -ext san=dns:1abc.com"
);
//begin with digit
testOK
(
""
,
pre
+
"san235 -ext san=uri:http://me.org,dns:me.org,oid:1.2.3.4"
);
ks
=
loadStore
(
"x.jks"
,
"changeit"
,
"JKS"
);
...
...
test/sun/security/x509/GeneralName/DNSNameTest.java
0 → 100644
浏览文件 @
37150460
/*
* Copyright (c) 2018, 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
* @summary DNSName parsing tests
* @bug 8213952
* @modules java.base/sun.security.x509
* @run testng DNSNameTest
*/
import
java.io.IOException
;
import
sun.security.x509.DNSName
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
static
org
.
testng
.
Assert
.*;
public
class
DNSNameTest
{
@DataProvider
(
name
=
"goodNames"
)
public
Object
[][]
goodNames
()
{
Object
[][]
data
=
{
{
"abc.com"
},
{
"ABC.COM"
},
{
"a12.com"
},
{
"a1b2c3.com"
},
{
"1abc.com"
},
{
"123.com"
},
{
"abc.com-"
},
// end with hyphen
{
"a-b-c.com"
},
// hyphens
};
return
data
;
}
@DataProvider
(
name
=
"badNames"
)
public
Object
[][]
badNames
()
{
Object
[][]
data
=
{
{
" 1abc.com"
},
// begin with space
{
"1abc.com "
},
// end with space
{
"1a bc.com "
},
// no space allowed
{
"-abc.com"
},
// begin with hyphen
{
"a..b"
},
// ..
{
".a"
},
// begin with .
{
"a."
},
// end with .
{
""
},
// empty
{
" "
},
// space only
};
return
data
;
}
@Test
(
dataProvider
=
"goodNames"
)
public
void
testGoodDNSName
(
String
dnsNameString
)
{
try
{
DNSName
dn
=
new
DNSName
(
dnsNameString
);
}
catch
(
IOException
e
)
{
fail
(
"Unexpected IOException"
);
}
}
@Test
(
dataProvider
=
"badNames"
)
public
void
testBadDNSName
(
String
dnsNameString
)
{
try
{
DNSName
dn
=
new
DNSName
(
dnsNameString
);
fail
(
"IOException expected"
);
}
catch
(
IOException
e
)
{
if
(!
e
.
getMessage
().
contains
(
"DNSName"
))
fail
(
"Unexpeceted message: "
+
e
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录