Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/sanity/pluggability/CheckSockFacExport2.java
41155 views
1
/*
2
* Copyright (c) 2003, 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 4635454
27
* @summary Check pluggability of SSLSocketFactory and
28
* SSLServerSocketFactory classes.
29
* @run main/othervm CheckSockFacExport2
30
*
31
* SunJSSE does not support dynamic system properties, no way to re-use
32
* system properties in samevm/agentvm mode.
33
*/
34
import java.security.*;
35
import java.net.*;
36
import javax.net.ssl.*;
37
38
public class CheckSockFacExport2 {
39
40
public static void main(String argv[]) throws Exception {
41
// reserve the security properties
42
String reservedSFacAlg =
43
Security.getProperty("ssl.SocketFactory.provider");
44
String reservedSSFacAlg =
45
Security.getProperty("ssl.ServerSocketFactory.provider");
46
47
try {
48
Security.setProperty("ssl.SocketFactory.provider",
49
"MySSLSocketFacImpl");
50
MySSLSocketFacImpl.useStandardCipherSuites();
51
Security.setProperty("ssl.ServerSocketFactory.provider",
52
"MySSLServerSocketFacImpl");
53
MySSLServerSocketFacImpl.useStandardCipherSuites();
54
55
boolean result = false;
56
for (int i = 0; i < 2; i++) {
57
switch (i) {
58
case 0:
59
System.out.println("Testing SSLSocketFactory:");
60
SSLSocketFactory sf = (SSLSocketFactory)
61
SSLSocketFactory.getDefault();
62
result = (sf instanceof MySSLSocketFacImpl);
63
break;
64
65
case 1:
66
System.out.println("Testing SSLServerSocketFactory:");
67
SSLServerSocketFactory ssf = (SSLServerSocketFactory)
68
SSLServerSocketFactory.getDefault();
69
result = (ssf instanceof MySSLServerSocketFacImpl);
70
break;
71
default:
72
throw new Exception("Internal Test Error");
73
}
74
if (result) {
75
System.out.println("...accepted valid SFs");
76
} else {
77
throw new Exception("...wrong SF is used");
78
}
79
}
80
System.out.println("Test Passed");
81
} finally {
82
// restore the security properties
83
if (reservedSFacAlg == null) {
84
reservedSFacAlg = "";
85
}
86
87
if (reservedSSFacAlg == null) {
88
reservedSSFacAlg = "";
89
}
90
Security.setProperty("ssl.SocketFactory.provider",
91
reservedSFacAlg);
92
Security.setProperty("ssl.ServerSocketFactory.provider",
93
reservedSSFacAlg);
94
}
95
}
96
}
97
98