src/java.base/share/classes/sun/security/ssl/SSLAlgorithmDecomposer.java
author wetmore
Fri, 11 May 2018 15:53:12 -0700
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
child 56782 b472b5917a1b
permissions -rw-r--r--
Initial TLSv1.3 Implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     1
/*
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     4
 *
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    10
 *
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    15
 * accompanied this code).
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    16
 *
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    20
 *
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    23
 * questions.
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    24
 */
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    25
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    26
package sun.security.ssl;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    27
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    28
import java.util.HashSet;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    29
import java.util.Set;
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    30
import sun.security.ssl.CipherSuite.HashAlg;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    31
import sun.security.ssl.CipherSuite.KeyExchange;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    32
import static sun.security.ssl.CipherSuite.KeyExchange.*;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    33
import sun.security.ssl.CipherSuite.MacAlg;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    34
import static sun.security.ssl.SSLCipher.B_3DES;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    35
import static sun.security.ssl.SSLCipher.B_AES_128;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    36
import static sun.security.ssl.SSLCipher.B_AES_128_GCM;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    37
import static sun.security.ssl.SSLCipher.B_AES_256;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    38
import static sun.security.ssl.SSLCipher.B_AES_256_GCM;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    39
import static sun.security.ssl.SSLCipher.B_DES;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    40
import static sun.security.ssl.SSLCipher.B_DES_40;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    41
import static sun.security.ssl.SSLCipher.B_NULL;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    42
import static sun.security.ssl.SSLCipher.B_RC2_40;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    43
import static sun.security.ssl.SSLCipher.B_RC4_128;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    44
import static sun.security.ssl.SSLCipher.B_RC4_40;
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    45
import sun.security.util.AlgorithmDecomposer;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    46
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    47
/**
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    48
 * The class decomposes standard SSL/TLS cipher suites into sub-elements.
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    49
 */
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    50
class SSLAlgorithmDecomposer extends AlgorithmDecomposer {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    51
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    52
    // indicates that only certification path algorithms need to be used
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    53
    private final boolean onlyX509;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    54
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    55
    SSLAlgorithmDecomposer(boolean onlyX509) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    56
        this.onlyX509 = onlyX509;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    57
    }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    58
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    59
    SSLAlgorithmDecomposer() {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    60
        this(false);
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    61
    }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    62
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    63
    private Set<String> decomposes(CipherSuite.KeyExchange keyExchange) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    64
        Set<String> components = new HashSet<>();
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    65
        switch (keyExchange) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    66
            case K_NULL:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    67
                if (!onlyX509) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    68
                    components.add("K_NULL");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    69
                }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    70
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    71
            case K_RSA:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    72
                components.add("RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    73
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    74
            case K_RSA_EXPORT:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    75
                components.add("RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    76
                components.add("RSA_EXPORT");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    77
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    78
            case K_DH_RSA:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    79
                components.add("RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    80
                components.add("DH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    81
                components.add("DiffieHellman");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    82
                components.add("DH_RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    83
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    84
            case K_DH_DSS:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    85
                components.add("DSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    86
                components.add("DSS");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    87
                components.add("DH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    88
                components.add("DiffieHellman");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    89
                components.add("DH_DSS");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    90
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    91
            case K_DHE_DSS:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    92
                components.add("DSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    93
                components.add("DSS");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    94
                components.add("DH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    95
                components.add("DHE");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    96
                components.add("DiffieHellman");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    97
                components.add("DHE_DSS");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    98
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
    99
            case K_DHE_RSA:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   100
                components.add("RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   101
                components.add("DH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   102
                components.add("DHE");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   103
                components.add("DiffieHellman");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   104
                components.add("DHE_RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   105
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   106
            case K_DH_ANON:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   107
                if (!onlyX509) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   108
                    components.add("ANON");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   109
                    components.add("DH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   110
                    components.add("DiffieHellman");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   111
                    components.add("DH_ANON");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   112
                }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   113
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   114
            case K_ECDH_ECDSA:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   115
                components.add("ECDH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   116
                components.add("ECDSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   117
                components.add("ECDH_ECDSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   118
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   119
            case K_ECDH_RSA:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   120
                components.add("ECDH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   121
                components.add("RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   122
                components.add("ECDH_RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   123
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   124
            case K_ECDHE_ECDSA:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   125
                components.add("ECDHE");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   126
                components.add("ECDSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   127
                components.add("ECDHE_ECDSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   128
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   129
            case K_ECDHE_RSA:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   130
                components.add("ECDHE");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   131
                components.add("RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   132
                components.add("ECDHE_RSA");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   133
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   134
            case K_ECDH_ANON:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   135
                if (!onlyX509) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   136
                    components.add("ECDH");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   137
                    components.add("ANON");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   138
                    components.add("ECDH_ANON");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   139
                }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   140
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   141
            default:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   142
                // otherwise ignore
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   143
            }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   144
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   145
        return components;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   146
    }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   147
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   148
    private Set<String> decomposes(SSLCipher bulkCipher) {
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   149
        Set<String> components = new HashSet<>();
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   150
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   151
        if (bulkCipher.transformation != null) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   152
            components.addAll(super.decompose(bulkCipher.transformation));
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   153
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   154
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   155
        switch (bulkCipher) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   156
            case B_NULL:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   157
                components.add("C_NULL");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   158
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   159
            case B_RC2_40:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   160
                components.add("RC2_CBC_40");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   161
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   162
            case B_RC4_40:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   163
                components.add("RC4_40");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   164
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   165
            case B_RC4_128:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   166
                components.add("RC4_128");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   167
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   168
            case B_DES_40:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   169
                components.add("DES40_CBC");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   170
                components.add("DES_CBC_40");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   171
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   172
            case B_DES:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   173
                components.add("DES_CBC");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   174
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   175
            case B_3DES:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   176
                components.add("3DES_EDE_CBC");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   177
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   178
            case B_AES_128:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   179
                components.add("AES_128_CBC");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   180
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   181
            case B_AES_256:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   182
                components.add("AES_256_CBC");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   183
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   184
            case B_AES_128_GCM:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   185
                components.add("AES_128_GCM");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   186
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   187
            case B_AES_256_GCM:
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   188
                components.add("AES_256_GCM");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   189
                break;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   190
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   191
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   192
        return components;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   193
    }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   194
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   195
    private Set<String> decomposes(CipherSuite.MacAlg macAlg,
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   196
            SSLCipher cipher) {
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   197
        Set<String> components = new HashSet<>();
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   198
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   199
        if (macAlg == CipherSuite.MacAlg.M_NULL
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   200
                && cipher.cipherType != CipherType.AEAD_CIPHER) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   201
            components.add("M_NULL");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   202
        } else if (macAlg == CipherSuite.MacAlg.M_MD5) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   203
            components.add("MD5");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   204
            components.add("HmacMD5");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   205
        } else if (macAlg == CipherSuite.MacAlg.M_SHA) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   206
            components.add("SHA1");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   207
            components.add("SHA-1");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   208
            components.add("HmacSHA1");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   209
        } else if (macAlg == CipherSuite.MacAlg.M_SHA256) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   210
            components.add("SHA256");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   211
            components.add("SHA-256");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   212
            components.add("HmacSHA256");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   213
        } else if (macAlg == CipherSuite.MacAlg.M_SHA384) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   214
            components.add("SHA384");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   215
            components.add("SHA-384");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   216
            components.add("HmacSHA384");
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   217
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   218
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   219
        return components;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   220
    }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   221
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   222
    private Set<String> decomposes(CipherSuite.HashAlg hashAlg) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   223
        Set<String> components = new HashSet<>();
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   224
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   225
        if (hashAlg == CipherSuite.HashAlg.H_SHA256) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   226
            components.add("SHA256");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   227
            components.add("SHA-256");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   228
            components.add("HmacSHA256");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   229
        } else if (hashAlg == CipherSuite.HashAlg.H_SHA384) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   230
            components.add("SHA384");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   231
            components.add("SHA-384");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   232
            components.add("HmacSHA384");
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   233
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   234
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   235
        return components;
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   236
    }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   237
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   238
    private Set<String> decompose(KeyExchange keyExchange,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   239
            SSLCipher cipher,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   240
            MacAlg macAlg,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   241
            HashAlg hashAlg) {
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   242
        Set<String> components = new HashSet<>();
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   243
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   244
        if (keyExchange != null) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   245
            components.addAll(decomposes(keyExchange));
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   246
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   247
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   248
        if (onlyX509) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   249
            // Certification path algorithm constraints do not apply
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   250
            // to cipher and macAlg.
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   251
            return components;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   252
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   253
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   254
        if (cipher != null) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   255
            components.addAll(decomposes(cipher));
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   256
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   257
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   258
        if (macAlg != null) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   259
            components.addAll(decomposes(macAlg, cipher));
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   260
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   261
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   262
        if (hashAlg != null) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   263
            components.addAll(decomposes(hashAlg));
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   264
        }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   265
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   266
        return components;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   267
    }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   268
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   269
    @Override
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   270
    public Set<String> decompose(String algorithm) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   271
        if (algorithm.startsWith("SSL_") || algorithm.startsWith("TLS_")) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   272
            CipherSuite cipherSuite = null;
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   273
            try {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   274
                cipherSuite = CipherSuite.nameOf(algorithm);
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   275
            } catch (IllegalArgumentException iae) {
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   276
                // ignore: unknown or unsupported ciphersuite
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   277
            }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   278
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   279
            if (cipherSuite != null) {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   280
                return decompose(cipherSuite.keyExchange,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   281
                        cipherSuite.bulkCipher,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   282
                        cipherSuite.macAlg,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   283
                        cipherSuite.hashAlg);
31689
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   284
            }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   285
        }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   286
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   287
        return super.decompose(algorithm);
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   288
    }
1201792aa3a3 8043201: Deprecate RC4 in SunJSSE provider
asmotrak
parents:
diff changeset
   289
}