0N/A/*
2362N/A * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.ssl;
0N/A
0N/Aimport java.util.List;
0N/Aimport java.util.Collections;
0N/A
0N/Aimport java.security.*;
0N/Aimport java.security.KeyStore.*;
0N/A
0N/Aimport javax.net.ssl.*;
0N/A
0N/Aabstract class KeyManagerFactoryImpl extends KeyManagerFactorySpi {
0N/A
0N/A X509ExtendedKeyManager keyManager;
0N/A boolean isInitialized;
0N/A
0N/A KeyManagerFactoryImpl() {
0N/A // empty
0N/A }
0N/A
0N/A /**
0N/A * Returns one key manager for each type of key material.
0N/A */
0N/A protected KeyManager[] engineGetKeyManagers() {
0N/A if (!isInitialized) {
0N/A throw new IllegalStateException(
0N/A "KeyManagerFactoryImpl is not initialized");
0N/A }
0N/A return new KeyManager[] { keyManager };
0N/A }
0N/A
0N/A // Factory for the SunX509 keymanager
0N/A public static final class SunX509 extends KeyManagerFactoryImpl {
0N/A
0N/A protected void engineInit(KeyStore ks, char[] password) throws
0N/A KeyStoreException, NoSuchAlgorithmException,
0N/A UnrecoverableKeyException {
0N/A if ((ks != null) && SunJSSE.isFIPS()) {
0N/A if (ks.getProvider() != SunJSSE.cryptoProvider) {
0N/A throw new KeyStoreException("FIPS mode: KeyStore must be "
0N/A + "from provider " + SunJSSE.cryptoProvider.getName());
0N/A }
0N/A }
0N/A keyManager = new SunX509KeyManagerImpl(ks, password);
0N/A isInitialized = true;
0N/A }
0N/A
0N/A protected void engineInit(ManagerFactoryParameters spec) throws
0N/A InvalidAlgorithmParameterException {
0N/A throw new InvalidAlgorithmParameterException(
0N/A "SunX509KeyManager does not use ManagerFactoryParameters");
0N/A }
0N/A
0N/A }
0N/A
0N/A // Factory for the X509 keymanager
0N/A public static final class X509 extends KeyManagerFactoryImpl {
0N/A
0N/A protected void engineInit(KeyStore ks, char[] password) throws
0N/A KeyStoreException, NoSuchAlgorithmException,
0N/A UnrecoverableKeyException {
0N/A if (ks == null) {
0N/A keyManager = new X509KeyManagerImpl(
0N/A Collections.<Builder>emptyList());
0N/A } else {
0N/A if (SunJSSE.isFIPS() && (ks.getProvider() != SunJSSE.cryptoProvider)) {
0N/A throw new KeyStoreException("FIPS mode: KeyStore must be "
0N/A + "from provider " + SunJSSE.cryptoProvider.getName());
0N/A }
0N/A try {
0N/A Builder builder = Builder.newInstance(ks,
0N/A new PasswordProtection(password));
0N/A keyManager = new X509KeyManagerImpl(builder);
0N/A } catch (RuntimeException e) {
0N/A throw new KeyStoreException("initialization failed", e);
0N/A }
0N/A }
0N/A isInitialized = true;
0N/A }
0N/A
0N/A protected void engineInit(ManagerFactoryParameters params) throws
0N/A InvalidAlgorithmParameterException {
0N/A if (params instanceof KeyStoreBuilderParameters == false) {
0N/A throw new InvalidAlgorithmParameterException(
0N/A "Parameters must be instance of KeyStoreBuilderParameters");
0N/A }
0N/A if (SunJSSE.isFIPS()) {
0N/A // XXX should be fixed
0N/A throw new InvalidAlgorithmParameterException
0N/A ("FIPS mode: KeyStoreBuilderParameters not supported");
0N/A }
0N/A List<Builder> builders =
0N/A ((KeyStoreBuilderParameters)params).getParameters();
0N/A keyManager = new X509KeyManagerImpl(builders);
0N/A isInitialized = true;
0N/A }
0N/A
0N/A }
0N/A
0N/A}