2
|
1 |
/*
|
|
2 |
* Copyright 2005-2007 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any 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 Dolphin (JDK 7)
|
|
43 |
*/
|
|
44 |
@Deprecated
|
|
45 |
public class TlsMasterSecretParameterSpec implements AlgorithmParameterSpec {
|
|
46 |
|
|
47 |
private final SecretKey premasterSecret;
|
|
48 |
private final int majorVersion, minorVersion;
|
|
49 |
private final byte[] clientRandom, serverRandom;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Constructs a new TlsMasterSecretParameterSpec.
|
|
53 |
*
|
|
54 |
* <p>The <code>getAlgorithm()</code> method of <code>premasterSecret</code>
|
|
55 |
* should return <code>"TlsRsaPremasterSecret"</code> if the key exchange
|
|
56 |
* algorithm was RSA and <code>"TlsPremasterSecret"</code> otherwise.
|
|
57 |
*
|
|
58 |
* @param premasterSecret the premaster secret
|
|
59 |
* @param majorVersion the major number of the protocol version
|
|
60 |
* @param minorVersion the minor number of the protocol version
|
|
61 |
* @param clientRandom the client's random value
|
|
62 |
* @param serverRandom the server's random value
|
|
63 |
*
|
|
64 |
* @throws NullPointerException if premasterSecret, clientRandom,
|
|
65 |
* or serverRandom are null
|
|
66 |
* @throws IllegalArgumentException if minorVersion or majorVersion are
|
|
67 |
* negative or larger than 255
|
|
68 |
*/
|
|
69 |
public TlsMasterSecretParameterSpec(SecretKey premasterSecret,
|
|
70 |
int majorVersion, int minorVersion, byte[] clientRandom, byte[] serverRandom) {
|
|
71 |
if (premasterSecret == null) {
|
|
72 |
throw new NullPointerException("premasterSecret must not be null");
|
|
73 |
}
|
|
74 |
this.premasterSecret = premasterSecret;
|
|
75 |
this.majorVersion = checkVersion(majorVersion);
|
|
76 |
this.minorVersion = checkVersion(minorVersion);
|
|
77 |
this.clientRandom = clientRandom.clone();
|
|
78 |
this.serverRandom = serverRandom.clone();
|
|
79 |
}
|
|
80 |
|
|
81 |
static int checkVersion(int version) {
|
|
82 |
if ((version < 0) || (version > 255)) {
|
|
83 |
throw new IllegalArgumentException("Version must be between 0 and 255");
|
|
84 |
}
|
|
85 |
return version;
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Returns the premaster secret.
|
|
90 |
*
|
|
91 |
* @return the premaster secret.
|
|
92 |
*/
|
|
93 |
public SecretKey getPremasterSecret() {
|
|
94 |
return premasterSecret;
|
|
95 |
}
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Returns the major version number.
|
|
99 |
*
|
|
100 |
* @return the major version number.
|
|
101 |
*/
|
|
102 |
public int getMajorVersion() {
|
|
103 |
return majorVersion;
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Returns the minor version number.
|
|
108 |
*
|
|
109 |
* @return the minor version number.
|
|
110 |
*/
|
|
111 |
public int getMinorVersion() {
|
|
112 |
return minorVersion;
|
|
113 |
}
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Returns a copy of the client's random value.
|
|
117 |
*
|
|
118 |
* @return a copy of the client's random value.
|
|
119 |
*/
|
|
120 |
public byte[] getClientRandom() {
|
|
121 |
return clientRandom.clone();
|
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Returns a copy of the server's random value.
|
|
126 |
*
|
|
127 |
* @return a copy of the server's random value.
|
|
128 |
*/
|
|
129 |
public byte[] getServerRandom() {
|
|
130 |
return serverRandom.clone();
|
|
131 |
}
|
|
132 |
|
|
133 |
}
|