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/URIName/Parse.java
38918 views
1
/*
2
* Copyright (c) 2013, 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 8005389
27
* @summary CRL Distribution Point URIs with spaces or backslashes should
28
* not be parseable
29
*/
30
import java.io.ByteArrayInputStream;
31
import java.io.IOException;
32
import java.security.cert.CertificateFactory;
33
import java.security.cert.X509Certificate;
34
import sun.security.util.DerValue;
35
import sun.security.x509.CRLDistributionPointsExtension;
36
import sun.security.x509.URIName;
37
38
39
public class Parse {
40
41
// certificate with a space in the CRLDistributionPointsExtension uri
42
// uri: file://crl file.crl
43
static String certWithSpaceInCDPStr =
44
"-----BEGIN CERTIFICATE-----\n" +
45
"MIIB8DCCAVmgAwIBAgIJAOgNnYA5nHtQMA0GCSqGSIb3DQEBBQUAMCUxETAPBgNV\n" +
46
"BAMTCHRlc3RuYW1lMRAwDgYDVQQLEwd0ZXN0b3JnMB4XDTEyMDgxMzIzMzgzN1oX\n" +
47
"DTEyMDkxMjIzMzgzN1owJTERMA8GA1UEAxMIdGVzdG5hbWUxEDAOBgNVBAsTB3Rl\n" +
48
"c3RvcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANx02RuD/Y2pvgVnXBbJ\n" +
49
"Sb+8j80geuoYEyRRnP6YiL2wmZqMmTHuznFwosO57KoVbz/XEr1bOnBMnPKax5Ll\n" +
50
"QlDI3nmnxmUq13ORQ6GkD3M+QRzzxc66BFJbKqUzgv1P3NngyIFr03zb/opXdCTZ\n" +
51
"4WfJuCf7Ouz44Ch6ZGQJ+7G5AgMBAAGjKDAmMCQGA1UdHwQdMBswGaAXoBWGE2Zp\n" +
52
"bGU6Ly9jcmwgZmlsZS5jcmwwDQYJKoZIhvcNAQEFBQADgYEAB+ublc1l1EnXtEJE\n" +
53
"jYeFzAdttHKQ4mn8CXGtHSy9gpckKyLdZUc9/n6yKuNXih29faepZ8mtaftTYpgR\n" +
54
"AUqZ+6YYik+rIqZpnWMPR9qZvshf/KPerXiZe7kYBKNvxgmCFfhK8QN6nxUGrR2F\n" +
55
"d53HWct6zXqlj+vQZsGC30f764M=\n" +
56
"-----END CERTIFICATE-----";
57
58
// a certificate with backslashes in the CRLDistributionPointsExtension uri
59
// uri: file://\\\\CRL\\crl_file.crl
60
static String certWithBackslashesInCDPStr =
61
"-----BEGIN CERTIFICATE-----\n" +
62
"MIIB9jCCAV+gAwIBAgIJAOQV9wTIgnc1MA0GCSqGSIb3DQEBBQUAMCUxETAPBgNV\n" +
63
"BAMTCHRlc3RuYW1lMRAwDgYDVQQLEwd0ZXN0b3JnMB4XDTEyMDgxMzIzMzcxM1oX\n" +
64
"DTEyMDkxMjIzMzcxM1owJTERMA8GA1UEAxMIdGVzdG5hbWUxEDAOBgNVBAsTB3Rl\n" +
65
"c3RvcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALdtczqZqI6RI17mz58/\n" +
66
"PgFNBmb/dX/MeVcuaUp79RVUbDQ68z4JxDNv4ImcAxigKXb2jObPAxOdM+VlXROS\n" +
67
"AmUNgYrIPuHNnKbd+rwilc6DsGWZnZLmZE63fUvTSqjOnSlsENSgDBVL/4r+yWBB\n" +
68
"8KKmFGRFqkCyN1EZl03IW9i7AgMBAAGjLjAsMCoGA1UdHwQjMCEwH6AdoBuGGWZp\n" +
69
"bGU6Ly9cXENSTFxjcmxfZmlsZS5jcmwwDQYJKoZIhvcNAQEFBQADgYEACOgZEaST\n" +
70
"BCFQVeXZ5d8J3dUZ+wRRkPvrlvopxMtZb3Hyte78PNoIZ78f1gYL18HiGYwKttau\n" +
71
"DyPp1lrG9xKPfIeKg+aDWTtVE7pexB4qCryID0+kJfdNzkdIgdGJzJ/RmfJ5heMF\n" +
72
"+R46Mhpua4c6gGsE2NGBFxmtS3YHpQsKtz8=\n" +
73
"-----END CERTIFICATE-----";
74
75
/*
76
* Create an X509Certificate then attempt to construct a
77
* CRLDistributionPointsExtension object from its extension value bytes.
78
*/
79
private static void CRLDistributionPointsExtensionTest(String certStr)
80
throws Exception {
81
CertificateFactory cf = CertificateFactory.getInstance("X.509");
82
ByteArrayInputStream is = new ByteArrayInputStream(certStr.getBytes());
83
X509Certificate cert = (X509Certificate) cf.generateCertificate(is);
84
85
// oid for CRL Distribution Points = 2.5.29.31
86
byte[] CDPExtBytes = cert.getExtensionValue("2.5.29.31");
87
DerValue val = new DerValue(CDPExtBytes);
88
byte[] data = val.getOctetString();
89
CRLDistributionPointsExtension CDPExt
90
= new CRLDistributionPointsExtension(false, data);
91
}
92
93
public static void main(String[] args) throws Exception {
94
/* Try to parse a CRLDistributionPointsExtension URI with a space. */
95
try {
96
CRLDistributionPointsExtensionTest(certWithSpaceInCDPStr);
97
throw new RuntimeException("Illegally parsed a "
98
+ "CRLDistributionPointsExtension uri with a space.");
99
} catch (IOException e) {
100
System.out.println("Caught the correct exception.");
101
102
}
103
104
/* Try to parse a CRLDistributionPointsExtension URI with backslashes. */
105
try {
106
CRLDistributionPointsExtensionTest(certWithBackslashesInCDPStr);
107
throw new RuntimeException("Illegally parsed a "
108
+ "CRLDistributionPointsExtension uri with a backslashes.");
109
} catch (IOException e) {
110
System.out.println("Caught the correct exception.");
111
}
112
113
/* Try to construct a URIName from a uri with a space. */
114
String uriWithSpace = "file://crl file.crl";
115
URIName name;
116
try {
117
name = new URIName(uriWithSpace);
118
throw new RuntimeException("Illegally created a URIName "
119
+ "from a uri with a space.");
120
} catch (IOException e) {
121
System.out.println("Caught the correct exception.");
122
}
123
124
/* Try to construct a URIName from a uri with backslashes. */
125
String uriWithBackslashes = "file://\\\\CRL\\crl_file.crl";
126
try {
127
name = new URIName(uriWithBackslashes);
128
throw new RuntimeException("Illegally created a URIName "
129
+ "from a uri with backslashes.");
130
} catch (IOException e) {
131
System.out.println("Caught the correct exception.");
132
}
133
134
System.out.println("Tests passed.");
135
}
136
}
137
138
139