Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/x509/AVA/DomainComponentEncoding.java
38853 views
1
/*
2
* Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6391482
27
* @summary incorrect ASN1 DER encoding of DomainComponent AttributeValue
28
*/
29
30
import javax.security.auth.x500.X500Principal;
31
import sun.security.util.DerInputStream;
32
import sun.security.util.DerValue;
33
import sun.security.util.ObjectIdentifier;
34
import sun.security.x509.X500Name;
35
36
public class DomainComponentEncoding {
37
38
public static void main(String[] args) throws Exception {
39
// RFC 2253 String DN
40
testDN("cn=hello, dc=com, dc=example");
41
// RFC 1779 String DN with embedded quotes
42
testDN("cn=hello, dc=\"com\", dc=example");
43
}
44
45
private static void testDN(String dn) throws Exception {
46
X500Principal p = new X500Principal(dn);
47
byte[] encoded = p.getEncoded();
48
49
// name is a sequence of RDN's
50
DerInputStream dis = new DerInputStream(encoded);
51
DerValue[] nameseq = dis.getSequence(3);
52
53
boolean passed = false;
54
for (int i = 0; i < nameseq.length; i++) {
55
56
// each RDN is a set of AttributeTypeAndValue
57
DerInputStream is = new DerInputStream(nameseq[i].toByteArray());
58
DerValue[] ava = is.getSet(3);
59
60
for (int j = 0; j < ava.length; j++) {
61
62
ObjectIdentifier oid = ava[j].data.getOID();
63
64
if (oid.equals(X500Name.DOMAIN_COMPONENT_OID)) {
65
DerValue value = ava[j].data.getDerValue();
66
if (value.getTag() == DerValue.tag_IA5String) {
67
passed = true;
68
break;
69
} else {
70
throw new SecurityException
71
("Test failed, expected DOMAIN_COMPONENT tag '" +
72
DerValue.tag_IA5String +
73
"', got '" +
74
value.getTag() + "'");
75
}
76
}
77
}
78
79
if (passed) {
80
break;
81
}
82
}
83
84
if (passed) {
85
System.out.println("Test passed");
86
} else {
87
throw new SecurityException("Test failed");
88
}
89
}
90
}
91
92