jdk/src/share/classes/sun/tools/jar/JarVerifierStream.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 51 6fe31bc95bbc
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 51
diff changeset
     2
 * Copyright 1996-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.zip.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.jar.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.provider.SystemIdentity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This is OBSOLETE. DO NOT USE THIS. Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * java.util.jar.JarEntry.getCertificates instead. It has to stay here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * because some apps (namely HJ and HJV) call directly into it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class is stripped down greatly from JDK 1.1.x.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Roland Schemers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class JarVerifierStream extends ZipInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private JarEntry current;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    51
    private Hashtable<String, Vector<SystemIdentity>> verified
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    52
        = new Hashtable<String, Vector<SystemIdentity>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private JarInputStream jis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private sun.tools.jar.Manifest man = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * construct a JarVerfierStream from an input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public JarVerifierStream(InputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        super(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        jis = new JarInputStream(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public void close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        jis.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public void closeEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        jis.closeEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * This method scans to see which entry we're parsing and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * keeps various state information depending on what type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * file is being parsed. Files it treats specially are: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * <li>Manifest files. At any point, this stream can be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * for a manifest. If it is present, a Manifest object will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <li>Block Signature file. Like with the manifest, the stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * can be queried at any time for all blocks parsed thus far.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public synchronized ZipEntry getNextEntry() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        current = (JarEntry) jis.getNextEntry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * read a single byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        int n = jis.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (n == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            addIds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * read an array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public int read(byte[] b, int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int n = jis.read(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (n == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            addIds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private void addIds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (current != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            Certificate[] certs = current.getCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (certs != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   123
                Vector<SystemIdentity> ids = getIds(certs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                if (ids != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    verified.put(current.getName(), ids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Returns a Hashtable mapping filenames to vectors of identities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public Hashtable getVerifiedSignatures() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        /* we may want to return a copy of this at some point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
           For now we simply trust the caller */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (verified.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            return verified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns an enumeration of PKCS7 blocks. This looks bogus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * but Hotjava just checks to see if enumeration is not null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * to see if anything was signed!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public Enumeration getBlocks() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (verified.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return new Enumeration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                public boolean hasMoreElements() { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                public Object nextElement() { return null; }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * This method used to be called by various versions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * AppletResourceLoader, even though they didn't do anything with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * the result. We leave them and return null for backwards compatability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public Hashtable getNameToHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Convert java.util.jar.Manifest object to a sun.tools.jar.Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public sun.tools.jar.Manifest getManifest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (man == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                java.util.jar.Manifest jman = jis.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                if (jman == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                jman.write(baos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                byte[] data = baos.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                man = new sun.tools.jar.Manifest(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                // return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    static class CertCache {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Certificate [] certs;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   192
        Vector<SystemIdentity> ids;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        boolean equals(Certificate[] certs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                if (this.certs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    if (certs!= null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (certs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                boolean match;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                for (int i = 0; i < certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    match = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    for (int j = 0; j < this.certs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        if (certs[i].equals(this.certs[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                            match = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    if (!match) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                for (int i = 0; i < this.certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    match = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    for (int j = 0; j < certs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        if (this.certs[i].equals(certs[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                            match = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    if (!match) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   232
    private ArrayList<CertCache> certCache = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Returns the Identity vector for the given array of Certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   238
    protected Vector<SystemIdentity> getIds(Certificate[] certs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (certs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (certCache == null)
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   243
            certCache = new ArrayList<CertCache>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        CertCache cc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        for (int i = 0; i < certCache.size(); i++) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   246
            cc = certCache.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            if (cc.equals(certs)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                return cc.ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        cc = new CertCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        cc.certs = certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (certs.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            for (int i=0; i<certs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    X509Certificate cert = (X509Certificate) certs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    Principal tmpName = cert.getSubjectDN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    final SystemIdentity id = new SystemIdentity(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                                           tmpName.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                                           null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    byte[] encoded = cert.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    final java.security.Certificate oldC =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        new sun.security.x509.X509Cert(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        AccessController.doPrivileged(
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   268
                         new java.security.PrivilegedExceptionAction<Void>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   269
                            public Void run()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                throws java.security.KeyManagementException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                id.addCertificate(oldC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    } catch (java.security.PrivilegedActionException pae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        throw (java.security.KeyManagementException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                            pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    if (cc.ids == null)
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   281
                        cc.ids = new Vector<SystemIdentity>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    cc.ids.addElement(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                } catch (java.security.KeyManagementException kme) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    // ignore if we can't create Identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    // ignore if we can't parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                } catch (java.security.cert.CertificateEncodingException cee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    // ignore if we can't encode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        certCache.add(cc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return cc.ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}