Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLEngineImpl/CloseStart.java
41152 views
1
/*
2
* Copyright (c) 2004, 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
// SunJSSE does not support dynamic system properties, no way to re-use
26
// system properties in samevm/agentvm mode.
27
//
28
29
/*
30
* @test
31
* @bug 5019096
32
* @summary Add scatter/gather APIs for SSLEngine
33
* @run main/othervm CloseStart
34
*/
35
36
//
37
// Check to see if the args are being parsed properly.
38
//
39
40
import javax.net.ssl.*;
41
import javax.net.ssl.SSLEngineResult.*;
42
import java.io.*;
43
import java.security.*;
44
import java.nio.*;
45
46
public class CloseStart {
47
48
private static boolean debug = false;
49
50
private static String pathToStores = "../../../../javax/net/ssl/etc";
51
private static String keyStoreFile = "keystore";
52
private static String trustStoreFile = "truststore";
53
private static String passwd = "passphrase";
54
55
private static String keyFilename =
56
System.getProperty("test.src", "./") + "/" + pathToStores +
57
"/" + keyStoreFile;
58
private static String trustFilename =
59
System.getProperty("test.src", "./") + "/" + pathToStores +
60
"/" + trustStoreFile;
61
62
private static void checkDone(SSLEngine ssle) throws Exception {
63
if (!ssle.isInboundDone()) {
64
throw new Exception("isInboundDone isn't done");
65
}
66
if (!ssle.isOutboundDone()) {
67
throw new Exception("isOutboundDone isn't done");
68
}
69
}
70
71
private static void runTest2(SSLEngine ssle) throws Exception {
72
ssle.closeOutbound();
73
checkDone(ssle);
74
}
75
76
public static void main(String args[]) throws Exception {
77
78
SSLEngine ssle = createSSLEngine(keyFilename, trustFilename);
79
ssle.closeInbound();
80
if (!ssle.isInboundDone()) {
81
throw new Exception("isInboundDone isn't done");
82
}
83
84
ssle = createSSLEngine(keyFilename, trustFilename);
85
ssle.closeOutbound();
86
if (!ssle.isOutboundDone()) {
87
throw new Exception("isOutboundDone isn't done");
88
}
89
90
System.out.println("Test Passed.");
91
}
92
93
/*
94
* Create an initialized SSLContext to use for this test.
95
*/
96
static private SSLEngine createSSLEngine(String keyFile, String trustFile)
97
throws Exception {
98
99
SSLEngine ssle;
100
101
KeyStore ks = KeyStore.getInstance("JKS");
102
KeyStore ts = KeyStore.getInstance("JKS");
103
104
char[] passphrase = "passphrase".toCharArray();
105
106
ks.load(new FileInputStream(keyFile), passphrase);
107
ts.load(new FileInputStream(trustFile), passphrase);
108
109
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
110
kmf.init(ks, passphrase);
111
112
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
113
tmf.init(ts);
114
115
SSLContext sslCtx = SSLContext.getInstance("TLS");
116
117
sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
118
119
ssle = sslCtx.createSSLEngine("client", 1001);
120
ssle.setUseClientMode(true);
121
122
return ssle;
123
}
124
}
125
126