jdk/src/share/classes/sun/security/ssl/SSLAlgorithmConstraints.java
author xuelei
Fri, 08 Apr 2011 02:00:09 -0700
changeset 9246 c459f79af46b
parent 7990 57019dc81b66
child 9035 1255eb81cc2f
permissions -rw-r--r--
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled Summary: Reorg the SSLContext implementation Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     1
/*
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     4
 *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    10
 *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    15
 * accompanied this code).
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    16
 *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    20
 *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    23
 * questions.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    24
 */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    25
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    26
package sun.security.ssl;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    27
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    28
import java.security.AlgorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    29
import java.security.CryptoPrimitive;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    30
import java.security.AlgorithmParameters;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    31
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    32
import javax.net.ssl.*;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    33
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    34
import java.security.Key;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    35
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    36
import java.util.Set;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    37
import java.util.HashSet;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    38
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    39
import sun.security.util.DisabledAlgorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    40
import sun.security.ssl.CipherSuite.*;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    41
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    42
/**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    43
 * Algorithm constraints for disabled algorithms property
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    44
 *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    45
 * See the "jdk.certpath.disabledAlgorithms" specification in java.security
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    46
 * for the syntax of the disabled algorithm string.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    47
 */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    48
final class SSLAlgorithmConstraints implements AlgorithmConstraints {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    49
    private final static AlgorithmConstraints tlsDisabledAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    50
            new TLSDisabledAlgConstraints();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    51
    private final static AlgorithmConstraints x509DisabledAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    52
            new X509DisabledAlgConstraints();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    53
    private AlgorithmConstraints userAlgConstraints = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    54
    private AlgorithmConstraints peerAlgConstraints = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    55
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    56
    private boolean enabledX509DisabledAlgConstraints = true;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    57
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    58
    SSLAlgorithmConstraints(AlgorithmConstraints algorithmConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    59
        userAlgConstraints = algorithmConstraints;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    60
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    61
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    62
    SSLAlgorithmConstraints(SSLSocket socket,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    63
            boolean withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    64
        if (socket != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    65
            userAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    66
                socket.getSSLParameters().getAlgorithmConstraints();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    67
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    68
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    69
        if (!withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    70
            enabledX509DisabledAlgConstraints = false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    71
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    72
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    73
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    74
    SSLAlgorithmConstraints(SSLEngine engine,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    75
            boolean withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    76
        if (engine != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    77
            userAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    78
                engine.getSSLParameters().getAlgorithmConstraints();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    79
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    80
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    81
        if (!withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    82
            enabledX509DisabledAlgConstraints = false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    83
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    84
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    85
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    86
    SSLAlgorithmConstraints(SSLSocket socket, String[] supportedAlgorithms,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    87
            boolean withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    88
        if (socket != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    89
            userAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    90
                socket.getSSLParameters().getAlgorithmConstraints();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    91
            peerAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    92
                new SupportedSignatureAlgorithmConstraints(supportedAlgorithms);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    93
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    94
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    95
        if (!withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    96
            enabledX509DisabledAlgConstraints = false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    97
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    98
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
    99
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   100
    SSLAlgorithmConstraints(SSLEngine engine, String[] supportedAlgorithms,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   101
            boolean withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   102
        if (engine != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   103
            userAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   104
                engine.getSSLParameters().getAlgorithmConstraints();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   105
            peerAlgConstraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   106
                new SupportedSignatureAlgorithmConstraints(supportedAlgorithms);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   107
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   108
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   109
        if (!withDefaultCertPathConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   110
            enabledX509DisabledAlgConstraints = false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   111
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   112
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   113
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   114
    public boolean permits(Set<CryptoPrimitive> primitives,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   115
            String algorithm, AlgorithmParameters parameters) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   116
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   117
        boolean permitted = true;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   118
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   119
        if (peerAlgConstraints != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   120
            permitted = peerAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   121
                                    primitives, algorithm, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   122
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   123
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   124
        if (permitted && userAlgConstraints != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   125
            permitted = userAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   126
                                    primitives, algorithm, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   127
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   128
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   129
        if (permitted) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   130
            permitted = tlsDisabledAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   131
                                    primitives, algorithm, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   132
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   133
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   134
        if (permitted && enabledX509DisabledAlgConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   135
            permitted = x509DisabledAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   136
                                    primitives, algorithm, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   137
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   138
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   139
        return permitted;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   140
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   141
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   142
    public boolean permits(Set<CryptoPrimitive> primitives, Key key) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   143
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   144
        boolean permitted = true;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   145
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   146
        if (peerAlgConstraints != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   147
            permitted = peerAlgConstraints.permits(primitives, key);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   148
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   149
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   150
        if (permitted && userAlgConstraints != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   151
            permitted = userAlgConstraints.permits(primitives, key);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   152
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   153
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   154
        if (permitted) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   155
            permitted = tlsDisabledAlgConstraints.permits(primitives, key);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   156
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   157
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   158
        if (permitted && enabledX509DisabledAlgConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   159
            permitted = x509DisabledAlgConstraints.permits(primitives, key);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   160
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   161
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   162
        return permitted;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   163
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   164
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   165
    public boolean permits(Set<CryptoPrimitive> primitives,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   166
            String algorithm, Key key, AlgorithmParameters parameters) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   167
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   168
        boolean permitted = true;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   169
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   170
        if (peerAlgConstraints != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   171
            permitted = peerAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   172
                                    primitives, algorithm, key, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   173
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   174
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   175
        if (permitted && userAlgConstraints != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   176
            permitted = userAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   177
                                    primitives, algorithm, key, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   178
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   179
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   180
        if (permitted) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   181
            permitted = tlsDisabledAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   182
                                    primitives, algorithm, key, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   183
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   184
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   185
        if (permitted && enabledX509DisabledAlgConstraints) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   186
            permitted = x509DisabledAlgConstraints.permits(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   187
                                    primitives, algorithm, key, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   188
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   189
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   190
        return permitted;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   191
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   192
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   193
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   194
    static private class SupportedSignatureAlgorithmConstraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   195
                                    implements AlgorithmConstraints {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   196
        // supported signature algorithms
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   197
        private String[] supportedAlgorithms;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   198
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   199
        SupportedSignatureAlgorithmConstraints(String[] supportedAlgorithms) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   200
            if (supportedAlgorithms != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   201
                this.supportedAlgorithms = supportedAlgorithms.clone();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   202
            } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   203
                this.supportedAlgorithms = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   204
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   205
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   206
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   207
        public boolean permits(Set<CryptoPrimitive> primitives,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   208
                String algorithm, AlgorithmParameters parameters) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   209
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   210
            if (algorithm == null || algorithm.length() == 0) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   211
                throw new IllegalArgumentException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   212
                        "No algorithm name specified");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   213
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   214
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   215
            if (primitives == null || primitives.isEmpty()) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   216
                throw new IllegalArgumentException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   217
                        "No cryptographic primitive specified");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   218
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   219
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   220
            if (supportedAlgorithms == null ||
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   221
                        supportedAlgorithms.length == 0) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   222
                return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   223
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   224
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   225
            // trim the MGF part: <digest>with<encryption>and<mgf>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   226
            int position = algorithm.indexOf("and");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   227
            if (position > 0) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   228
                algorithm = algorithm.substring(0, position);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   229
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   230
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   231
            for (String supportedAlgorithm : supportedAlgorithms) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   232
                if (algorithm.equalsIgnoreCase(supportedAlgorithm)) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   233
                    return true;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   234
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   235
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   236
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   237
            return false;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   238
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   239
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   240
        final public boolean permits(Set<CryptoPrimitive> primitives, Key key) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   241
            return true;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   242
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   243
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   244
        final public boolean permits(Set<CryptoPrimitive> primitives,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   245
                String algorithm, Key key, AlgorithmParameters parameters) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   246
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   247
            if (algorithm == null || algorithm.length() == 0) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   248
                throw new IllegalArgumentException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   249
                        "No algorithm name specified");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   250
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   251
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   252
            return permits(primitives, algorithm, parameters);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   253
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   254
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   255
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   256
    static private class BasicDisabledAlgConstraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   257
            extends DisabledAlgorithmConstraints {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   258
        BasicDisabledAlgConstraints(String propertyName) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   259
            super(propertyName);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   260
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   261
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   262
        protected Set<String> decomposes(KeyExchange keyExchange,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   263
                        boolean forCertPathOnly) {
7990
57019dc81b66 7012003: diamond conversion for ssl
smarks
parents: 7043
diff changeset
   264
            Set<String> components = new HashSet<>();
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   265
            switch (keyExchange) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   266
                case K_NULL:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   267
                    if (!forCertPathOnly) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   268
                        components.add("NULL");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   269
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   270
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   271
                case K_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   272
                    components.add("RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   273
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   274
                case K_RSA_EXPORT:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   275
                    components.add("RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   276
                    components.add("RSA_EXPORT");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   277
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   278
                case K_DH_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   279
                    components.add("RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   280
                    components.add("DH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   281
                    components.add("DiffieHellman");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   282
                    components.add("DH_RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   283
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   284
                case K_DH_DSS:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   285
                    components.add("DSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   286
                    components.add("DSS");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   287
                    components.add("DH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   288
                    components.add("DiffieHellman");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   289
                    components.add("DH_DSS");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   290
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   291
                case K_DHE_DSS:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   292
                    components.add("DSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   293
                    components.add("DSS");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   294
                    components.add("DH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   295
                    components.add("DHE");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   296
                    components.add("DiffieHellman");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   297
                    components.add("DHE_DSS");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   298
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   299
                case K_DHE_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   300
                    components.add("RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   301
                    components.add("DH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   302
                    components.add("DHE");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   303
                    components.add("DiffieHellman");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   304
                    components.add("DHE_RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   305
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   306
                case K_DH_ANON:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   307
                    if (!forCertPathOnly) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   308
                        components.add("ANON");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   309
                        components.add("DH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   310
                        components.add("DiffieHellman");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   311
                        components.add("DH_ANON");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   312
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   313
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   314
                case K_ECDH_ECDSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   315
                    components.add("ECDH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   316
                    components.add("ECDSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   317
                    components.add("ECDH_ECDSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   318
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   319
                case K_ECDH_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   320
                    components.add("ECDH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   321
                    components.add("RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   322
                    components.add("ECDH_RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   323
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   324
                case K_ECDHE_ECDSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   325
                    components.add("ECDHE");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   326
                    components.add("ECDSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   327
                    components.add("ECDHE_ECDSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   328
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   329
                case K_ECDHE_RSA:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   330
                    components.add("ECDHE");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   331
                    components.add("RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   332
                    components.add("ECDHE_RSA");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   333
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   334
                case K_ECDH_ANON:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   335
                    if (!forCertPathOnly) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   336
                        components.add("ECDH");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   337
                        components.add("ANON");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   338
                        components.add("ECDH_ANON");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   339
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   340
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   341
                case K_KRB5:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   342
                    if (!forCertPathOnly) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   343
                        components.add("KRB5");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   344
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   345
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   346
                case K_KRB5_EXPORT:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   347
                    if (!forCertPathOnly) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   348
                        components.add("KRB5_EXPORT");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   349
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   350
                    break;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   351
                default:
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   352
                    // ignore
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   353
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   354
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   355
            return components;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   356
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   357
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   358
        protected Set<String> decomposes(BulkCipher bulkCipher) {
7990
57019dc81b66 7012003: diamond conversion for ssl
smarks
parents: 7043
diff changeset
   359
            Set<String> components = new HashSet<>();
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   360
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   361
            if (bulkCipher.transformation != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   362
                components.addAll(super.decomposes(bulkCipher.transformation));
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   363
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   364
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   365
            return components;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   366
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   367
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   368
        protected Set<String> decomposes(MacAlg macAlg) {
7990
57019dc81b66 7012003: diamond conversion for ssl
smarks
parents: 7043
diff changeset
   369
            Set<String> components = new HashSet<>();
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   370
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   371
            if (macAlg == CipherSuite.M_MD5) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   372
                components.add("MD5");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   373
                components.add("HmacMD5");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   374
            } else if (macAlg == CipherSuite.M_SHA) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   375
                components.add("SHA1");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   376
                components.add("SHA-1");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   377
                components.add("HmacSHA1");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   378
            } else if (macAlg == CipherSuite.M_SHA256) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   379
                components.add("SHA256");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   380
                components.add("SHA-256");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   381
                components.add("HmacSHA256");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   382
            } else if (macAlg == CipherSuite.M_SHA384) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   383
                components.add("SHA384");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   384
                components.add("SHA-384");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   385
                components.add("HmacSHA384");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   386
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   387
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   388
            return components;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   389
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   390
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   391
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   392
    static private class TLSDisabledAlgConstraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   393
            extends BasicDisabledAlgConstraints {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   394
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   395
        TLSDisabledAlgConstraints() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   396
            super(DisabledAlgorithmConstraints.PROPERTY_TLS_DISABLED_ALGS);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   397
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   398
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   399
        @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   400
        protected Set<String> decomposes(String algorithm) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   401
            if (algorithm.startsWith("SSL_") || algorithm.startsWith("TLS_")) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   402
                CipherSuite cipherSuite = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   403
                try {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   404
                    cipherSuite = CipherSuite.valueOf(algorithm);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   405
                } catch (IllegalArgumentException iae) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   406
                    // ignore: unknown or unsupported ciphersuite
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   407
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   408
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   409
                if (cipherSuite != null) {
7990
57019dc81b66 7012003: diamond conversion for ssl
smarks
parents: 7043
diff changeset
   410
                    Set<String> components = new HashSet<>();
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   411
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   412
                    if(cipherSuite.keyExchange != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   413
                        components.addAll(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   414
                            decomposes(cipherSuite.keyExchange, false));
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   415
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   416
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   417
                    if (cipherSuite.cipher != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   418
                        components.addAll(decomposes(cipherSuite.cipher));
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   419
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   420
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   421
                    if (cipherSuite.macAlg != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   422
                        components.addAll(decomposes(cipherSuite.macAlg));
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   423
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   424
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   425
                    return components;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   426
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   427
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   428
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   429
            return super.decomposes(algorithm);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   430
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   431
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   432
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   433
    static private class X509DisabledAlgConstraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   434
            extends BasicDisabledAlgConstraints {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   435
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   436
        X509DisabledAlgConstraints() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   437
            super(DisabledAlgorithmConstraints.PROPERTY_CERTPATH_DISABLED_ALGS);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   438
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   439
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   440
        @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   441
        protected Set<String> decomposes(String algorithm) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   442
            if (algorithm.startsWith("SSL_") || algorithm.startsWith("TLS_")) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   443
                CipherSuite cipherSuite = null;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   444
                try {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   445
                    cipherSuite = CipherSuite.valueOf(algorithm);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   446
                } catch (IllegalArgumentException iae) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   447
                    // ignore: unknown or unsupported ciphersuite
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   448
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   449
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   450
                if (cipherSuite != null) {
7990
57019dc81b66 7012003: diamond conversion for ssl
smarks
parents: 7043
diff changeset
   451
                    Set<String> components = new HashSet<>();
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   452
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   453
                    if(cipherSuite.keyExchange != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   454
                        components.addAll(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   455
                            decomposes(cipherSuite.keyExchange, true));
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   456
                    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   457
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   458
                    // Certification path algorithm constraints do not apply
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   459
                    // to cipherSuite.cipher and cipherSuite.macAlg.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   460
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   461
                    return components;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   462
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   463
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   464
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   465
            return super.decomposes(algorithm);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   466
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   467
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   468
}
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents:
diff changeset
   469