1 /* 2 * Copyright 2014 Square Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.squareup.okhttp; 17 18 import java.io.IOException; 19 import java.io.InputStream; 20 import java.io.OutputStream; 21 import java.net.InetAddress; 22 import java.net.SocketAddress; 23 import java.net.SocketException; 24 import java.nio.channels.SocketChannel; 25 import javax.net.ssl.HandshakeCompletedListener; 26 import javax.net.ssl.SSLParameters; 27 import javax.net.ssl.SSLSession; 28 import javax.net.ssl.SSLSocket; 29 30 /** 31 * An {@link javax.net.ssl.SSLSocket} that delegates all calls. 32 */ 33 public abstract class DelegatingSSLSocket extends SSLSocket { 34 protected final SSLSocket delegate; 35 DelegatingSSLSocket(SSLSocket delegate)36 public DelegatingSSLSocket(SSLSocket delegate) { 37 this.delegate = delegate; 38 } 39 shutdownInput()40 @Override public void shutdownInput() throws IOException { 41 delegate.shutdownInput(); 42 } 43 shutdownOutput()44 @Override public void shutdownOutput() throws IOException { 45 delegate.shutdownOutput(); 46 } 47 getSupportedCipherSuites()48 @Override public String[] getSupportedCipherSuites() { 49 return delegate.getSupportedCipherSuites(); 50 } 51 getEnabledCipherSuites()52 @Override public String[] getEnabledCipherSuites() { 53 return delegate.getEnabledCipherSuites(); 54 } 55 setEnabledCipherSuites(String[] suites)56 @Override public void setEnabledCipherSuites(String[] suites) { 57 delegate.setEnabledCipherSuites(suites); 58 } 59 getSupportedProtocols()60 @Override public String[] getSupportedProtocols() { 61 return delegate.getSupportedProtocols(); 62 } 63 getEnabledProtocols()64 @Override public String[] getEnabledProtocols() { 65 return delegate.getEnabledProtocols(); 66 } 67 setEnabledProtocols(String[] protocols)68 @Override public void setEnabledProtocols(String[] protocols) { 69 delegate.setEnabledProtocols(protocols); 70 } 71 getSession()72 @Override public SSLSession getSession() { 73 return delegate.getSession(); 74 } 75 addHandshakeCompletedListener(HandshakeCompletedListener listener)76 @Override public void addHandshakeCompletedListener(HandshakeCompletedListener listener) { 77 delegate.addHandshakeCompletedListener(listener); 78 } 79 removeHandshakeCompletedListener(HandshakeCompletedListener listener)80 @Override public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) { 81 delegate.removeHandshakeCompletedListener(listener); 82 } 83 startHandshake()84 @Override public void startHandshake() throws IOException { 85 delegate.startHandshake(); 86 } 87 setUseClientMode(boolean mode)88 @Override public void setUseClientMode(boolean mode) { 89 delegate.setUseClientMode(mode); 90 } 91 getUseClientMode()92 @Override public boolean getUseClientMode() { 93 return delegate.getUseClientMode(); 94 } 95 setNeedClientAuth(boolean need)96 @Override public void setNeedClientAuth(boolean need) { 97 delegate.setNeedClientAuth(need); 98 } 99 setWantClientAuth(boolean want)100 @Override public void setWantClientAuth(boolean want) { 101 delegate.setWantClientAuth(want); 102 } 103 getNeedClientAuth()104 @Override public boolean getNeedClientAuth() { 105 return delegate.getNeedClientAuth(); 106 } 107 getWantClientAuth()108 @Override public boolean getWantClientAuth() { 109 return delegate.getWantClientAuth(); 110 } 111 setEnableSessionCreation(boolean flag)112 @Override public void setEnableSessionCreation(boolean flag) { 113 delegate.setEnableSessionCreation(flag); 114 } 115 getEnableSessionCreation()116 @Override public boolean getEnableSessionCreation() { 117 return delegate.getEnableSessionCreation(); 118 } 119 getSSLParameters()120 @Override public SSLParameters getSSLParameters() { 121 return delegate.getSSLParameters(); 122 } 123 setSSLParameters(SSLParameters p)124 @Override public void setSSLParameters(SSLParameters p) { 125 delegate.setSSLParameters(p); 126 } 127 close()128 @Override public void close() throws IOException { 129 delegate.close(); 130 } 131 getInetAddress()132 @Override public InetAddress getInetAddress() { 133 return delegate.getInetAddress(); 134 } 135 getInputStream()136 @Override public InputStream getInputStream() throws IOException { 137 return delegate.getInputStream(); 138 } 139 getKeepAlive()140 @Override public boolean getKeepAlive() throws SocketException { 141 return delegate.getKeepAlive(); 142 } 143 getLocalAddress()144 @Override public InetAddress getLocalAddress() { 145 return delegate.getLocalAddress(); 146 } 147 getLocalPort()148 @Override public int getLocalPort() { 149 return delegate.getLocalPort(); 150 } 151 getOutputStream()152 @Override public OutputStream getOutputStream() throws IOException { 153 return delegate.getOutputStream(); 154 } 155 getPort()156 @Override public int getPort() { 157 return delegate.getPort(); 158 } 159 getSoLinger()160 @Override public int getSoLinger() throws SocketException { 161 return delegate.getSoLinger(); 162 } 163 getReceiveBufferSize()164 @Override public int getReceiveBufferSize() throws SocketException { 165 return delegate.getReceiveBufferSize(); 166 } 167 getSendBufferSize()168 @Override public int getSendBufferSize() throws SocketException { 169 return delegate.getSendBufferSize(); 170 } 171 getSoTimeout()172 @Override public int getSoTimeout() throws SocketException { 173 return delegate.getSoTimeout(); 174 } 175 getTcpNoDelay()176 @Override public boolean getTcpNoDelay() throws SocketException { 177 return delegate.getTcpNoDelay(); 178 } 179 setKeepAlive(boolean keepAlive)180 @Override public void setKeepAlive(boolean keepAlive) throws SocketException { 181 delegate.setKeepAlive(keepAlive); 182 } 183 setSendBufferSize(int size)184 @Override public void setSendBufferSize(int size) throws SocketException { 185 delegate.setSendBufferSize(size); 186 } 187 setReceiveBufferSize(int size)188 @Override public void setReceiveBufferSize(int size) throws SocketException { 189 delegate.setReceiveBufferSize(size); 190 } 191 setSoLinger(boolean on, int timeout)192 @Override public void setSoLinger(boolean on, int timeout) throws SocketException { 193 delegate.setSoLinger(on, timeout); 194 } 195 setSoTimeout(int timeout)196 @Override public void setSoTimeout(int timeout) throws SocketException { 197 delegate.setSoTimeout(timeout); 198 } 199 setTcpNoDelay(boolean on)200 @Override public void setTcpNoDelay(boolean on) throws SocketException { 201 delegate.setTcpNoDelay(on); 202 } 203 toString()204 @Override public String toString() { 205 return delegate.toString(); 206 } 207 getLocalSocketAddress()208 @Override public SocketAddress getLocalSocketAddress() { 209 return delegate.getLocalSocketAddress(); 210 } 211 getRemoteSocketAddress()212 @Override public SocketAddress getRemoteSocketAddress() { 213 return delegate.getRemoteSocketAddress(); 214 } 215 isBound()216 @Override public boolean isBound() { 217 return delegate.isBound(); 218 } 219 isConnected()220 @Override public boolean isConnected() { 221 return delegate.isConnected(); 222 } 223 isClosed()224 @Override public boolean isClosed() { 225 return delegate.isClosed(); 226 } 227 bind(SocketAddress localAddr)228 @Override public void bind(SocketAddress localAddr) throws IOException { 229 delegate.bind(localAddr); 230 } 231 connect(SocketAddress remoteAddr)232 @Override public void connect(SocketAddress remoteAddr) throws IOException { 233 delegate.connect(remoteAddr); 234 } 235 connect(SocketAddress remoteAddr, int timeout)236 @Override public void connect(SocketAddress remoteAddr, int timeout) throws IOException { 237 delegate.connect(remoteAddr, timeout); 238 } 239 isInputShutdown()240 @Override public boolean isInputShutdown() { 241 return delegate.isInputShutdown(); 242 } 243 isOutputShutdown()244 @Override public boolean isOutputShutdown() { 245 return delegate.isOutputShutdown(); 246 } 247 setReuseAddress(boolean reuse)248 @Override public void setReuseAddress(boolean reuse) throws SocketException { 249 delegate.setReuseAddress(reuse); 250 } 251 getReuseAddress()252 @Override public boolean getReuseAddress() throws SocketException { 253 return delegate.getReuseAddress(); 254 } 255 setOOBInline(boolean oobinline)256 @Override public void setOOBInline(boolean oobinline) throws SocketException { 257 delegate.setOOBInline(oobinline); 258 } 259 getOOBInline()260 @Override public boolean getOOBInline() throws SocketException { 261 return delegate.getOOBInline(); 262 } 263 setTrafficClass(int value)264 @Override public void setTrafficClass(int value) throws SocketException { 265 delegate.setTrafficClass(value); 266 } 267 getTrafficClass()268 @Override public int getTrafficClass() throws SocketException { 269 return delegate.getTrafficClass(); 270 } 271 sendUrgentData(int value)272 @Override public void sendUrgentData(int value) throws IOException { 273 delegate.sendUrgentData(value); 274 } 275 getChannel()276 @Override public SocketChannel getChannel() { 277 return delegate.getChannel(); 278 } 279 setPerformancePreferences(int connectionTime, int latency, int bandwidth)280 @Override public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) { 281 delegate.setPerformancePreferences(connectionTime, latency, bandwidth); 282 } 283 } 284