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