< prev index next >

src/java.base/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2019, 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


  85 
  86     /*
  87      * The credentials from the KeyStore as
  88      * Map: String(alias) -> X509Credentials(credentials)
  89      */
  90     private Map<String,X509Credentials> credentialsMap;
  91 
  92     /*
  93      * Cached server aliases for the case issuers == null.
  94      * (in the current JSSE implementation, issuers are always null for
  95      * server certs). See chooseServerAlias() for details.
  96      *
  97      * Map: String(keyType) -> String[](alias)
  98      */
  99     private final Map<String,String[]> serverAliasCache;
 100 
 101     /*
 102      * Basic container for credentials implemented as an inner class.
 103      */
 104     private static class X509Credentials {
 105         final PrivateKey privateKey;
 106         final X509Certificate[] certificates;
 107         private final Set<X500Principal> issuerX500Principals;
 108 
 109         X509Credentials(PrivateKey privateKey, X509Certificate[] certificates) {
 110             // assert privateKey and certificates != null
 111             this.privateKey = privateKey;
 112             this.certificates = certificates;
 113             this.issuerX500Principals = new HashSet<>(certificates.length);
 114             for (X509Certificate certificate : certificates) {
 115                 issuerX500Principals.add(certificate.getIssuerX500Principal());
 116             }
 117         }
 118 
 119         Set<X500Principal> getIssuerX500Principals() {








 120             return issuerX500Principals;
 121         }
 122     }
 123 
 124     SunX509KeyManagerImpl(KeyStore ks, char[] password)
 125             throws KeyStoreException,
 126             NoSuchAlgorithmException, UnrecoverableKeyException {
 127 
 128         credentialsMap = new HashMap<String,X509Credentials>();
 129         serverAliasCache = Collections.synchronizedMap(
 130                             new HashMap<String,String[]>());
 131         if (ks == null) {
 132             return;
 133         }
 134 
 135         for (Enumeration<String> aliases = ks.aliases();
 136                                         aliases.hasMoreElements(); ) {
 137             String alias = aliases.nextElement();
 138             if (!ks.isKeyEntry(alias)) {
 139                 continue;


   1 /*
   2  * Copyright (c) 1999, 2018, 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


  85 
  86     /*
  87      * The credentials from the KeyStore as
  88      * Map: String(alias) -> X509Credentials(credentials)
  89      */
  90     private Map<String,X509Credentials> credentialsMap;
  91 
  92     /*
  93      * Cached server aliases for the case issuers == null.
  94      * (in the current JSSE implementation, issuers are always null for
  95      * server certs). See chooseServerAlias() for details.
  96      *
  97      * Map: String(keyType) -> String[](alias)
  98      */
  99     private final Map<String,String[]> serverAliasCache;
 100 
 101     /*
 102      * Basic container for credentials implemented as an inner class.
 103      */
 104     private static class X509Credentials {
 105         PrivateKey privateKey;
 106         X509Certificate[] certificates;
 107         private Set<X500Principal> issuerX500Principals;
 108 
 109         X509Credentials(PrivateKey privateKey, X509Certificate[] certificates) {
 110             // assert privateKey and certificates != null
 111             this.privateKey = privateKey;
 112             this.certificates = certificates;




 113         }
 114 
 115         synchronized Set<X500Principal> getIssuerX500Principals() {
 116             // lazy initialization
 117             if (issuerX500Principals == null) {
 118                 issuerX500Principals = new HashSet<X500Principal>();
 119                 for (int i = 0; i < certificates.length; i++) {
 120                     issuerX500Principals.add(
 121                                 certificates[i].getIssuerX500Principal());
 122                 }
 123             }
 124             return issuerX500Principals;
 125         }
 126     }
 127 
 128     SunX509KeyManagerImpl(KeyStore ks, char[] password)
 129             throws KeyStoreException,
 130             NoSuchAlgorithmException, UnrecoverableKeyException {
 131 
 132         credentialsMap = new HashMap<String,X509Credentials>();
 133         serverAliasCache = Collections.synchronizedMap(
 134                             new HashMap<String,String[]>());
 135         if (ks == null) {
 136             return;
 137         }
 138 
 139         for (Enumeration<String> aliases = ks.aliases();
 140                                         aliases.hasMoreElements(); ) {
 141             String alias = aliases.nextElement();
 142             if (!ks.isKeyEntry(alias)) {
 143                 continue;


< prev index next >