jdk/src/share/classes/javax/net/ssl/SSLParameters.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 7043 5e2d1edeb2c7
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Encapsulates parameters for an SSL/TLS connection. The parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * are the list of ciphersuites to be accepted in an SSL/TLS handshake,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * the list of protocols to be allowed, and whether SSL/TLS servers should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * request or require client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>SSLParameters can be created via the constructors in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Objects can also be obtained using the <code>getSSLParameters()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * {@link SSLSocket#getSSLParameters SSLSocket} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * {@link SSLEngine#getSSLParameters SSLEngine} or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * {@link SSLContext#getDefaultSSLParameters getDefaultSSLParameters()} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * {@link SSLContext#getSupportedSSLParameters getSupportedSSLParameters()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * methods in <code>SSLContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <P>SSLParameters can be applied to a connection via the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * {@link SSLSocket#setSSLParameters SSLSocket.setSSLParameters()} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * {@link SSLEngine#setSSLParameters SSLEngine.getSSLParameters()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @see SSLSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see SSLEngine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see SSLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class SSLParameters {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private String[] cipherSuites;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private String[] protocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private boolean wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private boolean needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Constructs SSLParameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * <p>The cipherSuites and protocols values are set to <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * wantClientAuth and needClientAuth are set to <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public SSLParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Constructs SSLParameters from the specified array of ciphersuites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * constructor followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <code>setCipherSuites(cipherSuites);</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public SSLParameters(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Constructs SSLParameters from the specified array of ciphersuites
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * and protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Calling this constructor is equivalent to calling the no-args
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * constructor followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <code>setCipherSuites(cipherSuites); setProtocols(protocols);</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public SSLParameters(String[] cipherSuites, String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        setCipherSuites(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        setProtocols(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static String[] clone(String[] s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return (s == null) ? null : s.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Returns a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return a copy of the array of ciphersuites or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public String[] getCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Sets the array of ciphersuites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param cipherSuites the array of ciphersuites (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void setCipherSuites(String[] cipherSuites) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this.cipherSuites = clone(cipherSuites);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Returns a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @return a copy of the array of protocols or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public String[] getProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Sets the array of protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param protocols the array of protocols (or null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void setProtocols(String[] protocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        this.protocols = clone(protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Returns whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return whether client authentication should be requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public boolean getWantClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Sets whether client authentication should be requested. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * this method clears the <code>needClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param wantClientAuth whether client authentication should be requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void setWantClientAuth(boolean wantClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        this.wantClientAuth = wantClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.needClientAuth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Returns whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return whether client authentication should be required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public boolean getNeedClientAuth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Sets whether client authentication should be required. Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * this method clears the <code>wantClientAuth</code> flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param needClientAuth whether client authentication should be required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void setNeedClientAuth(boolean needClientAuth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        this.wantClientAuth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        this.needClientAuth = needClientAuth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
}