Search code examples
javassltruststore

How to create an empty java trust store?


I want to make a https client in java which initially does not have any CA certs to trust. Since I don't want the JVM to use the default cacerts file I should make an empty trust store and point it to the JVM.
How can I make an empty trust store?


Solution

  • Using keytool, create a random key pair:

    keytool -genkeypair -alias boguscert -storepass storePassword -keypass secretPassword -keystore emptyStore.keystore -dname "CN=Developer, OU=Department, O=Company, L=City, ST=State, C=CA"
    

    then delete it

    keytool -delete -alias boguscert -storepass storePassword -keystore emptyStore.keystore
    

    review its contents:

    $ keytool -list -keystore emptyStore.keystore -storepass storePassword
    Keystore type: JKS
    Keystore provider: SUN
    Your keystore contains 0 entries