jdk/src/share/classes/com/sun/crypto/provider/JceKeyStore.java
changeset 25402 0c24d9aa8fb9
parent 10336 0bb1999251f8
equal deleted inserted replaced
25401:2e2b5a66a787 25402:0c24d9aa8fb9
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   105     public Key engineGetKey(String alias, char[] password)
   105     public Key engineGetKey(String alias, char[] password)
   106         throws NoSuchAlgorithmException, UnrecoverableKeyException
   106         throws NoSuchAlgorithmException, UnrecoverableKeyException
   107     {
   107     {
   108         Key key = null;
   108         Key key = null;
   109 
   109 
   110         Object entry = entries.get(alias.toLowerCase());
   110         Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
   111 
   111 
   112         if (!((entry instanceof PrivateKeyEntry) ||
   112         if (!((entry instanceof PrivateKeyEntry) ||
   113               (entry instanceof SecretKeyEntry))) {
   113               (entry instanceof SecretKeyEntry))) {
   114             return null;
   114             return null;
   115         }
   115         }
   148      */
   148      */
   149     public Certificate[] engineGetCertificateChain(String alias)
   149     public Certificate[] engineGetCertificateChain(String alias)
   150     {
   150     {
   151         Certificate[] chain = null;
   151         Certificate[] chain = null;
   152 
   152 
   153         Object entry = entries.get(alias.toLowerCase());
   153         Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
   154 
   154 
   155         if ((entry instanceof PrivateKeyEntry)
   155         if ((entry instanceof PrivateKeyEntry)
   156             && (((PrivateKeyEntry)entry).chain != null)) {
   156             && (((PrivateKeyEntry)entry).chain != null)) {
   157             chain = ((PrivateKeyEntry)entry).chain.clone();
   157             chain = ((PrivateKeyEntry)entry).chain.clone();
   158         }
   158         }
   176      * does not contain a certificate.
   176      * does not contain a certificate.
   177      */
   177      */
   178     public Certificate engineGetCertificate(String alias) {
   178     public Certificate engineGetCertificate(String alias) {
   179         Certificate cert = null;
   179         Certificate cert = null;
   180 
   180 
   181         Object entry = entries.get(alias.toLowerCase());
   181         Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
   182 
   182 
   183         if (entry != null) {
   183         if (entry != null) {
   184             if (entry instanceof TrustedCertEntry) {
   184             if (entry instanceof TrustedCertEntry) {
   185                 cert = ((TrustedCertEntry)entry).cert;
   185                 cert = ((TrustedCertEntry)entry).cert;
   186             } else if ((entry instanceof PrivateKeyEntry) &&
   186             } else if ((entry instanceof PrivateKeyEntry) &&
   201      * not exist
   201      * not exist
   202      */
   202      */
   203     public Date engineGetCreationDate(String alias) {
   203     public Date engineGetCreationDate(String alias) {
   204         Date date = null;
   204         Date date = null;
   205 
   205 
   206         Object entry = entries.get(alias.toLowerCase());
   206         Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
   207 
   207 
   208         if (entry != null) {
   208         if (entry != null) {
   209             // We have to create a new instance of java.util.Date because
   209             // We have to create a new instance of java.util.Date because
   210             // dates are not immutable
   210             // dates are not immutable
   211             if (entry instanceof TrustedCertEntry) {
   211             if (entry instanceof TrustedCertEntry) {
   264                     } else {
   264                     } else {
   265                         entry.chain = null;
   265                         entry.chain = null;
   266                     }
   266                     }
   267 
   267 
   268                     // store the entry
   268                     // store the entry
   269                     entries.put(alias.toLowerCase(), entry);
   269                     entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
   270 
   270 
   271                 } else {
   271                 } else {
   272                     SecretKeyEntry entry = new SecretKeyEntry();
   272                     SecretKeyEntry entry = new SecretKeyEntry();
   273                     entry.date = new Date();
   273                     entry.date = new Date();
   274 
   274 
   275                     // seal and store the key
   275                     // seal and store the key
   276                     entry.sealedKey = keyProtector.seal(key);
   276                     entry.sealedKey = keyProtector.seal(key);
   277                     entries.put(alias.toLowerCase(), entry);
   277                     entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
   278                 }
   278                 }
   279 
   279 
   280             } catch (Exception e) {
   280             } catch (Exception e) {
   281                 throw new KeyStoreException(e.getMessage());
   281                 throw new KeyStoreException(e.getMessage());
   282             }
   282             }
   320                 entry.chain = chain.clone();
   320                 entry.chain = chain.clone();
   321             } else {
   321             } else {
   322                 entry.chain = null;
   322                 entry.chain = null;
   323             }
   323             }
   324 
   324 
   325             entries.put(alias.toLowerCase(), entry);
   325             entries.put(alias.toLowerCase(Locale.ENGLISH), entry);
   326         }
   326         }
   327     }
   327     }
   328 
   328 
   329     /**
   329     /**
   330      * Assigns the given certificate to the given alias.
   330      * Assigns the given certificate to the given alias.
   343     public void engineSetCertificateEntry(String alias, Certificate cert)
   343     public void engineSetCertificateEntry(String alias, Certificate cert)
   344         throws KeyStoreException
   344         throws KeyStoreException
   345     {
   345     {
   346         synchronized(entries) {
   346         synchronized(entries) {
   347 
   347 
   348             Object entry = entries.get(alias.toLowerCase());
   348             Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
   349             if (entry != null) {
   349             if (entry != null) {
   350                 if (entry instanceof PrivateKeyEntry) {
   350                 if (entry instanceof PrivateKeyEntry) {
   351                     throw new KeyStoreException("Cannot overwrite own "
   351                     throw new KeyStoreException("Cannot overwrite own "
   352                                                 + "certificate");
   352                                                 + "certificate");
   353                 } else if (entry instanceof SecretKeyEntry) {
   353                 } else if (entry instanceof SecretKeyEntry) {
   356             }
   356             }
   357 
   357 
   358             TrustedCertEntry trustedCertEntry = new TrustedCertEntry();
   358             TrustedCertEntry trustedCertEntry = new TrustedCertEntry();
   359             trustedCertEntry.cert = cert;
   359             trustedCertEntry.cert = cert;
   360             trustedCertEntry.date = new Date();
   360             trustedCertEntry.date = new Date();
   361             entries.put(alias.toLowerCase(), trustedCertEntry);
   361             entries.put(alias.toLowerCase(Locale.ENGLISH), trustedCertEntry);
   362         }
   362         }
   363     }
   363     }
   364 
   364 
   365     /**
   365     /**
   366      * Deletes the entry identified by the given alias from this keystore.
   366      * Deletes the entry identified by the given alias from this keystore.
   371      */
   371      */
   372     public void engineDeleteEntry(String alias)
   372     public void engineDeleteEntry(String alias)
   373         throws KeyStoreException
   373         throws KeyStoreException
   374     {
   374     {
   375         synchronized(entries) {
   375         synchronized(entries) {
   376             entries.remove(alias.toLowerCase());
   376             entries.remove(alias.toLowerCase(Locale.ENGLISH));
   377         }
   377         }
   378     }
   378     }
   379 
   379 
   380     /**
   380     /**
   381      * Lists all the alias names of this keystore.
   381      * Lists all the alias names of this keystore.
   392      * @param alias the alias name
   392      * @param alias the alias name
   393      *
   393      *
   394      * @return true if the alias exists, false otherwise
   394      * @return true if the alias exists, false otherwise
   395      */
   395      */
   396     public boolean engineContainsAlias(String alias) {
   396     public boolean engineContainsAlias(String alias) {
   397         return entries.containsKey(alias.toLowerCase());
   397         return entries.containsKey(alias.toLowerCase(Locale.ENGLISH));
   398     }
   398     }
   399 
   399 
   400     /**
   400     /**
   401      * Retrieves the number of entries in this keystore.
   401      * Retrieves the number of entries in this keystore.
   402      *
   402      *
   414      * <i>key entry</i>, false otherwise.
   414      * <i>key entry</i>, false otherwise.
   415      */
   415      */
   416     public boolean engineIsKeyEntry(String alias) {
   416     public boolean engineIsKeyEntry(String alias) {
   417         boolean isKey = false;
   417         boolean isKey = false;
   418 
   418 
   419         Object entry = entries.get(alias.toLowerCase());
   419         Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
   420         if ((entry instanceof PrivateKeyEntry)
   420         if ((entry instanceof PrivateKeyEntry)
   421             || (entry instanceof SecretKeyEntry)) {
   421             || (entry instanceof SecretKeyEntry)) {
   422             isKey = true;
   422             isKey = true;
   423         }
   423         }
   424 
   424 
   432      * @return true if the entry identified by the given alias is a
   432      * @return true if the entry identified by the given alias is a
   433      * <i>trusted certificate entry</i>, false otherwise.
   433      * <i>trusted certificate entry</i>, false otherwise.
   434      */
   434      */
   435     public boolean engineIsCertificateEntry(String alias) {
   435     public boolean engineIsCertificateEntry(String alias) {
   436         boolean isCert = false;
   436         boolean isCert = false;
   437         Object entry = entries.get(alias.toLowerCase());
   437         Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
   438         if (entry instanceof TrustedCertEntry) {
   438         if (entry instanceof TrustedCertEntry) {
   439             isCert = true;
   439             isCert = true;
   440         }
   440         }
   441         return isCert;
   441         return isCert;
   442     }
   442     }