1 /* 2 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 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.ssl; 27 28 import java.io.IOException; 29 import javax.net.ssl.SSLProtocolException; 30 31 /** 32 * Extended Master Secret TLS extension (TLS 1.0+). This extension 33 * defines how to calculate the TLS connection master secret and 34 * mitigates some types of man-in-the-middle attacks. 35 * 36 * See further information in 37 * <a href="https://tools.ietf.org/html/rfc7627">RFC 7627</a>. 38 * 39 * @author Martin Balao (mbalao@redhat.com) 40 */ 41 final class ExtendedMasterSecretExtension extends HelloExtension { 42 ExtendedMasterSecretExtension() { 43 super(ExtensionType.EXT_EXTENDED_MASTER_SECRET); 44 } 45 46 ExtendedMasterSecretExtension(HandshakeInStream s, 47 int len) throws IOException { 48 super(ExtensionType.EXT_EXTENDED_MASTER_SECRET); 49 50 if (len != 0) { 51 throw new SSLProtocolException("Invalid " + type + " extension"); 52 } 53 } 54 55 @Override 56 int length() { 57 return 4; // 4: extension type and length fields 58 } 59 60 @Override 61 void send(HandshakeOutStream s) throws IOException { 62 s.putInt16(type.id); // ExtensionType extension_type; 63 s.putInt16(0); // extension_data length 64 } 65 66 @Override 67 public String toString() { 68 return "Extension " + type; 69 } 70 } 71