jdk/src/java.base/share/classes/sun/security/ssl/ClientKeyExchangeService.java
author redestad
Tue, 03 May 2016 15:50:54 +0200
changeset 37781 71ed5645f17c
parent 37593 824750ada3d6
permissions -rw-r--r--
8155775: Re-examine naming of privileged methods to access System properties Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     1
/*
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     4
 *
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    10
 *
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    15
 * accompanied this code).
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    16
 *
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    20
 *
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    23
 * questions.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    24
 */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    25
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    26
package sun.security.ssl;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    27
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    28
import sun.security.action.GetPropertyAction;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    29
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    30
import java.io.File;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    31
import java.io.FilePermission;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    32
import java.io.IOException;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    33
import java.security.AccessControlContext;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    34
import java.security.AccessController;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    35
import java.security.Principal;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    36
import java.security.PrivilegedAction;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    37
import java.security.SecureRandom;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    38
import java.util.*;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    39
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    40
/**
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    41
 * Models a service that provides support for a particular client key exchange
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    42
 * mode. Currently used to implement Kerberos-related cipher suites.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    43
 *
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 30905
diff changeset
    44
 * @since 9
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    45
 */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    46
public interface ClientKeyExchangeService {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    47
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    48
    static class Loader {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    49
        private static final Map<String,ClientKeyExchangeService>
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    50
                providers = new HashMap<>();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    51
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    52
        static {
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
    53
            String path = GetPropertyAction.privilegedGetProperty("java.home");
30905
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    54
            ServiceLoader<ClientKeyExchangeService> sc =
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    55
                    AccessController.doPrivileged(
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    56
                            (PrivilegedAction<ServiceLoader<ClientKeyExchangeService>>)
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    57
                                    () -> ServiceLoader.loadInstalled(ClientKeyExchangeService.class),
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    58
                            null,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    59
                            new FilePermission(new File(path, "-").toString(), "read"));
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    60
            Iterator<ClientKeyExchangeService> iter = sc.iterator();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    61
            while (iter.hasNext()) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    62
                ClientKeyExchangeService cs = iter.next();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    63
                for (String ex: cs.supported()) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    64
                    providers.put(ex, cs);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    65
                }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    66
            }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    67
        }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    68
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    69
    }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    70
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    71
    public static ClientKeyExchangeService find(String ex) {
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    72
        return Loader.providers.get(ex);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    73
    }
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    74
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    75
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    76
    /**
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    77
     * Returns the supported key exchange modes by this provider.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    78
     * @return the supported key exchange modes
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    79
     */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    80
    String[] supported();
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    81
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    82
    /**
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    83
     * Returns a generalized credential object on the server side. The server
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    84
     * side can use the info to determine if a cipher suite can be enabled.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    85
     * @param acc the AccessControlContext of the SSL session
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    86
     * @return the credential object
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    87
     */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    88
    Object getServiceCreds(AccessControlContext acc);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    89
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    90
    /**
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    91
     * Returns the host name for a service principal. The info can be used in
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    92
     * SNI or host name verifier.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    93
     * @param principal the principal of a service
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    94
     * @return the string formed host name
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    95
     */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    96
    String getServiceHostName(Principal principal);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    97
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    98
    /**
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
    99
     * Returns whether the specified principal is related to the current
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   100
     * SSLSession. The info can be used to verify a SSL resume.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   101
     * @param isClient if true called from client side, otherwise from server
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   102
     * @param acc the AccessControlContext of the SSL session
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   103
     * @param p the specified principal
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   104
     * @return true if related
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   105
     */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   106
    boolean isRelated(boolean isClient, AccessControlContext acc, Principal p);
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   107
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   108
    /**
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   109
     * Creates the ClientKeyExchange object on the client side.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   110
     * @param serverName the intented peer name
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   111
     * @param acc the AccessControlContext of the SSL session
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   112
     * @param protocolVersion the TLS protocol version
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   113
     * @param rand the SecureRandom that will used to generate the premaster
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   114
     * @return the new Exchanger object
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   115
     * @throws IOException if there is an error
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   116
     */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   117
    ClientKeyExchange createClientExchange(String serverName, AccessControlContext acc,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   118
            ProtocolVersion protocolVersion, SecureRandom rand) throws IOException;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   119
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   120
    /**
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   121
     * Create the ClientKeyExchange on the server side.
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   122
     * @param protocolVersion the protocol version
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   123
     * @param clientVersion the input protocol version
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   124
     * @param rand a SecureRandom object used to generate premaster
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   125
     *             (if the server has to create one)
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   126
     * @param encodedTicket the ticket from client
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   127
     * @param encrypted the encrypted premaster secret from client
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   128
     * @param acc the AccessControlContext of the SSL session
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   129
     * @param ServiceCreds the service side credentials object as retrived from
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   130
     *                     {@link #getServiceCreds}
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   131
     * @return the new Exchanger object
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   132
     * @throws IOException if there is an error
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   133
     */
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   134
    ClientKeyExchange createServerExchange(
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   135
            ProtocolVersion protocolVersion, ProtocolVersion clientVersion,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   136
            SecureRandom rand, byte[] encodedTicket, byte[] encrypted,
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   137
            AccessControlContext acc, Object ServiceCreds) throws IOException;
bba6fefdd660 8038089: TLS optional support for Kerberos cipher suites needs to be re-examine
weijun
parents:
diff changeset
   138
}