< prev index next >

src/windows/classes/sun/security/mscapi/KeyStore.java

Print this page
rev 11258 : 8139436: sun.security.mscapi.KeyStore might load incomplete data
Reviewed-by: vinnie, weijun
   1 /*
   2  * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 295      * entry is returned. If the given alias name identifies a
 296      * <i>key entry</i>, the first element of the certificate chain of that
 297      * entry is returned, or null if that entry does not have a certificate
 298      * chain.
 299      *
 300      * @param alias the alias name
 301      *
 302      * @return the certificate, or null if the given alias does not exist or
 303      * does not contain a certificate.
 304      */
 305     public Certificate engineGetCertificate(String alias)
 306     {
 307         if (alias == null) {
 308             return null;
 309         }
 310 
 311         for (KeyEntry entry : entries) {
 312             if (alias.equals(entry.getAlias()))
 313             {
 314                 X509Certificate[] certChain = entry.getCertificateChain();
 315                 return certChain[0];
 316             }
 317         }
 318 
 319         return null;
 320     }
 321 
 322     /**
 323      * Returns the creation date of the entry identified by the given alias.
 324      *
 325      * @param alias the alias name
 326      *
 327      * @return the creation date of this entry, or null if the given alias does
 328      * not exist
 329      */
 330     public Date engineGetCreationDate(String alias) {
 331         if (alias == null) {
 332             return null;
 333         }
 334         return new Date();
 335     }


 825         {
 826             // Ignore the exception and skip this entry
 827             // TODO - throw CertificateException?
 828         }
 829     }
 830 
 831     /**
 832      * Generates certificates from byte data and stores into cert collection.
 833      *
 834      * @param data Byte data.
 835      * @param certCollection Collection of certificates.
 836      */
 837     private void generateCertificate(byte[] data,
 838         Collection<Certificate> certCollection) {
 839         try
 840         {
 841             ByteArrayInputStream bis = new ByteArrayInputStream(data);
 842 
 843             // Obtain certificate factory
 844             if (certificateFactory == null) {
 845                 certificateFactory = CertificateFactory.getInstance("X.509");
 846             }
 847 
 848             // Generate certificate
 849             Collection<? extends Certificate> c =
 850                     certificateFactory.generateCertificates(bis);
 851             certCollection.addAll(c);
 852         }
 853         catch (CertificateException e)
 854         {
 855             // Ignore the exception and skip this certificate
 856             // TODO - throw CertificateException?
 857         }
 858         catch (Throwable te)
 859         {
 860             // Ignore the exception and skip this certificate
 861             // TODO - throw CertificateException?
 862         }
 863     }
 864 
 865     /**


   1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 295      * entry is returned. If the given alias name identifies a
 296      * <i>key entry</i>, the first element of the certificate chain of that
 297      * entry is returned, or null if that entry does not have a certificate
 298      * chain.
 299      *
 300      * @param alias the alias name
 301      *
 302      * @return the certificate, or null if the given alias does not exist or
 303      * does not contain a certificate.
 304      */
 305     public Certificate engineGetCertificate(String alias)
 306     {
 307         if (alias == null) {
 308             return null;
 309         }
 310 
 311         for (KeyEntry entry : entries) {
 312             if (alias.equals(entry.getAlias()))
 313             {
 314                 X509Certificate[] certChain = entry.getCertificateChain();
 315                 return certChain.length == 0 ? null : certChain[0];
 316             }
 317         }
 318 
 319         return null;
 320     }
 321 
 322     /**
 323      * Returns the creation date of the entry identified by the given alias.
 324      *
 325      * @param alias the alias name
 326      *
 327      * @return the creation date of this entry, or null if the given alias does
 328      * not exist
 329      */
 330     public Date engineGetCreationDate(String alias) {
 331         if (alias == null) {
 332             return null;
 333         }
 334         return new Date();
 335     }


 825         {
 826             // Ignore the exception and skip this entry
 827             // TODO - throw CertificateException?
 828         }
 829     }
 830 
 831     /**
 832      * Generates certificates from byte data and stores into cert collection.
 833      *
 834      * @param data Byte data.
 835      * @param certCollection Collection of certificates.
 836      */
 837     private void generateCertificate(byte[] data,
 838         Collection<Certificate> certCollection) {
 839         try
 840         {
 841             ByteArrayInputStream bis = new ByteArrayInputStream(data);
 842 
 843             // Obtain certificate factory
 844             if (certificateFactory == null) {
 845                 certificateFactory = CertificateFactory.getInstance("X.509", "SUN");
 846             }
 847 
 848             // Generate certificate
 849             Collection<? extends Certificate> c =
 850                     certificateFactory.generateCertificates(bis);
 851             certCollection.addAll(c);
 852         }
 853         catch (CertificateException e)
 854         {
 855             // Ignore the exception and skip this certificate
 856             // TODO - throw CertificateException?
 857         }
 858         catch (Throwable te)
 859         {
 860             // Ignore the exception and skip this certificate
 861             // TODO - throw CertificateException?
 862         }
 863     }
 864 
 865     /**


< prev index next >