Path: blob/master/test/jdk/sun/security/ssl/SSLEngineImpl/CloseStart.java
41152 views
/*1* Copyright (c) 2004, 2013, 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// SunJSSE does not support dynamic system properties, no way to re-use25// system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 501909631* @summary Add scatter/gather APIs for SSLEngine32* @run main/othervm CloseStart33*/3435//36// Check to see if the args are being parsed properly.37//3839import javax.net.ssl.*;40import javax.net.ssl.SSLEngineResult.*;41import java.io.*;42import java.security.*;43import java.nio.*;4445public class CloseStart {4647private static boolean debug = false;4849private static String pathToStores = "../../../../javax/net/ssl/etc";50private static String keyStoreFile = "keystore";51private static String trustStoreFile = "truststore";52private static String passwd = "passphrase";5354private static String keyFilename =55System.getProperty("test.src", "./") + "/" + pathToStores +56"/" + keyStoreFile;57private static String trustFilename =58System.getProperty("test.src", "./") + "/" + pathToStores +59"/" + trustStoreFile;6061private static void checkDone(SSLEngine ssle) throws Exception {62if (!ssle.isInboundDone()) {63throw new Exception("isInboundDone isn't done");64}65if (!ssle.isOutboundDone()) {66throw new Exception("isOutboundDone isn't done");67}68}6970private static void runTest2(SSLEngine ssle) throws Exception {71ssle.closeOutbound();72checkDone(ssle);73}7475public static void main(String args[]) throws Exception {7677SSLEngine ssle = createSSLEngine(keyFilename, trustFilename);78ssle.closeInbound();79if (!ssle.isInboundDone()) {80throw new Exception("isInboundDone isn't done");81}8283ssle = createSSLEngine(keyFilename, trustFilename);84ssle.closeOutbound();85if (!ssle.isOutboundDone()) {86throw new Exception("isOutboundDone isn't done");87}8889System.out.println("Test Passed.");90}9192/*93* Create an initialized SSLContext to use for this test.94*/95static private SSLEngine createSSLEngine(String keyFile, String trustFile)96throws Exception {9798SSLEngine ssle;99100KeyStore ks = KeyStore.getInstance("JKS");101KeyStore ts = KeyStore.getInstance("JKS");102103char[] passphrase = "passphrase".toCharArray();104105ks.load(new FileInputStream(keyFile), passphrase);106ts.load(new FileInputStream(trustFile), passphrase);107108KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");109kmf.init(ks, passphrase);110111TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");112tmf.init(ts);113114SSLContext sslCtx = SSLContext.getInstance("TLS");115116sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);117118ssle = sslCtx.createSSLEngine("client", 1001);119ssle.setUseClientMode(true);120121return ssle;122}123}124125126