1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.conscrypt; 19 20 import java.io.IOException; 21 import java.net.InetAddress; 22 import java.net.Socket; 23 import java.net.SocketAddress; 24 import java.net.SocketException; 25 26 /** 27 * This class wraps the SSL functionality over an existing connected socket. 28 */ 29 public class OpenSSLSocketImplWrapper extends OpenSSLSocketImpl { 30 31 private Socket socket; 32 OpenSSLSocketImplWrapper(Socket socket, String hostname, int port, boolean autoClose, SSLParametersImpl sslParameters)33 protected OpenSSLSocketImplWrapper(Socket socket, String hostname, int port, 34 boolean autoClose, SSLParametersImpl sslParameters) throws IOException { 35 super(socket, hostname, port, autoClose, sslParameters); 36 if (!socket.isConnected()) { 37 throw new SocketException("Socket is not connected."); 38 } 39 this.socket = socket; 40 } 41 42 @Override connect(SocketAddress sockaddr, int timeout)43 public void connect(SocketAddress sockaddr, int timeout) 44 throws IOException { 45 throw new IOException("Underlying socket is already connected."); 46 } 47 48 @Override connect(SocketAddress sockaddr)49 public void connect(SocketAddress sockaddr) throws IOException { 50 throw new IOException("Underlying socket is already connected."); 51 } 52 53 @Override bind(SocketAddress sockaddr)54 public void bind(SocketAddress sockaddr) throws IOException { 55 throw new IOException("Underlying socket is already connected."); 56 } 57 58 @Override getRemoteSocketAddress()59 public SocketAddress getRemoteSocketAddress() { 60 return socket.getRemoteSocketAddress(); 61 } 62 63 @Override getLocalSocketAddress()64 public SocketAddress getLocalSocketAddress() { 65 return socket.getLocalSocketAddress(); 66 } 67 68 @Override getLocalAddress()69 public InetAddress getLocalAddress() { 70 return socket.getLocalAddress(); 71 } 72 73 @Override getInetAddress()74 public InetAddress getInetAddress() { 75 return socket.getInetAddress(); 76 } 77 78 @Override toString()79 public String toString() { 80 return "SSL socket over " + socket.toString(); 81 } 82 83 @Override setSoLinger(boolean on, int linger)84 public void setSoLinger(boolean on, int linger) throws SocketException { 85 socket.setSoLinger(on, linger); 86 } 87 88 @Override setTcpNoDelay(boolean on)89 public void setTcpNoDelay(boolean on) throws SocketException { 90 socket.setTcpNoDelay(on); 91 } 92 93 @Override setReuseAddress(boolean on)94 public void setReuseAddress(boolean on) throws SocketException { 95 socket.setReuseAddress(on); 96 } 97 98 @Override setKeepAlive(boolean on)99 public void setKeepAlive(boolean on) throws SocketException { 100 socket.setKeepAlive(on); 101 } 102 103 @Override setTrafficClass(int tos)104 public void setTrafficClass(int tos) throws SocketException { 105 socket.setTrafficClass(tos); 106 } 107 108 @Override setSendBufferSize(int size)109 public void setSendBufferSize(int size) throws SocketException { 110 socket.setSendBufferSize(size); 111 } 112 113 @Override setReceiveBufferSize(int size)114 public void setReceiveBufferSize(int size) throws SocketException { 115 socket.setReceiveBufferSize(size); 116 } 117 118 @Override getTcpNoDelay()119 public boolean getTcpNoDelay() throws SocketException { 120 return socket.getTcpNoDelay(); 121 } 122 123 @Override getReuseAddress()124 public boolean getReuseAddress() throws SocketException { 125 return socket.getReuseAddress(); 126 } 127 128 @Override getOOBInline()129 public boolean getOOBInline() throws SocketException { 130 return socket.getOOBInline(); 131 } 132 133 @Override getKeepAlive()134 public boolean getKeepAlive() throws SocketException { 135 return socket.getKeepAlive(); 136 } 137 138 @Override getTrafficClass()139 public int getTrafficClass() throws SocketException { 140 return socket.getTrafficClass(); 141 } 142 143 @Override getSoTimeout()144 public int getSoTimeout() throws SocketException { 145 return socket.getSoTimeout(); 146 } 147 148 @Override getSoLinger()149 public int getSoLinger() throws SocketException { 150 return socket.getSoLinger(); 151 } 152 153 @Override getSendBufferSize()154 public int getSendBufferSize() throws SocketException { 155 return socket.getSendBufferSize(); 156 } 157 158 @Override getReceiveBufferSize()159 public int getReceiveBufferSize() throws SocketException { 160 return socket.getReceiveBufferSize(); 161 } 162 163 @Override isConnected()164 public boolean isConnected() { 165 return socket.isConnected(); 166 } 167 168 @Override isClosed()169 public boolean isClosed() { 170 return socket.isClosed(); 171 } 172 173 @Override isBound()174 public boolean isBound() { 175 return socket.isBound(); 176 } 177 178 @Override isOutputShutdown()179 public boolean isOutputShutdown() { 180 return socket.isOutputShutdown(); 181 } 182 183 @Override isInputShutdown()184 public boolean isInputShutdown() { 185 return socket.isInputShutdown(); 186 } 187 188 @Override getPort()189 public int getPort() { 190 return socket.getPort(); 191 } 192 193 @Override getLocalPort()194 public int getLocalPort() { 195 return socket.getLocalPort(); 196 } 197 } 198