2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
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 key material generation.
|
|
34 |
* This class is used to initialize KeyGenerator of the type
|
|
35 |
* "TlsKeyMaterial". The keys returned by such KeyGenerators will be
|
|
36 |
* instances of {@link TlsKeyMaterialSpec}.
|
|
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 Dolphin (JDK 7)
|
|
43 |
*/
|
|
44 |
@Deprecated
|
|
45 |
public class TlsKeyMaterialParameterSpec implements AlgorithmParameterSpec {
|
|
46 |
|
|
47 |
private final SecretKey masterSecret;
|
|
48 |
private final int majorVersion, minorVersion;
|
|
49 |
private final byte[] clientRandom, serverRandom;
|
|
50 |
private final String cipherAlgorithm;
|
|
51 |
private final int cipherKeyLength, ivLength, macKeyLength;
|
|
52 |
private final int expandedCipherKeyLength; // == 0 for domestic ciphersuites
|
|
53 |
|
|
54 |
/**
|
|
55 |
* Constructs a new TlsKeyMaterialParameterSpec.
|
|
56 |
*
|
|
57 |
* @param masterSecret the master secret
|
|
58 |
* @param majorVersion the major number of the protocol version
|
|
59 |
* @param minorVersion the minor number of the protocol version
|
|
60 |
* @param clientRandom the client's random value
|
|
61 |
* @param serverRandom the server's random value
|
|
62 |
* @param cipherAlgorithm the algorithm name of the cipher keys to
|
|
63 |
* be generated
|
|
64 |
* @param cipherKeyLength if 0, no cipher keys will be generated;
|
|
65 |
* otherwise, the length in bytes of cipher keys to be
|
|
66 |
* generated for domestic cipher suites; for cipher suites defined as
|
|
67 |
* exportable, the number of key material bytes to be generated;
|
|
68 |
* @param expandedCipherKeyLength 0 for domestic cipher suites; for
|
|
69 |
* exportable cipher suites the length in bytes of the key to be
|
|
70 |
* generated.
|
|
71 |
* @param ivLength the length in bytes of the initialization vector
|
|
72 |
* to be generated, or 0 if no initialization vector is required
|
|
73 |
* @param macKeyLength the length in bytes of the MAC key to be generated
|
|
74 |
*
|
|
75 |
* @throws NullPointerException if masterSecret, clientRandom,
|
|
76 |
* serverRandom, or cipherAlgorithm are null
|
|
77 |
* @throws IllegalArgumentException if the algorithm of masterSecret is
|
|
78 |
* not TlsMasterSecret, or if majorVersion or minorVersion are
|
|
79 |
* negative or larger than 255; or if cipherKeyLength, expandedKeyLength,
|
|
80 |
* ivLength, or macKeyLength are negative
|
|
81 |
*/
|
|
82 |
public TlsKeyMaterialParameterSpec(SecretKey masterSecret,
|
|
83 |
int majorVersion, int minorVersion, byte[] clientRandom,
|
|
84 |
byte[] serverRandom, String cipherAlgorithm, int cipherKeyLength,
|
|
85 |
int expandedCipherKeyLength, int ivLength, int macKeyLength) {
|
|
86 |
if (masterSecret.getAlgorithm().equals("TlsMasterSecret") == false) {
|
|
87 |
throw new IllegalArgumentException("Not a TLS master secret");
|
|
88 |
}
|
|
89 |
if (cipherAlgorithm == null) {
|
|
90 |
throw new NullPointerException();
|
|
91 |
}
|
|
92 |
this.masterSecret = masterSecret;
|
|
93 |
this.majorVersion = TlsMasterSecretParameterSpec.checkVersion(majorVersion);
|
|
94 |
this.minorVersion = TlsMasterSecretParameterSpec.checkVersion(minorVersion);
|
|
95 |
this.clientRandom = clientRandom.clone();
|
|
96 |
this.serverRandom = serverRandom.clone();
|
|
97 |
this.cipherAlgorithm = cipherAlgorithm;
|
|
98 |
this.cipherKeyLength = checkSign(cipherKeyLength);
|
|
99 |
this.expandedCipherKeyLength = checkSign(expandedCipherKeyLength);
|
|
100 |
this.ivLength = checkSign(ivLength);
|
|
101 |
this.macKeyLength = checkSign(macKeyLength);
|
|
102 |
}
|
|
103 |
|
|
104 |
private static int checkSign(int k) {
|
|
105 |
if (k < 0) {
|
|
106 |
throw new IllegalArgumentException("Value must not be negative");
|
|
107 |
}
|
|
108 |
return k;
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Returns the master secret.
|
|
113 |
*
|
|
114 |
* @return the master secret.
|
|
115 |
*/
|
|
116 |
public SecretKey getMasterSecret() {
|
|
117 |
return masterSecret;
|
|
118 |
}
|
|
119 |
|
|
120 |
/**
|
|
121 |
* Returns the major version number.
|
|
122 |
*
|
|
123 |
* @return the major version number.
|
|
124 |
*/
|
|
125 |
public int getMajorVersion() {
|
|
126 |
return majorVersion;
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Returns the minor version number.
|
|
131 |
*
|
|
132 |
* @return the minor version number.
|
|
133 |
*/
|
|
134 |
public int getMinorVersion() {
|
|
135 |
return minorVersion;
|
|
136 |
}
|
|
137 |
|
|
138 |
/**
|
|
139 |
* Returns a copy of the client's random value.
|
|
140 |
*
|
|
141 |
* @return a copy of the client's random value.
|
|
142 |
*/
|
|
143 |
public byte[] getClientRandom() {
|
|
144 |
return clientRandom.clone();
|
|
145 |
}
|
|
146 |
|
|
147 |
/**
|
|
148 |
* Returns a copy of the server's random value.
|
|
149 |
*
|
|
150 |
* @return a copy of the server's random value.
|
|
151 |
*/
|
|
152 |
public byte[] getServerRandom() {
|
|
153 |
return serverRandom.clone();
|
|
154 |
}
|
|
155 |
|
|
156 |
/**
|
|
157 |
* Returns the cipher algorithm.
|
|
158 |
*
|
|
159 |
* @return the cipher algorithm.
|
|
160 |
*/
|
|
161 |
public String getCipherAlgorithm() {
|
|
162 |
return cipherAlgorithm;
|
|
163 |
}
|
|
164 |
|
|
165 |
/**
|
|
166 |
* Returns the length in bytes of the encryption key to be generated.
|
|
167 |
*
|
|
168 |
* @return the length in bytes of the encryption key to be generated.
|
|
169 |
*/
|
|
170 |
public int getCipherKeyLength() {
|
|
171 |
return cipherKeyLength;
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Returns the length in bytes of the expanded encryption key to be generated.
|
|
176 |
*
|
|
177 |
* @return the length in bytes of the expanded encryption key to be generated.
|
|
178 |
*/
|
|
179 |
public int getExpandedCipherKeyLength() {
|
|
180 |
return expandedCipherKeyLength;
|
|
181 |
}
|
|
182 |
|
|
183 |
/**
|
|
184 |
* Returns the length in bytes of the initialization vector to be generated.
|
|
185 |
*
|
|
186 |
* @return the length in bytes of the initialization vector to be generated.
|
|
187 |
*/
|
|
188 |
public int getIvLength() {
|
|
189 |
return ivLength;
|
|
190 |
}
|
|
191 |
|
|
192 |
/**
|
|
193 |
* Returns the length in bytes of the MAC key to be generated.
|
|
194 |
*
|
|
195 |
* @return the length in bytes of the MAC key to be generated.
|
|
196 |
*/
|
|
197 |
public int getMacKeyLength() {
|
|
198 |
return macKeyLength;
|
|
199 |
}
|
|
200 |
|
|
201 |
}
|