From a34d5fc67bfbf568b0a8bd03994f13d36ceb92ac Mon Sep 17 00:00:00 2001 From: exceptionfactory Date: Thu, 23 Dec 2021 13:41:46 -0600 Subject: [PATCH] Removed deprecated proxy connect methods from SocketClient - Removed custom Jdk7HttpProxySocket class --- .../hierynomus/sshj/backport/JavaVersion.java | 26 ------- .../sshj/backport/Jdk7HttpProxySocket.java | 78 ------------------- .../java/net/schmizz/sshj/SocketClient.java | 70 ----------------- 3 files changed, 174 deletions(-) delete mode 100644 src/main/java/com/hierynomus/sshj/backport/JavaVersion.java delete mode 100644 src/main/java/com/hierynomus/sshj/backport/Jdk7HttpProxySocket.java diff --git a/src/main/java/com/hierynomus/sshj/backport/JavaVersion.java b/src/main/java/com/hierynomus/sshj/backport/JavaVersion.java deleted file mode 100644 index 20ebac6a6..000000000 --- a/src/main/java/com/hierynomus/sshj/backport/JavaVersion.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C)2009 - SSHJ Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.hierynomus.sshj.backport; - -public class JavaVersion { - public static boolean isJava7OrEarlier() { - String property = System.getProperty("java.specification.version"); - float diff = Float.parseFloat(property) - 1.7f; - - return diff < 0.01; - } - -} diff --git a/src/main/java/com/hierynomus/sshj/backport/Jdk7HttpProxySocket.java b/src/main/java/com/hierynomus/sshj/backport/Jdk7HttpProxySocket.java deleted file mode 100644 index 56ea256e6..000000000 --- a/src/main/java/com/hierynomus/sshj/backport/Jdk7HttpProxySocket.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C)2009 - SSHJ Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.hierynomus.sshj.backport; - -import net.schmizz.sshj.common.IOUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.net.*; - -public class Jdk7HttpProxySocket extends Socket { - - private Proxy httpProxy = null; - - public Jdk7HttpProxySocket(Proxy proxy) { - super(proxy.type() == Proxy.Type.HTTP ? Proxy.NO_PROXY : proxy); - if (proxy.type() == Proxy.Type.HTTP) { - this.httpProxy = proxy; - } - } - - @Override - public void connect(SocketAddress endpoint, int timeout) throws IOException { - if (httpProxy != null) { - connectHttpProxy(endpoint, timeout); - } else { - super.connect(endpoint, timeout); - } - } - - private void connectHttpProxy(SocketAddress endpoint, int timeout) throws IOException { - super.connect(httpProxy.address(), timeout); - - if (!(endpoint instanceof InetSocketAddress)) { - throw new SocketException("Expected an InetSocketAddress to connect to, got: " + endpoint); - } - InetSocketAddress isa = (InetSocketAddress) endpoint; - String httpConnect = "CONNECT " + isa.getHostName() + ":" + isa.getPort() + " HTTP/1.0\n\n"; - getOutputStream().write(httpConnect.getBytes(IOUtils.UTF8)); - checkAndFlushProxyResponse(); - } - - private void checkAndFlushProxyResponse()throws IOException { - InputStream socketInput = getInputStream(); - byte[] tmpBuffer = new byte[512]; - int len = socketInput.read(tmpBuffer, 0, tmpBuffer.length); - - if (len == 0) { - throw new SocketException("Empty response from proxy"); - } - - String proxyResponse = new String(tmpBuffer, 0, len, IOUtils.UTF8); - - // Expecting HTTP/1.x 200 OK - if (proxyResponse.contains("200")) { - // Flush any outstanding message in buffer - if (socketInput.available() > 0) { - socketInput.skip(socketInput.available()); - } - // Proxy Connect Successful - } else { - throw new SocketException("Fail to create Socket\nResponse was:" + proxyResponse); - } - } -} diff --git a/src/main/java/net/schmizz/sshj/SocketClient.java b/src/main/java/net/schmizz/sshj/SocketClient.java index 8d916f734..d7971243a 100644 --- a/src/main/java/net/schmizz/sshj/SocketClient.java +++ b/src/main/java/net/schmizz/sshj/SocketClient.java @@ -15,8 +15,6 @@ */ package net.schmizz.sshj; -import com.hierynomus.sshj.backport.JavaVersion; -import com.hierynomus.sshj.backport.Jdk7HttpProxySocket; import net.schmizz.sshj.connection.channel.Channel; import net.schmizz.sshj.connection.channel.direct.DirectConnection; @@ -26,7 +24,6 @@ import java.io.OutputStream; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.Proxy; import java.net.Socket; public abstract class SocketClient { @@ -57,73 +54,6 @@ protected InetSocketAddress makeInetSocketAddress(String hostname, int port) { return new InetSocketAddress(hostname, port); } - /** - * Connect to a host via a proxy. - * @param hostname The host name to connect to. - * @param proxy The proxy to connect via. - * @deprecated This method will be removed after v0.12.0. If you want to connect via a proxy, you can do this by injecting a {@link javax.net.SocketFactory} - * into the SocketClient. The SocketFactory should create sockets using the {@link java.net.Socket#Socket(java.net.Proxy)} constructor. - */ - @Deprecated - public void connect(String hostname, Proxy proxy) throws IOException { - connect(hostname, defaultPort, proxy); - } - - /** - * Connect to a host via a proxy. - * @param hostname The host name to connect to. - * @param port The port to connect to. - * @param proxy The proxy to connect via. - * @deprecated This method will be removed after v0.12.0. If you want to connect via a proxy, you can do this by injecting a {@link javax.net.SocketFactory} - * into the SocketClient. The SocketFactory should create sockets using the {@link java.net.Socket#Socket(java.net.Proxy)} constructor. - */ - @Deprecated - public void connect(String hostname, int port, Proxy proxy) throws IOException { - this.hostname = hostname; - this.port = port; - if (JavaVersion.isJava7OrEarlier() && proxy.type() == Proxy.Type.HTTP) { - // Java7 and earlier have no support for HTTP Connect proxies, return our custom socket. - socket = new Jdk7HttpProxySocket(proxy); - } else { - socket = new Socket(proxy); - } - socket.connect(makeInetSocketAddress(hostname, port), connectTimeout); - onConnect(); - } - - /** - * Connect to a host via a proxy. - * @param host The host address to connect to. - * @param proxy The proxy to connect via. - * @deprecated This method will be removed after v0.12.0. If you want to connect via a proxy, you can do this by injecting a {@link javax.net.SocketFactory} - * into the SocketClient. The SocketFactory should create sockets using the {@link java.net.Socket#Socket(java.net.Proxy)} constructor. - */ - @Deprecated - public void connect(InetAddress host, Proxy proxy) throws IOException { - connect(host, defaultPort, proxy); - } - - /** - * Connect to a host via a proxy. - * @param host The host address to connect to. - * @param port The port to connect to. - * @param proxy The proxy to connect via. - * @deprecated This method will be removed after v0.12.0. If you want to connect via a proxy, you can do this by injecting a {@link javax.net.SocketFactory} - * into the SocketClient. The SocketFactory should create sockets using the {@link java.net.Socket#Socket(java.net.Proxy)} constructor. - */ - @Deprecated - public void connect(InetAddress host, int port, Proxy proxy) throws IOException { - this.port = port; - if (JavaVersion.isJava7OrEarlier() && proxy.type() == Proxy.Type.HTTP) { - // Java7 and earlier have no support for HTTP Connect proxies, return our custom socket. - socket = new Jdk7HttpProxySocket(proxy); - } else { - socket = new Socket(proxy); - } - socket.connect(new InetSocketAddress(host, port), connectTimeout); - onConnect(); - } - public void connect(String hostname) throws IOException { connect(hostname, defaultPort); }