Path: blob/master/test/jdk/javax/net/ssl/sanity/pluggability/CheckSockFacExport1.java
41155 views
/*1* Copyright (c) 2003, 2011, 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* @bug 4635454 620802226* @summary Check pluggability of SSLSocketFactory and27* SSLServerSocketFactory classes.28* @run main/othervm CheckSockFacExport129*30* SunJSSE does not support dynamic system properties, no way to re-use31* system properties in samevm/agentvm mode.32*/3334import java.util.*;3536import java.security.*;37import java.net.*;38import javax.net.ssl.*;3940public class CheckSockFacExport1 {4142public static void main(String argv[]) throws Exception {43// reserve the security properties44String reservedSFacAlg =45Security.getProperty("ssl.SocketFactory.provider");46String reservedSSFacAlg =47Security.getProperty("ssl.ServerSocketFactory.provider");4849try {50Security.setProperty("ssl.SocketFactory.provider",51"MySSLSocketFacImpl");52MySSLSocketFacImpl.useCustomCipherSuites();53Security.setProperty("ssl.ServerSocketFactory.provider",54"MySSLServerSocketFacImpl");55MySSLServerSocketFacImpl.useCustomCipherSuites();5657String[] supportedCS = null;58for (int i = 0; i < 2; i++) {59switch (i) {60case 0:61System.out.println("Testing SSLSocketFactory:");62SSLSocketFactory sf = (SSLSocketFactory)63SSLSocketFactory.getDefault();64supportedCS = sf.getSupportedCipherSuites();65break;66case 1:67System.out.println("Testing SSLServerSocketFactory:");68SSLServerSocketFactory ssf = (SSLServerSocketFactory)69SSLServerSocketFactory.getDefault();70supportedCS = ssf.getSupportedCipherSuites();71break;72default:73throw new Exception("Internal Test Error");74}75System.out.println(Arrays.asList(supportedCS));76if (supportedCS.length == 0) {77throw new Exception("supported ciphersuites are empty");78}79}80System.out.println("Test Passed");81} finally {82// restore the security properties83if (reservedSFacAlg == null) {84reservedSFacAlg = "";85}8687if (reservedSSFacAlg == null) {88reservedSSFacAlg = "";89}90Security.setProperty("ssl.SocketFactory.provider",91reservedSFacAlg);92Security.setProperty("ssl.ServerSocketFactory.provider",93reservedSSFacAlg);94}95}96}979899