Guest User

Untitled

a guest
Sep 1st, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 50.16 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
  3.  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4.  *
  5.  * This code is free software; you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License version 2 only, as
  7.  * published by the Free Software Foundation.  Oracle designates this
  8.  * particular file as subject to the "Classpath" exception as provided
  9.  * by Oracle in the LICENSE file that accompanied this code.
  10.  *
  11.  * This code is distributed in the hope that it will be useful, but WITHOUT
  12.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14.  * version 2 for more details (a copy is included in the LICENSE file that
  15.  * accompanied this code).
  16.  *
  17.  * You should have received a copy of the GNU General Public License version
  18.  * 2 along with this work; if not, write to the Free Software Foundation,
  19.  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20.  *
  21.  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22.  * or visit www.oracle.com if you need additional information or have any
  23.  * questions.
  24.  */
  25.  
  26. package sun.security.ssl;
  27.  
  28. import java.io.IOException;
  29. import java.nio.ByteBuffer;
  30. import java.text.MessageFormat;
  31. import java.util.*;
  32.  
  33. import sun.security.action.GetPropertyAction;
  34. import sun.security.ssl.SSLHandshake.HandshakeMessage;
  35. import sun.security.util.HexDumpEncoder;
  36.  
  37. enum SSLExtension implements SSLStringizer {
  38.     // Extensions defined in RFC 6066 (TLS Extensions: Extension Definitions)
  39.     CH_SERVER_NAME          (0x0000,  "server_name",
  40.                                 SSLHandshake.CLIENT_HELLO,
  41.                                 ProtocolVersion.PROTOCOLS_TO_13,
  42.                                 ServerNameExtension.chNetworkProducer,
  43.                                 ServerNameExtension.chOnLoadConsumer,
  44.                                 null,
  45.                                 null,
  46.                                 null,
  47.                                 ServerNameExtension.chStringizer),
  48.     SH_SERVER_NAME          (0x0000, "server_name",
  49.                                 SSLHandshake.SERVER_HELLO,
  50.                                 ProtocolVersion.PROTOCOLS_TO_12,
  51.                                 ServerNameExtension.shNetworkProducer,
  52.                                 ServerNameExtension.shOnLoadConsumer,
  53.                                 null,
  54.                                 null,
  55.                                 null,
  56.                                 ServerNameExtension.shStringizer),
  57.     EE_SERVER_NAME          (0x0000, "server_name",
  58.                                 SSLHandshake.ENCRYPTED_EXTENSIONS,
  59.                                 ProtocolVersion.PROTOCOLS_OF_13,
  60.                                 ServerNameExtension.eeNetworkProducer,
  61.                                 ServerNameExtension.eeOnLoadConsumer,
  62.                                 null,
  63.                                 null,
  64.                                 null,
  65.                                 ServerNameExtension.shStringizer),
  66.  
  67.     CH_MAX_FRAGMENT_LENGTH (0x0001, "max_fragment_length",
  68.                                 SSLHandshake.CLIENT_HELLO,
  69.                                 ProtocolVersion.PROTOCOLS_TO_13,
  70.                                 MaxFragExtension.chNetworkProducer,
  71.                                 MaxFragExtension.chOnLoadConsumer,
  72.                                 null,
  73.                                 null,
  74.                                 null,
  75.                                 MaxFragExtension.maxFragLenStringizer),
  76.     SH_MAX_FRAGMENT_LENGTH (0x0001, "max_fragment_length",
  77.                                 SSLHandshake.SERVER_HELLO,
  78.                                 ProtocolVersion.PROTOCOLS_TO_12,
  79.                                 MaxFragExtension.shNetworkProducer,
  80.                                 MaxFragExtension.shOnLoadConsumer,
  81.                                 null,
  82.                                 MaxFragExtension.shOnTradeConsumer,
  83.                                 null,
  84.                                 MaxFragExtension.maxFragLenStringizer),
  85.     EE_MAX_FRAGMENT_LENGTH (0x0001, "max_fragment_length",
  86.                                 SSLHandshake.ENCRYPTED_EXTENSIONS,
  87.                                 ProtocolVersion.PROTOCOLS_OF_13,
  88.                                 MaxFragExtension.eeNetworkProducer,
  89.                                 MaxFragExtension.eeOnLoadConsumer,
  90.                                 null,
  91.                                 MaxFragExtension.eeOnTradeConsumer,
  92.                                 null,
  93.                                 MaxFragExtension.maxFragLenStringizer),
  94.  
  95.     CLIENT_CERTIFICATE_URL  (0x0002, "client_certificate_url"),
  96.     TRUSTED_CA_KEYS         (0x0003, "trusted_ca_keys"),
  97.     TRUNCATED_HMAC          (0x0004, "truncated_hmac"),
  98.  
  99.     CH_STATUS_REQUEST       (0x0005, "status_request",
  100.                                 SSLHandshake.CLIENT_HELLO,
  101.                                 ProtocolVersion.PROTOCOLS_TO_13,
  102.                                 CertStatusExtension.chNetworkProducer,
  103.                                 CertStatusExtension.chOnLoadConsumer,
  104.                                 null,
  105.                                 null,
  106.                                 null,
  107.                                 CertStatusExtension.certStatusReqStringizer),
  108.     SH_STATUS_REQUEST       (0x0005, "status_request",
  109.                                 SSLHandshake.SERVER_HELLO,
  110.                                 ProtocolVersion.PROTOCOLS_TO_12,
  111.                                 CertStatusExtension.shNetworkProducer,
  112.                                 CertStatusExtension.shOnLoadConsumer,
  113.                                 null,
  114.                                 null,
  115.                                 null,
  116.                                 CertStatusExtension.certStatusReqStringizer),
  117.     CR_STATUS_REQUEST       (0x0005, "status_request"),
  118.     CT_STATUS_REQUEST       (0x0005, "status_request",
  119.                                 SSLHandshake.CERTIFICATE,
  120.                                 ProtocolVersion.PROTOCOLS_OF_13,
  121.                                 CertStatusExtension.ctNetworkProducer,
  122.                                 CertStatusExtension.ctOnLoadConsumer,
  123.                                 null,
  124.                                 null,
  125.                                 null,
  126.                                 CertStatusExtension.certStatusRespStringizer),
  127.  
  128.     // Extensions defined in RFC 4681 (TLS User Mapping Extension)
  129.     USER_MAPPING            (0x0006, "user_mapping"),
  130.  
  131.     // Extensions defined in RFC 5878 (TLS Authorization Extensions)
  132.     CLIENT_AUTHZ            (0x0007, "client_authz"),
  133.     SERVER_AUTHZ            (0x0008, "server_authz"),
  134.  
  135.     // Extensions defined in RFC 6091 (Using OpenPGP Keys for TLS Authentication)
  136.     CERT_TYPE               (0x0009, "cert_type"),
  137.  
  138.     // Extensions defined in RFC 8422 (ECC Cipher Suites for TLS Versions 1.2 and Earlier)
  139.     CH_SUPPORTED_GROUPS     (0x000A, "supported_groups",
  140.                                 SSLHandshake.CLIENT_HELLO,
  141.                                 ProtocolVersion.PROTOCOLS_TO_13,
  142.                                 SupportedGroupsExtension.chNetworkProducer,
  143.                                 SupportedGroupsExtension.chOnLoadConsumer,
  144.                                 null,
  145.                                 null,
  146.                                 SupportedGroupsExtension.chOnTradAbsence,
  147.                                 SupportedGroupsExtension.sgsStringizer),
  148.     EE_SUPPORTED_GROUPS     (0x000A, "supported_groups",
  149.                                 SSLHandshake.ENCRYPTED_EXTENSIONS,
  150.                                 ProtocolVersion.PROTOCOLS_OF_13,
  151.                                 SupportedGroupsExtension.eeNetworkProducer,
  152.                                 SupportedGroupsExtension.eeOnLoadConsumer,
  153.                                 null,
  154.                                 null,
  155.                                 null,
  156.                                 SupportedGroupsExtension.sgsStringizer),
  157.  
  158.     CH_EC_POINT_FORMATS     (0x000B, "ec_point_formats",
  159.                                 SSLHandshake.CLIENT_HELLO,
  160.                                 ProtocolVersion.PROTOCOLS_TO_13,
  161.                                 ECPointFormatsExtension.chNetworkProducer,
  162.                                 ECPointFormatsExtension.chOnLoadConsumer,
  163.                                 null,
  164.                                 null,
  165.                                 null,
  166.                                 ECPointFormatsExtension.epfStringizer),
  167.     SH_EC_POINT_FORMATS     (0x000B, "ec_point_formats",
  168.                                 SSLHandshake.SERVER_HELLO,
  169.                                 ProtocolVersion.PROTOCOLS_TO_13,
  170.                                 null,   // not use of the producer
  171.                                 ECPointFormatsExtension.shOnLoadConsumer,
  172.                                 null,
  173.                                 null,
  174.                                 null,
  175.                                 ECPointFormatsExtension.epfStringizer),
  176.  
  177.     // Extensions defined in RFC 5054 (Using the SRP Protocol for TLS Authentication)
  178.     SRP                     (0x000C, "srp"),
  179.  
  180.     // Extensions defined in RFC 5764 (DTLS Extension to Establish Keys for the SRTP)
  181.     USE_SRTP                (0x000E, "use_srtp"),
  182.  
  183.     // Extensions defined in RFC 6520 (TLS and DTLS Heartbeat Extension)
  184.     HEARTBEAT               (0x000E, "heartbeat"),
  185.  
  186.     // Extensions defined in RFC 7301 (TLS Application-Layer Protocol Negotiation Extension)
  187.     CH_ALPN                 (0x0010, "application_layer_protocol_negotiation",
  188.                                 SSLHandshake.CLIENT_HELLO,
  189.                                 ProtocolVersion.PROTOCOLS_TO_13,
  190.                                 AlpnExtension.chNetworkProducer,
  191.                                 AlpnExtension.chOnLoadConsumer,
  192.                                 AlpnExtension.chOnLoadAbsence,
  193.                                 null,
  194.                                 null,
  195.                                 AlpnExtension.alpnStringizer),
  196.     SH_ALPN                 (0x0010, "application_layer_protocol_negotiation",
  197.                                 SSLHandshake.SERVER_HELLO,
  198.                                 ProtocolVersion.PROTOCOLS_TO_12,
  199.                                 AlpnExtension.shNetworkProducer,
  200.                                 AlpnExtension.shOnLoadConsumer,
  201.                                 AlpnExtension.shOnLoadAbsence,
  202.                                 null,
  203.                                 null,
  204.                                 AlpnExtension.alpnStringizer),
  205.     EE_ALPN                 (0x0010, "application_layer_protocol_negotiation",
  206.                                 SSLHandshake.ENCRYPTED_EXTENSIONS,
  207.                                 ProtocolVersion.PROTOCOLS_OF_13,
  208.                                 AlpnExtension.shNetworkProducer,
  209.                                 AlpnExtension.shOnLoadConsumer,
  210.                                 AlpnExtension.shOnLoadAbsence,
  211.                                 null,
  212.                                 null,
  213.                                 AlpnExtension.alpnStringizer),
  214.  
  215.     // Extensions defined in RFC 6961 (TLS Multiple Certificate Status Request Extension)
  216.     CH_STATUS_REQUEST_V2    (0x0011, "status_request_v2",
  217.                                 SSLHandshake.NOT_APPLICABLE,
  218.                                 ProtocolVersion.PROTOCOLS_TO_12,
  219.                                 CertStatusExtension.chV2NetworkProducer,
  220.                                 CertStatusExtension.chV2OnLoadConsumer,
  221.                                 null,
  222.                                 null,
  223.                                 null,
  224.                                 CertStatusExtension.certStatusReqV2Stringizer),
  225.     SH_STATUS_REQUEST_V2    (0x0011, "status_request_v2",
  226.                                 SSLHandshake.SERVER_HELLO,
  227.                                 ProtocolVersion.PROTOCOLS_TO_12,
  228.                                 CertStatusExtension.shV2NetworkProducer,
  229.                                 CertStatusExtension.shV2OnLoadConsumer,
  230.                                 null,
  231.                                 null,
  232.                                 null,
  233.                                 CertStatusExtension.certStatusReqV2Stringizer),
  234.  
  235.     // Extensions defined in RFC 6962 (Certificate Transparency)
  236.     SIGNED_CERT_TIMESTAMP   (0x0012, "signed_certificate_timestamp",
  237.                                 SSLHandshake.CLIENT_HELLO,
  238.                                 ProtocolVersion.PROTOCOLS_TO_13,
  239.                                 SignedCertificateTimestampExtension.chNetworkProducer,
  240.                                 SignedCertificateTimestampExtension.chOnLoadConsumer,
  241.                                 SignedCertificateTimestampExtension.chOnLoadAbsence,
  242.                                 null,
  243.                                 null,
  244.                                 SignedCertificateTimestampExtension.emsStringizer),
  245.  
  246.     TLS_GREASE_0A0A         (0x0A0A, "TLS_GREASE (0x0a0a)",
  247.                                 SSLHandshake.CLIENT_HELLO,
  248.                                 ProtocolVersion.PROTOCOLS_TO_13,
  249.                                 TLSGreaseExtension.chNetworkProducer,
  250.                                 TLSGreaseExtension.chOnLoadConsumer,
  251.                                 TLSGreaseExtension.chOnLoadAbsence,
  252.                                 null,
  253.                                 null,
  254.                                 TLSGreaseExtension.emsStringizer),
  255.     TLS_GREASE_1A1A         (0x1A1A, "TLS_GREASE (0x1a1a)",
  256.                                 SSLHandshake.CLIENT_HELLO,
  257.                                 ProtocolVersion.PROTOCOLS_TO_13,
  258.                                 TLSGreaseExtension.chNetworkProducer,
  259.                                 TLSGreaseExtension.chOnLoadConsumer,
  260.                                 TLSGreaseExtension.chOnLoadAbsence,
  261.                                 null,
  262.                                 null,
  263.                                 TLSGreaseExtension.emsStringizer),
  264.     TLS_GREASE_2A2A         (0x2A2A, "TLS_GREASE (0x2a2a)",
  265.                                 SSLHandshake.CLIENT_HELLO,
  266.                                 ProtocolVersion.PROTOCOLS_TO_13,
  267.                                 TLSGreaseExtension.chNetworkProducer,
  268.                                 TLSGreaseExtension.chOnLoadConsumer,
  269.                                 TLSGreaseExtension.chOnLoadAbsence,
  270.                                 null,
  271.                                 null,
  272.                                 TLSGreaseExtension.emsStringizer),
  273.     TLS_GREASE_3A3A         (0x3A3A, "TLS_GREASE (0x3a3a)",
  274.                                 SSLHandshake.CLIENT_HELLO,
  275.                                 ProtocolVersion.PROTOCOLS_TO_13,
  276.                                 TLSGreaseExtension.chNetworkProducer,
  277.                                 TLSGreaseExtension.chOnLoadConsumer,
  278.                                 TLSGreaseExtension.chOnLoadAbsence,
  279.                                 null,
  280.                                 null,
  281.                                 TLSGreaseExtension.emsStringizer),
  282.     TLS_GREASE_4A4A         (0x4A4A, "TLS_GREASE (0x4a4a)",
  283.                                 SSLHandshake.CLIENT_HELLO,
  284.                                 ProtocolVersion.PROTOCOLS_TO_13,
  285.                                 TLSGreaseExtension.chNetworkProducer,
  286.                                 TLSGreaseExtension.chOnLoadConsumer,
  287.                                 TLSGreaseExtension.chOnLoadAbsence,
  288.                                 null,
  289.                                 null,
  290.                                 TLSGreaseExtension.emsStringizer),
  291.     TLS_GREASE_5A5A         (0x5A5A, "TLS_GREASE (0x5a5a)",
  292.                                 SSLHandshake.CLIENT_HELLO,
  293.                                 ProtocolVersion.PROTOCOLS_TO_13,
  294.                                 TLSGreaseExtension.chNetworkProducer,
  295.                                 TLSGreaseExtension.chOnLoadConsumer,
  296.                                 TLSGreaseExtension.chOnLoadAbsence,
  297.                                 null,
  298.                                 null,
  299.                                 TLSGreaseExtension.emsStringizer),
  300.     TLS_GREASE_6A6A         (0x6A6A, "TLS_GREASE (0x6a6a)",
  301.                                 SSLHandshake.CLIENT_HELLO,
  302.                                 ProtocolVersion.PROTOCOLS_TO_13,
  303.                                 TLSGreaseExtension.chNetworkProducer,
  304.                                 TLSGreaseExtension.chOnLoadConsumer,
  305.                                 TLSGreaseExtension.chOnLoadAbsence,
  306.                                 null,
  307.                                 null,
  308.                                 TLSGreaseExtension.emsStringizer),
  309.     TLS_GREASE_7A7A         (0x7A7A, "TLS_GREASE (0x7a7a)",
  310.                                 SSLHandshake.CLIENT_HELLO,
  311.                                 ProtocolVersion.PROTOCOLS_TO_13,
  312.                                 TLSGreaseExtension.chNetworkProducer,
  313.                                 TLSGreaseExtension.chOnLoadConsumer,
  314.                                 TLSGreaseExtension.chOnLoadAbsence,
  315.                                 null,
  316.                                 null,
  317.                                 TLSGreaseExtension.emsStringizer),
  318.     TLS_GREASE_8A8A         (0x8A8A, "TLS_GREASE (0x8a8a)",
  319.                                 SSLHandshake.CLIENT_HELLO,
  320.                                 ProtocolVersion.PROTOCOLS_TO_13,
  321.                                 TLSGreaseExtension.chNetworkProducer,
  322.                                 TLSGreaseExtension.chOnLoadConsumer,
  323.                                 TLSGreaseExtension.chOnLoadAbsence,
  324.                                 null,
  325.                                 null,
  326.                                 TLSGreaseExtension.emsStringizer),
  327.     TLS_GREASE_9A9A         (0x9A9A, "TLS_GREASE (0x9a9a)",
  328.                                 SSLHandshake.CLIENT_HELLO,
  329.                                 ProtocolVersion.PROTOCOLS_TO_13,
  330.                                 TLSGreaseExtension.chNetworkProducer,
  331.                                 TLSGreaseExtension.chOnLoadConsumer,
  332.                                 TLSGreaseExtension.chOnLoadAbsence,
  333.                                 null,
  334.                                 null,
  335.                                 TLSGreaseExtension.emsStringizer),
  336.     TLS_GREASE_AAAA         (0xAAAA, "TLS_GREASE (0xaaaa)",
  337.                                 SSLHandshake.CLIENT_HELLO,
  338.                                 ProtocolVersion.PROTOCOLS_TO_13,
  339.                                 TLSGreaseExtension.chNetworkProducer,
  340.                                 TLSGreaseExtension.chOnLoadConsumer,
  341.                                 TLSGreaseExtension.chOnLoadAbsence,
  342.                                 null,
  343.                                 null,
  344.                                 TLSGreaseExtension.emsStringizer),
  345.  
  346.     // Extensions defined in RFC 7250 (Using Raw Public Keys in TLS and DTLS)
  347.     CLIENT_CERT_TYPE        (0x0013, "client_certificate_type"),
  348.     SERVER_CERT_TYPE        (0x0014, "server_certificate_type"),
  349.  
  350.     // Extensions defined in RFC 7685 (TLS ClientHello Padding Extension)
  351.     PADDING                 (0x0015, "padding",
  352.                                 SSLHandshake.CLIENT_HELLO,
  353.                                 ProtocolVersion.PROTOCOLS_TO_13,
  354.                                 PaddingExtension.chNetworkProducer,
  355.                                 PaddingExtension.chOnLoadConsumer,
  356.                                 PaddingExtension.chOnLoadAbsence,
  357.                                 null,
  358.                                 null,
  359.                                 PaddingExtension.emsStringizer),
  360.  
  361.     // Extensions defined in RFC 7366 (Encrypt-then-MAC for TLS and DTLS)
  362.     ENCRYPT_THEN_MAC        (0x0016, "encrypt_then_mac"),
  363.  
  364.     // Extensions defined in RFC 7627 (TLS Session Hash and Extended Master Secret Extension)
  365.     CH_EXTENDED_MASTER_SECRET  (0x0017, "extended_master_secret",
  366.                                 SSLHandshake.CLIENT_HELLO,
  367.                                 ProtocolVersion.PROTOCOLS_TO_13,
  368.                                 ExtendedMasterSecretExtension.chNetworkProducer,
  369.                                 ExtendedMasterSecretExtension.chOnLoadConsumer,
  370.                                 ExtendedMasterSecretExtension.chOnLoadAbsence,
  371.                                 null,
  372.                                 null,
  373.                                 ExtendedMasterSecretExtension.emsStringizer),
  374.     SH_EXTENDED_MASTER_SECRET  (0x0017, "extended_master_secret",
  375.                                 SSLHandshake.SERVER_HELLO,
  376.                                 ProtocolVersion.PROTOCOLS_TO_13,
  377.                                 ExtendedMasterSecretExtension.shNetworkProducer,
  378.                                 ExtendedMasterSecretExtension.shOnLoadConsumer,
  379.                                 ExtendedMasterSecretExtension.shOnLoadAbsence,
  380.                                 null,
  381.                                 null,
  382.                                 ExtendedMasterSecretExtension.emsStringizer),
  383.  
  384.     APPLICATION_SETTINGS       (0x4469, "application_settings",
  385.                                 SSLHandshake.CLIENT_HELLO,
  386.                                 ProtocolVersion.PROTOCOLS_TO_13,
  387.                                 ApplicationSettingsExtension.chNetworkProducer,
  388.                                 ApplicationSettingsExtension.chOnLoadConsumer,
  389.                                 ApplicationSettingsExtension.chOnLoadAbsence,
  390.                                 null,
  391.                                 null,
  392.                                 ApplicationSettingsExtension.emsStringizer),
  393.  
  394.     // Extensions defined in RFC 8472 (TLS Extension for Token Binding Protocol Negotiation)
  395.     TOKEN_BINDING           (0x0018, "token_binding"),
  396.  
  397.     // Extensions defined in RFC 7924 (TLS Cached Information Extension)
  398.     CACHED_INFO             (0x0019, "cached_info"),
  399.  
  400.     COMPRESS_CERTIFICATE    (0x001b, "compress_certificate",
  401.                                 SSLHandshake.CLIENT_HELLO,
  402.                                 ProtocolVersion.PROTOCOLS_TO_12,
  403.                                 CompressCertificateExtension.chNetworkProducer,
  404.                                 CompressCertificateExtension.chOnLoadConsumer,
  405.                                 CompressCertificateExtension.chOnLoadAbsence,
  406.                                 null,
  407.                                 null,
  408.                                 CompressCertificateExtension.emsStringizer),
  409.  
  410.     // Extensions defined in RFC 5077 (TLS Session Resumption without Server-Side State)
  411.     CH_SESSION_TICKET       (0x0023, "session_ticket",
  412.             SSLHandshake.CLIENT_HELLO,
  413.             ProtocolVersion.PROTOCOLS_TO_13,
  414.             SessionTicketExtension.chNetworkProducer,
  415.             SessionTicketExtension.chOnLoadConsumer,
  416.             null,
  417.             null,
  418.             null,
  419.             SessionTicketExtension.steStringizer),
  420.             //null),
  421.     SH_SESSION_TICKET       (0x0023, "session_ticket",
  422.             SSLHandshake.SERVER_HELLO,
  423.             ProtocolVersion.PROTOCOLS_TO_13,
  424.             SessionTicketExtension.shNetworkProducer,
  425.             SessionTicketExtension.shOnLoadConsumer,
  426.             null,
  427.             null,
  428.             null,
  429.             SessionTicketExtension.steStringizer),
  430.             //null),
  431.  
  432.     // Extensions defined in RFC 8446 (TLS Protocol Version 1.3)
  433.     CH_SIGNATURE_ALGORITHMS (0x000D, "signature_algorithms",
  434.                                 SSLHandshake.CLIENT_HELLO,
  435.                                 ProtocolVersion.PROTOCOLS_12_13,
  436.                                 SignatureAlgorithmsExtension.chNetworkProducer,
  437.                                 SignatureAlgorithmsExtension.chOnLoadConsumer,
  438.                                 SignatureAlgorithmsExtension.chOnLoadAbsence,
  439.                                 SignatureAlgorithmsExtension.chOnTradeConsumer,
  440.                                 SignatureAlgorithmsExtension.chOnTradeAbsence,
  441.                                 SignatureAlgorithmsExtension.ssStringizer),
  442.     CR_SIGNATURE_ALGORITHMS (0x000D, "signature_algorithms",
  443.                                 SSLHandshake.CERTIFICATE_REQUEST,
  444.                                 ProtocolVersion.PROTOCOLS_OF_13,
  445.                                 SignatureAlgorithmsExtension.crNetworkProducer,
  446.                                 SignatureAlgorithmsExtension.crOnLoadConsumer,
  447.                                 SignatureAlgorithmsExtension.crOnLoadAbsence,
  448.                                 SignatureAlgorithmsExtension.crOnTradeConsumer,
  449.                                 null,
  450.                                 SignatureAlgorithmsExtension.ssStringizer),
  451.  
  452.     CH_EARLY_DATA           (0x002A, "early_data"),
  453.     EE_EARLY_DATA           (0x002A, "early_data"),
  454.     NST_EARLY_DATA          (0x002A, "early_data"),
  455.  
  456.     CH_SUPPORTED_VERSIONS   (0x002B, "supported_versions",
  457.                                 SSLHandshake.CLIENT_HELLO,
  458.                                 ProtocolVersion.PROTOCOLS_TO_13,
  459.                                 SupportedVersionsExtension.chNetworkProducer,
  460.                                 SupportedVersionsExtension.chOnLoadConsumer,
  461.                                 null,
  462.                                 null,
  463.                                 null,
  464.                                 SupportedVersionsExtension.chStringizer),
  465.     SH_SUPPORTED_VERSIONS   (0x002B, "supported_versions",
  466.                                 SSLHandshake.SERVER_HELLO,
  467.                                 ProtocolVersion.PROTOCOLS_OF_13,
  468.                                 SupportedVersionsExtension.shNetworkProducer,
  469.                                 SupportedVersionsExtension.shOnLoadConsumer,
  470.                                 null,
  471.                                 null,
  472.                                 null,
  473.                                 SupportedVersionsExtension.shStringizer),
  474.     HRR_SUPPORTED_VERSIONS  (0x002B, "supported_versions",
  475.                                 SSLHandshake.HELLO_RETRY_REQUEST,
  476.                                 ProtocolVersion.PROTOCOLS_OF_13,
  477.                                 SupportedVersionsExtension.hrrNetworkProducer,
  478.                                 SupportedVersionsExtension.hrrOnLoadConsumer,
  479.                                 null,
  480.                                 null,
  481.                                 null,
  482.                                 SupportedVersionsExtension.hrrStringizer),
  483.     MH_SUPPORTED_VERSIONS   (0x002B, "supported_versions",
  484.                                 SSLHandshake.MESSAGE_HASH,
  485.                                 ProtocolVersion.PROTOCOLS_OF_13,
  486.                                 SupportedVersionsExtension.hrrReproducer,
  487.                                 null, null, null,
  488.                                 null,
  489.                                 SupportedVersionsExtension.hrrStringizer),
  490.  
  491.     CH_COOKIE               (0x002C, "cookie",
  492.                                 SSLHandshake.CLIENT_HELLO,
  493.                                 ProtocolVersion.PROTOCOLS_OF_13,
  494.                                 CookieExtension.chNetworkProducer,
  495.                                 CookieExtension.chOnLoadConsumer,
  496.                                 null,
  497.                                 CookieExtension.chOnTradeConsumer,
  498.                                 null,
  499.                                 CookieExtension.cookieStringizer),
  500.     HRR_COOKIE              (0x002C, "cookie",
  501.                                 SSLHandshake.HELLO_RETRY_REQUEST,
  502.                                 ProtocolVersion.PROTOCOLS_OF_13,
  503.                                 CookieExtension.hrrNetworkProducer,
  504.                                 CookieExtension.hrrOnLoadConsumer,
  505.                                 null, null,
  506.                                 null,
  507.                                 CookieExtension.cookieStringizer),
  508.     MH_COOKIE               (0x002C, "cookie",
  509.                                 SSLHandshake.MESSAGE_HASH,
  510.                                 ProtocolVersion.PROTOCOLS_OF_13,
  511.                                 CookieExtension.hrrNetworkReproducer,
  512.                                 null, null, null,
  513.                                 null,
  514.                                 CookieExtension.cookieStringizer),
  515.  
  516.     PSK_KEY_EXCHANGE_MODES  (0x002D, "psk_key_exchange_modes",
  517.                                 SSLHandshake.CLIENT_HELLO,
  518.                                 ProtocolVersion.PROTOCOLS_OF_13,
  519.                                 PskKeyExchangeModesExtension.chNetworkProducer,
  520.                                 PskKeyExchangeModesExtension.chOnLoadConsumer,
  521.                                 PskKeyExchangeModesExtension.chOnLoadAbsence,
  522.                                 null,
  523.                                 PskKeyExchangeModesExtension.chOnTradeAbsence,
  524.                                 PskKeyExchangeModesExtension.pkemStringizer),
  525.     CH_CERTIFICATE_AUTHORITIES (0x002F, "certificate_authorities",
  526.                                 SSLHandshake.CLIENT_HELLO,
  527.                                 ProtocolVersion.PROTOCOLS_OF_13,
  528.                                 CertificateAuthoritiesExtension.chNetworkProducer,
  529.                                 CertificateAuthoritiesExtension.chOnLoadConsumer,
  530.                                 null,
  531.                                 null,
  532.                                 null,
  533.                                 CertificateAuthoritiesExtension.ssStringizer),
  534.     CR_CERTIFICATE_AUTHORITIES (0x002F, "certificate_authorities",
  535.                                 SSLHandshake.CERTIFICATE_REQUEST,
  536.                                 ProtocolVersion.PROTOCOLS_OF_13,
  537.                                 CertificateAuthoritiesExtension.crNetworkProducer,
  538.                                 CertificateAuthoritiesExtension.crOnLoadConsumer,
  539.                                 null,
  540.                                 null,
  541.                                 null,
  542.                                 CertificateAuthoritiesExtension.ssStringizer),
  543.  
  544.     OID_FILTERS             (0x0030, "oid_filters"),
  545.     POST_HANDSHAKE_AUTH     (0x0030, "post_handshake_auth"),
  546.  
  547.     CH_SIGNATURE_ALGORITHMS_CERT (0x0032, "signature_algorithms_cert",
  548.                                 SSLHandshake.NOT_APPLICABLE,
  549.                                 ProtocolVersion.PROTOCOLS_12_13,
  550.                                 CertSignAlgsExtension.chNetworkProducer,
  551.                                 CertSignAlgsExtension.chOnLoadConsumer,
  552.                                 null,
  553.                                 CertSignAlgsExtension.chOnTradeConsumer,
  554.                                 null,
  555.                                 CertSignAlgsExtension.ssStringizer),
  556.     CR_SIGNATURE_ALGORITHMS_CERT (0x0032, "signature_algorithms_cert",
  557.                                 SSLHandshake.CERTIFICATE_REQUEST,
  558.                                 ProtocolVersion.PROTOCOLS_OF_13,
  559.                                 CertSignAlgsExtension.crNetworkProducer,
  560.                                 CertSignAlgsExtension.crOnLoadConsumer,
  561.                                 null,
  562.                                 CertSignAlgsExtension.crOnTradeConsumer,
  563.                                 null,
  564.                                 CertSignAlgsExtension.ssStringizer),
  565.  
  566.     CH_KEY_SHARE            (0x0033, "key_share",
  567.                                 SSLHandshake.CLIENT_HELLO,
  568.                                 ProtocolVersion.PROTOCOLS_OF_13,
  569.                                 KeyShareExtension.chNetworkProducer,
  570.                                 KeyShareExtension.chOnLoadConsumer,
  571.                                 null,
  572.                                 null,
  573.                                 KeyShareExtension.chOnTradAbsence,
  574.                                 KeyShareExtension.chStringizer),
  575.     SH_KEY_SHARE            (0x0033, "key_share",
  576.                                 SSLHandshake.SERVER_HELLO,
  577.                                 ProtocolVersion.PROTOCOLS_OF_13,
  578.                                 KeyShareExtension.shNetworkProducer,
  579.                                 KeyShareExtension.shOnLoadConsumer,
  580.                                 KeyShareExtension.shOnLoadAbsence,
  581.                                 null,
  582.                                 null,
  583.                                 KeyShareExtension.shStringizer),
  584.     HRR_KEY_SHARE           (0x0033, "key_share",
  585.                                 SSLHandshake.HELLO_RETRY_REQUEST,
  586.                                 ProtocolVersion.PROTOCOLS_OF_13,
  587.                                 KeyShareExtension.hrrNetworkProducer,
  588.                                 KeyShareExtension.hrrOnLoadConsumer,
  589.                                 null, null, null,
  590.                                 KeyShareExtension.hrrStringizer),
  591.     MH_KEY_SHARE            (0x0033, "key_share",
  592.                                 SSLHandshake.MESSAGE_HASH,
  593.                                 ProtocolVersion.PROTOCOLS_OF_13,
  594.                                 KeyShareExtension.hrrNetworkReproducer,
  595.                                 null, null, null, null,
  596.                                 KeyShareExtension.hrrStringizer),
  597.  
  598.     // Extensions defined in RFC 5746 (TLS Renegotiation Indication Extension)
  599.     CH_RENEGOTIATION_INFO   (0xff01, "renegotiation_info",
  600.                                 SSLHandshake.CLIENT_HELLO,
  601.                                 ProtocolVersion.PROTOCOLS_TO_13,
  602.                                 RenegoInfoExtension.chNetworkProducer,
  603.                                 RenegoInfoExtension.chOnLoadConsumer,
  604.                                 RenegoInfoExtension.chOnLoadAbsence,
  605.                                 null,
  606.                                 null,
  607.                                 RenegoInfoExtension.rniStringizer),
  608.     SH_RENEGOTIATION_INFO   (0xff01, "renegotiation_info",
  609.                                 SSLHandshake.SERVER_HELLO,
  610.                                 ProtocolVersion.PROTOCOLS_TO_13,
  611.                                 RenegoInfoExtension.shNetworkProducer,
  612.                                 RenegoInfoExtension.shOnLoadConsumer,
  613.                                 RenegoInfoExtension.shOnLoadAbsence,
  614.                                 null,
  615.                                 null,
  616.                                 RenegoInfoExtension.rniStringizer),
  617.  
  618.     // RFC 8446 (TLS Protocol Version 1.3) PSK extension must be last
  619.     CH_PRE_SHARED_KEY       (0x0029, "pre_shared_key",
  620.                                 SSLHandshake.CLIENT_HELLO,
  621.                                 ProtocolVersion.PROTOCOLS_OF_13,
  622.                                 PreSharedKeyExtension.chNetworkProducer,
  623.                                 PreSharedKeyExtension.chOnLoadConsumer,
  624.                                 PreSharedKeyExtension.chOnLoadAbsence,
  625.                                 PreSharedKeyExtension.chOnTradeConsumer,
  626.                                 PreSharedKeyExtension.chOnTradAbsence,
  627.                                 PreSharedKeyExtension.chStringizer),
  628.     SH_PRE_SHARED_KEY       (0x0029, "pre_shared_key",
  629.                                 SSLHandshake.SERVER_HELLO,
  630.                                 ProtocolVersion.PROTOCOLS_OF_13,
  631.                                 PreSharedKeyExtension.shNetworkProducer,
  632.                                 PreSharedKeyExtension.shOnLoadConsumer,
  633.                                 PreSharedKeyExtension.shOnLoadAbsence,
  634.                                 null, null,
  635.                                 PreSharedKeyExtension.shStringizer);
  636.  
  637.     final int id;
  638.     final SSLHandshake handshakeType;
  639.     final String name;
  640.     final ProtocolVersion[] supportedProtocols;
  641.  
  642.     /*
  643.      * networkProducer: produces outbound handshake data.
  644.      *
  645.      * onLoadConsumer:  parses inbound data.  It may not be appropriate
  646.      *                  to act until all the message inputs have
  647.      *                  been parsed.  (e.g. parsing keyShares and choosing
  648.      *                  a local value without having seen the SupportedGroups
  649.      *                  extension.)
  650.      *
  651.      * onLoadAbsence:   if a missing message needs special handling
  652.      *                  during the load phase.
  653.      *
  654.      * onTradeConsumer: act on the parsed message once all inbound data has
  655.      *                  been traded and parsed.
  656.      *
  657.      * onTradeAbsence:  if a missing message needs special handling
  658.      *                  during the trade phase.
  659.      */
  660.     final HandshakeProducer networkProducer;
  661.     final ExtensionConsumer onLoadConsumer;
  662.     final HandshakeAbsence  onLoadAbsence;
  663.     final HandshakeConsumer onTradeConsumer;
  664.     final HandshakeAbsence  onTradeAbsence;
  665.     final SSLStringizer stringizer;
  666.  
  667.     // known but unsupported extension
  668.     SSLExtension(int id, String name) {
  669.         this.id = id;
  670.         this.handshakeType = SSLHandshake.NOT_APPLICABLE;
  671.         this.name = name;
  672.         this.supportedProtocols = new ProtocolVersion[0];
  673.         this.networkProducer = null;
  674.         this.onLoadConsumer = null;
  675.         this.onLoadAbsence = null;
  676.         this.onTradeConsumer = null;
  677.         this.onTradeAbsence = null;
  678.         this.stringizer = null;
  679.     }
  680.  
  681.     // supported extension
  682.     SSLExtension(int id, String name, SSLHandshake handshakeType,
  683.             ProtocolVersion[] supportedProtocols,
  684.             HandshakeProducer producer,
  685.             ExtensionConsumer onLoadConsumer, HandshakeAbsence onLoadAbsence,
  686.             HandshakeConsumer onTradeConsumer, HandshakeAbsence onTradeAbsence,
  687.             SSLStringizer stringize) {
  688.         this.id = id;
  689.         this.handshakeType = handshakeType;
  690.         this.name = name;
  691.         this.supportedProtocols = supportedProtocols;
  692.         this.networkProducer = producer;
  693.         this.onLoadConsumer = onLoadConsumer;
  694.         this.onLoadAbsence = onLoadAbsence;
  695.         this.onTradeConsumer = onTradeConsumer;
  696.         this.onTradeAbsence = onTradeAbsence;
  697.         this.stringizer = stringize;
  698.     }
  699.  
  700.     static SSLExtension valueOf(SSLHandshake handshakeType, int extensionType) {
  701.         for (SSLExtension ext : SSLExtension.values()) {
  702.             if (ext.id == extensionType &&
  703.                     ext.handshakeType == handshakeType) {
  704.                 return ext;
  705.             }
  706.         }
  707.  
  708.         return null;
  709.     }
  710.  
  711.     static String nameOf(int extensionType) {
  712.         for (SSLExtension ext : SSLExtension.values()) {
  713.             if (ext.id == extensionType) {
  714.                 return ext.name;
  715.             }
  716.         }
  717.  
  718.         return "unknown extension";
  719.     }
  720.  
  721.     static boolean isConsumable(int extensionType) {
  722.         for (SSLExtension ext : SSLExtension.values()) {
  723.             if (ext.id == extensionType &&
  724.                     ext.onLoadConsumer != null) {
  725.                 return true;
  726.             }
  727.         }
  728.  
  729.         return false;
  730.     }
  731.  
  732.     public byte[] produce(ConnectionContext context,
  733.             HandshakeMessage message) throws IOException {
  734.         if (networkProducer != null) {
  735.             return networkProducer.produce(context, message);
  736.         } else {
  737.             throw new UnsupportedOperationException(
  738.                     "Not yet supported extension producing.");
  739.         }
  740.     }
  741.  
  742.     public void consumeOnLoad(ConnectionContext context,
  743.             HandshakeMessage message, ByteBuffer buffer) throws IOException {
  744.         if (onLoadConsumer != null) {
  745.             onLoadConsumer.consume(context, message, buffer);
  746.         } else {
  747.             throw new UnsupportedOperationException(
  748.                     "Not yet supported extension loading.");
  749.         }
  750.     }
  751.  
  752.     public void consumeOnTrade(ConnectionContext context,
  753.             HandshakeMessage message) throws IOException {
  754.         if (onTradeConsumer != null) {
  755.             onTradeConsumer.consume(context, message);
  756.         } else {
  757.             throw new UnsupportedOperationException(
  758.                     "Not yet supported extension processing.");
  759.         }
  760.     }
  761.  
  762.     void absentOnLoad(ConnectionContext context,
  763.             HandshakeMessage message) throws IOException {
  764.         if (onLoadAbsence != null) {
  765.             onLoadAbsence.absent(context, message);
  766.         } else {
  767.             throw new UnsupportedOperationException(
  768.                     "Not yet supported extension absence processing.");
  769.         }
  770.     }
  771.  
  772.     void absentOnTrade(ConnectionContext context,
  773.             HandshakeMessage message) throws IOException {
  774.         if (onTradeAbsence != null) {
  775.             onTradeAbsence.absent(context, message);
  776.         } else {
  777.             throw new UnsupportedOperationException(
  778.                     "Not yet supported extension absence processing.");
  779.         }
  780.     }
  781.  
  782.     public boolean isAvailable(ProtocolVersion protocolVersion) {
  783.         for (ProtocolVersion supportedProtocol : supportedProtocols) {
  784.             if (supportedProtocol == protocolVersion) {
  785.                 return true;
  786.             }
  787.         }
  788.  
  789.         return false;
  790.     }
  791.  
  792.     @Override
  793.     public String toString() {
  794.         return name;
  795.     }
  796.  
  797.     @Override
  798.     public String toString(
  799.             HandshakeContext handshakeContext, ByteBuffer byteBuffer) {
  800.         MessageFormat messageFormat = new MessageFormat(
  801.                 """
  802.                        "{0} ({1})": '{'
  803.                        {2}
  804.                        '}'""",
  805.             Locale.ENGLISH);
  806.  
  807.         String extData;
  808.         if (stringizer == null) {
  809.             HexDumpEncoder hexEncoder = new HexDumpEncoder();
  810.             extData = hexEncoder.encode(byteBuffer.duplicate());
  811.         } else {
  812.             extData = stringizer.toString(handshakeContext, byteBuffer);
  813.         }
  814.  
  815.         Object[] messageFields = {
  816.             this.name,
  817.             this.id,
  818.             Utilities.indent(extData)
  819.         };
  820.  
  821.         return messageFormat.format(messageFields);
  822.     }
  823.  
  824.     //////////////////////////////////////////////////////
  825.     // Nested extension, consumer and producer interfaces.
  826.  
  827.     interface ExtensionConsumer {
  828.         void consume(ConnectionContext context,
  829.                 HandshakeMessage message, ByteBuffer buffer) throws IOException;
  830.     }
  831.  
  832.     /**
  833.      * A (transparent) specification of extension data.
  834.      *
  835.      * This interface contains no methods or constants. Its only purpose is to
  836.      * group all extension data.  All extension data should implement this
  837.      * interface if the data is expected to handle in the following handshake
  838.      * processes.
  839.      */
  840.     interface SSLExtensionSpec {
  841.         // blank
  842.     }
  843.  
  844.     // Default enabled client extensions.
  845.     static final class ClientExtensions {
  846.         static final Collection<SSLExtension> defaults;
  847.  
  848.         static {
  849.             Collection<String> clientDisabledExtensions =
  850.                     getDisabledExtensions("jdk.tls.client.disableExtensions");
  851.             Collection<SSLExtension> extensions = new LinkedList<>();
  852.             for (SSLExtension extension : SSLExtension.values()) {
  853.                 if (extension.handshakeType != SSLHandshake.NOT_APPLICABLE &&
  854.                         !clientDisabledExtensions.contains(extension.name)) {
  855.                     extensions.add(extension);
  856.                 }
  857.             }
  858.  
  859.             // Switch off SNI extension?
  860.             if (extensions.contains(CH_SERVER_NAME)) {
  861.                 boolean enableExtension = Utilities.getBooleanProperty(
  862.                         "jsse.enableSNIExtension", true);
  863.                 if (!enableExtension) {
  864.                     extensions.remove(CH_SERVER_NAME);
  865.                 }
  866.             }
  867.  
  868.             // To switch off the max_fragment_length extension.
  869.             //
  870.             // Note that "jsse.enableMFLNExtension" is the CSR approved
  871.             // property name.  However, "jsse.enableMFLExtension" was used
  872.             // in the original implementation.  Temporarily, if either of
  873.             // the two properties set to true, the extension is switch on.
  874.             // We may remove the "jsse.enableMFLExtension" property in the
  875.             // future.  Please don't continue to use the misspelling property.
  876.             if (extensions.contains(CH_MAX_FRAGMENT_LENGTH)) {
  877.                 boolean enableExtension =
  878.                         Utilities.getBooleanProperty(
  879.                                 "jsse.enableMFLNExtension", false) ||
  880.                         Utilities.getBooleanProperty(
  881.                                 "jsse.enableMFLExtension", false);
  882.                 if (!enableExtension) {
  883.                     extensions.remove(CH_MAX_FRAGMENT_LENGTH);
  884.                 }
  885.             }
  886.  
  887.             // To switch on certificate_authorities extension in ClientHello.
  888.             //
  889.             // Note: Please be careful to enable this extension in ClientHello.
  890.             //
  891.             // In practice, if the server certificate cannot be validated by
  892.             // the underlying programs, the user may manually check the
  893.             // certificate in order to access the service.  The certificate
  894.             // could be accepted manually, and the handshake continues.  For
  895.             // example, the browsers provide the manual option to accept
  896.             // untrusted server certificate. If this extension is enabled in
  897.             // the ClientHello handshake message, and the server's certificate
  898.             // does not chain back to any of the CAs in the extension, then the
  899.             // server will terminate the handshake and close the connection.
  900.             // There is no chance for the client to perform the manual check.
  901.             // Therefore, enabling this extension in ClientHello may lead to
  902.             // unexpected compatibility issues for such cases.
  903.             //
  904.             // According to TLS 1.3 specification [RFC 8446] the maximum size
  905.             // of the certificate_authorities extension is 2^16 bytes.  The
  906.             // maximum TLS record size is 2^14 bytes.  If the handshake
  907.             // message is bigger than maximum TLS record size, it should be
  908.             // split into several records.  In fact, some server
  909.             // implementations do not allow ClientHello messages bigger than
  910.             // the maximum TLS record size and will immediately abort the
  911.             // connection with a fatal alert.  Therefore, if the client trusts
  912.             // too many certificate authorities, there may be unexpected
  913.             // interoperability issues.
  914.             //
  915.             // Furthermore, if the client trusts more CAs such that it exceeds
  916.             // the size limit of the extension, enabling this extension in
  917.             // client side does not really make sense any longer as there is
  918.             // no way to indicate the server certificate selection accurately.
  919.             //
  920.             // In general, a server does not use multiple certificates issued
  921.             // from different CAs.  It is not expected to use this extension a
  922.             // lot in practice.  When there is a need to use this extension
  923.             // in ClientHello handshake message, please take care of the
  924.             // potential compatibility and interoperability issues above.
  925.             if (extensions.contains(CH_CERTIFICATE_AUTHORITIES)) {
  926.                 boolean enableExtension = Utilities.getBooleanProperty(
  927.                         "jdk.tls.client.enableCAExtension", false);
  928.                 if (!enableExtension) {
  929.                     extensions.remove(CH_CERTIFICATE_AUTHORITIES);
  930.                 }
  931.             }
  932.  
  933.             SSLExtension[] tlsGreases = new SSLExtension[11];
  934.             tlsGreases[0] = TLS_GREASE_0A0A;
  935.             tlsGreases[1] = TLS_GREASE_1A1A;
  936.             tlsGreases[2] = TLS_GREASE_2A2A;
  937.             tlsGreases[3] = TLS_GREASE_3A3A;
  938.             tlsGreases[4] = TLS_GREASE_4A4A;
  939.             tlsGreases[5] = TLS_GREASE_5A5A;
  940.             tlsGreases[6] = TLS_GREASE_6A6A;
  941.             tlsGreases[7] = TLS_GREASE_7A7A;
  942.             tlsGreases[8] = TLS_GREASE_8A8A;
  943.             tlsGreases[9] = TLS_GREASE_9A9A;
  944.             tlsGreases[10] = TLS_GREASE_AAAA;
  945.  
  946.             Random rand = new Random();
  947.             int index1 = rand.nextInt(10 - 0) + 0;
  948.             int index2 = rand.nextInt(10 - 0) + 0;
  949.  
  950.             for (int i = 0; i < tlsGreases.length; ++i) {
  951.                 if (index1 != i && index2 != i) {
  952.                     extensions.remove(tlsGreases[i]);
  953.                 }
  954.             }
  955.  
  956.             defaults = Collections.unmodifiableCollection(extensions);
  957.         }
  958.     }
  959.  
  960.     // Default enabled server extensions.
  961.     static final class ServerExtensions {
  962.         static final Collection<SSLExtension> defaults;
  963.  
  964.         static {
  965.             Collection<String> serverDisabledExtensions =
  966.                     getDisabledExtensions("jdk.tls.server.disableExtensions");
  967.             Collection<SSLExtension> extensions = new LinkedList<>();
  968.             for (SSLExtension extension : SSLExtension.values()) {
  969.                 if (extension.handshakeType != SSLHandshake.NOT_APPLICABLE &&
  970.                         !serverDisabledExtensions.contains(extension.name)) {
  971.                     extensions.add(extension);
  972.                 }
  973.             }
  974.  
  975.             defaults = Collections.unmodifiableCollection(extensions);
  976.         }
  977.     }
  978.  
  979.     // Get disabled extensions, which could be customized with System Properties.
  980.     private static Collection<String> getDisabledExtensions(
  981.                 String propertyName) {
  982.         String property = GetPropertyAction.privilegedGetProperty(propertyName);
  983.         if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) {
  984.             SSLLogger.fine(
  985.                     "System property " + propertyName + " is set to '" +
  986.                             property + "'");
  987.         }
  988.         if (property != null && !property.isEmpty()) {
  989.             // remove double quote marks from beginning/end of the property
  990.             if (property.length() > 1 && property.charAt(0) == '"' &&
  991.                     property.charAt(property.length() - 1) == '"') {
  992.                 property = property.substring(1, property.length() - 1);
  993.             }
  994.         }
  995.  
  996.         if (property != null && !property.isEmpty()) {
  997.             String[] extensionNames = property.split(",");
  998.             Collection<String> extensions =
  999.                     new ArrayList<>(extensionNames.length);
  1000.             for (String extension : extensionNames) {
  1001.                 extension = extension.trim();
  1002.                 if (!extension.isEmpty()) {
  1003.                     extensions.add(extension);
  1004.                 }
  1005.             }
  1006.  
  1007.             return extensions;
  1008.         }
  1009.  
  1010.         return Collections.emptyList();
  1011.     }
  1012. }
  1013.  
Add Comment
Please, Sign In to add comment