Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/net/ssl/SSLContextSpi.java
38918 views
/*1* Copyright (c) 1999, 2012, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.net.ssl;2627import java.security.*;2829/**30* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)31* for the <code>SSLContext</code> class.32*33* <p> All the abstract methods in this class must be implemented by each34* cryptographic service provider who wishes to supply the implementation35* of a particular SSL context.36*37* @since 1.438* @see SSLContext39*/40public abstract class SSLContextSpi {41/**42* Initializes this context.43*44* @param km the sources of authentication keys45* @param tm the sources of peer authentication trust decisions46* @param sr the source of randomness47* @throws KeyManagementException if this operation fails48* @see SSLContext#init(KeyManager [], TrustManager [], SecureRandom)49*/50protected abstract void engineInit(KeyManager[] km, TrustManager[] tm,51SecureRandom sr) throws KeyManagementException;5253/**54* Returns a <code>SocketFactory</code> object for this55* context.56*57* @return the <code>SocketFactory</code> object58* @throws IllegalStateException if the SSLContextImpl requires59* initialization and the <code>engineInit()</code>60* has not been called61* @see javax.net.ssl.SSLContext#getSocketFactory()62*/63protected abstract SSLSocketFactory engineGetSocketFactory();6465/**66* Returns a <code>ServerSocketFactory</code> object for67* this context.68*69* @return the <code>ServerSocketFactory</code> object70* @throws IllegalStateException if the SSLContextImpl requires71* initialization and the <code>engineInit()</code>72* has not been called73* @see javax.net.ssl.SSLContext#getServerSocketFactory()74*/75protected abstract SSLServerSocketFactory engineGetServerSocketFactory();7677/**78* Creates a new <code>SSLEngine</code> using this context.79* <P>80* Applications using this factory method are providing no hints81* for an internal session reuse strategy. If hints are desired,82* {@link #engineCreateSSLEngine(String, int)} should be used83* instead.84* <P>85* Some cipher suites (such as Kerberos) require remote hostname86* information, in which case this factory method should not be used.87*88* @return the <code>SSLEngine</code> Object89* @throws IllegalStateException if the SSLContextImpl requires90* initialization and the <code>engineInit()</code>91* has not been called92*93* @see SSLContext#createSSLEngine()94*95* @since 1.596*/97protected abstract SSLEngine engineCreateSSLEngine();9899/**100* Creates a <code>SSLEngine</code> using this context.101* <P>102* Applications using this factory method are providing hints103* for an internal session reuse strategy.104* <P>105* Some cipher suites (such as Kerberos) require remote hostname106* information, in which case peerHost needs to be specified.107*108* @param host the non-authoritative name of the host109* @param port the non-authoritative port110* @return the <code>SSLEngine</code> Object111* @throws IllegalStateException if the SSLContextImpl requires112* initialization and the <code>engineInit()</code>113* has not been called114*115* @see SSLContext#createSSLEngine(String, int)116*117* @since 1.5118*/119protected abstract SSLEngine engineCreateSSLEngine(String host, int port);120121/**122* Returns a server <code>SSLSessionContext</code> object for123* this context.124*125* @return the <code>SSLSessionContext</code> object126* @see javax.net.ssl.SSLContext#getServerSessionContext()127*/128protected abstract SSLSessionContext engineGetServerSessionContext();129130/**131* Returns a client <code>SSLSessionContext</code> object for132* this context.133*134* @return the <code>SSLSessionContext</code> object135* @see javax.net.ssl.SSLContext#getClientSessionContext()136*/137protected abstract SSLSessionContext engineGetClientSessionContext();138139private SSLSocket getDefaultSocket() {140try {141SSLSocketFactory factory = engineGetSocketFactory();142return (SSLSocket)factory.createSocket();143} catch (java.io.IOException e) {144throw new UnsupportedOperationException("Could not obtain parameters", e);145}146}147148/**149* Returns a copy of the SSLParameters indicating the default150* settings for this SSL context.151*152* <p>The parameters will always have the ciphersuite and protocols153* arrays set to non-null values.154*155* <p>The default implementation obtains the parameters from an156* SSLSocket created by calling the157* {@linkplain javax.net.SocketFactory#createSocket158* SocketFactory.createSocket()} method of this context's SocketFactory.159*160* @return a copy of the SSLParameters object with the default settings161* @throws UnsupportedOperationException if the default SSL parameters162* could not be obtained.163*164* @since 1.6165*/166protected SSLParameters engineGetDefaultSSLParameters() {167SSLSocket socket = getDefaultSocket();168return socket.getSSLParameters();169}170171/**172* Returns a copy of the SSLParameters indicating the maximum supported173* settings for this SSL context.174*175* <p>The parameters will always have the ciphersuite and protocols176* arrays set to non-null values.177*178* <p>The default implementation obtains the parameters from an179* SSLSocket created by calling the180* {@linkplain javax.net.SocketFactory#createSocket181* SocketFactory.createSocket()} method of this context's SocketFactory.182*183* @return a copy of the SSLParameters object with the maximum supported184* settings185* @throws UnsupportedOperationException if the supported SSL parameters186* could not be obtained.187*188* @since 1.6189*/190protected SSLParameters engineGetSupportedSSLParameters() {191SSLSocket socket = getDefaultSocket();192SSLParameters params = new SSLParameters();193params.setCipherSuites(socket.getSupportedCipherSuites());194params.setProtocols(socket.getSupportedProtocols());195return params;196}197198}199200201