Skip to content

Commit

Permalink
add every certificate in the file to the trust store
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcz committed Oct 1, 2021
1 parent 677d7a1 commit 441c5b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/pemToJks/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fun addToKeyStore(ksFile: File, ksPass: CharArray, alias: String, aliasPass: Cha
ks.setKeyEntry(alias, key, aliasPass, chain)
} else {
println("Adding certificate entries to keystore")
chain.forEach { ks.setCertificateEntry(alias, it) }
chain.forEachIndexed { idx, cert -> ks.setCertificateEntry(alias + idx, cert) }
}

println("Saving keystore")
Expand Down
5 changes: 3 additions & 2 deletions src/test/kotlin/pemToJks/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ class MainTest {
}

@Test
fun shouldWriteFirstCertToKeyStore() {
fun shouldWriteCertsToKeyStore() {
val certs = readCertChain(certFile)

addToKeyStore(ksFile, ksPass, alias, aliasPass, certs.toTypedArray(), null)

val ks = KeyStore.getInstance("JKS")
ksFile.inputStream().use { ks.load(it, ksPass) }

assertEquals(certs[0], ks.getCertificate(alias))
assertEquals(certs[0], ks.getCertificate("alias0"))
assertEquals(certs[1], ks.getCertificate("alias1"))
}

@Test
Expand Down

0 comments on commit 441c5b9

Please sign in to comment.