1 /* 2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.security.internal.spec; 27 28 import java.security.spec.AlgorithmParameterSpec; 29 30 import javax.crypto.SecretKey; 31 32 /** 33 * Parameters for SSL/TLS master secret generation. 34 * This class encapsulates the information necessary to calculate a SSL/TLS 35 * master secret from the premaster secret and other parameters. 36 * It is used to initialize KeyGenerators of the type "TlsMasterSecret". 37 * 38 * <p>Instances of this class are immutable. 39 * 40 * @since 1.6 41 * @author Andreas Sterbenz 42 * @deprecated Sun JDK internal use only --- WILL BE REMOVED in a future 43 * release. 44 */ 45 @Deprecated 46 public class TlsMasterSecretParameterSpec implements AlgorithmParameterSpec { 47 48 private final SecretKey premasterSecret; 49 private final int majorVersion, minorVersion; 50 private final byte[] clientRandom, serverRandom, extendedMasterSecretSessionHash; 51 private final String prfHashAlg; 52 private final int prfHashLength; 53 private final int prfBlockSize; 54 55 /** 56 * Constructs a new TlsMasterSecretParameterSpec. 57 * 58 * <p>The <code>getAlgorithm()</code> method of <code>premasterSecret</code> 59 * should return <code>"TlsRsaPremasterSecret"</code> if the key exchange 60 * algorithm was RSA and <code>"TlsPremasterSecret"</code> otherwise. 61 * 62 * @param premasterSecret the premaster secret 63 * @param majorVersion the major number of the protocol version 64 * @param minorVersion the minor number of the protocol version 65 * @param clientRandom the client's random value 66 * @param serverRandom the server's random value 67 * @param extendedMasterSecretSessionHash the session hash for Extended Master Secret 68 * @param prfHashAlg the name of the TLS PRF hash algorithm to use. 69 * Used only for TLS 1.2+. TLS1.1 and earlier use a fixed PRF. 70 * @param prfHashLength the output length of the TLS PRF hash algorithm. 71 * Used only for TLS 1.2+. 72 * @param prfBlockSize the input block size of the TLS PRF hash algorithm. 73 * Used only for TLS 1.2+. 74 * 75 * @throws NullPointerException if premasterSecret, clientRandom, 76 * or serverRandom are null 77 * @throws IllegalArgumentException if minorVersion or majorVersion are 78 * negative or larger than 255 79 */ 80 public TlsMasterSecretParameterSpec(SecretKey premasterSecret, 81 int majorVersion, int minorVersion, 82 byte[] clientRandom, byte[] serverRandom, 83 byte[] extendedMasterSecretSessionHash, 84 String prfHashAlg, int prfHashLength, int prfBlockSize) { 85 if (premasterSecret == null) { 86 throw new NullPointerException("premasterSecret must not be null"); 87 } 88 this.premasterSecret = premasterSecret; 89 this.majorVersion = checkVersion(majorVersion); 90 this.minorVersion = checkVersion(minorVersion); 91 this.clientRandom = clientRandom.clone(); 92 this.serverRandom = serverRandom.clone(); 93 this.extendedMasterSecretSessionHash = 94 (extendedMasterSecretSessionHash != null ? 95 extendedMasterSecretSessionHash.clone() : null); 96 this.prfHashAlg = prfHashAlg; 97 this.prfHashLength = prfHashLength; 98 this.prfBlockSize = prfBlockSize; 99 } 100 101 static int checkVersion(int version) { 102 if ((version < 0) || (version > 255)) { 103 throw new IllegalArgumentException( 104 "Version must be between 0 and 255"); 105 } 106 return version; 107 } 108 109 /** 110 * Returns the premaster secret. 111 * 112 * @return the premaster secret. 113 */ 114 public SecretKey getPremasterSecret() { 115 return premasterSecret; 116 } 117 118 /** 119 * Returns the major version number. 120 * 121 * @return the major version number. 122 */ 123 public int getMajorVersion() { 124 return majorVersion; 125 } 126 127 /** 128 * Returns the minor version number. 129 * 130 * @return the minor version number. 131 */ 132 public int getMinorVersion() { 133 return minorVersion; 134 } 135 136 /** 137 * Returns a copy of the client's random value. 138 * 139 * @return a copy of the client's random value. 140 */ 141 public byte[] getClientRandom() { 142 return clientRandom.clone(); 143 } 144 145 /** 146 * Returns a copy of the server's random value. 147 * 148 * @return a copy of the server's random value. 149 */ 150 public byte[] getServerRandom() { 151 return serverRandom.clone(); 152 } 153 154 /** 155 * Returns a copy of the Extended Master Secret session hash. 156 * 157 * @return a copy of the Extended Master Secret session hash. 158 */ 159 public byte[] getExtendedMasterSecretSessionHash() { 160 return (extendedMasterSecretSessionHash != null ? 161 extendedMasterSecretSessionHash.clone() : 162 null); 163 } 164 165 /** 166 * Obtains the PRF hash algorithm to use in the PRF calculation. 167 * 168 * @return the hash algorithm. 169 */ 170 public String getPRFHashAlg() { 171 return prfHashAlg; 172 } 173 174 /** 175 * Obtains the length of the PRF hash algorithm. 176 * 177 * @return the hash algorithm length. 178 */ 179 public int getPRFHashLength() { 180 return prfHashLength; 181 } 182 183 /** 184 * Obtains the block size of the PRF hash algorithm. 185 * 186 * @return the hash algorithm block size. 187 */ 188 public int getPRFBlockSize() { 189 return prfBlockSize; 190 } 191 }