Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/x509/X509CRLImpl/Verify.java
41153 views
1
/*
2
* Copyright (c) 2012, 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 7026347
27
* @summary X509CRL should have verify(PublicKey key, Provider sigProvider)
28
*/
29
30
import java.io.ByteArrayInputStream;
31
import java.security.*;
32
import java.security.cert.*;
33
34
public class Verify {
35
36
static String selfSignedCertStr =
37
"-----BEGIN CERTIFICATE-----\n" +
38
"MIICPjCCAaegAwIBAgIBADANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
39
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzJaFw0zMDA0MDcwMjI0MzJa\n" +
40
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
41
"AQUAA4GNADCBiQKBgQC4OTag24sTxL2tXTNuvpmUEtdxrYAZoFsslFQ60T+WD9wQ\n" +
42
"Jeiw87FSPsR2vxRuv0j8DNm2a4h7LNNIFcLurfNldbz5pvgZ7VqdbbUMPE9qP85n\n" +
43
"jgDl4woyRTSUeRI4A7O0CO6NpES21dtbdhroWQrEkHxpnrDPxsxrz5gf2m3gqwID\n" +
44
"AQABo4GJMIGGMB0GA1UdDgQWBBSCJd0hpl5PdAD9IZS+Hzng4lXLGzBHBgNVHSME\n" +
45
"QDA+gBSCJd0hpl5PdAD9IZS+Hzng4lXLG6EjpCEwHzELMAkGA1UEBhMCVVMxEDAO\n" +
46
"BgNVBAoTB0V4YW1wbGWCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAgQw\n" +
47
"DQYJKoZIhvcNAQEEBQADgYEAluy6HIjWcq009lTLmhp+Np6dxU78pInBK8RZkza0\n" +
48
"484qGaxFGD3UGyZkI5uWmsH2XuMbuox5khfIq6781gmkPBHXBIEtJN8eLusOHEye\n" +
49
"iE8h7WI+N3qa6Pj56WionMrioqC/3X+b06o147bbhx8U0vkYv/HyPaITOFfMXTdz\n" +
50
"Vjw=\n" +
51
"-----END CERTIFICATE-----";
52
53
static String crlIssuerCertStr =
54
"-----BEGIN CERTIFICATE-----\n" +
55
"MIICKzCCAZSgAwIBAgIBAjANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQ\n" +
56
"MA4GA1UEChMHRXhhbXBsZTAeFw0wOTA0MjcwMjI0MzNaFw0yOTAxMTIwMjI0MzNa\n" +
57
"MB8xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFeGFtcGxlMIGfMA0GCSqGSIb3DQEB\n" +
58
"AQUAA4GNADCBiQKBgQDMJeBMBybHykI/YpwUJ4O9euqDSLb1kpWpceBS8TVqvgBC\n" +
59
"SgUJWtFZL0i6bdvF6mMdlbuBkGzhXqHiVAi96/zRLbUC9F8SMEJ6MuD+YhQ0ZFTQ\n" +
60
"atKy8zf8O9XzztelLJ26Gqb7QPV133WY3haAqHtCXOhEKkCN16NOYNC37DTaJwID\n" +
61
"AQABo3cwdTAdBgNVHQ4EFgQULXSWzXzUOIpOJpzbSCpW42IJUugwRwYDVR0jBEAw\n" +
62
"PoAUgiXdIaZeT3QA/SGUvh854OJVyxuhI6QhMB8xCzAJBgNVBAYTAlVTMRAwDgYD\n" +
63
"VQQKEwdFeGFtcGxlggEAMAsGA1UdDwQEAwIBAjANBgkqhkiG9w0BAQQFAAOBgQAY\n" +
64
"eMnf5AHSNlyUlzXk8o2S0h4gCuvKX6C3kFfKuZcWvFAbx4yQOWLS2s15/nzR4+AP\n" +
65
"FGX3lgJjROyAh7fGedTQK+NFWwkM2ag1g3hXktnlnT1qHohi0w31nVBJxXEDO/Ck\n" +
66
"uJTpJGt8XxxbFaw5v7cHy7XuTAeU/sekvjEiNHW00Q==\n" +
67
"-----END CERTIFICATE-----";
68
69
static String crlStr =
70
"-----BEGIN X509 CRL-----\n" +
71
"MIIBGzCBhQIBATANBgkqhkiG9w0BAQQFADAfMQswCQYDVQQGEwJVUzEQMA4GA1UE\n" +
72
"ChMHRXhhbXBsZRcNMDkwNDI3MDIzODA0WhcNMjgwNjI2MDIzODA0WjAiMCACAQUX\n" +
73
"DTA5MDQyNzAyMzgwMFowDDAKBgNVHRUEAwoBBKAOMAwwCgYDVR0UBAMCAQIwDQYJ\n" +
74
"KoZIhvcNAQEEBQADgYEAoarfzXEtw3ZDi4f9U8eSvRIipHSyxOrJC7HR/hM5VhmY\n" +
75
"CErChny6x9lBVg9s57tfD/P9PSzBLusCcHwHMAbMOEcTltVVKUWZnnbumpywlYyg\n" +
76
"oKLrE9+yCOkYUOpiRlz43/3vkEL5hjIKMcDSZnPKBZi1h16Yj2hPe9GMibNip54=\n" +
77
"-----END X509 CRL-----";
78
79
private static X509CRL crl;
80
private static PublicKey selfSignedCertPubKey;
81
private static PublicKey crlIssuerCertPubKey;
82
83
public static void main(String[] args) throws Exception {
84
setup();
85
86
/*
87
* Verify CRL with its own public key.
88
* Should pass.
89
*/
90
verifyCRL(crlIssuerCertPubKey, "SunRsaSign");
91
92
/*
93
* Try to verify CRL with a provider that does not have a Signature
94
* implementation.
95
* Should fail with NoSuchAlgorithmException.
96
*/
97
try {
98
verifyCRL(crlIssuerCertPubKey, "SunJCE");
99
throw new RuntimeException("Didn't catch the exception properly");
100
} catch (NoSuchAlgorithmException e) {
101
System.out.println("Caught the correct exception.");
102
}
103
104
/*
105
* Try to verify CRL with a provider that has a Signature implementation
106
* but not of the right algorithm (MD5withRSA).
107
* Should fail with NoSuchAlgorithmException.
108
*/
109
try {
110
verifyCRL(crlIssuerCertPubKey, "SUN");
111
throw new RuntimeException("Didn't catch the exception properly");
112
} catch (NoSuchAlgorithmException e) {
113
System.out.println("Caught the correct exception.");
114
}
115
116
/*
117
* Try to verify CRL with the wrong public key.
118
* Should fail with SignatureException.
119
*/
120
try {
121
verifyCRL(selfSignedCertPubKey, "SunRsaSign");
122
throw new RuntimeException("Didn't catch the exception properly");
123
} catch (SignatureException e) {
124
System.out.println("Caught the correct exception.");
125
}
126
}
127
128
private static void setup() throws CertificateException, CRLException {
129
CertificateFactory cf = CertificateFactory.getInstance("X.509");
130
131
/* Create CRL */
132
ByteArrayInputStream inputStream =
133
new ByteArrayInputStream(crlStr.getBytes());
134
crl = (X509CRL)cf.generateCRL(inputStream);
135
136
/* Get public key of the CRL issuer cert */
137
inputStream = new ByteArrayInputStream(crlIssuerCertStr.getBytes());
138
X509Certificate cert
139
= (X509Certificate)cf.generateCertificate(inputStream);
140
crlIssuerCertPubKey = cert.getPublicKey();
141
142
/* Get public key of the self-signed Cert */
143
inputStream = new ByteArrayInputStream(selfSignedCertStr.getBytes());
144
selfSignedCertPubKey = cf.generateCertificate(inputStream).getPublicKey();
145
}
146
147
private static void verifyCRL(PublicKey key, String providerName)
148
throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
149
SignatureException {
150
Provider provider = Security.getProvider(providerName);
151
if (provider == null) {
152
throw new RuntimeException("Provider " + providerName
153
+ " not found.");
154
}
155
crl.verify(key, provider);
156
}
157
}
158
159