Path: blob/master/src/java.base/share/classes/sun/security/ssl/KeyManagerFactoryImpl.java
41159 views
/*1* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.ssl;2627import java.util.List;28import java.util.Collections;2930import java.security.*;31import java.security.KeyStore.*;3233import javax.net.ssl.*;3435abstract class KeyManagerFactoryImpl extends KeyManagerFactorySpi {3637X509ExtendedKeyManager keyManager;38boolean isInitialized;3940KeyManagerFactoryImpl() {41// empty42}4344/**45* Returns one key manager for each type of key material.46*/47@Override48protected KeyManager[] engineGetKeyManagers() {49if (!isInitialized) {50throw new IllegalStateException(51"KeyManagerFactoryImpl is not initialized");52}53return new KeyManager[] { keyManager };54}5556// Factory for the SunX509 keymanager57public static final class SunX509 extends KeyManagerFactoryImpl {5859@Override60protected void engineInit(KeyStore ks, char[] password) throws61KeyStoreException, NoSuchAlgorithmException,62UnrecoverableKeyException {63keyManager = new SunX509KeyManagerImpl(ks, password);64isInitialized = true;65}6667@Override68protected void engineInit(ManagerFactoryParameters spec) throws69InvalidAlgorithmParameterException {70throw new InvalidAlgorithmParameterException(71"SunX509KeyManager does not use ManagerFactoryParameters");72}7374}7576// Factory for the X509 keymanager77public static final class X509 extends KeyManagerFactoryImpl {7879@Override80protected void engineInit(KeyStore ks, char[] password) throws81KeyStoreException, NoSuchAlgorithmException,82UnrecoverableKeyException {83if (ks == null) {84keyManager = new X509KeyManagerImpl(85Collections.<Builder>emptyList());86} else {87try {88Builder builder = Builder.newInstance(ks,89new PasswordProtection(password));90keyManager = new X509KeyManagerImpl(builder);91} catch (RuntimeException e) {92throw new KeyStoreException("initialization failed", e);93}94}95isInitialized = true;96}9798@Override99protected void engineInit(ManagerFactoryParameters params) throws100InvalidAlgorithmParameterException {101if (!(params instanceof KeyStoreBuilderParameters)) {102throw new InvalidAlgorithmParameterException(103"Parameters must be instance of KeyStoreBuilderParameters");104}105106List<Builder> builders =107((KeyStoreBuilderParameters)params).getParameters();108keyManager = new X509KeyManagerImpl(builders);109isInitialized = true;110}111112}113114}115116117