1 /* 2 * Copyright (c) 2001, 2016, 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 4387882 27 * @summary Need to revisit the javadocs for JSSE, especially the 28 * promoted classes. 29 * @library /javax/net/ssl/templates 30 * @run main/othervm SSLSessionNulls 31 * 32 * SunJSSE does not support dynamic system properties, no way to re-use 33 * system properties in samevm/agentvm mode. 34 * @author Brad Wetmore 35 */ 36 37 import java.io.IOException; 38 import java.io.InputStream; 39 import java.io.OutputStream; 40 41 import javax.net.ssl.SSLSession; 42 43 public class SSLSessionNulls { 44 45 /* 46 * Where do we find the keystores? 47 */ 48 static String pathToStores = "../etc"; 49 static String keyStoreFile = "keystore"; 50 static String trustStoreFile = "truststore"; 51 static String passwd = "passphrase"; 52 53 public static void main(String[] args) throws Exception { 54 String keyFilename = 55 System.getProperty("test.src", "./") + "/" + pathToStores + 56 "/" + keyStoreFile; 57 String trustFilename = 58 System.getProperty("test.src", "./") + "/" + pathToStores + 59 "/" + trustStoreFile; 60 SSLTest.setup(keyFilename, trustFilename, passwd); 61 62 new SSLTest() 63 .setServerApplication((socket, test) -> { 64 InputStream sslIS = socket.getInputStream(); 65 OutputStream sslOS = socket.getOutputStream(); 66 67 sslIS.read(); 68 sslOS.write(85); 69 sslOS.flush(); 70 }) 71 .setClientApplication((socket, test) -> { 72 InputStream sslIS = socket.getInputStream(); 73 OutputStream sslOS = socket.getOutputStream(); 74 75 sslOS.write(280); 76 sslOS.flush(); 77 sslIS.read(); 78 79 SSLSession sslSession = socket.getSession(); 80 81 try { 82 sslSession.getValue(null); 83 } catch (IllegalArgumentException e) { 84 System.out.print("Caught proper exception: "); 85 System.out.println(e.getMessage()); 86 } 87 88 try { 89 sslSession.putValue(null, null); 90 } catch (IllegalArgumentException e) { 91 System.out.print("Caught proper exception: "); 92 System.out.println(e.getMessage()); 93 } 94 95 try { 96 sslSession.removeValue(null); 97 } catch (IllegalArgumentException e) { 98 System.out.print("Caught proper exception: "); 99 System.out.println(e.getMessage()); 100 } 101 102 String [] names = sslSession.getValueNames(); 103 if ((names == null) || (names.length != 0)) { 104 throw new IOException( 105 "getValueNames didn't return 0-length arrary"); 106 } 107 }) 108 .runTest(); 109 } 110 }