001/* 002 * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.9/src/java/org/apache/commons/ssl/SSLWrapperFactory.java $ 003 * $Revision: 129 $ 004 * $Date: 2007-11-14 19:21:33 -0800 (Wed, 14 Nov 2007) $ 005 * 006 * ==================================================================== 007 * Licensed to the Apache Software Foundation (ASF) under one 008 * or more contributor license agreements. See the NOTICE file 009 * distributed with this work for additional information 010 * regarding copyright ownership. The ASF licenses this file 011 * to you under the Apache License, Version 2.0 (the 012 * "License"); you may not use this file except in compliance 013 * with the License. You may obtain a copy of the License at 014 * 015 * http://www.apache.org/licenses/LICENSE-2.0 016 * 017 * Unless required by applicable law or agreed to in writing, 018 * software distributed under the License is distributed on an 019 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 020 * KIND, either express or implied. See the License for the 021 * specific language governing permissions and limitations 022 * under the License. 023 * ==================================================================== 024 * 025 * This software consists of voluntary contributions made by many 026 * individuals on behalf of the Apache Software Foundation. For more 027 * information on the Apache Software Foundation, please see 028 * <http://www.apache.org/>. 029 * 030 */ 031 032package org.apache.commons.ssl; 033 034import javax.net.ssl.SSLServerSocket; 035import javax.net.ssl.SSLSocket; 036import java.io.IOException; 037 038/** 039 * @author Credit Union Central of British Columbia 040 * @author <a href="http://www.cucbc.com/">www.cucbc.com</a> 041 * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a> 042 * @since 19-Sep-2006 043 */ 044public interface SSLWrapperFactory { 045 046 /** 047 * Wraps an SSLSSocket. 048 * 049 * @param s SSLSocket to wrap. 050 * @return The new wrapped SSLSocket. 051 * @throws IOException if wrapping failed 052 */ 053 public SSLSocket wrap(SSLSocket s) throws IOException; 054 055 /** 056 * Wraps an SSLServerSocket. 057 * 058 * @param s The SSLServerSocket to wrap. 059 * @param ssl The SSL object that created the SSLServerSocket. 060 * This way some important commons-ssl config can be applied 061 * to the returned socket. 062 * @return The new wrapped SSLServerSocket. 063 * @throws IOException if wrapping failed 064 */ 065 public SSLServerSocket wrap(SSLServerSocket s, SSL ssl) 066 throws IOException; 067 068 069 /** 070 * NO_WRAP doesn't wrap the SSLSocket. It does wrap the SSLServerSocket 071 * so that we can do the usual housekeeping after accept() that we like to 072 * do on every socket. E.g. setSoTimeout, setEnabledProtocols, 073 * setEnabledCiphers, setUseClientMode, and the hostname verifier (which 074 * should be very rare on SSLServerSockets!). 075 */ 076 public final static SSLWrapperFactory NO_WRAP = new SSLWrapperFactory() { 077 // Notice! No wrapping! 078 public SSLSocket wrap(SSLSocket s) { return s; } 079 080 // We still wrap the ServerSocket, but we don't wrap the result of the 081 // the accept() call. 082 public SSLServerSocket wrap(SSLServerSocket s, SSL ssl) 083 throws IOException { 084 // Can't wrap with Java 1.3 because SSLServerSocket's constructor has 085 // default access instead of protected access in Java 1.3. 086 boolean java13 = JavaImpl.isJava13(); 087 return java13 ? s : new SSLServerSocketWrapper(s, ssl, this); 088 } 089 }; 090 091 /** 092 * DUMB_WRAP is useful to make sure that wrapping the sockets doesn't break 093 * anything. It doesn't actually do anything interesting in its wrapped 094 * implementations. 095 */ 096 public final static SSLWrapperFactory DUMB_WRAP = new SSLWrapperFactory() { 097 public SSLSocket wrap(SSLSocket s) { return new SSLSocketWrapper(s); } 098 099 public SSLServerSocket wrap(SSLServerSocket s, SSL ssl) 100 throws IOException { 101 // Can't wrap with Java 1.3 because SSLServerSocket's constructor has 102 // default access instead of protected access in Java 1.3. 103 boolean java13 = JavaImpl.isJava13(); 104 return java13 ? s : new SSLServerSocketWrapper(s, ssl, this); 105 } 106 }; 107 108 109}