Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/ssl/KeyManagerFactoryImpl.java
38830 views
/*1* Copyright (c) 1999, 2018, 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 {63if ((ks != null) && SunJSSE.isFIPS()) {64if (ks.getProvider() != SunJSSE.cryptoProvider) {65throw new KeyStoreException("FIPS mode: KeyStore must be "66+ "from provider " + SunJSSE.cryptoProvider.getName());67}68}69keyManager = new SunX509KeyManagerImpl(ks, password);70isInitialized = true;71}7273@Override74protected void engineInit(ManagerFactoryParameters spec) throws75InvalidAlgorithmParameterException {76throw new InvalidAlgorithmParameterException(77"SunX509KeyManager does not use ManagerFactoryParameters");78}7980}8182// Factory for the X509 keymanager83public static final class X509 extends KeyManagerFactoryImpl {8485@Override86protected void engineInit(KeyStore ks, char[] password) throws87KeyStoreException, NoSuchAlgorithmException,88UnrecoverableKeyException {89if (ks == null) {90keyManager = new X509KeyManagerImpl(91Collections.<Builder>emptyList());92} else {93if (SunJSSE.isFIPS() &&94(ks.getProvider() != SunJSSE.cryptoProvider)) {95throw new KeyStoreException(96"FIPS mode: KeyStore must be " +97"from provider " + SunJSSE.cryptoProvider.getName());98}99try {100Builder builder = Builder.newInstance(ks,101new PasswordProtection(password));102keyManager = new X509KeyManagerImpl(builder);103} catch (RuntimeException e) {104throw new KeyStoreException("initialization failed", e);105}106}107isInitialized = true;108}109110@Override111protected void engineInit(ManagerFactoryParameters params) throws112InvalidAlgorithmParameterException {113if (params instanceof KeyStoreBuilderParameters == false) {114throw new InvalidAlgorithmParameterException(115"Parameters must be instance of KeyStoreBuilderParameters");116}117if (SunJSSE.isFIPS()) {118throw new InvalidAlgorithmParameterException119("FIPS mode: KeyStoreBuilderParameters not supported");120}121List<Builder> builders =122((KeyStoreBuilderParameters)params).getParameters();123keyManager = new X509KeyManagerImpl(builders);124isInitialized = true;125}126127}128129}130131132