001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.xnet.provider.jsse;
022:
023: import org.apache.harmony.xnet.provider.jsse.SSLSocketFactoryImpl;
024: import org.apache.harmony.xnet.provider.jsse.SSLEngineImpl;
025: import org.apache.harmony.xnet.provider.jsse.SSLParameters;
026: import org.apache.harmony.xnet.provider.jsse.SSLServerSocketFactoryImpl;
027:
028: import java.security.KeyManagementException;
029: import java.security.SecureRandom;
030:
031: import javax.net.ssl.KeyManager;
032: import javax.net.ssl.SSLContextSpi;
033: import javax.net.ssl.SSLEngine;
034: import javax.net.ssl.SSLServerSocketFactory;
035: import javax.net.ssl.SSLSessionContext;
036: import javax.net.ssl.SSLSocketFactory;
037: import javax.net.ssl.TrustManager;
038:
039: /**
040: * Implementation of SSLContext service provider interface.
041: */
042: public class SSLContextImpl extends SSLContextSpi {
043:
044: // client session context contains the set of reusable
045: // client-side SSL sessions
046: private SSLSessionContextImpl clientSessionContext = new SSLSessionContextImpl();
047: // server session context contains the set of reusable
048: // server-side SSL sessions
049: private SSLSessionContextImpl serverSessionContext = new SSLSessionContextImpl();
050:
051: protected SSLParameters sslParameters;
052:
053: public SSLContextImpl() {
054: super ();
055: }
056:
057: public void engineInit(KeyManager[] kms, TrustManager[] tms,
058: SecureRandom sr) throws KeyManagementException {
059: sslParameters = new SSLParameters(kms, tms, sr,
060: clientSessionContext, serverSessionContext);
061: }
062:
063: public SSLSocketFactory engineGetSocketFactory() {
064: if (sslParameters == null) {
065: throw new IllegalStateException(
066: "SSLContext is not initiallized.");
067: }
068: return new SSLSocketFactoryImpl(sslParameters);
069: }
070:
071: public SSLServerSocketFactory engineGetServerSocketFactory() {
072: if (sslParameters == null) {
073: throw new IllegalStateException(
074: "SSLContext is not initiallized.");
075: }
076: return new SSLServerSocketFactoryImpl(sslParameters);
077: }
078:
079: public SSLEngine engineCreateSSLEngine(String host, int port) {
080: if (sslParameters == null) {
081: throw new IllegalStateException(
082: "SSLContext is not initiallized.");
083: }
084: return new SSLEngineImpl(host, port,
085: (SSLParameters) sslParameters.clone());
086: }
087:
088: public SSLEngine engineCreateSSLEngine() {
089: if (sslParameters == null) {
090: throw new IllegalStateException(
091: "SSLContext is not initiallized.");
092: }
093: return new SSLEngineImpl((SSLParameters) sslParameters.clone());
094: }
095:
096: public SSLSessionContext engineGetServerSessionContext() {
097: return serverSessionContext;
098: }
099:
100: public SSLSessionContext engineGetClientSessionContext() {
101: return clientSessionContext;
102: }
103: }
|