1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package javax.net.ssl;
18
19/**
20 * SSL handshake parameters that include protocols, cipher suites, and
21 * client authentication requirements.
22 * @since 1.6
23 */
24public class SSLParameters {
25
26    private String[] cipherSuites;
27    private String[] protocols;
28    private boolean needClientAuth;
29    private boolean wantClientAuth;
30    private String endpointIdentificationAlgorithm;
31
32    /**
33     * The default SSLParameters constructor. Cipher suites and
34     * protocols are initialized to null and client authentication
35     * options are initialized to false.
36     */
37    public SSLParameters() {}
38
39    /**
40     * A SSLParameters constructor that allows the values for the
41     * initial cipher suites array to be provided. Other values
42     * default as specified in {@link #SSLParameters()}.
43     *
44     * @param cipherSuites An array of cipherSuites that is cloned for
45     * use within the SSLParameters, or null.
46     */
47    public SSLParameters(String[] cipherSuites) {
48        setCipherSuites(cipherSuites);
49    }
50
51    /**
52     * A SSLParameters constructor that allows the values for initial
53     * cipher suites and protocols arrays to be provided. Other values
54     * default as specified in {@link #SSLParameters()}.
55     *
56     * @param cipherSuites An array of cipher names that is cloned for
57     * use within the SSLParameters, or null.
58     * @param protocols An array of protocol names that is cloned for
59     * use within the SSLParameters, or null.
60     */
61    public SSLParameters(String[] cipherSuites,
62                         String[] protocols) {
63        setCipherSuites(cipherSuites);
64        setProtocols(protocols);
65    }
66
67    /**
68     * Returns a copy of the cipher suites, or null if none have been
69     * specified.
70     */
71    public String[] getCipherSuites() {
72        if (cipherSuites == null) {
73            return null;
74        }
75        return cipherSuites.clone();
76    }
77
78    /**
79     * Sets the cipher suites to a copy of the input, or null
80     */
81    public void setCipherSuites(String[] cipherSuites) {
82        this.cipherSuites = ((cipherSuites == null)
83                             ? null
84                             : cipherSuites.clone());
85    }
86
87    /**
88     * Returns a copy of the protocols, or null if none have been
89     * specified.
90     */
91    public String[] getProtocols() {
92        if (protocols == null) {
93            return null;
94        }
95        return protocols.clone();
96    }
97
98    /**
99     * Sets the protocols to a copy of the input, or null
100     */
101    public void setProtocols(String[] protocols) {
102        this.protocols = ((protocols == null)
103                             ? null
104                             : protocols.clone());
105    }
106
107    /**
108     * Returns true if a server requires authentication from a client
109     * during handshaking. If this returns true, {@link
110     * #getWantClientAuth} will return false.
111     */
112    public boolean getNeedClientAuth () {
113        return needClientAuth;
114    }
115
116    /**
117     * Sets whether or not to a server needs client authentication.
118     * After calling this, #getWantClientAuth() will return false.
119     */
120    public void setNeedClientAuth (boolean needClientAuth) {
121        this.needClientAuth = needClientAuth;
122        this.wantClientAuth = false;
123    }
124
125    /**
126     * Returns true if a server optionally wants to authenticate a
127     * client during handshaking. If this returns true, {@link
128     * #getNeedClientAuth} will return false.
129     */
130    public boolean getWantClientAuth () {
131        return wantClientAuth;
132    }
133
134    /**
135     * Sets whether or not to a server wants client authentication.
136     * After calling this, #getNeedClientAuth() will return false.
137     */
138    public void setWantClientAuth (boolean wantClientAuth) {
139        this.wantClientAuth = wantClientAuth;
140        this.needClientAuth = false;
141    }
142}
143