Close certificate InputStream after use

This commit is contained in:
Niko Diamadis
2024-06-11 21:12:45 +02:00
parent 9d2d49794b
commit cdb807c806

View File

@@ -87,8 +87,9 @@ internal object CertUtils {
@Throws(GeneralSecurityException::class) @Throws(GeneralSecurityException::class)
private fun certToTrustManager(certPath: String): Array<TrustManager> { private fun certToTrustManager(certPath: String): Array<TrustManager> {
val certificateFactory = CertificateFactory.getInstance("X.509") val certificateFactory = CertificateFactory.getInstance("X.509")
val inputStream = FileInputStream(File(certPath)) val certificates = FileInputStream(File(certPath)).use(
val certificates = certificateFactory.generateCertificates(inputStream) certificateFactory::generateCertificates
)
require(certificates.isNotEmpty()) { "expected non-empty set of trusted certificates" } require(certificates.isNotEmpty()) { "expected non-empty set of trusted certificates" }
val caKeyStore = KeyStore.getInstance(KeyStore.getDefaultType()).apply { load(null) } val caKeyStore = KeyStore.getInstance(KeyStore.getDefaultType()).apply { load(null) }