You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2016/11/18 09:27:27 UTC

svn commit: r1770350 - /qpid/java/trunk/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java

Author: orudyy
Date: Fri Nov 18 09:27:27 2016
New Revision: 1770350

URL: http://svn.apache.org/viewvc?rev=1770350&view=rev
Log:
QPID-7521: [Java Broker] Close stream in SSLUtil#readPrivateKey

Modified:
    qpid/java/trunk/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java

Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java?rev=1770350&r1=1770349&r2=1770350&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java Fri Nov 18 09:27:27 2016
@@ -354,16 +354,7 @@ public class SSLUtil
     public static PrivateKey readPrivateKey(InputStream input)
             throws IOException, GeneralSecurityException
     {
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
-        byte[] tmp = new byte[1024];
-        int read;
-        while ((read = input.read(tmp)) != -1)
-        {
-            buffer.write(tmp, 0, read);
-        }
-
-        byte[] content = buffer.toByteArray();
+        byte[] content = toByteArray(input);
         String contentAsString = new String(content, StandardCharsets.US_ASCII);
         if(contentAsString.contains("-----BEGIN ") && contentAsString.contains(" PRIVATE KEY-----"))
         {
@@ -394,6 +385,23 @@ public class SSLUtil
         return readPrivateKey(content, "RSA");
     }
 
+    private static byte[] toByteArray(final InputStream input) throws IOException
+    {
+        try(ByteArrayOutputStream buffer = new ByteArrayOutputStream())
+        {
+
+            byte[] tmp = new byte[1024];
+            int read;
+            while((read=input.read(tmp))!=-1)
+
+            {
+                buffer.write(tmp, 0, read);
+            }
+
+            return buffer.toByteArray();
+        }
+    }
+
     public static PrivateKey readPrivateKey(final byte[] content, final String algorithm)
             throws NoSuchAlgorithmException, InvalidKeySpecException
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org