1 /* 2 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 3 * 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 package sun.security.ssl; 26 27 import java.io.IOException; 28 import javax.net.ssl.SSLProtocolException; 29 30 /** 31 * Extended Master Secret TLS extension (TLS 1.0+). This extension 32 * defines how to calculate the TLS connection master secret and 33 * mitigates some types of man-in-the-middle attacks. 34 * 35 * See further information in 36 * <a href="https://tools.ietf.org/html/rfc7627">RFC 7627</a>. 37 * 38 * @author Martin Balao (mbalao@redhat.com) 39 */ 40 final class ExtendedMasterSecretExtension extends HelloExtension { 41 ExtendedMasterSecretExtension() { 42 super(ExtensionType.EXT_EXTENDED_MASTER_SECRET); 43 } 44 45 ExtendedMasterSecretExtension(HandshakeInStream s, 46 int len) throws IOException { 47 super(ExtensionType.EXT_EXTENDED_MASTER_SECRET); 48 49 if (len != 0) { 50 throw new SSLProtocolException("Invalid " + type + " extension"); 51 } 52 } 53 54 @Override 55 int length() { 56 return 4; // 4: extension type and length fields 57 } 58 59 @Override 60 void send(HandshakeOutStream s) throws IOException { 61 s.putInt16(type.id); // ExtensionType extension_type; 62 s.putInt16(0); // extension_data length 63 } 64 65 @Override 66 public String toString() { 67 return "Extension " + type; 68 } 69 } 70