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 31 /** 32 * The default SSLParameters constructor. Cipher suites and 33 * protocols are initialized to null and client authentication 34 * options are initialized to false. 35 */ 36 public SSLParameters() {} 37 38 /** 39 * A SSLParameters constructor that allows the values for the 40 * initial cipher suites array to be provided. Other values 41 * default as specified in {@link #SSLParameters()}. 42 * 43 * @param cipherSuites An array of cipherSuites that is cloned for 44 * use within the SSLParameters, or null. 45 */ 46 public SSLParameters(String[] cipherSuites) { 47 setCipherSuites(cipherSuites); 48 } 49 50 /** 51 * A SSLParameters constructor that allows the values for initial 52 * cipher suites and protocols arrays to be provided. Other values 53 * default as specified in {@link #SSLParameters()}. 54 * 55 * @param cipherSuites An array of cipher names that is cloned for 56 * use within the SSLParameters, or null. 57 * @param protocols An array of protocol names that is cloned for 58 * use within the SSLParameters, or null. 59 */ 60 public SSLParameters(String[] cipherSuites, 61 String[] protocols) { 62 setCipherSuites(cipherSuites); 63 setProtocols(protocols); 64 } 65 66 /** 67 * Returns a copy of the cipher suites, or null if none have been 68 * specified. 69 */ 70 public String[] getCipherSuites() { 71 if (cipherSuites == null) { 72 return null; 73 } 74 return cipherSuites.clone(); 75 } 76 77 /** 78 * Sets the cipher suites to a copy of the input, or null 79 */ 80 public void setCipherSuites(String[] cipherSuites) { 81 this.cipherSuites = ((cipherSuites == null) 82 ? null 83 : cipherSuites.clone()); 84 } 85 86 /** 87 * Returns a copy of the protocols, or null if none have been 88 * specified. 89 */ 90 public String[] getProtocols() { 91 if (protocols == null) { 92 return null; 93 } 94 return protocols.clone(); 95 } 96 97 /** 98 * Sets the protocols to a copy of the input, or null 99 */ 100 public void setProtocols(String[] protocols) { 101 this.protocols = ((protocols == null) 102 ? null 103 : protocols.clone()); 104 } 105 106 /** 107 * Returns true if a server requires authentication from a client 108 * during handshaking. If this returns true, {@link 109 * #getWantClientAuth} will return false. 110 */ 111 public boolean getNeedClientAuth () { 112 return needClientAuth; 113 } 114 115 /** 116 * Sets whether or not to a server needs client authentication. 117 * After calling this, #getWantClientAuth() will return false. 118 */ 119 public void setNeedClientAuth (boolean needClientAuth) { 120 this.needClientAuth = needClientAuth; 121 this.wantClientAuth = false; 122 } 123 124 /** 125 * Returns true if a server optionally wants to authenticate a 126 * client during handshaking. If this returns true, {@link 127 * #getNeedClientAuth} will return false. 128 */ 129 public boolean getWantClientAuth () { 130 return wantClientAuth; 131 } 132 133 /** 134 * Sets whether or not to a server wants client authentication. 135 * After calling this, #getNeedClientAuth() will return false. 136 */ 137 public void setWantClientAuth (boolean wantClientAuth) { 138 this.wantClientAuth = wantClientAuth; 139 this.needClientAuth = false; 140 } 141} 142