src/java.security.jgss/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java
author weijun
Fri, 19 Apr 2019 10:22:20 +0800
changeset 58611 53ddf218eddd
parent 47216 71c04702a3d5
permissions -rw-r--r--
8220302: Better Kerberos ccache handling Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 77
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 77
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 77
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 77
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 77
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
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
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package sun.security.krb5.internal.ccache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.InputStream;
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
    35
import java.util.ArrayList;
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
    36
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.StringTokenizer;
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
    38
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.krb5.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.krb5.internal.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.security.krb5.internal.util.KrbDataInputStream;
32933
83d50f1247bb 8138978: Examine usages of sun.misc.IOUtils
chegar
parents: 31538
diff changeset
    42
import sun.security.util.IOUtils;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This class extends KrbDataInputStream. It is used for parsing FCC-format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * data from file to memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Yanni Zhang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class CCacheInputStream extends KrbDataInputStream implements FileCCacheConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * FCC version 2 contains type information for principals.  FCC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * version 1 does not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * FCC version 3 contains keyblock encryption type information, and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * architecture independent.  Previous versions are not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * The code will accept version 1, 2, and 3 ccaches, and depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * what KRB5_FCC_DEFAULT_FVNO is set to, it will create version 1, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * or 3 FCC caches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * The default credentials cache should be type 3 for now (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * init_ctx.c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /* V4 of the credentials cache format allows for header tags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public CCacheInputStream(InputStream is){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /* Read tag field introduced in KRB5_FCC_FVNO_4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // this needs to be public for Kinit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public Tag readTag() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        char[] buf = new char[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        int tag = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int taglen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        Integer time_offset = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        Integer usec_offset = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        len = read(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (len < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throw new IOException("stop.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (len > buf.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new IOException("Invalid tag length.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        while (len > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            tag    = read(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            taglen = read(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            case FCC_TAG_DELTATIME:
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25169
diff changeset
    97
                time_offset = read(4);
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25169
diff changeset
    98
                usec_offset = read(4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            len = len - (4 + taglen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   104
        return new Tag(len, tag, time_offset, usec_offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * In file-based credential cache, the realm name is stored as part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * principal name at the first place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // made public for KinitOptions to call directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public PrincipalName readPrincipal(int version) throws IOException, RealmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        int type, length, namelength, kret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        String[] pname = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        String realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        /* Read principal type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (version == KRB5_FCC_FVNO_1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            type = KRB5_NT_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            type = read(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   121
        length = readLength4();
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   122
        List<String> result = new ArrayList<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * DCE includes the principal's realm in the count; the new format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * does not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (version == KRB5_FCC_FVNO_1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            length--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        for (int i = 0; i <= length; i++) {
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   130
            namelength = readLength4();
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   131
            byte[] bytes = IOUtils.readFully(this, namelength, true);
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   132
            result.add(new String(bytes));
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   133
        }
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   134
        if (result.isEmpty()) {
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   135
            throw new IOException("No realm or principal");
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   136
        }
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   137
        if (isRealm(result.get(0))) {
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   138
            realm = result.remove(0);
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   139
            if (result.isEmpty()) {
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   140
                throw new IOException("No principal name components");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   142
            return new PrincipalName(
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   143
                    type,
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   144
                    result.toArray(new String[result.size()]),
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   145
                    new Realm(realm));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 11011
diff changeset
   147
        try {
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   148
            return new PrincipalName(
33282
00f3c40fd3af 8048030: Expectations should be consistent
weijun
parents: 32933
diff changeset
   149
                    type,
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   150
                    result.toArray(new String[result.size()]),
33282
00f3c40fd3af 8048030: Expectations should be consistent
weijun
parents: 32933
diff changeset
   151
                    Realm.getDefault());
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 11011
diff changeset
   152
        } catch (RealmException re) {
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 11011
diff changeset
   153
            return null;
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 11011
diff changeset
   154
        }
2
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
     * In practice, a realm is named by uppercasing the DNS domain name. we currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * rely on this to determine if the string within the principal identifier is realm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    boolean isRealm(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            Realm r = new Realm(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        StringTokenizer st = new StringTokenizer(str, ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            s = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            for (int i = 0; i < s.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (s.charAt(i) >= 141) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    EncryptionKey readKey(int version) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int keyType, keyLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        keyType = read(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (version == KRB5_FCC_FVNO_3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            read(2); /* keytype recorded twice in fvno 3 */
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   188
        keyLen = readLength4();
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   189
        byte[] bytes = IOUtils.readFully(this, keyLen, true);
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25169
diff changeset
   190
        return new EncryptionKey(bytes, keyType, version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    long[] readTimes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        long[] times = new long[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        times[0] = (long)read(4) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        times[1] = (long)read(4) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        times[2] = (long)read(4) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        times[3] = (long)read(4) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return times;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    boolean readskey() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (read() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        else return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    HostAddress[] readAddr() throws IOException, KrbApErrException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        int numAddrs, addrType, addrLength;
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   211
        numAddrs = readLength4();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (numAddrs > 0) {
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   213
            List<HostAddress> addrs = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            for (int i = 0; i < numAddrs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                addrType = read(2);
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   216
                addrLength = readLength4();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                if (!(addrLength == 4 || addrLength == 16)) {
77
41259df8c6e4 6664612: debug output leaked
weijun
parents: 76
diff changeset
   218
                    if (DEBUG) {
41259df8c6e4 6664612: debug output leaked
weijun
parents: 76
diff changeset
   219
                        System.out.println("Incorrect address format.");
41259df8c6e4 6664612: debug output leaked
weijun
parents: 76
diff changeset
   220
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                byte[] result = new byte[addrLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                for (int j = 0; j < addrLength; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    result[j] = (byte)read(1);
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   226
                addrs.add(new HostAddress(addrType, result));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   228
            return addrs.toArray(new HostAddress[addrs.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    AuthorizationDataEntry[] readAuth() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        int num, adtype, adlength;
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   235
        num = readLength4();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (num > 0) {
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   237
            List<AuthorizationDataEntry> auData = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            byte[] data = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                adtype = read(2);
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   241
                adlength = readLength4();
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   242
                data = IOUtils.readFully(this, adlength, true);
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   243
                auData.add(new AuthorizationDataEntry(adtype, data));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   245
            return auData.toArray(new AuthorizationDataEntry[auData.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        else return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   250
    byte[] readData() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        int length;
28553
6c0b398bd744 8060474: Resolve more parsing ambiguity
weijun
parents: 25859
diff changeset
   252
        length = readLength4();
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   253
        if (length == 0) {
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   254
            return null;
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   255
        } else {
22093
741504ef3df7 8028780: JDK KRB5 module throws OutOfMemoryError when CCache is corrupt
weijun
parents: 13247
diff changeset
   256
            return IOUtils.readFully(this, length, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    boolean[] readFlags() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        boolean[] flags = new boolean[Krb5.TKT_OPTS_MAX+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        int ticketFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ticketFlags = read(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if ((ticketFlags & 0x40000000) == TKT_FLG_FORWARDABLE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        flags[1] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if ((ticketFlags & 0x20000000) == TKT_FLG_FORWARDED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        flags[2] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if ((ticketFlags & 0x10000000) == TKT_FLG_PROXIABLE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        flags[3] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if ((ticketFlags & 0x08000000) == TKT_FLG_PROXY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        flags[4] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if ((ticketFlags & 0x04000000) == TKT_FLG_MAY_POSTDATE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        flags[5] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if ((ticketFlags & 0x02000000) == TKT_FLG_POSTDATED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        flags[6] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if ((ticketFlags & 0x01000000) == TKT_FLG_INVALID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        flags[7] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if ((ticketFlags & 0x00800000) == TKT_FLG_RENEWABLE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        flags[8] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if ((ticketFlags & 0x00400000) == TKT_FLG_INITIAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        flags[9] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if ((ticketFlags & 0x00200000) == TKT_FLG_PRE_AUTH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        flags[10] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if ((ticketFlags & 0x00100000) == TKT_FLG_HW_AUTH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        flags[11] = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            String msg = ">>> CCacheInputStream: readFlags() ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (flags[1] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                msg += " FORWARDABLE;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (flags[2] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                msg += " FORWARDED;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (flags[3] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                msg += " PROXIABLE;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if (flags[4] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                msg += " PROXY;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (flags[5] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                msg += " MAY_POSTDATE;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            if (flags[6] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                msg += " POSTDATED;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (flags[7] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                msg += " INVALID;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (flags[8] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                msg += " RENEWABLE;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (flags[9] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                msg += " INITIAL;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            if (flags[10] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                msg += " PRE_AUTH;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            if (flags[11] == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                msg += " HW_AUTH;";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            System.out.println(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   326
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   327
    /**
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   328
     * Reads the next cred or config entry in stream.
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   329
     * @return the next cred or config entry, null if data unparseable.
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   330
     *
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   331
     * When data is unparseable, this method makes sure the correct number of
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   332
     * bytes are consumed so it's safe to start reading the next element.
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   333
     */
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   334
    Object readCred(int version) throws IOException,RealmException, KrbApErrException, Asn1Exception {
25169
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   335
        PrincipalName cpname = null;
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   336
        try {
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   337
            cpname = readPrincipal(version);
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   338
        } catch (Exception e) {
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   339
            // Do not return here. All data for this cred should be fully
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   340
            // consumed so that we can read the next one.
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   341
        }
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   342
        if (DEBUG) {
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 11011
diff changeset
   343
            System.out.println(">>>DEBUG <CCacheInputStream>  client principal is " + cpname);
25169
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   344
        }
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   345
        PrincipalName spname = null;
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   346
        try {
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   347
            spname = readPrincipal(version);
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   348
        } catch (Exception e) {
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   349
            // same as above
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   350
        }
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   351
        if (DEBUG) {
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 11011
diff changeset
   352
            System.out.println(">>>DEBUG <CCacheInputStream> server principal is " + spname);
25169
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   353
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        EncryptionKey key = readKey(version);
25169
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   355
        if (DEBUG) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            System.out.println(">>>DEBUG <CCacheInputStream> key type: " + key.getEType());
25169
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   357
        }
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 28553
diff changeset
   358
        long[] times = readTimes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        KerberosTime authtime = new KerberosTime(times[0]);
76
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   360
        KerberosTime starttime =
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   361
                (times[1]==0) ? null : new KerberosTime(times[1]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        KerberosTime endtime = new KerberosTime(times[2]);
76
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   363
        KerberosTime renewTill =
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   364
                (times[3]==0) ? null : new KerberosTime(times[3]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            System.out.println(">>>DEBUG <CCacheInputStream> auth time: " + authtime.toDate().toString());
76
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   368
            System.out.println(">>>DEBUG <CCacheInputStream> start time: " +
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   369
                    ((starttime==null)?"null":starttime.toDate().toString()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            System.out.println(">>>DEBUG <CCacheInputStream> end time: " + endtime.toDate().toString());
76
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   371
            System.out.println(">>>DEBUG <CCacheInputStream> renew_till time: " +
87bd6df367b8 6590930: reed/write does not match for ccache
weijun
parents: 2
diff changeset
   372
                    ((renewTill==null)?"null":renewTill.toDate().toString()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        boolean skey = readskey();
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 28553
diff changeset
   375
        boolean[] flags = readFlags();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        TicketFlags tFlags = new TicketFlags(flags);
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 28553
diff changeset
   377
        HostAddress[] addr = readAddr();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        HostAddresses addrs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (addr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            addrs = new HostAddresses(addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        AuthorizationDataEntry[] auDataEntry = readAuth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        AuthorizationData auData = null;
11011
d14a696e3ab5 7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents: 7288
diff changeset
   384
        if (auDataEntry != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            auData = new AuthorizationData(auDataEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   387
        byte[] ticketData = readData();
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   388
        byte[] ticketData2 = readData();
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   389
25169
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   390
        // Skip this cred if either cpname or spname isn't created.
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   391
        if (cpname == null || spname == null) {
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   392
            return null;
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   393
        }
365cba5326f9 8048073: Cannot read ccache entry with a realm-less service name
weijun
parents: 22093
diff changeset
   394
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   395
        try {
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   396
            if (spname.getRealmString().equals("X-CACHECONF:")) {
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   397
                String[] nameParts = spname.getNameStrings();
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   398
                if (nameParts[0].equals("krb5_ccache_conf_data")) {
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   399
                    return new CredentialsCache.ConfigEntry(nameParts[1],
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   400
                            nameParts.length > 2 ? new PrincipalName(nameParts[2]) : null,
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   401
                            ticketData);
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   402
                }
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   403
            }
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   404
            return new Credentials(cpname, spname, key, authtime, starttime,
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   405
                    endtime, renewTill, skey, tFlags,
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   406
                    addrs, auData,
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   407
                    ticketData != null ? new Ticket(ticketData) : null,
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   408
                    ticketData2 != null ? new Ticket(ticketData2) : null);
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   409
        } catch (Exception e) {     // If any of new Ticket(*) fails.
58611
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   410
            if (DEBUG) {
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   411
                e.printStackTrace(System.out);
53ddf218eddd 8220302: Better Kerberos ccache handling
weijun
parents: 47216
diff changeset
   412
            }
7288
a38f3099e518 6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents: 5506
diff changeset
   413
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
}