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/TlsRsaPremasterSecretParameterSpec.java
41161 views
1
/*
2
* Copyright (c) 2005, 2018, 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 sun.security.action.GetBooleanAction;
29
30
import java.security.spec.AlgorithmParameterSpec;
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
* Default is "false" (old behavior) for compatibility reasons in
55
* SSLv3/TLSv1. Later protocols (TLSv1.1+) do not use this property.
56
*/
57
private static final boolean rsaPreMasterSecretFix = GetBooleanAction
58
.privilegedGetProperty("com.sun.net.ssl.rsaPreMasterSecretFix");
59
60
private final int clientVersion;
61
private final int serverVersion;
62
63
/**
64
* Constructs a new TlsRsaPremasterSecretParameterSpec.
65
*
66
* @param clientVersion the version of the TLS protocol by which the
67
* client wishes to communicate during this session
68
* @param serverVersion the negotiated version of the TLS protocol which
69
* contains the lower of that suggested by the client in the client
70
* hello and the highest supported by the server.
71
*
72
* @throws IllegalArgumentException if clientVersion or serverVersion are
73
* negative or larger than (2^16 - 1)
74
*/
75
public TlsRsaPremasterSecretParameterSpec(
76
int clientVersion, int serverVersion) {
77
78
this.clientVersion = checkVersion(clientVersion);
79
this.serverVersion = checkVersion(serverVersion);
80
this.encodedSecret = null;
81
}
82
83
/**
84
* Constructs a new TlsRsaPremasterSecretParameterSpec.
85
*
86
* @param clientVersion the version of the TLS protocol by which the
87
* client wishes to communicate during this session
88
* @param serverVersion the negotiated version of the TLS protocol which
89
* contains the lower of that suggested by the client in the client
90
* hello and the highest supported by the server.
91
* @param encodedSecret the encoded secret key
92
*
93
* @throws IllegalArgumentException if clientVersion or serverVersion are
94
* negative or larger than (2^16 - 1) or if encodedSecret is not
95
* exactly 48 bytes
96
*/
97
public TlsRsaPremasterSecretParameterSpec(
98
int clientVersion, int serverVersion, byte[] encodedSecret) {
99
100
this.clientVersion = checkVersion(clientVersion);
101
this.serverVersion = checkVersion(serverVersion);
102
if (encodedSecret == null || encodedSecret.length != 48) {
103
throw new IllegalArgumentException(
104
"Encoded secret is not exactly 48 bytes");
105
}
106
this.encodedSecret = encodedSecret.clone();
107
}
108
109
/**
110
* Returns the version of the TLS protocol by which the client wishes to
111
* communicate during this session.
112
*
113
* @return the version of the TLS protocol in ClientHello message
114
*/
115
public int getClientVersion() {
116
return clientVersion;
117
}
118
119
/**
120
* Returns the negotiated version of the TLS protocol which contains the
121
* lower of that suggested by the client in the client hello and the
122
* highest supported by the server.
123
*
124
* @return the negotiated version of the TLS protocol in ServerHello message
125
*/
126
public int getServerVersion() {
127
return serverVersion;
128
}
129
130
/**
131
* Returns the major version used in RSA premaster secret.
132
*
133
* @return the major version used in RSA premaster secret.
134
*/
135
public int getMajorVersion() {
136
if (rsaPreMasterSecretFix || clientVersion >= 0x0302) {
137
// 0x0302: TLSv1.1
138
return (clientVersion >>> 8) & 0xFF;
139
}
140
141
return (serverVersion >>> 8) & 0xFF;
142
}
143
144
/**
145
* Returns the minor version used in RSA premaster secret.
146
*
147
* @return the minor version used in RSA premaster secret.
148
*/
149
public int getMinorVersion() {
150
if (rsaPreMasterSecretFix || clientVersion >= 0x0302) {
151
// 0x0302: TLSv1.1
152
return clientVersion & 0xFF;
153
}
154
155
return serverVersion & 0xFF;
156
}
157
158
private int checkVersion(int version) {
159
if ((version < 0) || (version > 0xFFFF)) {
160
throw new IllegalArgumentException(
161
"Version must be between 0 and 65,535");
162
}
163
return version;
164
}
165
166
/**
167
* Returns the encoded secret.
168
*
169
* @return the encoded secret, may be null if no encoded secret.
170
*/
171
public byte[] getEncodedSecret() {
172
return encodedSecret == null ? null : encodedSecret.clone();
173
}
174
}
175
176