/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This file contains all the classes relevant to TLS Extensions for the
* ClientHello and ServerHello messages. The extension mechanism and
* several extensions are defined in RFC 3546. Additional extensions are
* defined in the ECC RFC 4492.
*
* Currently, only the two ECC extensions are fully supported.
*
* The classes contained in this file are:
* . HelloExtensions: a List of extensions as used in the client hello
* and server hello messages.
* . ExtensionType: an enum style class for the extension type
* . HelloExtension: abstract base class for all extensions. All subclasses
* must be immutable.
*
* . UnknownExtension: used to represent all parsed extensions that we do not
* explicitly support.
* . ServerNameExtension: the server_name extension.
* . SignatureAlgorithmsExtension: the signature_algorithms extension.
* . SupportedEllipticCurvesExtension: the ECC supported curves extension.
* . SupportedEllipticPointFormatsExtension: the ECC supported point formats
* (compressed/uncompressed) extension.
*
* @since 1.6
* @author Andreas Sterbenz
*/
final class HelloExtensions {
private int encodedLength;
HelloExtensions() {
}
while (len > 0) {
} else {
}
}
if (len != 0) {
throw new SSLProtocolException(
"Error parsing extensions: extra data");
}
}
// Return the List of extensions. Must not be modified by the caller.
return extensions;
}
if (extensions.isEmpty()) {
}
encodedLength = -1;
}
return ext;
}
}
return null;
}
int length() {
if (encodedLength >= 0) {
return encodedLength;
}
if (extensions.isEmpty()) {
encodedLength = 0;
} else {
encodedLength = 2;
}
}
return encodedLength;
}
if (length == 0) {
return;
}
}
}
}
}
}
final class ExtensionType {
final int id;
}
return name;
}
return ext;
}
}
}
return ext;
}
// extensions defined in RFC 3546
e(0x0000, "server_name"); // IANA registry value: 0
e(0x0001, "max_fragment_length"); // IANA registry value: 1
e(0x0002, "client_certificate_url"); // IANA registry value: 2
e(0x0003, "trusted_ca_keys"); // IANA registry value: 3
e(0x0004, "truncated_hmac"); // IANA registry value: 4
e(0x0005, "status_request"); // IANA registry value: 5
// extensions defined in RFC 4681
e(0x0006, "user_mapping"); // IANA registry value: 6
// extensions defined in RFC 5081
e(0x0009, "cert_type"); // IANA registry value: 9
// extensions defined in RFC 4492 (ECC)
e(0x000A, "elliptic_curves"); // IANA registry value: 10
e(0x000B, "ec_point_formats"); // IANA registry value: 11
// extensions defined in RFC 5054
e(0x000C, "srp"); // IANA registry value: 12
// extensions defined in RFC 5246
e(0x000D, "signature_algorithms"); // IANA registry value: 13
// extensions defined in RFC 5746
e(0xff01, "renegotiation_info"); // IANA registry value: 65281
}
abstract class HelloExtension {
}
// Length of the encoded extension, including the type and length fields
abstract int length();
}
private final byte[] data;
throws IOException {
super(type);
// s.read() does not handle 0-length arrays.
if (len != 0) {
}
}
int length() {
}
s.putBytes16(data);
}
}
}
/*
* [RFC4366] To facilitate secure connections to servers that host multiple
* 'virtual' servers at a single underlying network address, clients MAY
* include an extension of type "server_name" in the (extended) client hello.
* The "extension_data" field of this extension SHALL contain "ServerNameList"
* where:
*
* struct {
* NameType name_type;
* select (name_type) {
* case host_name: HostName;
* } name;
* } ServerName;
*
* enum {
* host_name(0), (255)
* } NameType;
*
* opaque HostName<1..2^16-1>;
*
* struct {
* ServerName server_name_list<1..2^16-1>
* } ServerNameList;
*/
super(ExtensionType.EXT_SERVER_NAME);
listLength = 0;
// we only support DNS hostname now.
}
}
// As we only support DNS hostname now, the hostname list must
// not contain more than one hostname
throw new SSLProtocolException(
"The ServerNameList MUST NOT contain more than " +
"one name of the same name_type");
}
// We only need to add "server_name" extension in ClientHello unless
// we support SNI in server side in the future. It is possible that
// the SNI is empty in ServerHello. As we don't support SNI in
// ServerHello now, we will throw exception for empty list for now.
if (listLength == 0) {
throw new SSLProtocolException(
"The ServerNameList cannot be empty");
}
}
throws IOException {
super(ExtensionType.EXT_SERVER_NAME);
throw new SSLProtocolException(
}
remains -= 2;
while (remains > 0) {
// we may need to check the duplicated ServerName type
}
listLength = 0;
}
if (remains != 0) {
throw new SSLProtocolException("Invalid server_name extension");
}
}
static class ServerName {
final int length;
final int type;
final byte[] data;
// HostName length: 2 bytes
}
// HostName length: 2 bytes
if (type == NAME_HOST_NAME) {
} else {
}
}
if (type == NAME_HOST_NAME) {
return "host_name: " + hostname;
} else {
}
}
}
int length() {
}
if (listLength != 0) {
s.putInt16(listLength);
}
}
}
}
}
}
// the extension value to send in the ClientHello message
private static final boolean fips;
static {
int[] ids;
if (fips == false) {
ids = new int[] {
// NIST curves first
// prefer NIST P-256, rest in order of increasing key length
23, 1, 3, 19, 21, 6, 7, 9, 10, 24, 11, 12, 25, 13, 14,
// non-NIST curves
15, 16, 17, 2, 18, 4, 5, 20, 8, 22,
};
} else {
ids = new int[] {
// same as above, but allow only NIST curves in FIPS mode
23, 1, 3, 19, 21, 6, 7, 9, 10, 24, 11, 12, 25, 13, 14,
};
}
}
private final int[] curveIds;
super(ExtensionType.EXT_ELLIPTIC_CURVES);
}
throws IOException {
super(ExtensionType.EXT_ELLIPTIC_CURVES);
int k = s.getInt16();
}
curveIds = new int[k >> 1];
}
}
return true;
}
}
return false;
}
// Return a reference to the internal curveIds array.
// The caller must NOT modify the contents.
int[] curveIds() {
return curveIds;
}
int length() {
}
s.putInt16(k + 2);
s.putInt16(k);
}
}
boolean first = true;
if (first) {
first = false;
} else {
}
// first check if it is a known named curve, then try other cases.
// this toString() output will look nice for the current
// implementation of the ECParameterSpec class in the Sun
// provider, but may not look good for other implementations.
} else {
}
} else if (curveId == ARBITRARY_PRIME) {
} else if (curveId == ARBITRARY_CHAR2) {
} else {
}
}
}
// Test whether we support the curve with the given index.
return false;
}
if (fips == false) {
// in non-FIPS mode, we support all valid indices
return true;
}
}
return -1;
}
return (n == null) ? -1 : n;
}
return NAMED_CURVE_OID_TABLE[index];
}
return null;
}
// See sun.security.ec.NamedCurve for the OIDs
null, // (0) unused
"1.3.132.0.1", // (1) sect163k1, NIST K-163
"1.3.132.0.2", // (2) sect163r1
"1.3.132.0.15", // (3) sect163r2, NIST B-163
"1.3.132.0.24", // (4) sect193r1
"1.3.132.0.25", // (5) sect193r2
"1.3.132.0.26", // (6) sect233k1, NIST K-233
"1.3.132.0.27", // (7) sect233r1, NIST B-233
"1.3.132.0.3", // (8) sect239k1
"1.3.132.0.16", // (9) sect283k1, NIST K-283
"1.3.132.0.17", // (10) sect283r1, NIST B-283
"1.3.132.0.36", // (11) sect409k1, NIST K-409
"1.3.132.0.37", // (12) sect409r1, NIST B-409
"1.3.132.0.38", // (13) sect571k1, NIST K-571
"1.3.132.0.39", // (14) sect571r1, NIST B-571
"1.3.132.0.9", // (15) secp160k1
"1.3.132.0.8", // (16) secp160r1
"1.3.132.0.30", // (17) secp160r2
"1.3.132.0.31", // (18) secp192k1
"1.2.840.10045.3.1.1", // (19) secp192r1, NIST P-192
"1.3.132.0.32", // (20) secp224k1
"1.3.132.0.33", // (21) secp224r1, NIST P-224
"1.3.132.0.10", // (22) secp256k1
"1.2.840.10045.3.1.7", // (23) secp256r1, NIST P-256
"1.3.132.0.34", // (24) secp384r1, NIST P-384
"1.3.132.0.35", // (25) secp521r1, NIST P-521
};
static {
}
}
}
new byte[] {FMT_UNCOMPRESSED});
private final byte[] formats;
super(ExtensionType.EXT_EC_POINT_FORMATS);
}
throws IOException {
super(ExtensionType.EXT_EC_POINT_FORMATS);
// RFC 4492 says uncompressed points must always be supported.
// Check just to make sure.
boolean uncompressed = false;
if (format == FMT_UNCOMPRESSED) {
uncompressed = true;
break;
}
}
if (uncompressed == false) {
throw new SSLProtocolException
("Peer does not support uncompressed points");
}
}
int length() {
}
}
int f = format & 0xff;
switch (f) {
case FMT_UNCOMPRESSED:
return "uncompressed";
return "ansiX962_compressed_prime";
return "ansiX962_compressed_char2";
default:
return "unknown-" + f;
}
}
}
}
}
/*
* For secure renegotiation, RFC5746 defines a new TLS extension,
* "renegotiation_info" (with extension type 0xff01), which contains a
* cryptographic binding to the enclosing TLS connection (if any) for
* which the renegotiation is being performed. The "extension data"
* field of this extension contains a "RenegotiationInfo" structure:
*
* struct {
* opaque renegotiated_connection<0..255>;
* } RenegotiationInfo;
*/
private final byte[] renegotiated_connection;
byte[] serverVerifyData) {
super(ExtensionType.EXT_RENEGOTIATION_INFO);
}
} else {
// ignore both the client and server verify data.
renegotiated_connection = new byte[0];
}
}
throws IOException {
super(ExtensionType.EXT_RENEGOTIATION_INFO);
// check the extension length
if (len < 1) {
}
int renegoInfoDataLen = s.getInt8();
}
renegotiated_connection = new byte[renegoInfoDataLen];
if (renegoInfoDataLen != 0) {
}
}
// Length of the encoded extension, including the type and length fields
int length() {
}
}
boolean isEmpty() {
}
byte[] getRenegotiatedConnection() {
return renegotiated_connection;
}
}
}
/*
* [RFC5246] The client uses the "signature_algorithms" extension to
* used in digital signatures. The "extension_data" field of this
* extension contains a "supported_signature_algorithms" value.
*
* enum {
* none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
* sha512(6), (255)
* } HashAlgorithm;
*
* enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
* SignatureAlgorithm;
*
* struct {
* HashAlgorithm hash;
* SignatureAlgorithm signature;
* } SignatureAndHashAlgorithm;
*
* SignatureAndHashAlgorithm
* supported_signature_algorithms<2..2^16-2>;
*/
}
throws IOException {
algorithmsLen = s.getInt16();
}
int remains = algorithmsLen;
int sequence = 0;
}
if (remains != 0) {
throw new SSLProtocolException("Invalid server_name extension");
}
}
return algorithms;
}
int length() {
return 6 + algorithmsLen;
}
}
}
boolean opened = false;
if (opened) {
} else {
opened = true;
}
}
}
}