src/java.base/share/classes/sun/security/ssl/SignatureAlgorithmsExtension.java
author xuelei
Wed, 23 May 2018 11:55:41 -0700
branchJDK-8145252-TLS13-branch
changeset 56600 58ad02eb44c3
parent 56584 a0f3377c58c7
child 56704 c3ee22c3a0f6
permissions -rw-r--r--
mismatching sign_alg and sign_alg_cert
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     1
/*
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     4
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    10
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    15
 * accompanied this code).
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    16
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    20
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    23
 * questions.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    24
 */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    25
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    26
package sun.security.ssl;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    27
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    28
import java.io.IOException;
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    29
import java.nio.ByteBuffer;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    30
import java.text.MessageFormat;
56584
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
    31
import java.util.Arrays;
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    32
import java.util.LinkedList;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    33
import java.util.List;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    34
import java.util.Locale;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    35
import javax.net.ssl.SSLProtocolException;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    36
import sun.security.ssl.SSLExtension.ExtensionConsumer;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    37
import sun.security.ssl.SSLExtension.SSLExtensionSpec;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    38
import sun.security.ssl.SSLHandshake.HandshakeMessage;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    39
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    40
/**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    41
 * Pack of the "signature_algorithms" extensions [RFC 5246].
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    42
 */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    43
