src/java.base/share/classes/javax/net/ssl/SSLContext.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45118 jdk/src/java.base/share/classes/javax/net/ssl/SSLContext.java@e4258d800b54
child 52762 b3866f3879e1
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 473
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 473
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 473
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 473
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 473
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.net.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.*;
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
    29
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.security.jca.GetInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Instances of this class represent a secure socket protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * implementation which acts as a factory for secure socket
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    36
 * factories or {@code SSLEngine}s. This class is initialized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * with an optional set of key and trust managers and source of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * secure random bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
    40
 * <p> Every implementation of the Java platform is required to support the
32647
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 32210
diff changeset
    41
 * following standard {@code SSLContext} protocols:
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
    42
 * <ul>
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 30904
diff changeset
    43
 * <li>{@code TLSv1}</li>
32647
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 32210
diff changeset
    44
 * <li>{@code TLSv1.1}</li>
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 32210
diff changeset
    45
 * <li>{@code TLSv1.2}</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
    46
 * </ul>
32647
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 32210
diff changeset
    47
 * These protocols are described in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
    48
 * "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms">
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
    49
 * SSLContext section</a> of the
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
    50
 * Java Security Standard Algorithm Names Specification.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
    51
 * Consult the release documentation for your implementation to see if any
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
    52
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
    53
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class SSLContext {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private final Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private final SSLContextSpi contextSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final String protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Creates an SSLContext object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @param contextSpi the delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param protocol the protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected SSLContext(SSLContextSpi contextSpi, Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            String protocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.contextSpi = contextSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.protocol = protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static SSLContext defaultContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Returns the default SSL context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * <p>If a default context was set using the {@link #setDefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * SSLContext.setDefault()} method, it is returned. Otherwise, the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * call of this method triggers the call
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    85
     * {@code SSLContext.getInstance("Default")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * If successful, that object is made the default SSL context and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * <p>The default context is immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * usable and does not require {@linkplain #init initialization}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @return the default SSL context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @throws NoSuchAlgorithmException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *   {@link SSLContext#getInstance SSLContext.getInstance()} call fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static synchronized SSLContext getDefault()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (defaultContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            defaultContext = SSLContext.getInstance("Default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return defaultContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Sets the default SSL context. It will be returned by subsequent calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * to {@link #getDefault}. The default context must be immediately usable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * and not require {@linkplain #init initialization}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param context the SSLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @throws  NullPointerException if context is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @throws  SecurityException if a security manager exists and its
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   112
     *          {@code checkPermission} method does not allow
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   113
     *          {@code SSLPermission("setDefaultSSLContext")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static synchronized void setDefault(SSLContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            sm.checkPermission(new SSLPermission("setDefaultSSLContext"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        defaultContext = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   128
     * Returns a {@code SSLContext} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * specified secure socket protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * A new SSLContext object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * SSLContextSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Provider that supports the specified protocol is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   140
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   141
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   142
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   143
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   144
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   145
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   146
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   147
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param protocol the standard name of the requested protocol.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
   149
     *          See the SSLContext section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   150
     * "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   151
     *          Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *          for information about standard protocol names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   154
     * @return the new {@code SSLContext} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   156
     * @throws NoSuchAlgorithmException if no {@code Provider} supports a
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   157
     *         {@code SSLContextSpi} implementation for the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   158
     *         specified protocol
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   159
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   160
     * @throws NullPointerException if {@code protocol} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static SSLContext getInstance(String protocol)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throws NoSuchAlgorithmException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   166
        Objects.requireNonNull(protocol, "null protocol name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                ("SSLContext", SSLContextSpi.class, protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   174
     * Returns a {@code SSLContext} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * specified secure socket protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <p> A new SSLContext object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * SSLContextSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param protocol the standard name of the requested protocol.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
   186
     *          See the SSLContext section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   187
     * "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   188
     *          Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *          for information about standard protocol names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   193
     * @return the new {@code SSLContext} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   195
     * @throws IllegalArgumentException if the provider name is
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   196
     *         {@code null} or empty
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   197
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   198
     * @throws NoSuchAlgorithmException if a {@code SSLContextSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   199
     *         implementation for the specified protocol is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   200
     *         available from the specified provider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @throws NoSuchProviderException if the specified provider is not
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   203
     *         registered in the security provider list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   205
     * @throws NullPointerException if {@code protocol} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public static SSLContext getInstance(String protocol, String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            throws NoSuchAlgorithmException, NoSuchProviderException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   211
        Objects.requireNonNull(protocol, "null protocol name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                ("SSLContext", SSLContextSpi.class, protocol, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   219
     * Returns a {@code SSLContext} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * specified secure socket protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <p> A new SSLContext object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * SSLContextSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param protocol the standard name of the requested protocol.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5820
diff changeset
   228
     *          See the SSLContext section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   229
     * "{@docRoot}/../specs/security/standard-names.html#sslcontext-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   230
     *          Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *          for information about standard protocol names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param provider an instance of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   235
     * @return the new {@code SSLContext} object
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   236
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   237
     * @throws IllegalArgumentException if the provider is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   239
     * @throws NoSuchAlgorithmException if a {@code SSLContextSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   240
     *         implementation for the specified protocol is not available
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   241
     *         from the specified {@code Provider} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   243
     * @throws NullPointerException if {@code protocol} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public static SSLContext getInstance(String protocol, Provider provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            throws NoSuchAlgorithmException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   249
        Objects.requireNonNull(protocol, "null protocol name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                ("SSLContext", SSLContextSpi.class, protocol, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   257
     * Returns the protocol name of this {@code SSLContext} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * <p>This is the same name that was specified in one of the
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   260
     * {@code getInstance} calls that created this
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   261
     * {@code SSLContext} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   263
     * @return the protocol name of this {@code SSLContext} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public final String getProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return this.protocol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   270
     * Returns the provider of this {@code SSLContext} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   272
     * @return the provider of this {@code SSLContext} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Initializes this context. Either of the first two parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * may be null in which case the installed security providers will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * be searched for the highest priority implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * appropriate factory. Likewise, the secure random parameter may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * be null in which case the default implementation will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Only the first instance of a particular key and/or trust manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * implementation type in the array is used.  (For example, only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * the first javax.net.ssl.X509KeyManager in the array will be used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param km the sources of authentication keys or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param tm the sources of peer authentication trust decisions or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param random the source of randomness for this generator or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @throws KeyManagementException if this operation fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public final void init(KeyManager[] km, TrustManager[] tm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        contextSpi.engineInit(km, tm, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   301
     * Returns a {@code SocketFactory} object for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   304
     * @return the {@code SocketFactory} object
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   305
     * @throws UnsupportedOperationException if the underlying provider
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   306
     *         does not implement the operation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @throws IllegalStateException if the SSLContextImpl requires
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   308
     *         initialization and the {@code init()} has not been called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public final SSLSocketFactory getSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return contextSpi.engineGetSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   315
     * Returns a {@code ServerSocketFactory} object for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   318
     * @return the {@code ServerSocketFactory} object
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   319
     * @throws UnsupportedOperationException if the underlying provider
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   320
     *         does not implement the operation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @throws IllegalStateException if the SSLContextImpl requires
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   322
     *         initialization and the {@code init()} has not been called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public final SSLServerSocketFactory getServerSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return contextSpi.engineGetServerSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   329
     * Creates a new {@code SSLEngine} using this context.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Applications using this factory method are providing no hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * for an internal session reuse strategy. If hints are desired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * {@link #createSSLEngine(String, int)} should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Some cipher suites (such as Kerberos) require remote hostname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * information, in which case this factory method should not be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   339
     * @return  the {@code SSLEngine} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @throws  UnsupportedOperationException if the underlying provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *          does not implement the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @throws  IllegalStateException if the SSLContextImpl requires
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   343
     *          initialization and the {@code init()} has not been called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public final SSLEngine createSSLEngine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return contextSpi.engineCreateSSLEngine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        } catch (AbstractMethodError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            UnsupportedOperationException unsup =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    "Provider: " + getProvider() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    " doesn't support this operation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            unsup.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            throw unsup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   360
     * Creates a new {@code SSLEngine} using this context using
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * advisory peer information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Applications using this factory method are providing hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * for an internal session reuse strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Some cipher suites (such as Kerberos) require remote hostname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * information, in which case peerHost needs to be specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param   peerHost the non-authoritative name of the host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param   peerPort the non-authoritative port
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   371
     * @return  the new {@code SSLEngine} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @throws  UnsupportedOperationException if the underlying provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *          does not implement the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @throws  IllegalStateException if the SSLContextImpl requires
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   375
     *          initialization and the {@code init()} has not been called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public final SSLEngine createSSLEngine(String peerHost, int peerPort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            return contextSpi.engineCreateSSLEngine(peerHost, peerPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        } catch (AbstractMethodError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            UnsupportedOperationException unsup =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    "Provider: " + getProvider() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    " does not support this operation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            unsup.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            throw unsup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Returns the server session context, which represents the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * SSL sessions available for use during the handshake phase of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * server-side SSL sockets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * This context may be unavailable in some environments, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * case this method returns null. For example, when the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * SSL provider does not provide an implementation of SSLSessionContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * interface, this method returns null. A non-null session context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * is returned otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @return server session context bound to this SSL context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public final SSLSessionContext getServerSessionContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return contextSpi.engineGetServerSessionContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Returns the client session context, which represents the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * SSL sessions available for use during the handshake phase of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * client-side SSL sockets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * This context may be unavailable in some environments, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * case this method returns null. For example, when the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * SSL provider does not provide an implementation of SSLSessionContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * interface, this method returns null. A non-null session context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * is returned otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return client session context bound to this SSL context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public final SSLSessionContext getClientSessionContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return contextSpi.engineGetClientSessionContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Returns a copy of the SSLParameters indicating the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * settings for this SSL context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * <p>The parameters will always have the ciphersuites and protocols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * arrays set to non-null values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @return a copy of the SSLParameters object with the default settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @throws UnsupportedOperationException if the default SSL parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *   could not be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public final SSLParameters getDefaultSSLParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return contextSpi.engineGetDefaultSSLParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Returns a copy of the SSLParameters indicating the supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * settings for this SSL context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <p>The parameters will always have the ciphersuites and protocols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * arrays set to non-null values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @return a copy of the SSLParameters object with the supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *   settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @throws UnsupportedOperationException if the supported SSL parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *   could not be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public final SSLParameters getSupportedSSLParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return contextSpi.engineGetSupportedSSLParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
}