Hello, i'm having difficulties setting up the ssl ...
# ktor
b
Hello, i'm having difficulties setting up the ssl certificate for android for my multiplatform with ktor. I have tried to follow the documentation available on ktor website/github (https://ktor.io/docs/client-ssl.html and https://github.com/ktorio/ktor-documentation/tree/2.3.11/codeSnippets/snippets/client-ssl-config), but to no avail. I'mm stuck at the first step of creating the SslSettings object due to not being able to open my keystore.jks. It is currently located at the root of my project and have tried to place it in nearly all the directories. Can anyone guide me to where it should be located/what path should be used when using FileInputStream?
a
Can you share the code for reading
keystore.jks
?
b
I am trying to load like in the ktor documentation. I have tried some other ways including putting in it the composeResources and the androidMain res and loading it with anyway I could find. I tried to search github but I've come up empty handed
Copy code
private fun getKeyStore(): KeyStore {
    val keyStoreFile = FileInputStream("keystore.jks")
    val keyStorePassword = "test".toCharArray()
    val keyStore: KeyStore = KeyStore.getInstance(KeyStore.getDefaultType())
    keyStore.load(keyStoreFile, keyStorePassword)
    return keyStore
}
a
The code from the documentation should work only on JVM (non-Android), and it's assumed that the
keystore.jks
file is located in the current working directory, The Android environment (an emulator or a physical device) has its own file system. I suggest reading about Android resources to load the key store from a file packed into the app's final distribution.
b
thank you very much. I'll go read about that