Path: blob/master/test/jdk/javax/net/ssl/SSLSession/CheckSessionContext.java
41152 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @library /javax/net/ssl/templates26* @bug 824200827* @summary Verify SSLSession.getSessionContext() is not null for the initial28* and the resumed session29* @run main/othervm -Djdk.tls.client.protocols=TLSv1.2 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=false CheckSessionContext30* @run main/othervm -Djdk.tls.client.protocols=TLSv1.2 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=true CheckSessionContext31* @run main/othervm -Djdk.tls.client.protocols=TLSv1.3 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=false CheckSessionContext32* @run main/othervm -Djdk.tls.client.protocols=TLSv1.3 -Djdk.tls.server.enableSessionTicketExtension=true -Djdk.tls.client.enableSessionTicketExtension=true CheckSessionContext33* @run main/othervm -Djdk.tls.client.protocols=TLSv1.3 -Djdk.tls.server.enableSessionTicketExtension=false -Djdk.tls.client.enableSessionTicketExtension=true CheckSessionContext34*35*/3637import javax.net.ssl.SSLSession;3839public class CheckSessionContext {4041static void toHex(byte[] id) {42for (byte b : id) {43System.out.printf("%02X ", b);44}45System.out.println();46}4748public static void main(String[] args) throws Exception {49TLSBase.Server server = new TLSBase.Server();5051// Initial client session52TLSBase.Client client1 = new TLSBase.Client();53if (server.getSession(client1).getSessionContext() == null) {54throw new Exception("Context was null");55} else {56System.out.println("Context was found");57}58SSLSession ss = server.getSession(client1);59System.out.println(ss);60byte[] id = ss.getId();61System.out.print("id = ");62toHex(id);63System.out.println("ss.getSessionContext().getSession(id) = " + ss.getSessionContext().getSession(id));64if (ss.getSessionContext().getSession(id) != null) {65id = ss.getSessionContext().getSession(id).getId();66System.out.print("id = ");67toHex(id);68}69server.close(client1);70client1.close();7172// Resume the client session73TLSBase.Client client2 = new TLSBase.Client();74if (server.getSession(client2).getSessionContext() == null) {75throw new Exception("Context was null on resumption");76} else {77System.out.println("Context was found on resumption");78}79server.close(client2);80client2.close();81server.done();82}83}848586