From cdb807c806a6e2907b358ace55a5029e94fbc6fb Mon Sep 17 00:00:00 2001 From: Niko Diamadis Date: Tue, 11 Jun 2024 21:12:45 +0200 Subject: [PATCH] Close certificate InputStream after use --- app/src/main/kotlin/com/github/gotify/api/CertUtils.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt b/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt index 3d15a9da..a362c588 100644 --- a/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt +++ b/app/src/main/kotlin/com/github/gotify/api/CertUtils.kt @@ -87,8 +87,9 @@ internal object CertUtils { @Throws(GeneralSecurityException::class) private fun certToTrustManager(certPath: String): Array { val certificateFactory = CertificateFactory.getInstance("X.509") - val inputStream = FileInputStream(File(certPath)) - val certificates = certificateFactory.generateCertificates(inputStream) + val certificates = FileInputStream(File(certPath)).use( + certificateFactory::generateCertificates + ) require(certificates.isNotEmpty()) { "expected non-empty set of trusted certificates" } val caKeyStore = KeyStore.getInstance(KeyStore.getDefaultType()).apply { load(null) }