FileDocCategorySizeDatePackage
SSLContext.javaAPI DocAndroid 1.5 API9759Wed May 06 22:41:06 BST 2009javax.net.ssl

SSLContext

public class SSLContext extends Object
The public API for secure socket protocol implementations. It acts as factory for {@code SSLSocketFactory}'s and {@code SSLEngine}s.
since
Android 1.0

Fields Summary
private static final String
SERVICE
private static org.apache.harmony.security.fortress.Engine
engine
private final Provider
provider
private final SSLContextSpi
spiImpl
private final String
protocol
Constructors Summary
protected SSLContext(SSLContextSpi contextSpi, Provider provider, String protocol)
Creates a new {@code SSLContext}.

param
contextSpi the implementation delegate.
param
provider the provider.
param
protocol the protocol name.
since
Android 1.0


                                                                 
        
              
        this.provider = provider;
        this.protocol = protocol;
        this.spiImpl = contextSpi;
    
Methods Summary
public final javax.net.ssl.SSLEnginecreateSSLEngine()
Creates an {@code SSLEngine} instance from this context.

return
an {@code SSLEngine} instance from this context.
throws
UnsupportedOperationException if the provider does not support the operation.
since
Android 1.0

        return spiImpl.engineCreateSSLEngine();
    
public final javax.net.ssl.SSLEnginecreateSSLEngine(java.lang.String peerHost, int peerPort)
Creates an {@code SSLEngine} instance from this context with the specified hostname and port.

param
peerHost the name of the host
param
peerPort the port
return
an {@code SSLEngine} instance from this context.
throws
UnsupportedOperationException if the provider does not support the operation.
since
Android 1.0

        return spiImpl.engineCreateSSLEngine(peerHost, peerPort);
    
public final javax.net.ssl.SSLSessionContextgetClientSessionContext()
Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of client-side SSL sockets.

return
the SSL client session context for this context or {@code null} if the underlying provider does not provide an implementation of the {@code SSLSessionContext} interface.
since
Android 1.0

        return spiImpl.engineGetClientSessionContext();
    
public static javax.net.ssl.SSLContextgetInstance(java.lang.String protocol)
Creates a new {@code SSLContext} instance for the specified protocol.

param
protocol the requested protocol to create a context for.
return
the created {@code SSLContext} instance.
throws
NoSuchAlgorithmException if no installed provider can provide the requested protocol
throws
NullPointerException if {@code protocol} is {@code null} (instead of NoSuchAlgorithmException as in 1.4 release)
since
Android 1.0

        if (protocol == null) {
            throw new NullPointerException("protocol is null");
        }
        synchronized (engine) {
            engine.getInstance(protocol, null);
            return new SSLContext((SSLContextSpi) engine.spi, engine.provider,
                    protocol);
        }
    
public static javax.net.ssl.SSLContextgetInstance(java.lang.String protocol, java.lang.String provider)
Creates a new {@code SSLContext} instance for the specified protocol from the specified provider.

param
protocol the requested protocol to create a context for.
param
provider the name of the provider that provides the requested protocol.
return
an {@code SSLContext} for the requested protocol.
throws
NoSuchAlgorithmException if the specified provider cannot provider the requested protocol.
throws
NoSuchProviderException if the specified provider does not exits.
throws
NullPointerException if {@code protocol} is {@code null} (instead of NoSuchAlgorithmException as in 1.4 release)
since
Android 1.0

        if (provider == null) {
            throw new IllegalArgumentException("Provider is null");
        }
        if (provider.length() == 0) {
            throw new IllegalArgumentException("Provider is empty");
        }
        Provider impProvider = Security.getProvider(provider);
        if (impProvider == null) {
            throw new NoSuchProviderException(provider);
        }
        return getInstance(protocol, impProvider);
    
public static javax.net.ssl.SSLContextgetInstance(java.lang.String protocol, java.security.Provider provider)
Creates a new {@code SSLContext} instance for the specified protocol from the specified provider.

param
protocol the requested protocol to create a context for
param
provider the provider that provides the requested protocol.
return
an {@code SSLContext} for the requested protocol.
throws
NoSuchAlgorithmException if the specified provider cannot provide the requested protocol.
throws
NullPointerException if {@code protocol} is {@code null} (instead of NoSuchAlgorithmException as in 1.4 release)
since
Android 1.0

        if (provider == null) {
            throw new IllegalArgumentException("provider is null");
        }
        if (protocol == null) {
            throw new NullPointerException("protocol is null");
        }
        synchronized (engine) {
            engine.getInstance(protocol, provider, null);
            return new SSLContext((SSLContextSpi) engine.spi, provider, protocol);
        }
    
public final java.lang.StringgetProtocol()
Returns the name of the secure socket protocol of this instance.

return
the name of the secure socket protocol of this instance.
since
Android 1.0

        return protocol;
    
public final java.security.ProvidergetProvider()
Returns the provider of this {@code SSLContext} instance.

return
the provider of this {@code SSLContext} instance.
since
Android 1.0

        return provider;
    
public final javax.net.ssl.SSLSessionContextgetServerSessionContext()
Returns the SSL session context that encapsulates the set of SSL sessions that can be used for handshake of server-side SSL sockets.

return
the SSL server session context for this context or {@code null} if the underlying provider does not provide an implementation of the {@code SSLSessionContext} interface.
since
Android 1.0

        return spiImpl.engineGetServerSessionContext();
    
public final javax.net.ssl.SSLServerSocketFactorygetServerSocketFactory()
Returns a server socket factory for this instance.

return
a server socket factory for this instance.
since
Android 1.0

        return spiImpl.engineGetServerSocketFactory();
    
public final javax.net.ssl.SSLSocketFactorygetSocketFactory()
Returns a socket factory for this instance.

return
a socket factory for this instance.
since
Android 1.0

        return spiImpl.engineGetSocketFactory();
    
public final voidinit(javax.net.ssl.KeyManager[] km, javax.net.ssl.TrustManager[] tm, java.security.SecureRandom sr)
Initializes this {@code SSLContext} instance. All of the arguments are optional, and the security providers will be searched for the required implementations of the needed algorithms.

param
km the key sources or {@code null}.
param
tm the trust decision sources or {@code null}.
param
sr the randomness source or {@code null.}
throws
KeyManagementException if initializing this instance fails.
since
Android 1.0

        spiImpl.engineInit(km, tm, sr);