From 5f9456db0d19e20ad1f8a63e91a4775b323b6d18 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Mon, 12 Feb 2007 03:08:40 +0000 Subject: [PATCH] Close trust store after loading (SMACK-188). git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7074 b35dd754-fafc-0310-a699-88a17e54d16e --- .../jivesoftware/smack/ServerTrustManager.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/source/org/jivesoftware/smack/ServerTrustManager.java b/source/org/jivesoftware/smack/ServerTrustManager.java index 8347512ce..a54d0fcf9 100644 --- a/source/org/jivesoftware/smack/ServerTrustManager.java +++ b/source/org/jivesoftware/smack/ServerTrustManager.java @@ -22,6 +22,8 @@ package org.jivesoftware.smack; import javax.net.ssl.X509TrustManager; import java.io.FileInputStream; +import java.io.InputStream; +import java.io.IOException; import java.security.*; import java.security.cert.CertificateException; import java.security.cert.CertificateParsingException; @@ -54,16 +56,27 @@ class ServerTrustManager implements X509TrustManager { this.configuration = configuration; this.server = server; + InputStream in = null; try { trustStore = KeyStore.getInstance(configuration.getTruststoreType()); - trustStore.load(new FileInputStream(configuration.getTruststorePath()), - configuration.getTruststorePassword().toCharArray()); + in = new FileInputStream(configuration.getTruststorePath()); + trustStore.load(in, configuration.getTruststorePassword().toCharArray()); } catch (Exception e) { e.printStackTrace(); // Disable root CA checking configuration.setVerifyRootCAEnabled(false); } + finally { + if (in != null) { + try { + in.close(); + } + catch (IOException ioe) { + // Ignore. + } + } + } } public X509Certificate[] getAcceptedIssuers() {