Skip to content

Commit

Permalink
Remove assumption "JKS" is always available. (#3854)
Browse files Browse the repository at this point in the history
On some platforms (e.g. Android) Java KeyStore (JKS) support is not
available. Using the default platform keystore ensures that keys can
still be stored on those platforms.
  • Loading branch information
alsutton committed Jan 2, 2024
1 parent 856da89 commit b323584
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public fun KeyStore.generateCertificate(
* If [file] is set, all certificates are stored in a JKS keystore in [file] with [password].
*/
public fun KeyStore.trustStore(file: File? = null, password: CharArray = "changeit".toCharArray()): KeyStore {
val trustStore = KeyStore.getInstance("JKS")!!
val trustStore = KeyStore.getInstance(KeyStore.getDefaultType())!!
trustStore.load(null, null)
aliases().toList().forEach { alias ->
val cert: Certificate = getCertificate(alias)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public class KeyStoreBuilder internal constructor() {
}

internal fun build(): KeyStore {
val store = KeyStore.getInstance("JKS")!!
val store = KeyStore.getInstance(KeyStore.getDefaultType())!!
store.load(null, null)

certificates.forEach { (alias, info) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal actual fun ApplicationEngine.Configuration.configureSSLConnectors(
val keyStoreFile = File(sslKeyStorePath).let { file ->
if (file.exists() || file.isAbsolute) file else File(".", sslKeyStorePath).absoluteFile
}
val keyStore = KeyStore.getInstance("JKS").apply {
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()).apply {
FileInputStream(keyStoreFile).use {
load(it, sslKeyStorePassword.toCharArray())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class NettyChannelInitializer(
private fun EngineSSLConnectorConfig.trustManagerFactory(): TrustManagerFactory? {
val trustStore = trustStore ?: trustStorePath?.let { file ->
FileInputStream(file).use { fis ->
KeyStore.getInstance("JKS").also { it.load(fis, null) }
KeyStore.getInstance(KeyStore.getDefaultType()).also { it.load(fis, null) }
}
}
return trustStore?.let { store ->
Expand Down

0 comments on commit b323584

Please sign in to comment.