Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/internal/spec/TlsRsaPremasterSecretParameterSpec.java
38922 views
1
/*
2
* Copyright (c) 2005, 2013, 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
import java.security.AccessController;
30
import java.security.PrivilegedAction;
31
32
/**
33
* Parameters for SSL/TLS RSA premaster secret.
34
*
35
* <p>Instances of this class are immutable.
36
*
37
* @since 1.6
38
* @author Andreas Sterbenz
39
* @deprecated Sun JDK internal use only --- WILL BE REMOVED in a future
40
* release.
41
*/
42
@Deprecated
43
public class TlsRsaPremasterSecretParameterSpec
44
implements AlgorithmParameterSpec {
45
46
private final byte[] encodedSecret;
47
48
/*
49
* The TLS spec says that the version in the RSA premaster secret must
50
* be the maximum version supported by the client (i.e. the version it
51
* requested in its client hello version). However, we (and other
52
* implementations) used to send the active negotiated version. The
53
* system property below allows to toggle the behavior.
54
*/
55
private final static String PROP_NAME =
56
"com.sun.net.ssl.rsaPreMasterSecretFix";
57
58
/*
59
* Default is "false" (old behavior) for compatibility reasons in
60
* SSLv3/TLSv1. Later protocols (TLSv1.1+) do not use this property.
61
*/
62
private final static boolean rsaPreMasterSecretFix =
63
AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
64
public Boolean run() {
65
String value = System.getProperty(PROP_NAME);
66
if (value != null && value.equalsIgnoreCase("true")) {
67
return Boolean.TRUE;
68
}
69
70
return Boolean.FALSE;
71
}
72
});
73
74
private final int clientVersion;
75
private final int serverVersion;
76
77
/**
78
* Constructs a new TlsRsaPremasterSecretParameterSpec.
79
*
80
* @param clientVersion the version of the TLS protocol by which the
81
* client wishes to communicate during this session
82
* @param serverVersion the negotiated version of the TLS protocol which
83
* contains the lower of that suggested by the client in the client
84
* hello and the highest supported by the server.
85
*
86
* @throws IllegalArgumentException if clientVersion or serverVersion are
87
* negative or larger than (2^16 - 1)
88
*/
89
public TlsRsaPremasterSecretParameterSpec(
90
int clientVersion, int serverVersion) {
91
92
this.clientVersion = checkVersion(clientVersion);
93
this.serverVersion = checkVersion(serverVersion);
94
this.encodedSecret = null;
95
}
96
97
/**
98
* Constructs a new TlsRsaPremasterSecretParameterSpec.
99
*
100
* @param clientVersion the version of the TLS protocol by which the
101
* client wishes to communicate during this session
102
* @param serverVersion the negotiated version of the TLS protocol which
103
* contains the lower of that suggested by the client in the client
104
* hello and the highest supported by the server.
105
* @param encodedSecret the encoded secret key
106
*
107
* @throws IllegalArgumentException if clientVersion or serverVersion are
108
* negative or larger than (2^16 - 1) or if encodedSecret is not
109
* exactly 48 bytes
110
*/
111
public TlsRsaPremasterSecretParameterSpec(
112
int clientVersion, int serverVersion, byte[] encodedSecret) {
113
114
this.clientVersion = checkVersion(clientVersion);
115
this.serverVersion = checkVersion(serverVersion);
116
if (encodedSecret == null || encodedSecret.length != 48) {
117
throw new IllegalArgumentException(
118
"Encoded secret is not exactly 48 bytes");
119
}
120
this.encodedSecret = encodedSecret.clone();
121
}
122
123
/**
124
* Returns the version of the TLS protocol by which the client wishes to
125
* communicate during this session.
126
*
127
* @return the version of the TLS protocol in ClientHello message
128
*/
129
public int getClientVersion() {
130
return clientVersion;
131
}
132
133
/**
134
* Returns the negotiated version of the TLS protocol which contains the
135
* lower of that suggested by the client in the client hello and the
136
* highest supported by the server.
137
*
138
* @return the negotiated version of the TLS protocol in ServerHello message
139
*/
140
public int getServerVersion() {
141
return serverVersion;
142
}
143
144
/**
145
* Returns the major version used in RSA premaster secret.
146
*
147
* @return the major version used in RSA premaster secret.
148
*/
149
public int getMajorVersion() {
150
if (rsaPreMasterSecretFix || clientVersion >= 0x0302) {
151
// 0x0302: TLSv1.1
152
return (clientVersion >>> 8) & 0xFF;
153
}
154
155
return (serverVersion >>> 8) & 0xFF;
156
}
157
158
/**
159
* Returns the minor version used in RSA premaster secret.
160
*
161
* @return the minor version used in RSA premaster secret.
162
*/
163
public int getMinorVersion() {
164
if (rsaPreMasterSecretFix || clientVersion >= 0x0302) {
165
// 0x0302: TLSv1.1
166
return clientVersion & 0xFF;
167
}
168
169
return serverVersion & 0xFF;
170
}
171
172
private int checkVersion(int version) {
173
if ((version < 0) || (version > 0xFFFF)) {
174
throw new IllegalArgumentException(
175
"Version must be between 0 and 65,535");
176
}
177
return version;
178
}
179
180
/**
181
* Returns the encoded secret.
182
*
183
* @return the encoded secret, may be null if no encoded secret.
184
*/
185
public byte[] getEncodedSecret() {
186
return encodedSecret == null ? null : encodedSecret.clone();
187
}
188
}
189
190