PageRenderTime 79ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/src/compat/java/org/conscrypt/KitKatPlatformOpenSSLSocketImplAdapter.java

https://gitlab.com/cde/debian_android-tools_android-platform-external-conscrypt
Java | 448 lines | 335 code | 85 blank | 28 comment | 0 complexity | 9576bcc5cca2db1430c7a9b42db259ef MD5 | raw file
  1. /*
  2. * Copyright (C) 2015 The Android Open Source Project
  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 org.conscrypt;
  17. import java.io.FileDescriptor;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.io.OutputStream;
  21. import java.net.InetAddress;
  22. import java.net.Socket;
  23. import java.net.SocketAddress;
  24. import java.net.SocketException;
  25. import java.nio.channels.SocketChannel;
  26. import java.security.PrivateKey;
  27. import java.security.cert.CertificateEncodingException;
  28. import java.security.cert.CertificateException;
  29. import javax.net.ssl.HandshakeCompletedEvent;
  30. import javax.net.ssl.HandshakeCompletedListener;
  31. import javax.net.ssl.SSLException;
  32. import javax.net.ssl.SSLParameters;
  33. import javax.net.ssl.SSLSession;
  34. /**
  35. * This class delegates all calls to an {@code org.conscrypt.OpenSSLSocketImpl}.
  36. * This is to work around code that checks that the socket is an
  37. * {@code org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl} before
  38. * calling methods, such as setting SNI. This is only for KitKat.
  39. *
  40. * It delegates all public methods in Socket, SSLSocket, and OpenSSLSocket from
  41. * KK.
  42. */
  43. public class KitKatPlatformOpenSSLSocketImplAdapter
  44. extends com.android.org.conscrypt.OpenSSLSocketImpl {
  45. private final org.conscrypt.OpenSSLSocketImpl delegate;
  46. public KitKatPlatformOpenSSLSocketImplAdapter(org.conscrypt.OpenSSLSocketImpl delegate)
  47. throws IOException {
  48. super(null);
  49. this.delegate = delegate;
  50. }
  51. // Socket methods.
  52. @Override
  53. public void close() throws IOException {
  54. delegate.close();
  55. }
  56. @Override
  57. public InputStream getInputStream() throws IOException {
  58. return delegate.getInputStream();
  59. }
  60. @Override
  61. public int getLocalPort() {
  62. return delegate.getLocalPort();
  63. }
  64. @Override
  65. public OutputStream getOutputStream() throws IOException {
  66. return delegate.getOutputStream();
  67. }
  68. @Override
  69. public int getPort() {
  70. return delegate.getPort();
  71. }
  72. @Override
  73. public void connect(SocketAddress sockaddr, int timeout) throws IOException {
  74. delegate.connect(sockaddr, timeout);
  75. }
  76. @Override
  77. public void connect(SocketAddress sockaddr) throws IOException {
  78. delegate.connect(sockaddr);
  79. }
  80. @Override
  81. public void bind(SocketAddress sockaddr) throws IOException {
  82. delegate.bind(sockaddr);
  83. }
  84. @Override
  85. public SocketAddress getRemoteSocketAddress() {
  86. return delegate.getRemoteSocketAddress();
  87. }
  88. @Override
  89. public SocketAddress getLocalSocketAddress() {
  90. return delegate.getLocalSocketAddress();
  91. }
  92. @Override
  93. public InetAddress getLocalAddress() {
  94. return delegate.getLocalAddress();
  95. }
  96. @Override
  97. public InetAddress getInetAddress() {
  98. return delegate.getInetAddress();
  99. }
  100. @Override
  101. public String toString() {
  102. return delegate.toString();
  103. }
  104. @Override
  105. public void setSoLinger(boolean on, int linger) throws SocketException {
  106. delegate.setSoLinger(on, linger);
  107. }
  108. @Override
  109. public void setTcpNoDelay(boolean on) throws SocketException {
  110. delegate.setTcpNoDelay(on);
  111. }
  112. @Override
  113. public void setReuseAddress(boolean on) throws SocketException {
  114. delegate.setReuseAddress(on);
  115. }
  116. @Override
  117. public void setKeepAlive(boolean on) throws SocketException {
  118. delegate.setKeepAlive(on);
  119. }
  120. @Override
  121. public void setTrafficClass(int tos) throws SocketException {
  122. delegate.setTrafficClass(tos);
  123. }
  124. @Override
  125. public void setSoTimeout(int to) throws SocketException {
  126. delegate.setSoTimeout(to);
  127. }
  128. @Override
  129. public void setSendBufferSize(int size) throws SocketException {
  130. delegate.setSendBufferSize(size);
  131. }
  132. @Override
  133. public void setReceiveBufferSize(int size) throws SocketException {
  134. delegate.setReceiveBufferSize(size);
  135. }
  136. @Override
  137. public boolean getTcpNoDelay() throws SocketException {
  138. return delegate.getTcpNoDelay();
  139. }
  140. @Override
  141. public boolean getReuseAddress() throws SocketException {
  142. return delegate.getReuseAddress();
  143. }
  144. @Override
  145. public boolean getKeepAlive() throws SocketException {
  146. return delegate.getKeepAlive();
  147. }
  148. @Override
  149. public int getSoTimeout() throws SocketException {
  150. return delegate.getSoTimeout();
  151. }
  152. @Override
  153. public int getSoLinger() throws SocketException {
  154. return delegate.getSoLinger();
  155. }
  156. @Override
  157. public int getSendBufferSize() throws SocketException {
  158. return delegate.getSendBufferSize();
  159. }
  160. @Override
  161. public int getReceiveBufferSize() throws SocketException {
  162. return delegate.getReceiveBufferSize();
  163. }
  164. @Override
  165. public boolean isConnected() {
  166. return delegate.isConnected();
  167. }
  168. @Override
  169. public boolean isClosed() {
  170. return delegate.isClosed();
  171. }
  172. @Override
  173. public boolean isBound() {
  174. return delegate.isBound();
  175. }
  176. @Override
  177. public boolean isOutputShutdown() {
  178. return delegate.isOutputShutdown();
  179. }
  180. @Override
  181. public boolean isInputShutdown() {
  182. return delegate.isInputShutdown();
  183. }
  184. @Override
  185. public void shutdownInput() throws IOException {
  186. delegate.shutdownInput();
  187. }
  188. @Override
  189. public void shutdownOutput() throws IOException {
  190. delegate.shutdownOutput();
  191. }
  192. @Override
  193. public void setOOBInline(boolean oobinline) throws SocketException {
  194. delegate.setOOBInline(oobinline);
  195. }
  196. @Override
  197. public boolean getOOBInline() throws SocketException {
  198. return delegate.getOOBInline();
  199. }
  200. @Override
  201. public int getTrafficClass() throws SocketException {
  202. return delegate.getTrafficClass();
  203. }
  204. @Override
  205. public void sendUrgentData(int value) throws IOException {
  206. delegate.sendUrgentData(value);
  207. }
  208. @Override
  209. public SocketChannel getChannel() {
  210. return delegate.getChannel();
  211. }
  212. @Override
  213. public FileDescriptor getFileDescriptor$() {
  214. return delegate.getFileDescriptor$();
  215. }
  216. @Override
  217. public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
  218. delegate.setPerformancePreferences(connectionTime, latency, bandwidth);
  219. }
  220. // SSLSocket methods.
  221. @Override
  222. public String[] getSupportedCipherSuites() {
  223. return delegate.getSupportedCipherSuites();
  224. }
  225. @Override
  226. public String[] getEnabledCipherSuites() {
  227. return delegate.getEnabledCipherSuites();
  228. }
  229. @Override
  230. public void setEnabledCipherSuites(String[] suites) {
  231. delegate.setEnabledCipherSuites(suites);
  232. }
  233. @Override
  234. public String[] getSupportedProtocols() {
  235. return delegate.getSupportedProtocols();
  236. }
  237. @Override
  238. public String[] getEnabledProtocols() {
  239. return delegate.getEnabledProtocols();
  240. }
  241. @Override
  242. public void setEnabledProtocols(String[] protocols) {
  243. delegate.setEnabledProtocols(protocols);
  244. }
  245. @Override
  246. public SSLSession getSession() {
  247. return delegate.getSession();
  248. }
  249. @Override
  250. public void addHandshakeCompletedListener(HandshakeCompletedListener listener) {
  251. delegate.addHandshakeCompletedListener(listener);
  252. }
  253. @Override
  254. public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {
  255. delegate.removeHandshakeCompletedListener(listener);
  256. }
  257. @Override
  258. public void startHandshake() throws IOException {
  259. delegate.startHandshake();
  260. }
  261. @Override
  262. public void setUseClientMode(boolean mode) {
  263. delegate.setUseClientMode(mode);
  264. }
  265. @Override
  266. public boolean getUseClientMode() {
  267. return delegate.getUseClientMode();
  268. }
  269. @Override
  270. public void setNeedClientAuth(boolean need) {
  271. delegate.setNeedClientAuth(need);
  272. }
  273. @Override
  274. public void setWantClientAuth(boolean want) {
  275. delegate.setWantClientAuth(want);
  276. }
  277. @Override
  278. public boolean getNeedClientAuth() {
  279. return delegate.getNeedClientAuth();
  280. }
  281. @Override
  282. public boolean getWantClientAuth() {
  283. return delegate.getWantClientAuth();
  284. }
  285. @Override
  286. public void setEnableSessionCreation(boolean flag) {
  287. delegate.setEnableSessionCreation(flag);
  288. }
  289. @Override
  290. public boolean getEnableSessionCreation() {
  291. return delegate.getEnableSessionCreation();
  292. }
  293. @Override
  294. public SSLParameters getSSLParameters() {
  295. return delegate.getSSLParameters();
  296. }
  297. @Override
  298. public void setSSLParameters(SSLParameters p) {
  299. delegate.setSSLParameters(p);
  300. }
  301. // OpenSSLSocket methods.
  302. @Override
  303. public void clientCertificateRequested(byte[] keyTypeBytes, byte[][] asn1DerEncodedPrincipals)
  304. throws CertificateEncodingException, SSLException {
  305. throw new RuntimeException("Shouldn't be here!");
  306. }
  307. @Override
  308. public void handshakeCompleted() {
  309. throw new RuntimeException("Shouldn't be here!");
  310. }
  311. @Override
  312. public void verifyCertificateChain(byte[][] bytes, String authMethod)
  313. throws CertificateException {
  314. throw new RuntimeException("Shouldn't be here!");
  315. }
  316. @Override
  317. public void setUseSessionTickets(boolean useSessionTickets) {
  318. delegate.setUseSessionTickets(useSessionTickets);
  319. }
  320. @Override
  321. public void setHostname(String hostname) {
  322. delegate.setHostname(hostname);
  323. }
  324. @Override
  325. public void setChannelIdEnabled(boolean enabled) {
  326. delegate.setChannelIdEnabled(enabled);
  327. }
  328. @Override
  329. public byte[] getChannelId() throws SSLException {
  330. return delegate.getChannelId();
  331. }
  332. @Override
  333. public void setChannelIdPrivateKey(PrivateKey privateKey) {
  334. delegate.setChannelIdPrivateKey(privateKey);
  335. }
  336. @Override
  337. public void setSoWriteTimeout(int writeTimeoutMilliseconds) throws SocketException {
  338. delegate.setSoWriteTimeout(writeTimeoutMilliseconds);
  339. }
  340. @Override
  341. public int getSoWriteTimeout() throws SocketException {
  342. return delegate.getSoWriteTimeout();
  343. }
  344. @Override
  345. public void setHandshakeTimeout(int handshakeTimeoutMilliseconds) throws SocketException {
  346. delegate.setHandshakeTimeout(handshakeTimeoutMilliseconds);
  347. }
  348. @Override
  349. public byte[] getNpnSelectedProtocol() {
  350. return delegate.getNpnSelectedProtocol();
  351. }
  352. @Override
  353. public void setNpnProtocols(byte[] npnProtocols) {
  354. delegate.setNpnProtocols(npnProtocols);
  355. }
  356. // These aren't in the Platform's OpenSSLSocketImpl but we have them to support duck typing.
  357. public byte[] getAlpnSelectedProtocol() {
  358. return delegate.getAlpnSelectedProtocol();
  359. }
  360. public void setAlpnProtocols(byte[] alpnProtocols) {
  361. delegate.setAlpnProtocols(alpnProtocols);
  362. }
  363. }