final class SignatureAlgorithmsExtension {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    44
    static final HandshakeProducer chNetworkProducer =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    45
            new CHSignatureSchemesProducer();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    46
    static final ExtensionConsumer chOnLoadConcumer =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    47
            new CHSignatureSchemesConsumer();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    48
    static final HandshakeAbsence chOnLoadAbsence =
56584
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
    49
            new CHSignatureSchemesOnLoadAbsence();
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    50
    static final HandshakeConsumer chOnTradeConsumer =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    51
            new CHSignatureSchemesUpdate();
56584
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
    52
    static final HandshakeAbsence chOnTradeAbsence =
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
    53
            new CHSignatureSchemesOnTradeAbsence();
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    54
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    55
    static final HandshakeProducer crNetworkProducer =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    56
            new CRSignatureSchemesProducer();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    57
    static final ExtensionConsumer crOnLoadConcumer =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    58
            new CRSignatureSchemesConsumer();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    59
    static final HandshakeAbsence crOnLoadAbsence =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    60
            new CRSignatureSchemesAbsence();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    61
    static final HandshakeConsumer crOnTradeConsumer =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    62
            new CRSignatureSchemesUpdate();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    63
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    64
    static final SSLStringize ssStringize =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    65
            new SignatureSchemesStringize();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    66
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    67
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    68
     * The "signature_algorithms" extension.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    69
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    70
    static final class SignatureSchemesSpec implements SSLExtensionSpec {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    71
        final int[] signatureSchemes;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    72
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    73
        SignatureSchemesSpec(List<SignatureScheme> schemes) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    74
            if (schemes != null) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    75
                signatureSchemes = new int[schemes.size()];
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    76
                int i = 0;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    77
                for (SignatureScheme scheme : schemes) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    78
                    signatureSchemes[i++] = scheme.id;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    79
                }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    80
            } else {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    81
                this.signatureSchemes = new int[0];
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    82
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    83
        }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    84
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    85
        SignatureSchemesSpec(ByteBuffer buffer) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    86
            if (buffer.remaining() < 2) {      // 2: the length of the list
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    87
                throw new SSLProtocolException(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    88
                    "Invalid signature_algorithms: insufficient data");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    89
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    90
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    91
            byte[] algs = Record.getBytes16(buffer);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    92
            if (buffer.hasRemaining()) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    93
                throw new SSLProtocolException(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    94
                    "Invalid signature_algorithms: unknown extra data");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    95
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    96
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    97
            if (algs == null || algs.length == 0 || (algs.length & 0x01) != 0) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    98
                throw new SSLProtocolException(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    99
                    "Invalid signature_algorithms: incomplete data");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   100
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   101
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   102
            int[] schemes = new int[algs.length / 2];
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   103
            for (int i = 0, j = 0; i < algs.length;) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   104
                byte hash = algs[i++];
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   105
                byte sign = algs[i++];
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   106
                schemes[j++] = ((hash & 0xFF) << 8) | (sign & 0xFF);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   107
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   108
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   109
            this.signatureSchemes = schemes;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   110
        }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   111
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   112
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   113
        public String toString() {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   114
            MessageFormat messageFormat = new MessageFormat(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   115
                "\"signature schemes\": '['{0}']'", Locale.ENGLISH);
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   116
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   117
            if (signatureSchemes == null || signatureSchemes.length == 0) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   118
                Object[] messageFields = {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   119
                        "<no supported signature schemes specified>"
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   120
                    };
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   121
                return messageFormat.format(messageFields);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   122
            } else {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   123
                StringBuilder builder = new StringBuilder(512);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   124
                boolean isFirst = true;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   125
                for (int pv : signatureSchemes) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   126
                    if (isFirst) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   127
                        isFirst = false;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   128
                    } else {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   129
                        builder.append(", ");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   130
                    }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   131
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   132
                    builder.append(SignatureScheme.nameOf(pv));
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   133
                }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   134
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   135
                Object[] messageFields = {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   136
                        builder.toString()
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   137
                    };
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   138
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   139
                return messageFormat.format(messageFields);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   140
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   141
        }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   142
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   143
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   144
    private static final
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   145
            class SignatureSchemesStringize implements SSLStringize {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   146
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   147
        public String toString(ByteBuffer buffer) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   148
            try {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   149
                return (new SignatureSchemesSpec(buffer)).toString();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   150
            } catch (IOException ioe) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   151
                // For debug logging only, so please swallow exceptions.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   152
                return ioe.getMessage();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   153
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   154
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   155
    }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   156
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   157
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   158
     * Network data producer of a "signature_algorithms" extension in
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   159
     * the ClientHello handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   160
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   161
    private static final
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   162
            class CHSignatureSchemesProducer implements HandshakeProducer {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   163
        // Prevent instantiation of this class.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   164
        private CHSignatureSchemesProducer() {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   165
            // blank
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   166
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   167
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   168
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   169
        public byte[] produce(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   170
                HandshakeMessage message) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   171
            // The producing happens in client side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   172
            ClientHandshakeContext chc = (ClientHandshakeContext)context;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   173
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   174
            // Is it a supported and enabled extension?
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   175
            if (!chc.sslConfig.isAvailable(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   176
                    SSLExtension.CH_SIGNATURE_ALGORITHMS)) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   177
                if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   178
                    SSLLogger.fine(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   179
                        "Ignore unavailable signature_algorithms extension");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   180
                }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   181
                return null;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   182
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   183
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   184
            // Produce the extension.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   185
            if (chc.localSupportedSignAlgs == null) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   186
                chc.localSupportedSignAlgs =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   187
                    SignatureScheme.getSupportedAlgorithms(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   188
                            chc.algorithmConstraints, chc.activeProtocols);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   189
            }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   190
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   191
            int vectorLen = SignatureScheme.sizeInRecord() *
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   192
                    chc.localSupportedSignAlgs.size();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   193
            byte[] extData = new byte[vectorLen + 2];
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   194
            ByteBuffer m = ByteBuffer.wrap(extData);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   195
            Record.putInt16(m, vectorLen);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   196
            for (SignatureScheme ss : chc.localSupportedSignAlgs) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   197
                Record.putInt16(m, ss.id);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   198
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   199
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   200
            // Update the context.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   201
            chc.handshakeExtensions.put(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   202
                    SSLExtension.CH_SIGNATURE_ALGORITHMS,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   203
                    new SignatureSchemesSpec(chc.localSupportedSignAlgs));
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   204
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   205
            return extData;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   206
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   207
    }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   208
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   209
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   210
     * Network data consumer of a "signature_algorithms" extension in
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   211
     * the ClientHello handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   212
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   213
    private static final
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   214
            class CHSignatureSchemesConsumer implements ExtensionConsumer {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   215
        // Prevent instantiation of this class.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   216
        private CHSignatureSchemesConsumer() {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   217
            // blank
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   218
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   219
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   220
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   221
        public void consume(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   222
            HandshakeMessage message, ByteBuffer buffer) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   223
            // The comsuming happens in server side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   224
            ServerHandshakeContext shc = (ServerHandshakeContext)context;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   225
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   226
            // Is it a supported and enabled extension?
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   227
            if (!shc.sslConfig.isAvailable(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   228
                    SSLExtension.CH_SIGNATURE_ALGORITHMS)) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   229
                if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   230
                    SSLLogger.fine(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   231
                        "Ignore unavailable signature_algorithms extension");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   232
                }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   233
                return;     // ignore the extension
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   234
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   235
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   236
            // Parse the extension.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   237
            SignatureSchemesSpec spec;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   238
            try {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   239
                spec = new SignatureSchemesSpec(buffer);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   240
            } catch (IOException ioe) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   241
                shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   242
                return;     // fatal() always throws, make the compiler happy.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   243
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   244
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   245
            // Update the context.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   246
            shc.handshakeExtensions.put(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   247
                    SSLExtension.CH_SIGNATURE_ALGORITHMS, spec);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   248
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   249
            // No impact on session resumption.
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   250
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   251
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   252
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   253
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   254
     * After session creation consuming of a "signature_algorithms"
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   255
     * extension in the ClientHello handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   256
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   257
    private static final class CHSignatureSchemesUpdate
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   258
            implements HandshakeConsumer {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   259
        // Prevent instantiation of this class.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   260
        private CHSignatureSchemesUpdate() {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   261
            // blank
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   262
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   263
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   264
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   265
        public void consume(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   266
                HandshakeMessage message) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   267
            // The comsuming happens in server side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   268
            ServerHandshakeContext shc = (ServerHandshakeContext)context;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   269
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   270
            SignatureSchemesSpec spec =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   271
                    (SignatureSchemesSpec)shc.handshakeExtensions.get(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   272
                            SSLExtension.CH_SIGNATURE_ALGORITHMS);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   273
            if (spec == null) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   274
                // Ignore, no "signature_algorithms" extension requested.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   275
                return;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   276
            }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   277
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   278
            // update the context
56600
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   279
            List<SignatureScheme> sss =
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   280
                    SignatureScheme.getSupportedAlgorithms(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   281
                            shc.algorithmConstraints, shc.negotiatedProtocol,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   282
                            spec.signatureSchemes);
56600
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   283
            shc.peerRequestedSignatureSchemes = sss;
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   284
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   285
            // If no "signature_algorithms_cert" extension is present, then
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   286
            // the "signature_algorithms" extension also applies to
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   287
            // signatures appearing in certificates.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   288
            SignatureSchemesSpec certSpec =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   289
                    (SignatureSchemesSpec)shc.handshakeExtensions.get(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   290
                            SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   291
            if (certSpec == null) {
56600
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   292
                shc.peerRequestedCertSignSchemes = sss;
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   293
                shc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   294
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   295
56600
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   296
            if (!shc.isResumption &&
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   297
                    shc.negotiatedProtocol.useTLS13PlusSpec()) {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   298
                if (shc.sslConfig.clientAuthType !=
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   299
                        ClientAuthType.CLIENT_AUTH_NONE) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   300
                    shc.handshakeProducers.putIfAbsent(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   301
                            SSLHandshake.CERTIFICATE_REQUEST.id,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   302
                            SSLHandshake.CERTIFICATE_REQUEST);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   303
                }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   304
                shc.handshakeProducers.put(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   305
                        SSLHandshake.CERTIFICATE.id,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   306
                        SSLHandshake.CERTIFICATE);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   307
                shc.handshakeProducers.putIfAbsent(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   308
                        SSLHandshake.CERTIFICATE_VERIFY.id,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   309
                        SSLHandshake.CERTIFICATE_VERIFY);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   310
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   311
        }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   312
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   313
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   314
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   315
     * The absence processing if a "signature_algorithms" extension is
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   316
     * not present in the ClientHello handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   317
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   318
    private static final
56584
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   319
            class CHSignatureSchemesOnLoadAbsence implements HandshakeAbsence {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   320
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   321
        public void absent(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   322
                HandshakeMessage message) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   323
            // The comsuming happens in server side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   324
            ServerHandshakeContext shc = (ServerHandshakeContext)context;
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   325
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   326
            // This is a mandatory extension for certificate authentication
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   327
            // in TLS 1.3.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   328
            //
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   329
            // We may support the server authentication other than X.509
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   330
            // certificate later.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   331
            if (shc.negotiatedProtocol.useTLS13PlusSpec()) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   332
                shc.conContext.fatal(Alert.MISSING_EXTENSION,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   333
                    "No mandatory signature_algorithms extension in the " +
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   334
                    "received CertificateRequest handshake message");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   335
            }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   336
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   337
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   338
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   339
    /**
56584
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   340
     * The absence processing if a "signature_algorithms" extension is
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   341
     * not present in the ClientHello handshake message.
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   342
     */
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   343
    private static final
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   344
            class CHSignatureSchemesOnTradeAbsence implements HandshakeAbsence {
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   345
        @Override
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   346
        public void absent(ConnectionContext context,
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   347
                HandshakeMessage message) throws IOException {
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   348
            // The comsuming happens in server side only.
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   349
            ServerHandshakeContext shc = (ServerHandshakeContext)context;
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   350
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   351
            if (shc.negotiatedProtocol.useTLS12PlusSpec()) {
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   352
                // Use default hash and signature algorithm:
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   353
                //      {sha1,rsa}
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   354
                //      {sha1,dsa}
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   355
                //      {sha1,ecdsa}
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   356
                // Per RFC 5246, If the client supports only the default hash
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   357
                // and signature algorithms, it MAY omit the
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   358
                // signature_algorithms extension.  If the client does not
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   359
                // support the default algorithms, or supports other hash
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   360
                // and signature algorithms (and it is willing to use them
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   361
                // for verifying messages sent by the server, i.e., server
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   362
                // certificates and server key exchange), it MUST send the
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   363
                // signature_algorithms extension, listing the algorithms it
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   364
                // is willing to accept.
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   365
                List<SignatureScheme> shemes = Arrays.asList(
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   366
                        SignatureScheme.RSA_PKCS1_SHA1,
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   367
                        SignatureScheme.DSA_SHA1,
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   368
                        SignatureScheme.ECDSA_SHA1
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   369
                );
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   370
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   371
                shc.peerRequestedSignatureSchemes = shemes;
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   372
                if (shc.peerRequestedCertSignSchemes == null ||
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   373
                    shc.peerRequestedCertSignSchemes.isEmpty()) {
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   374
                        shc.peerRequestedCertSignSchemes = shemes;
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   375
                }
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   376
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   377
                // Use the default peer signature algorithms.
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   378
                shc.handshakeSession.setUseDefaultPeerSignAlgs();
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   379
            }
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   380
        }
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   381
    }
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   382
a0f3377c58c7 Use default signature algorithms for TLS 1.2
xuelei
parents: 56542
diff changeset
   383
    /**
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   384
     * Network data producer of a "signature_algorithms" extension in
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   385
     * the CertificateRequest handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   386
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   387
    private static final
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   388
            class CRSignatureSchemesProducer implements HandshakeProducer {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   389
        // Prevent instantiation of this class.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   390
        private CRSignatureSchemesProducer() {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   391
            // blank
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   392
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   393
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   394
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   395
        public byte[] produce(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   396
                HandshakeMessage message) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   397
            // The producing happens in server side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   398
            ServerHandshakeContext shc = (ServerHandshakeContext)context;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   399
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   400
            // Is it a supported and enabled extension?
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   401
            //
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   402
            // Note that this is a mandatory extension for CertificateRequest
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   403
            // handshake message in TLS 1.3.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   404
            if (!shc.sslConfig.isAvailable(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   405
                    SSLExtension.CR_SIGNATURE_ALGORITHMS)) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   406
                shc.conContext.fatal(Alert.MISSING_EXTENSION,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   407
                        "No available signature_algorithms extension " +
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   408
                        "for client certificate authentication");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   409
                return null;    // make the compiler happy
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   410
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   411
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   412
            // Produce the extension.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   413
            if (shc.localSupportedSignAlgs == null) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   414
                shc.localSupportedSignAlgs =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   415
                    SignatureScheme.getSupportedAlgorithms(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   416
                            shc.algorithmConstraints, shc.activeProtocols);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   417
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   418
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   419
            int vectorLen = SignatureScheme.sizeInRecord() *
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   420
                    shc.localSupportedSignAlgs.size();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   421
            byte[] extData = new byte[vectorLen + 2];
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   422
            ByteBuffer m = ByteBuffer.wrap(extData);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   423
            Record.putInt16(m, vectorLen);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   424
            for (SignatureScheme ss : shc.localSupportedSignAlgs) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   425
                Record.putInt16(m, ss.id);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   426
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   427
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   428
            // Update the context.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   429
            shc.handshakeExtensions.put(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   430
                    SSLExtension.CR_SIGNATURE_ALGORITHMS,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   431
                    new SignatureSchemesSpec(shc.localSupportedSignAlgs));
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   432
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   433
            return extData;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   434
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   435
    }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   436
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   437
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   438
     * Network data consumer of a "signature_algorithms" extension in
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   439
     * the CertificateRequest handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   440
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   441
    private static final
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   442
            class CRSignatureSchemesConsumer implements ExtensionConsumer {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   443
        // Prevent instantiation of this class.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   444
        private CRSignatureSchemesConsumer() {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   445
            // blank
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   446
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   447
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   448
        public void consume(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   449
            HandshakeMessage message, ByteBuffer buffer) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   450
            // The comsuming happens in client side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   451
            ClientHandshakeContext chc = (ClientHandshakeContext)context;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   452
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   453
            // Is it a supported and enabled extension?
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   454
            //
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   455
            // Note that this is a mandatory extension for CertificateRequest
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   456
            // handshake message in TLS 1.3.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   457
            if (!chc.sslConfig.isAvailable(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   458
                    SSLExtension.CR_SIGNATURE_ALGORITHMS)) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   459
                chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   460
                        "No available signature_algorithms extension " +
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   461
                        "for client certificate authentication");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   462
                return;     // make the compiler happy
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   463
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   464
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   465
            // Parse the extension.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   466
            SignatureSchemesSpec spec;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   467
            try {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   468
                spec = new SignatureSchemesSpec(buffer);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   469
            } catch (IOException ioe) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   470
                chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   471
                return;     // fatal() always throws, make the compiler happy.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   472
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   473
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   474
            List<SignatureScheme> knownSignatureSchemes = new LinkedList<>();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   475
            for (int id : spec.signatureSchemes) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   476
                SignatureScheme ss = SignatureScheme.valueOf(id);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   477
                if (ss != null) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   478
                    knownSignatureSchemes.add(ss);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   479
                }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   480
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   481
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   482
            // Update the context.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   483
            // chc.peerRequestedSignatureSchemes = knownSignatureSchemes;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   484
            chc.handshakeExtensions.put(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   485
                    SSLExtension.CR_SIGNATURE_ALGORITHMS, spec);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   486
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   487
            // No impact on session resumption.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   488
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   489
    }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   490
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   491
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   492
     * After session creation consuming of a "signature_algorithms"
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   493
     * extension in the CertificateRequest handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   494
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   495
    private static final class CRSignatureSchemesUpdate
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   496
            implements HandshakeConsumer {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   497
        // Prevent instantiation of this class.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   498
        private CRSignatureSchemesUpdate() {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   499
            // blank
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   500
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   501
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   502
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   503
        public void consume(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   504
                HandshakeMessage message) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   505
            // The comsuming happens in client side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   506
            ClientHandshakeContext chc = (ClientHandshakeContext)context;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   507
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   508
            SignatureSchemesSpec spec =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   509
                    (SignatureSchemesSpec)chc.handshakeExtensions.get(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   510
                            SSLExtension.CR_SIGNATURE_ALGORITHMS);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   511
            if (spec == null) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   512
                // Ignore, no "signature_algorithms" extension requested.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   513
                return;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   514
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   515
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   516
            // update the context
56600
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   517
            List<SignatureScheme> sss =
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   518
                    SignatureScheme.getSupportedAlgorithms(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   519
                            chc.algorithmConstraints, chc.negotiatedProtocol,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   520
                            spec.signatureSchemes);
56600
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   521
            chc.peerRequestedSignatureSchemes = sss;
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   522
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   523
            // If no "signature_algorithms_cert" extension is present, then
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   524
            // the "signature_algorithms" extension also applies to
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   525
            // signatures appearing in certificates.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   526
            SignatureSchemesSpec certSpec =
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   527
                    (SignatureSchemesSpec)chc.handshakeExtensions.get(
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   528
                            SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   529
            if (certSpec == null) {
56600
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   530
                chc.peerRequestedCertSignSchemes = sss;
58ad02eb44c3 mismatching sign_alg and sign_alg_cert
xuelei
parents: 56584
diff changeset
   531
                chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   532
            }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   533
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   534
    }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   535
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   536
    /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   537
     * The absence processing if a "signature_algorithms" extension is
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   538
     * not present in the CertificateRequest handshake message.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   539
     */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   540
    private static final
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   541
            class CRSignatureSchemesAbsence implements HandshakeAbsence {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   542
        @Override
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   543
        public void absent(ConnectionContext context,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   544
                HandshakeMessage message) throws IOException {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   545
            // The comsuming happens in client side only.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   546
            ClientHandshakeContext chc = (ClientHandshakeContext)context;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   547
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   548
            // This is a mandatory extension for CertificateRequest handshake
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   549
            // message in TLS 1.3.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   550
            chc.conContext.fatal(Alert.MISSING_EXTENSION,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   551
                    "No mandatory signature_algorithms extension in the " +
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   552
                    "received CertificateRequest handshake message");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   553
        }
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   554
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   555
}