You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/11/12 21:05:23 UTC

[commons-net] branch master updated (d4596f75 -> 5b3b12d7)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


    from d4596f75 Add OpenSSF Scorecard badge
     new 986c4c16 Remove useless comment
     new b902b425 Use try-with-resources
     new 5b3b12d7 Remove reflection from SSLSocketUtils

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  3 +++
 .../org/apache/commons/net/bsd/RCommandClient.java |  3 +--
 .../org/apache/commons/net/bsd/RExecClient.java    | 15 ++++++-------
 .../apache/commons/net/io/SocketInputStream.java   |  2 --
 .../apache/commons/net/util/SSLSocketUtils.java    | 25 +++++++---------------
 5 files changed, 18 insertions(+), 30 deletions(-)


[commons-net] 02/03: Use try-with-resources

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit b902b4255e2254f6978156d0319dd2267e659517
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 12 15:58:31 2022 -0500

    Use try-with-resources
---
 .../java/org/apache/commons/net/bsd/RCommandClient.java   |  3 +--
 src/main/java/org/apache/commons/net/bsd/RExecClient.java | 15 ++++++---------
 .../java/org/apache/commons/net/io/SocketInputStream.java |  2 --
 3 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/bsd/RCommandClient.java b/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
index 909d9ce9..dcb5a370 100644
--- a/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
+++ b/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
@@ -219,11 +219,10 @@ public class RCommandClient extends RExecClient {
     @Override
     InputStream createErrorStream() throws IOException {
         int localPort;
-        ServerSocket server;
         final Socket socket;
 
         localPort = MAX_CLIENT_PORT;
-        server = null;
+        ServerSocket server = null;
 
         for (localPort = MAX_CLIENT_PORT; localPort >= MIN_CLIENT_PORT; --localPort) {
             try {
diff --git a/src/main/java/org/apache/commons/net/bsd/RExecClient.java b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
index 1c8ce930..bce823c8 100644
--- a/src/main/java/org/apache/commons/net/bsd/RExecClient.java
+++ b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
@@ -79,17 +79,14 @@ public class RExecClient extends SocketClient {
     // This can be overridden in local package to implement port range
     // limitations of rcmd and rlogin
     InputStream createErrorStream() throws IOException {
-        final ServerSocket server;
         final Socket socket;
 
-        server = _serverSocketFactory_.createServerSocket(0, 1, getLocalAddress());
-
-        _output_.write(Integer.toString(server.getLocalPort()).getBytes(StandardCharsets.UTF_8)); // $NON-NLS-1$
-        _output_.write(NULL_CHAR);
-        _output_.flush();
-
-        socket = server.accept();
-        server.close();
+        try (final ServerSocket server = _serverSocketFactory_.createServerSocket(0, 1, getLocalAddress())) {
+            _output_.write(Integer.toString(server.getLocalPort()).getBytes(StandardCharsets.UTF_8)); // $NON-NLS-1$
+            _output_.write(NULL_CHAR);
+            _output_.flush();
+            socket = server.accept();
+        }
 
         if (remoteVerificationEnabled && !verifyRemote(socket)) {
             socket.close();
diff --git a/src/main/java/org/apache/commons/net/io/SocketInputStream.java b/src/main/java/org/apache/commons/net/io/SocketInputStream.java
index f21eb40d..f38c3321 100644
--- a/src/main/java/org/apache/commons/net/io/SocketInputStream.java
+++ b/src/main/java/org/apache/commons/net/io/SocketInputStream.java
@@ -27,10 +27,8 @@ import java.net.Socket;
  * afterward. This class is useful for situations where you are dealing with a stream originating from a socket, but do not have a reference to the socket, and
  * want to make sure it closes when the stream closes.
  *
- *
  * @see SocketOutputStream
  */
-
 public class SocketInputStream extends FilterInputStream {
     private final Socket socket;
 


[commons-net] 01/03: Remove useless comment

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 986c4c16718df31488b08cd8c963f6091e319666
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 12 15:53:13 2022 -0500

    Remove useless comment
---
 src/main/java/org/apache/commons/net/bsd/RCommandClient.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/net/bsd/RCommandClient.java b/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
index c03f5c45..909d9ce9 100644
--- a/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
+++ b/src/main/java/org/apache/commons/net/bsd/RCommandClient.java
@@ -223,7 +223,7 @@ public class RCommandClient extends RExecClient {
         final Socket socket;
 
         localPort = MAX_CLIENT_PORT;
-        server = null; // Keep compiler from barfing
+        server = null;
 
         for (localPort = MAX_CLIENT_PORT; localPort >= MIN_CLIENT_PORT; --localPort) {
             try {


[commons-net] 03/03: Remove reflection from SSLSocketUtils

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git

commit 5b3b12d78601c5476081f31887610d6d0e0cbe2a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 12 16:05:18 2022 -0500

    Remove reflection from SSLSocketUtils
---
 src/changes/changes.xml                            |  3 +++
 .../apache/commons/net/util/SSLSocketUtils.java    | 25 +++++++---------------
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2c299be0..f59ce292 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -89,6 +89,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Arturo Bernal, Gary Gregory">
         Simplify conditions avoiding extra operations #88.
       </action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">
+        Remove reflection from SSLSocketUtils.
+      </action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">
         [FTP] Add FTPClient.mdtmInstant(String).
diff --git a/src/main/java/org/apache/commons/net/util/SSLSocketUtils.java b/src/main/java/org/apache/commons/net/util/SSLSocketUtils.java
index 3261c08c..5485a8b7 100644
--- a/src/main/java/org/apache/commons/net/util/SSLSocketUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SSLSocketUtils.java
@@ -18,9 +18,7 @@
 
 package org.apache.commons.net.util;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
+import javax.net.ssl.SSLParameters;
 import javax.net.ssl.SSLSocket;
 
 /**
@@ -29,26 +27,19 @@ import javax.net.ssl.SSLSocket;
  * @since 3.4
  */
 public class SSLSocketUtils {
+
     /**
      * Enable the HTTPS endpoint identification algorithm on an SSLSocket.
      *
      * @param socket the SSL socket
-     * @return {@code true} on success (this is only supported on Java 1.7+)
+     * @return {@code true} on success
      */
     public static boolean enableEndpointNameVerification(final SSLSocket socket) {
-        try {
-            final Class<?> cls = Class.forName("javax.net.ssl.SSLParameters");
-            final Method setEndpointIdentificationAlgorithm = cls.getDeclaredMethod("setEndpointIdentificationAlgorithm", String.class);
-            final Method getSSLParameters = SSLSocket.class.getDeclaredMethod("getSSLParameters");
-            final Method setSSLParameters = SSLSocket.class.getDeclaredMethod("setSSLParameters", cls);
-            final Object sslParams = getSSLParameters.invoke(socket);
-            if (sslParams != null) {
-                setEndpointIdentificationAlgorithm.invoke(sslParams, "HTTPS");
-                setSSLParameters.invoke(socket, sslParams);
-                return true;
-            }
-        } catch (final SecurityException | ClassNotFoundException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException
-                | InvocationTargetException e) { // Ignored
+        final SSLParameters sslParameters = socket.getSSLParameters();
+        if (sslParameters != null) {
+            sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
+            socket.setSSLParameters(sslParameters);
+            return true;
         }
         return false;
     }