src/java.base/share/classes/sun/security/ssl/SignatureAlgorithmsExtension.java
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
child 56584 a0f3377c58c7
equal deleted inserted replaced
56541:92cbbfc996f3 56542:56aaa6cb3693
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package sun.security.ssl;
    26 package sun.security.ssl;
    27 
    27 
    28 import java.io.IOException;
    28 import java.io.IOException;
    29 import java.util.ArrayList;
    29 import java.nio.ByteBuffer;
    30 import java.util.Collection;
    30 import java.text.MessageFormat;
    31 
    31 import java.util.LinkedList;
       
    32 import java.util.List;
       
    33 import java.util.Locale;
    32 import javax.net.ssl.SSLProtocolException;
    34 import javax.net.ssl.SSLProtocolException;
    33 
    35 import sun.security.ssl.SSLExtension.ExtensionConsumer;
    34 /*
    36 import sun.security.ssl.SSLExtension.SSLExtensionSpec;
    35  * [RFC5246] The client uses the "signature_algorithms" extension to
    37 import sun.security.ssl.SSLHandshake.HandshakeMessage;
    36  * indicate to the server which signature/hash algorithm pairs may be
    38 
    37  * used in digital signatures.  The "extension_data" field of this
    39 /**
    38  * extension contains a "supported_signature_algorithms" value.
    40  * Pack of the "signature_algorithms" extensions [RFC 5246].
    39  *
       
    40  *     enum {
       
    41  *         none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
       
    42  *         sha512(6), (255)
       
    43  *     } HashAlgorithm;
       
    44  *
       
    45  *     enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
       
    46  *       SignatureAlgorithm;
       
    47  *
       
    48  *     struct {
       
    49  *           HashAlgorithm hash;
       
    50  *           SignatureAlgorithm signature;
       
    51  *     } SignatureAndHashAlgorithm;
       
    52  *
       
    53  *     SignatureAndHashAlgorithm
       
    54  *       supported_signature_algorithms<2..2^16-2>;
       
    55  */
    41  */
    56 final class SignatureAlgorithmsExtension extends HelloExtension {
    42 final class SignatureAlgorithmsExtension {
    57 
    43     static final HandshakeProducer chNetworkProducer =
    58     private Collection<SignatureAndHashAlgorithm> algorithms;
    44             new CHSignatureSchemesProducer();
    59     private int algorithmsLen;  // length of supported_signature_algorithms
    45     static final ExtensionConsumer chOnLoadConcumer =
    60 
    46             new CHSignatureSchemesConsumer();
    61     SignatureAlgorithmsExtension(
    47     static final HandshakeAbsence chOnLoadAbsence =
    62             Collection<SignatureAndHashAlgorithm> signAlgs) {
    48             new CHSignatureSchemesAbsence();
    63 
    49     static final HandshakeConsumer chOnTradeConsumer =
    64         super(ExtensionType.EXT_SIGNATURE_ALGORITHMS);
    50             new CHSignatureSchemesUpdate();
    65 
    51 
    66         algorithms = new ArrayList<SignatureAndHashAlgorithm>(signAlgs);
    52     static final HandshakeProducer crNetworkProducer =
    67         algorithmsLen =
    53             new CRSignatureSchemesProducer();
    68             SignatureAndHashAlgorithm.sizeInRecord() * algorithms.size();
    54     static final ExtensionConsumer crOnLoadConcumer =
    69     }
    55             new CRSignatureSchemesConsumer();
    70 
    56     static final HandshakeAbsence crOnLoadAbsence =
    71     SignatureAlgorithmsExtension(HandshakeInStream s, int len)
    57             new CRSignatureSchemesAbsence();
    72                 throws IOException {
    58     static final HandshakeConsumer crOnTradeConsumer =
    73         super(ExtensionType.EXT_SIGNATURE_ALGORITHMS);
    59             new CRSignatureSchemesUpdate();
    74 
    60 
    75         algorithmsLen = s.getInt16();
    61     static final SSLStringize ssStringize =
    76         if (algorithmsLen == 0 || algorithmsLen + 2 != len) {
    62             new SignatureSchemesStringize();
    77             throw new SSLProtocolException("Invalid " + type + " extension");
    63 
    78         }
    64     /**
    79 
    65      * The "signature_algorithms" extension.
    80         algorithms = new ArrayList<SignatureAndHashAlgorithm>();
    66      */
    81         int remains = algorithmsLen;
    67     static final class SignatureSchemesSpec implements SSLExtensionSpec {
    82         int sequence = 0;
    68         final int[] signatureSchemes;
    83         while (remains > 1) {   // needs at least two bytes
    69 
    84             int hash = s.getInt8();         // hash algorithm
    70         SignatureSchemesSpec(List<SignatureScheme> schemes) {
    85             int signature = s.getInt8();    // signature algorithm
    71             if (schemes != null) {
    86 
    72                 signatureSchemes = new int[schemes.size()];
    87             SignatureAndHashAlgorithm algorithm =
    73                 int i = 0;
    88                 SignatureAndHashAlgorithm.valueOf(hash, signature, ++sequence);
    74                 for (SignatureScheme scheme : schemes) {
    89             algorithms.add(algorithm);
    75                     signatureSchemes[i++] = scheme.id;
    90             remains -= 2;  // one byte for hash, one byte for signature
    76                 }
    91         }
       
    92 
       
    93         if (remains != 0) {
       
    94             throw new SSLProtocolException("Invalid server_name extension");
       
    95         }
       
    96     }
       
    97 
       
    98     Collection<SignatureAndHashAlgorithm> getSignAlgorithms() {
       
    99         return algorithms;
       
   100     }
       
   101 
       
   102     @Override
       
   103     int length() {
       
   104         return 6 + algorithmsLen;
       
   105     }
       
   106 
       
   107     @Override
       
   108     void send(HandshakeOutStream s) throws IOException {
       
   109         s.putInt16(type.id);
       
   110         s.putInt16(algorithmsLen + 2);
       
   111         s.putInt16(algorithmsLen);
       
   112 
       
   113         for (SignatureAndHashAlgorithm algorithm : algorithms) {
       
   114             s.putInt8(algorithm.getHashValue());      // HashAlgorithm
       
   115             s.putInt8(algorithm.getSignatureValue()); // SignatureAlgorithm
       
   116         }
       
   117     }
       
   118 
       
   119     @Override
       
   120     public String toString() {
       
   121         StringBuilder sb = new StringBuilder();
       
   122         boolean opened = false;
       
   123         for (SignatureAndHashAlgorithm signAlg : algorithms) {
       
   124             if (opened) {
       
   125                 sb.append(", " + signAlg.getAlgorithmName());
       
   126             } else {
    77             } else {
   127                 sb.append(signAlg.getAlgorithmName());
    78                 this.signatureSchemes = new int[0];
   128                 opened = true;
    79             }
   129             }
    80         }
   130         }
    81 
   131 
    82         SignatureSchemesSpec(ByteBuffer buffer) throws IOException {
   132         return "Extension " + type + ", signature_algorithms: " + sb;
    83             if (buffer.remaining() < 2) {      // 2: the length of the list
       
    84                 throw new SSLProtocolException(
       
    85                     "Invalid signature_algorithms: insufficient data");
       
    86             }
       
    87 
       
    88             byte[] algs = Record.getBytes16(buffer);
       
    89             if (buffer.hasRemaining()) {
       
    90                 throw new SSLProtocolException(
       
    91                     "Invalid signature_algorithms: unknown extra data");
       
    92             }
       
    93 
       
    94             if (algs == null || algs.length == 0 || (algs.length & 0x01) != 0) {
       
    95                 throw new SSLProtocolException(
       
    96                     "Invalid signature_algorithms: incomplete data");
       
    97             }
       
    98 
       
    99             int[] schemes = new int[algs.length / 2];
       
   100             for (int i = 0, j = 0; i < algs.length;) {
       
   101                 byte hash = algs[i++];
       
   102                 byte sign = algs[i++];
       
   103                 schemes[j++] = ((hash & 0xFF) << 8) | (sign & 0xFF);
       
   104             }
       
   105 
       
   106             this.signatureSchemes = schemes;
       
   107         }
       
   108 
       
   109         @Override
       
   110         public String toString() {
       
   111             MessageFormat messageFormat = new MessageFormat(
       
   112                 "\"signature schemes\": '['{0}']'", Locale.ENGLISH);
       
   113 
       
   114             if (signatureSchemes == null || signatureSchemes.length == 0) {
       
   115                 Object[] messageFields = {
       
   116                         "<no supported signature schemes specified>"
       
   117                     };
       
   118                 return messageFormat.format(messageFields);
       
   119             } else {
       
   120                 StringBuilder builder = new StringBuilder(512);
       
   121                 boolean isFirst = true;
       
   122                 for (int pv : signatureSchemes) {
       
   123                     if (isFirst) {
       
   124                         isFirst = false;
       
   125                     } else {
       
   126                         builder.append(", ");
       
   127                     }
       
   128 
       
   129                     builder.append(SignatureScheme.nameOf(pv));
       
   130                 }
       
   131 
       
   132                 Object[] messageFields = {
       
   133                         builder.toString()
       
   134                     };
       
   135 
       
   136                 return messageFormat.format(messageFields);
       
   137             }
       
   138         }
       
   139     }
       
   140 
       
   141     private static final
       
   142             class SignatureSchemesStringize implements SSLStringize {
       
   143         @Override
       
   144         public String toString(ByteBuffer buffer) {
       
   145             try {
       
   146                 return (new SignatureSchemesSpec(buffer)).toString();
       
   147             } catch (IOException ioe) {
       
   148                 // For debug logging only, so please swallow exceptions.
       
   149                 return ioe.getMessage();
       
   150             }
       
   151         }
       
   152     }
       
   153 
       
   154     /**
       
   155      * Network data producer of a "signature_algorithms" extension in
       
   156      * the ClientHello handshake message.
       
   157      */
       
   158     private static final
       
   159             class CHSignatureSchemesProducer implements HandshakeProducer {
       
   160         // Prevent instantiation of this class.
       
   161         private CHSignatureSchemesProducer() {
       
   162             // blank
       
   163         }
       
   164 
       
   165         @Override
       
   166         public byte[] produce(ConnectionContext context,
       
   167                 HandshakeMessage message) throws IOException {
       
   168             // The producing happens in client side only.
       
   169             ClientHandshakeContext chc = (ClientHandshakeContext)context;
       
   170 
       
   171             // Is it a supported and enabled extension?
       
   172             if (!chc.sslConfig.isAvailable(
       
   173                     SSLExtension.CH_SIGNATURE_ALGORITHMS)) {
       
   174                 if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
       
   175                     SSLLogger.fine(
       
   176                         "Ignore unavailable signature_algorithms extension");
       
   177                 }
       
   178                 return null;
       
   179             }
       
   180 
       
   181             // Produce the extension.
       
   182             if (chc.localSupportedSignAlgs == null) {
       
   183                 chc.localSupportedSignAlgs =
       
   184                     SignatureScheme.getSupportedAlgorithms(
       
   185                             chc.algorithmConstraints, chc.activeProtocols);
       
   186             }
       
   187 
       
   188             int vectorLen = SignatureScheme.sizeInRecord() *
       
   189                     chc.localSupportedSignAlgs.size();
       
   190             byte[] extData = new byte[vectorLen + 2];
       
   191             ByteBuffer m = ByteBuffer.wrap(extData);
       
   192             Record.putInt16(m, vectorLen);
       
   193             for (SignatureScheme ss : chc.localSupportedSignAlgs) {
       
   194                 Record.putInt16(m, ss.id);
       
   195             }
       
   196 
       
   197             // Update the context.
       
   198             chc.handshakeExtensions.put(
       
   199                     SSLExtension.CH_SIGNATURE_ALGORITHMS,
       
   200                     new SignatureSchemesSpec(chc.localSupportedSignAlgs));
       
   201 
       
   202             return extData;
       
   203         }
       
   204     }
       
   205 
       
   206     /**
       
   207      * Network data consumer of a "signature_algorithms" extension in
       
   208      * the ClientHello handshake message.
       
   209      */
       
   210     private static final
       
   211             class CHSignatureSchemesConsumer implements ExtensionConsumer {
       
   212         // Prevent instantiation of this class.
       
   213         private CHSignatureSchemesConsumer() {
       
   214             // blank
       
   215         }
       
   216 
       
   217         @Override
       
   218         public void consume(ConnectionContext context,
       
   219             HandshakeMessage message, ByteBuffer buffer) throws IOException {
       
   220             // The comsuming happens in server side only.
       
   221             ServerHandshakeContext shc = (ServerHandshakeContext)context;
       
   222 
       
   223             // Is it a supported and enabled extension?
       
   224             if (!shc.sslConfig.isAvailable(
       
   225                     SSLExtension.CH_SIGNATURE_ALGORITHMS)) {
       
   226                 if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
       
   227                     SSLLogger.fine(
       
   228                         "Ignore unavailable signature_algorithms extension");
       
   229                 }
       
   230                 return;     // ignore the extension
       
   231             }
       
   232 
       
   233             // Parse the extension.
       
   234             SignatureSchemesSpec spec;
       
   235             try {
       
   236                 spec = new SignatureSchemesSpec(buffer);
       
   237             } catch (IOException ioe) {
       
   238                 shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe);
       
   239                 return;     // fatal() always throws, make the compiler happy.
       
   240             }
       
   241 
       
   242             // Update the context.
       
   243             shc.handshakeExtensions.put(
       
   244                     SSLExtension.CH_SIGNATURE_ALGORITHMS, spec);
       
   245 
       
   246             // No impact on session resumption.
       
   247         }
       
   248     }
       
   249 
       
   250     /**
       
   251      * After session creation consuming of a "signature_algorithms"
       
   252      * extension in the ClientHello handshake message.
       
   253      */
       
   254     private static final class CHSignatureSchemesUpdate
       
   255             implements HandshakeConsumer {
       
   256         // Prevent instantiation of this class.
       
   257         private CHSignatureSchemesUpdate() {
       
   258             // blank
       
   259         }
       
   260 
       
   261         @Override
       
   262         public void consume(ConnectionContext context,
       
   263                 HandshakeMessage message) throws IOException {
       
   264             // The comsuming happens in server side only.
       
   265             ServerHandshakeContext shc = (ServerHandshakeContext)context;
       
   266 
       
   267             SignatureSchemesSpec spec =
       
   268                     (SignatureSchemesSpec)shc.handshakeExtensions.get(
       
   269                             SSLExtension.CH_SIGNATURE_ALGORITHMS);
       
   270             if (spec == null) {
       
   271                 // Ignore, no "signature_algorithms" extension requested.
       
   272                 return;
       
   273             }
       
   274 
       
   275             // update the context
       
   276             List<SignatureScheme> shemes =
       
   277                     SignatureScheme.getSupportedAlgorithms(
       
   278                             shc.algorithmConstraints, shc.negotiatedProtocol,
       
   279                             spec.signatureSchemes);
       
   280             shc.peerRequestedSignatureSchemes = shemes;
       
   281 
       
   282             // If no "signature_algorithms_cert" extension is present, then
       
   283             // the "signature_algorithms" extension also applies to
       
   284             // signatures appearing in certificates.
       
   285             SignatureSchemesSpec certSpec =
       
   286                     (SignatureSchemesSpec)shc.handshakeExtensions.get(
       
   287                             SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
       
   288             if (certSpec == null) {
       
   289                 shc.peerRequestedCertSignSchemes = shemes;
       
   290             }
       
   291 
       
   292             shc.handshakeSession.setPeerSupportedSignatureAlgorithms(shemes);
       
   293 
       
   294             if (!shc.isResumption && shc.negotiatedProtocol.useTLS13PlusSpec()) {
       
   295                 if (shc.sslConfig.clientAuthType !=
       
   296                         ClientAuthType.CLIENT_AUTH_NONE) {
       
   297                     shc.handshakeProducers.putIfAbsent(
       
   298                             SSLHandshake.CERTIFICATE_REQUEST.id,
       
   299                             SSLHandshake.CERTIFICATE_REQUEST);
       
   300                 }
       
   301                 shc.handshakeProducers.put(
       
   302                         SSLHandshake.CERTIFICATE.id,
       
   303                         SSLHandshake.CERTIFICATE);
       
   304                 shc.handshakeProducers.putIfAbsent(
       
   305                         SSLHandshake.CERTIFICATE_VERIFY.id,
       
   306                         SSLHandshake.CERTIFICATE_VERIFY);
       
   307             }
       
   308         }
       
   309     }
       
   310 
       
   311     /**
       
   312      * The absence processing if a "signature_algorithms" extension is
       
   313      * not present in the ClientHello handshake message.
       
   314      */
       
   315     private static final
       
   316             class CHSignatureSchemesAbsence implements HandshakeAbsence {
       
   317         @Override
       
   318         public void absent(ConnectionContext context,
       
   319                 HandshakeMessage message) throws IOException {
       
   320             // The comsuming happens in server side only.
       
   321             ServerHandshakeContext shc = (ServerHandshakeContext)context;
       
   322 
       
   323             // This is a mandatory extension for certificate authentication
       
   324             // in TLS 1.3.
       
   325             //
       
   326             // We may support the server authentication other than X.509
       
   327             // certificate later.
       
   328             if (shc.negotiatedProtocol.useTLS13PlusSpec()) {
       
   329                 shc.conContext.fatal(Alert.MISSING_EXTENSION,
       
   330                     "No mandatory signature_algorithms extension in the " +
       
   331                     "received CertificateRequest handshake message");
       
   332             }
       
   333         }
       
   334     }
       
   335 
       
   336     /**
       
   337      * Network data producer of a "signature_algorithms" extension in
       
   338      * the CertificateRequest handshake message.
       
   339      */
       
   340     private static final
       
   341             class CRSignatureSchemesProducer implements HandshakeProducer {
       
   342         // Prevent instantiation of this class.
       
   343         private CRSignatureSchemesProducer() {
       
   344             // blank
       
   345         }
       
   346 
       
   347         @Override
       
   348         public byte[] produce(ConnectionContext context,
       
   349                 HandshakeMessage message) throws IOException {
       
   350             // The producing happens in server side only.
       
   351             ServerHandshakeContext shc = (ServerHandshakeContext)context;
       
   352 
       
   353             // Is it a supported and enabled extension?
       
   354             //
       
   355             // Note that this is a mandatory extension for CertificateRequest
       
   356             // handshake message in TLS 1.3.
       
   357             if (!shc.sslConfig.isAvailable(
       
   358                     SSLExtension.CR_SIGNATURE_ALGORITHMS)) {
       
   359                 shc.conContext.fatal(Alert.MISSING_EXTENSION,
       
   360                         "No available signature_algorithms extension " +
       
   361                         "for client certificate authentication");
       
   362                 return null;    // make the compiler happy
       
   363             }
       
   364 
       
   365             // Produce the extension.
       
   366             if (shc.localSupportedSignAlgs == null) {
       
   367                 shc.localSupportedSignAlgs =
       
   368                     SignatureScheme.getSupportedAlgorithms(
       
   369                             shc.algorithmConstraints, shc.activeProtocols);
       
   370             }
       
   371 
       
   372             int vectorLen = SignatureScheme.sizeInRecord() *
       
   373                     shc.localSupportedSignAlgs.size();
       
   374             byte[] extData = new byte[vectorLen + 2];
       
   375             ByteBuffer m = ByteBuffer.wrap(extData);
       
   376             Record.putInt16(m, vectorLen);
       
   377             for (SignatureScheme ss : shc.localSupportedSignAlgs) {
       
   378                 Record.putInt16(m, ss.id);
       
   379             }
       
   380 
       
   381             // Update the context.
       
   382             shc.handshakeExtensions.put(
       
   383                     SSLExtension.CR_SIGNATURE_ALGORITHMS,
       
   384                     new SignatureSchemesSpec(shc.localSupportedSignAlgs));
       
   385 
       
   386             return extData;
       
   387         }
       
   388     }
       
   389 
       
   390     /**
       
   391      * Network data consumer of a "signature_algorithms" extension in
       
   392      * the CertificateRequest handshake message.
       
   393      */
       
   394     private static final
       
   395             class CRSignatureSchemesConsumer implements ExtensionConsumer {
       
   396         // Prevent instantiation of this class.
       
   397         private CRSignatureSchemesConsumer() {
       
   398             // blank
       
   399         }
       
   400         @Override
       
   401         public void consume(ConnectionContext context,
       
   402             HandshakeMessage message, ByteBuffer buffer) throws IOException {
       
   403             // The comsuming happens in client side only.
       
   404             ClientHandshakeContext chc = (ClientHandshakeContext)context;
       
   405 
       
   406             // Is it a supported and enabled extension?
       
   407             //
       
   408             // Note that this is a mandatory extension for CertificateRequest
       
   409             // handshake message in TLS 1.3.
       
   410             if (!chc.sslConfig.isAvailable(
       
   411                     SSLExtension.CR_SIGNATURE_ALGORITHMS)) {
       
   412                 chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
       
   413                         "No available signature_algorithms extension " +
       
   414                         "for client certificate authentication");
       
   415                 return;     // make the compiler happy
       
   416             }
       
   417 
       
   418             // Parse the extension.
       
   419             SignatureSchemesSpec spec;
       
   420             try {
       
   421                 spec = new SignatureSchemesSpec(buffer);
       
   422             } catch (IOException ioe) {
       
   423                 chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe);
       
   424                 return;     // fatal() always throws, make the compiler happy.
       
   425             }
       
   426 
       
   427             List<SignatureScheme> knownSignatureSchemes = new LinkedList<>();
       
   428             for (int id : spec.signatureSchemes) {
       
   429                 SignatureScheme ss = SignatureScheme.valueOf(id);
       
   430                 if (ss != null) {
       
   431                     knownSignatureSchemes.add(ss);
       
   432                 }
       
   433             }
       
   434 
       
   435             // Update the context.
       
   436             // chc.peerRequestedSignatureSchemes = knownSignatureSchemes;
       
   437             chc.handshakeExtensions.put(
       
   438                     SSLExtension.CR_SIGNATURE_ALGORITHMS, spec);
       
   439 
       
   440             // No impact on session resumption.
       
   441         }
       
   442     }
       
   443 
       
   444     /**
       
   445      * After session creation consuming of a "signature_algorithms"
       
   446      * extension in the CertificateRequest handshake message.
       
   447      */
       
   448     private static final class CRSignatureSchemesUpdate
       
   449             implements HandshakeConsumer {
       
   450         // Prevent instantiation of this class.
       
   451         private CRSignatureSchemesUpdate() {
       
   452             // blank
       
   453         }
       
   454 
       
   455         @Override
       
   456         public void consume(ConnectionContext context,
       
   457                 HandshakeMessage message) throws IOException {
       
   458             // The comsuming happens in client side only.
       
   459             ClientHandshakeContext chc = (ClientHandshakeContext)context;
       
   460 
       
   461             SignatureSchemesSpec spec =
       
   462                     (SignatureSchemesSpec)chc.handshakeExtensions.get(
       
   463                             SSLExtension.CR_SIGNATURE_ALGORITHMS);
       
   464             if (spec == null) {
       
   465                 // Ignore, no "signature_algorithms" extension requested.
       
   466                 return;
       
   467             }
       
   468 
       
   469             // update the context
       
   470             List<SignatureScheme> shemes =
       
   471                     SignatureScheme.getSupportedAlgorithms(
       
   472                             chc.algorithmConstraints, chc.negotiatedProtocol,
       
   473                             spec.signatureSchemes);
       
   474             chc.peerRequestedSignatureSchemes = shemes;
       
   475 
       
   476             // If no "signature_algorithms_cert" extension is present, then
       
   477             // the "signature_algorithms" extension also applies to
       
   478             // signatures appearing in certificates.
       
   479             SignatureSchemesSpec certSpec =
       
   480                     (SignatureSchemesSpec)chc.handshakeExtensions.get(
       
   481                             SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
       
   482             if (certSpec == null) {
       
   483                 chc.peerRequestedCertSignSchemes = shemes;
       
   484             }
       
   485 
       
   486             chc.handshakeSession.setPeerSupportedSignatureAlgorithms(shemes);
       
   487         }
       
   488     }
       
   489 
       
   490     /**
       
   491      * The absence processing if a "signature_algorithms" extension is
       
   492      * not present in the CertificateRequest handshake message.
       
   493      */
       
   494     private static final
       
   495             class CRSignatureSchemesAbsence implements HandshakeAbsence {
       
   496         @Override
       
   497         public void absent(ConnectionContext context,
       
   498                 HandshakeMessage message) throws IOException {
       
   499             // The comsuming happens in client side only.
       
   500             ClientHandshakeContext chc = (ClientHandshakeContext)context;
       
   501 
       
   502             // This is a mandatory extension for CertificateRequest handshake
       
   503             // message in TLS 1.3.
       
   504             chc.conContext.fatal(Alert.MISSING_EXTENSION,
       
   505                     "No mandatory signature_algorithms extension in the " +
       
   506                     "received CertificateRequest handshake message");
       
   507         }
   133     }
   508     }
   134 }
   509 }
   135