Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
- * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * 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.
- */
- package sun.security.ssl;
- import java.io.IOException;
- import java.nio.ByteBuffer;
- import java.util.Map;
- import java.util.Random;
- import javax.net.ssl.SSLProtocolException;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_0A0A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_1A1A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_2A2A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_3A3A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_4A4A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_5A5A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_6A6A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_7A7A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_8A8A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_9A9A;
- import static sun.security.ssl.SSLExtension.TLS_GREASE_AAAA;
- import sun.security.ssl.SSLExtension.ExtensionConsumer;
- import sun.security.ssl.SSLExtension.SSLExtensionSpec;
- import sun.security.ssl.SSLHandshake.HandshakeMessage;
- /**
- * Pack of the "TLS_GREASE" extensions [RFC 7627].
- */
- final class TLSGreaseExtension {
- static final HandshakeProducer chNetworkProducer =
- new TLSGreaseProducer();
- static final ExtensionConsumer chOnLoadConsumer =
- new TLSGreaseConsumer();
- static final HandshakeAbsence chOnLoadAbsence =
- new TLSGreaseAbsence();
- static final SSLStringizer emsStringizer =
- new TLSGreaseStringizer();
- /**
- * The "TLS_GREASE" extension.
- */
- static final class TLSGreaseSpec implements SSLExtensionSpec {
- // A nominal object that does not hold any real renegotiation info.
- static final TLSGreaseSpec NOMINAL =
- new TLSGreaseSpec();
- private TLSGreaseSpec() {
- // blank
- }
- private TLSGreaseSpec(HandshakeContext hc,
- ByteBuffer m) throws IOException {
- // Parse the extension.
- if (m.hasRemaining()) {
- throw hc.conContext.fatal(Alert.DECODE_ERROR,
- new SSLProtocolException(
- "Invalid TLS_GREASE extension data: " +
- "not empty"));
- }
- }
- @Override
- public String toString() {
- return "<empty>";
- }
- }
- private static final
- class TLSGreaseStringizer implements SSLStringizer {
- @Override
- public String toString(HandshakeContext hc, ByteBuffer buffer) {
- try {
- return (new TLSGreaseSpec(hc, buffer)).toString();
- } catch (IOException ioe) {
- // For debug logging only, so please swallow exceptions.
- return ioe.getMessage();
- }
- }
- }
- /**
- * Network data producer of an "TLS_GREASE" extension in
- * the ClientHello handshake message.
- */
- private static final
- class TLSGreaseProducer implements HandshakeProducer {
- // Prevent instantiation of this class.
- private TLSGreaseProducer() {
- // blank
- }
- @Override
- public byte[] produce(ConnectionContext context,
- HandshakeMessage message) throws IOException {
- // The producing happens in client side only.
- ClientHandshakeContext chc = (ClientHandshakeContext)context;
- chc.handshakeExtensions.put(TLS_GREASE_0A0A,
- TLSGreaseSpec.NOMINAL);
- byte[] extData = new byte[1];
- ByteBuffer m = ByteBuffer.wrap(extData);
- Record.putInt8(m, 0x0);
- return extData;
- }
- }
- /**
- * Network data producer of an "TLS_GREASE" extension in
- * the ServerHello handshake message.
- */
- private static final
- class TLSGreaseConsumer implements ExtensionConsumer {
- // Prevent instantiation of this class.
- private TLSGreaseConsumer() {
- // blank
- }
- @Override
- public void consume(ConnectionContext context,
- HandshakeMessage message, ByteBuffer buffer) throws IOException {
- // The consuming happens in server side only.
- ServerHandshakeContext shc = (ServerHandshakeContext)context;
- // Update the context.
- //
- shc.handshakeExtensions.put(
- TLS_GREASE_0A0A, TLSGreaseSpec.NOMINAL);
- // No impact on session resumption.
- }
- }
- /**
- * The absence processing if an "TLS_GREASE" extension is
- * not present in the ClientHello handshake message.
- */
- private static final
- class TLSGreaseAbsence implements HandshakeAbsence {
- @Override
- public void absent(ConnectionContext context,
- HandshakeMessage message) throws IOException {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment