src/java.security.jgss/share/classes/sun/security/krb5/Credentials.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58611 53ddf218eddd
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
package sun.security.krb5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
51398
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
    34
import sun.security.action.GetPropertyAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.krb5.internal.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.krb5.internal.ccache.CredentialsCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.krb5.internal.crypto.EType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Date;
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5974
diff changeset
    40
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class encapsulates the concept of a Kerberos service
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * credential. That includes a Kerberos ticket and an associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * session key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class Credentials {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    Ticket ticket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    PrincipalName client;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
    52
    PrincipalName clientAlias;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    PrincipalName server;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
    54
    PrincipalName serverAlias;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    EncryptionKey key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    TicketFlags flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    KerberosTime authTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    KerberosTime startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    KerberosTime endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    KerberosTime renewTill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    HostAddresses cAddr;
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    62
    AuthorizationData authzData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static CredentialsCache cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static boolean alreadyLoaded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static boolean alreadyTried = false;
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
    67
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    68
    private Credentials proxy = null;
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    69
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    70
    public Credentials getProxy() {
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    71
        return proxy;
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    72
    }
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    73
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    74
    public Credentials setProxy(Credentials proxy) {
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    75
        this.proxy = proxy;
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    76
        return this;
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    77
    }
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
    78
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
    79
    // Read native ticket with session key type in the given list
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
    80
    private static native Credentials acquireDefaultNativeCreds(int[] eTypes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public Credentials(Ticket new_ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                       PrincipalName new_client,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
    84
                       PrincipalName new_client_alias,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                       PrincipalName new_server,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
    86
                       PrincipalName new_server_alias,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                       EncryptionKey new_key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                       TicketFlags new_flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                       KerberosTime authTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                       KerberosTime new_startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                       KerberosTime new_endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                       KerberosTime renewTill,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    93
                       HostAddresses cAddr,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    94
                       AuthorizationData authzData) {
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
    95
        this(new_ticket, new_client, new_client_alias, new_server,
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
    96
                new_server_alias, new_key, new_flags, authTime,
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
    97
                new_startTime, new_endTime, renewTill, cAddr);
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    98
        this.authzData = authzData;
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
    99
    }
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   100
58331
e4ce29f6094e 8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents: 57487
diff changeset
   101
    // Warning: called by NativeCreds.c and nativeccache.c
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   102
    public Credentials(Ticket new_ticket,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   103
                       PrincipalName new_client,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   104
                       PrincipalName new_client_alias,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   105
                       PrincipalName new_server,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   106
                       PrincipalName new_server_alias,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   107
                       EncryptionKey new_key,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   108
                       TicketFlags new_flags,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   109
                       KerberosTime authTime,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   110
                       KerberosTime new_startTime,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   111
                       KerberosTime new_endTime,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   112
                       KerberosTime renewTill,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                       HostAddresses cAddr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        ticket = new_ticket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        client = new_client;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   116
        clientAlias = new_client_alias;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        server = new_server;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   118
        serverAlias = new_server_alias;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        key = new_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        flags = new_flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.authTime = authTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        startTime = new_startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        endTime = new_endTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.renewTill = renewTill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.cAddr = cAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public Credentials(byte[] encoding,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                       String client,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   130
                       String clientAlias,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                       String server,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   132
                       String serverAlias,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                       byte[] keyBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                       int keyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                       boolean[] flags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                       Date authTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                       Date startTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                       Date endTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                       Date renewTill,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                       InetAddress[] cAddrs) throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this(new Ticket(encoding),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
             new PrincipalName(client, PrincipalName.KRB_NT_PRINCIPAL),
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   143
             (clientAlias == null? null : new PrincipalName(clientAlias,
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   144
                     PrincipalName.KRB_NT_PRINCIPAL)),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
             new PrincipalName(server, PrincipalName.KRB_NT_SRV_INST),
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   146
             (serverAlias == null? null : new PrincipalName(serverAlias,
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   147
                     PrincipalName.KRB_NT_SRV_INST)),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
             new EncryptionKey(keyType, keyBytes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
             (flags == null? null: new TicketFlags(flags)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
             (authTime == null? null: new KerberosTime(authTime)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
             (startTime == null? null: new KerberosTime(startTime)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
             (endTime == null? null: new KerberosTime(endTime)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
             (renewTill == null? null: new KerberosTime(renewTill)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
             null); // caddrs are in the encoding at this point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Acquires a service ticket for the specified service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * principal. If the service ticket is not already available, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * obtains a new one from the KDC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public Credentials(Credentials tgt, PrincipalName service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public final PrincipalName getClient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   172
    public final PrincipalName getClientAlias() {
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   173
        return clientAlias;
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   174
    }
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   175
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public final PrincipalName getServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   180
    public final PrincipalName getServerAlias() {
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   181
        return serverAlias;
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   182
    }
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   183
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public final EncryptionKey getSessionKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public final Date getAuthTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (authTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return authTime.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public final Date getStartTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (startTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                return startTime.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public final Date getEndTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (endTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                return endTime.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public final Date getRenewTill() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (renewTill != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                return renewTill.toDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public final boolean[] getFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (flags == null) // Can be in a KRB-CRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return flags.toBooleanArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public final InetAddress[] getClientAddresses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (cAddr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return cAddr.getInetAddresses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public final byte[] getEncoded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        byte[] retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            retVal = ticket.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } catch (Asn1Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            System.out.println(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            System.out.println(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public boolean isForwardable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return flags.get(Krb5.TKT_OPTS_FORWARDABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public boolean isRenewable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return flags.get(Krb5.TKT_OPTS_RENEWABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public Ticket getTicket() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return ticket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public TicketFlags getTicketFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   264
    public AuthorizationData getAuthzData() {
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   265
        return authzData;
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 2
diff changeset
   266
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Checks if the service ticket returned by the KDC has the OK-AS-DELEGATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * flag set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @return true if OK-AS_DELEGATE flag is set, otherwise, return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public boolean checkDelegate() {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   273
        return flags.get(Krb5.TKT_OPTS_DELEGATE);
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   274
    }
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   275
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   276
    /**
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   277
     * Reset TKT_OPTS_DELEGATE to false, called at credentials acquirement
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   278
     * when one of the cross-realm TGTs does not have the OK-AS-DELEGATE
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   279
     * flag set. This info must be preservable and restorable through
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   280
     * the Krb5Util.credsToTicket/ticketToCreds() methods so that even if
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   281
     * the service ticket is cached it still remembers the cross-realm
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   282
     * authentication result.
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   283
     */
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   284
    public void resetDelegate() {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3949
diff changeset
   285
        flags.set(Krb5.TKT_OPTS_DELEGATE, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public Credentials renew() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        KDCOptions options = new KDCOptions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        options.set(KDCOptions.RENEW, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         * Added here to pass KrbKdcRep.check:73
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        options.set(KDCOptions.RENEWABLE, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return new KrbTgsReq(options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                             this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                             server,
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   299
                             serverAlias,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                             null, // from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                             null, // till
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                             null, // rtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                             null, // eTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                             cAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                             null).sendAndGetCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Returns a TGT for the given client principal from a ticket cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param princ the client principal. A value of null means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * default principal name in the credentials cache will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param ticketCache the path to the tickets file. A value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * of null will be accepted to indicate that the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * path should be searched
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 27946
diff changeset
   318
     * @return the TGT credentials or null if none were found. If the tgt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * expired, it is the responsibility of the caller to determine this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public static Credentials acquireTGTFromCache(PrincipalName princ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                                  String ticketCache)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (ticketCache == null) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   326
            // The default ticket cache on Windows and Mac is not a file.
51398
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
   327
            String os = GetPropertyAction.privilegedGetProperty("os.name");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   328
            if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") ||
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12423
diff changeset
   329
                    os.toUpperCase(Locale.ENGLISH).contains("OS X")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                Credentials creds = acquireDefaultCreds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                if (creds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        System.out.println(">>> Found no TGT's in LSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                if (princ != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    if (creds.getClient().equals(princ)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                            System.out.println(">>> Obtained TGT from LSA: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                               + creds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        return creds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                            System.out.println(">>> LSA contains TGT for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                               + creds.getClient()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                               + " not "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                               + princ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        System.out.println(">>> Obtained TGT from LSA: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                           + creds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    return creds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * Returns the appropriate cache. If ticketCache is null, it is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * default cache otherwise it is the cache filename contained in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        CredentialsCache ccache =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            CredentialsCache.getInstance(princ, ticketCache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   370
        if (ccache == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return null;
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   372
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   374
        Credentials tgtCred = ccache.getInitialCreds();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   376
        if (tgtCred == null) {
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   377
            return null;
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   378
        }
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   379
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   380
        if (EType.isSupported(tgtCred.key.getEType())) {
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   381
            return tgtCred;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    ">>> unsupported key type found the default TGT: " +
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   386
                    tgtCred.key.getEType());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Acquires default credentials.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * <br>The possible locations for default credentials cache is searched in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * the following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * <li> The directory and cache file name specified by "KRB5CCNAME" system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <li> The directory and cache file name specified by "KRB5CCNAME"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * environment variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <li> A cache file named krb5cc_{user.name} at {user.home} directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @return a <code>KrbCreds</code> object if the credential is found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    // this method is intentionally changed to not check if the caller's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    // principal name matches cache file's principal name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    // It assumes that the GSS call has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    // the privilege to access the default cache file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   412
    // This method is only called on Windows and Mac OS X, the native
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   413
    // acquireDefaultNativeCreds is also available on these platforms.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public static synchronized Credentials acquireDefaultCreds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        Credentials result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (cache == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            cache = CredentialsCache.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (cache != null) {
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   421
            Credentials temp = cache.getInitialCreds();
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   422
            if (temp != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                if (DEBUG) {
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   424
                    System.out.println(">>> KrbCreds found the default ticket"
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   425
                            + " granting ticket in credential cache.");
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   426
                }
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   427
                if (EType.isSupported(temp.key.getEType())) {
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   428
                    result = temp;
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   429
                } else {
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   430
                    if (DEBUG) {
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   431
                        System.out.println(
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   432
                            ">>> unsupported key type found the default TGT: " +
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 58331
diff changeset
   433
                            temp.key.getEType());
12423
a69d7fadb9f8 7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents: 12047
diff changeset
   434
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            // Doesn't seem to be a default cache on this system or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            // TGT has unsupported encryption type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (!alreadyTried) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                // See if there's any native code to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    ensureLoaded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        System.out.println("Can not load credentials cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                        e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    alreadyTried = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (alreadyLoaded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                // There is some native code
19373
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   456
                if (DEBUG) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   457
                    System.out.println(">> Acquire default native Credentials");
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   458
                }
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   459
                try {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   460
                    result = acquireDefaultNativeCreds(
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   461
                            EType.getDefaults("default_tkt_enctypes"));
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   462
                } catch (KrbException ke) {
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   463
                    // when there is no default_tkt_enctypes.
4bb12c72a46f 8016594: Native Windows ccache still reads DES tickets
weijun
parents: 14413
diff changeset
   464
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Acquires credentials for a specified service using initial credential.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * When the service has a different realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * from the initial credential, we do cross-realm authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * - first, we use the current credential to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * a cross-realm credential from the local KDC, then use that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * cross-realm credential to request service credential
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * from the foreigh KDC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @param service the name of service principal using format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * components@realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @param ccreds client's initial credential.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @exception IOException if an error occurs in reading the credentials
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @exception KrbException if an error occurs specific to Kerberos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @return a <code>Credentials</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public static Credentials acquireServiceCreds(String service,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                                  Credentials ccreds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return CredentialsUtil.acquireServiceCreds(service, ccreds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   494
    public static Credentials acquireS4U2selfCreds(PrincipalName user,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   495
            Credentials ccreds) throws KrbException, IOException {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   496
        return CredentialsUtil.acquireS4U2selfCreds(user, ccreds);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   497
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   498
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   499
    public static Credentials acquireS4U2proxyCreds(String service,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   500
            Ticket second, PrincipalName client, Credentials ccreds)
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   501
        throws KrbException, IOException {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   502
        return CredentialsUtil.acquireS4U2proxyCreds(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   503
                service, second, client, ccreds);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   504
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   505
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public CredentialsCache getCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Prints out debug info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public static void printDebug(Credentials c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        System.out.println(">>> DEBUG: ----Credentials----");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        System.out.println("\tclient: " + c.client.toString());
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   516
        if (c.clientAlias != null)
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   517
            System.out.println("\tclient alias: " + c.clientAlias.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        System.out.println("\tserver: " + c.server.toString());
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   519
        if (c.serverAlias != null)
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   520
            System.out.println("\tserver alias: " + c.serverAlias.toString());
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 12538
diff changeset
   521
        System.out.println("\tticket: sname: " + c.ticket.sname.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (c.startTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            System.out.println("\tstartTime: " + c.startTime.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        System.out.println("\tendTime: " + c.endTime.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        System.out.println("        ----Credentials end----");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    static void ensureLoaded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                new java.security.PrivilegedAction<Void> () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                        public Void run() {
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12423
diff changeset
   534
                                if (System.getProperty("os.name").contains("OS X")) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   535
                                    System.loadLibrary("osxkrb5");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   536
                                } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   537
                                    System.loadLibrary("w2k_lsa_auth");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7183
diff changeset
   538
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        alreadyLoaded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   546
        StringBuilder sb = new StringBuilder("Credentials:");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   547
        sb.append(    "\n      client=").append(client);
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   548
        if (clientAlias != null)
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   549
            sb.append(    "\n      clientAlias=").append(clientAlias);
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   550
        sb.append(    "\n      server=").append(server);
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   551
        if (serverAlias != null)
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 51398
diff changeset
   552
            sb.append(    "\n      serverAlias=").append(serverAlias);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (authTime != null) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   554
            sb.append("\n    authTime=").append(authTime);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (startTime != null) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   557
            sb.append("\n   startTime=").append(startTime);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   559
        sb.append(    "\n     endTime=").append(endTime);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   560
        sb.append(    "\n   renewTill=").append(renewTill);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   561
        sb.append(    "\n       flags=").append(flags);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   562
        sb.append(    "\nEType (skey)=").append(key.getEType());
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   563
        sb.append(    "\n   (tkt key)=").append(ticket.encPart.eType);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   564
        return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   567
    public sun.security.krb5.internal.ccache.Credentials toCCacheCreds() {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   568
        return new sun.security.krb5.internal.ccache.Credentials(
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   569
                getClient(), getServer(),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   570
                getSessionKey(),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   571
                date2kt(getAuthTime()),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   572
                date2kt(getStartTime()),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   573
                date2kt(getEndTime()),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   574
                date2kt(getRenewTill()),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   575
                false,
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   576
                flags,
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   577
                new HostAddresses(getClientAddresses()),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   578
                getAuthzData(),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   579
                getTicket(),
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   580
                null);
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   581
    }
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   582
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   583
    private static KerberosTime date2kt(Date d) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   584
        return d == null ? null : new KerberosTime(d);
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 25859
diff changeset
   585
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
}