Path: blob/master/test/jdk/javax/net/ssl/sanity/pluggability/CheckSockFacExport2.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 463545426* @summary Check pluggability of SSLSocketFactory and27* SSLServerSocketFactory classes.28* @run main/othervm CheckSockFacExport229*30* SunJSSE does not support dynamic system properties, no way to re-use31* system properties in samevm/agentvm mode.32*/33import java.security.*;34import java.net.*;35import javax.net.ssl.*;3637public class CheckSockFacExport2 {3839public static void main(String argv[]) throws Exception {40// reserve the security properties41String reservedSFacAlg =42Security.getProperty("ssl.SocketFactory.provider");43String reservedSSFacAlg =44Security.getProperty("ssl.ServerSocketFactory.provider");4546try {47Security.setProperty("ssl.SocketFactory.provider",48"MySSLSocketFacImpl");49MySSLSocketFacImpl.useStandardCipherSuites();50Security.setProperty("ssl.ServerSocketFactory.provider",51"MySSLServerSocketFacImpl");52MySSLServerSocketFacImpl.useStandardCipherSuites();5354boolean result = false;55for (int i = 0; i < 2; i++) {56switch (i) {57case 0:58System.out.println("Testing SSLSocketFactory:");59SSLSocketFactory sf = (SSLSocketFactory)60SSLSocketFactory.getDefault();61result = (sf instanceof MySSLSocketFacImpl);62break;6364case 1:65System.out.println("Testing SSLServerSocketFactory:");66SSLServerSocketFactory ssf = (SSLServerSocketFactory)67SSLServerSocketFactory.getDefault();68result = (ssf instanceof MySSLServerSocketFacImpl);69break;70default:71throw new Exception("Internal Test Error");72}73if (result) {74System.out.println("...accepted valid SFs");75} else {76throw new Exception("...wrong SF is used");77}78}79System.out.println("Test Passed");80} finally {81// restore the security properties82if (reservedSFacAlg == null) {83reservedSFacAlg = "";84}8586if (reservedSSFacAlg == null) {87reservedSSFacAlg = "";88}89Security.setProperty("ssl.SocketFactory.provider",90reservedSFacAlg);91Security.setProperty("ssl.ServerSocketFactory.provider",92reservedSSFacAlg);93}94}95}969798