Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/security/internal/spec/TlsMasterSecretParameterSpec.java
41161 views
1
/*
2
* Copyright (c) 2005, 2017, 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;
51
private final byte[] extendedMasterSecretSessionHash;
52
private final String prfHashAlg;
53
private final int prfHashLength;
54
private final int prfBlockSize;
55
56
/**
57
* Constructs a new TlsMasterSecretParameterSpec.
58
*
59
* <p>The <code>getAlgorithm()</code> method of <code>premasterSecret</code>
60
* should return <code>"TlsRsaPremasterSecret"</code> if the key exchange
61
* algorithm was RSA and <code>"TlsPremasterSecret"</code> otherwise.
62
*
63
* @param premasterSecret the premaster secret
64
* @param majorVersion the major number of the protocol version
65
* @param minorVersion the minor number of the protocol version
66
* @param clientRandom the client's random value
67
* @param serverRandom the server's random value
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
String prfHashAlg, int prfHashLength, int prfBlockSize) {
84
this(premasterSecret, majorVersion, minorVersion,
85
clientRandom, serverRandom,
86
new byte[0],
87
prfHashAlg, prfHashLength, prfBlockSize);
88
}
89
90
/**
91
* Constructs a new TlsMasterSecretParameterSpec.
92
*
93
* <p>The <code>getAlgorithm()</code> method of <code>premasterSecret</code>
94
* should return <code>"TlsRsaPremasterSecret"</code> if the key exchange
95
* algorithm was RSA and <code>"TlsPremasterSecret"</code> otherwise.
96
*
97
* @param premasterSecret the premaster secret
98
* @param majorVersion the major number of the protocol version
99
* @param minorVersion the minor number of the protocol version
100
* @param extendedMasterSecretSessionHash the session hash for
101
* Extended Master Secret
102
* @param prfHashAlg the name of the TLS PRF hash algorithm to use.
103
* Used only for TLS 1.2+. TLS1.1 and earlier use a fixed PRF.
104
* @param prfHashLength the output length of the TLS PRF hash algorithm.
105
* Used only for TLS 1.2+.
106
* @param prfBlockSize the input block size of the TLS PRF hash algorithm.
107
* Used only for TLS 1.2+.
108
*
109
* @throws NullPointerException if premasterSecret is null
110
* @throws IllegalArgumentException if minorVersion or majorVersion are
111
* negative or larger than 255
112
*/
113
public TlsMasterSecretParameterSpec(SecretKey premasterSecret,
114
int majorVersion, int minorVersion,
115
byte[] extendedMasterSecretSessionHash,
116
String prfHashAlg, int prfHashLength, int prfBlockSize) {
117
this(premasterSecret, majorVersion, minorVersion,
118
new byte[0], new byte[0],
119
extendedMasterSecretSessionHash,
120
prfHashAlg, prfHashLength, prfBlockSize);
121
}
122
123
private TlsMasterSecretParameterSpec(SecretKey premasterSecret,
124
int majorVersion, int minorVersion,
125
byte[] clientRandom, byte[] serverRandom,
126
byte[] extendedMasterSecretSessionHash,
127
String prfHashAlg, int prfHashLength, int prfBlockSize) {
128
if (premasterSecret == null) {
129
throw new NullPointerException("premasterSecret must not be null");
130
}
131
this.premasterSecret = premasterSecret;
132
this.majorVersion = checkVersion(majorVersion);
133
this.minorVersion = checkVersion(minorVersion);
134
this.clientRandom = clientRandom.clone();
135
this.serverRandom = serverRandom.clone();
136
this.extendedMasterSecretSessionHash =
137
(extendedMasterSecretSessionHash != null ?
138
extendedMasterSecretSessionHash.clone() : new byte[0]);
139
this.prfHashAlg = prfHashAlg;
140
this.prfHashLength = prfHashLength;
141
this.prfBlockSize = prfBlockSize;
142
}
143
144
static int checkVersion(int version) {
145
if ((version < 0) || (version > 255)) {
146
throw new IllegalArgumentException(
147
"Version must be between 0 and 255");
148
}
149
return version;
150
}
151
152
/**
153
* Returns the premaster secret.
154
*
155
* @return the premaster secret.
156
*/
157
public SecretKey getPremasterSecret() {
158
return premasterSecret;
159
}
160
161
/**
162
* Returns the major version number.
163
*
164
* @return the major version number.
165
*/
166
public int getMajorVersion() {
167
return majorVersion;
168
}
169
170
/**
171
* Returns the minor version number.
172
*
173
* @return the minor version number.
174
*/
175
public int getMinorVersion() {
176
return minorVersion;
177
}
178
179
/**
180
* Returns a copy of the client's random value.
181
*
182
* @return a copy of the client's random value.
183
*/
184
public byte[] getClientRandom() {
185
return clientRandom.clone();
186
}
187
188
/**
189
* Returns a copy of the server's random value.
190
*
191
* @return a copy of the server's random value.
192
*/
193
public byte[] getServerRandom() {
194
return serverRandom.clone();
195
}
196
197
/**
198
* Returns a copy of the Extended Master Secret session hash.
199
*
200
* @return a copy of the Extended Master Secret session hash, or an empty
201
* array if no extended master secret session hash was provided
202
* at instantiation time
203
*/
204
public byte[] getExtendedMasterSecretSessionHash() {
205
return extendedMasterSecretSessionHash.clone();
206
}
207
208
/**
209
* Obtains the PRF hash algorithm to use in the PRF calculation.
210
*
211
* @return the hash algorithm.
212
*/
213
public String getPRFHashAlg() {
214
return prfHashAlg;
215
}
216
217
/**
218
* Obtains the length of the PRF hash algorithm.
219
*
220
* @return the hash algorithm length.
221
*/
222
public int getPRFHashLength() {
223
return prfHashLength;
224
}
225
226
/**
227
* Obtains the block size of the PRF hash algorithm.
228
*
229
* @return the hash algorithm block size.
230
*/
231
public int getPRFBlockSize() {
232
return prfBlockSize;
233
}
234
}
235
236