Commit 946881b0c0ff98fbf46dbc85180de49889df567e
Committed by
Andrew Shvayka
1 parent
559183e9
close the stream after generateCertificate
close the stream after generateCertificate
Showing
1 changed file
with
4 additions
and
1 deletions
@@ -38,6 +38,7 @@ import javax.crypto.spec.PBEKeySpec; | @@ -38,6 +38,7 @@ import javax.crypto.spec.PBEKeySpec; | ||
38 | import javax.net.ssl.KeyManagerFactory; | 38 | import javax.net.ssl.KeyManagerFactory; |
39 | import javax.net.ssl.TrustManagerFactory; | 39 | import javax.net.ssl.TrustManagerFactory; |
40 | import java.io.ByteArrayInputStream; | 40 | import java.io.ByteArrayInputStream; |
41 | +import java.io.InputStream; | ||
41 | import java.security.AlgorithmParameters; | 42 | import java.security.AlgorithmParameters; |
42 | import java.security.Key; | 43 | import java.security.Key; |
43 | import java.security.KeyFactory; | 44 | import java.security.KeyFactory; |
@@ -142,7 +143,9 @@ public class CertPemClientCredentials implements MqttClientCredentials { | @@ -142,7 +143,9 @@ public class CertPemClientCredentials implements MqttClientCredentials { | ||
142 | .replaceAll("\\s", ""); | 143 | .replaceAll("\\s", ""); |
143 | byte[] decoded = Base64.decodeBase64(fileContent); | 144 | byte[] decoded = Base64.decodeBase64(fileContent); |
144 | CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); | 145 | CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
145 | - certificate = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(decoded)); | 146 | + try (InputStream inStream = new ByteArrayInputStream(decoded)) { |
147 | + certificate = (X509Certificate) certFactory.generateCertificate(inStream); | ||
148 | + } | ||
146 | } | 149 | } |
147 | return certificate; | 150 | return certificate; |
148 | } | 151 | } |