Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/SSLSession/KeyManagerTrustManager.java
41152 views
1
/*
2
* Copyright (c) 2001, 2011, 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 4387949 4302197 4396290 4395286
27
* @summary A compile test to make sure some of the new functionality
28
* is there. It doesn't actually call anything, just compiles it.
29
*
30
* 4387949: Need to add Sockets and key arrays to the
31
* X509KeyManager.choose*Alias() methods
32
* chooseServerAlias method is reverted back to accept a single
33
* keytype as a parameter, please see RFE: 4501014
34
* 4302197: There's no mechanism to select one key out of many in a keystore.
35
* 4396290: Need a way to pass algorithm specific parameters to TM's and KM's
36
* 4395286: The property for setting the default
37
* KeyManagerFactory/TrustManagerFactory algorithms needs real name
38
* @run main/othervm KeyManagerTrustManager
39
*
40
* SunJSSE does not support dynamic system properties, no way to re-use
41
* system properties in samevm/agentvm mode.
42
* @author Brad Wetmore
43
*/
44
45
import java.net.*;
46
import java.security.*;
47
import java.security.cert.*;
48
import java.security.spec.*;
49
import javax.net.ssl.*;
50
51
public class KeyManagerTrustManager implements X509KeyManager {
52
53
public String[] getServerAliases(String keyType, Principal[] issuers) {
54
return null;
55
}
56
public String[] getClientAliases(String keyType, Principal[] issuers) {
57
return null;
58
}
59
public String chooseServerAlias(String keyType, Principal[] issuers,
60
Socket socket) {
61
return null;
62
}
63
public String chooseClientAlias(String [] keyType, Principal[] issuers,
64
Socket socket) {
65
return null;
66
}
67
public PrivateKey getPrivateKey(String alias) {
68
return null;
69
}
70
public X509Certificate[] getCertificateChain(String alias) {
71
return null;
72
}
73
74
public void doit(KeyManagerFactory kmf, TrustManagerFactory tmf,
75
ManagerFactoryParameters mfp) throws Exception {
76
kmf.init(mfp);
77
tmf.init(mfp);
78
}
79
80
public static void main(String args[]) throws Exception {
81
String kmfAlg = null;
82
String tmfAlg = null;
83
84
// reserve the security properties
85
String reservedKMFacAlg =
86
Security.getProperty("ssl.KeyManagerFactory.algorithm");
87
String reservedTMFacAlg =
88
Security.getProperty("ssl.TrustManagerFactory.algorithm");
89
90
try {
91
Security.setProperty("ssl.KeyManagerFactory.algorithm", "hello");
92
Security.setProperty("ssl.TrustManagerFactory.algorithm",
93
"goodbye");
94
95
kmfAlg = KeyManagerFactory.getDefaultAlgorithm();
96
tmfAlg = TrustManagerFactory.getDefaultAlgorithm();
97
98
if (!kmfAlg.equals("hello")) {
99
throw new Exception("ssl.KeyManagerFactory.algorithm not set");
100
}
101
if (!tmfAlg.equals("goodbye")) {
102
throw new Exception(
103
"ssl.TrustManagerFactory.algorithm not set");
104
}
105
} finally {
106
// restore the security properties
107
if (reservedKMFacAlg == null) {
108
reservedKMFacAlg = "";
109
}
110
111
if (reservedTMFacAlg == null) {
112
reservedTMFacAlg = "";
113
}
114
Security.setProperty("ssl.KeyManagerFactory.algorithm",
115
reservedKMFacAlg);
116
Security.setProperty("ssl.TrustManagerFactory.algorithm",
117
reservedTMFacAlg);
118
}
119
}
120
}
121
122