Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/SSLSession/CheckSessionContext.java
41152 views
1
/*
2
* Copyright (c) 2020, 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
* @library /javax/net/ssl/templates
27
* @bug 8242008
28
* @summary Verify SSLSession.getSessionContext() is not null for the initial
29
* and the resumed session
30
* @run main/othervm -Djdk.tls.client.protocols=TLSv1.2 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=false CheckSessionContext
31
* @run main/othervm -Djdk.tls.client.protocols=TLSv1.2 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=true CheckSessionContext
32
* @run main/othervm -Djdk.tls.client.protocols=TLSv1.3 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=false CheckSessionContext
33
* @run main/othervm -Djdk.tls.client.protocols=TLSv1.3 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=true CheckSessionContext
34
* @run main/othervm -Djdk.tls.client.protocols=TLSv1.3 -Djdk.tls.server.enableSessionTicketExtension=false -Djdk.tls.client.enableSessionTicketExtension=true CheckSessionContext
35
*
36
*/
37
38
import javax.net.ssl.SSLSession;
39
40
public class CheckSessionContext {
41
42
static void toHex(byte[] id) {
43
for (byte b : id) {
44
System.out.printf("%02X ", b);
45
}
46
System.out.println();
47
}
48
49
public static void main(String[] args) throws Exception {
50
TLSBase.Server server = new TLSBase.Server();
51
52
// Initial client session
53
TLSBase.Client client1 = new TLSBase.Client();
54
if (server.getSession(client1).getSessionContext() == null) {
55
throw new Exception("Context was null");
56
} else {
57
System.out.println("Context was found");
58
}
59
SSLSession ss = server.getSession(client1);
60
System.out.println(ss);
61
byte[] id = ss.getId();
62
System.out.print("id = ");
63
toHex(id);
64
System.out.println("ss.getSessionContext().getSession(id) = " + ss.getSessionContext().getSession(id));
65
if (ss.getSessionContext().getSession(id) != null) {
66
id = ss.getSessionContext().getSession(id).getId();
67
System.out.print("id = ");
68
toHex(id);
69
}
70
server.close(client1);
71
client1.close();
72
73
// Resume the client session
74
TLSBase.Client client2 = new TLSBase.Client();
75
if (server.getSession(client2).getSessionContext() == null) {
76
throw new Exception("Context was null on resumption");
77
} else {
78
System.out.println("Context was found on resumption");
79
}
80
server.close(client2);
81
client2.close();
82
server.done();
83
}
84
}
85
86