# Java Keystore Connect [**Return to main sample list**](../README.md) This sample is similar to the [Basic Connect](../BasicConnect/README.md) sample, in that it connects via Mutual TLS (mTLS) using a certificate and key file. However, unlike the Basic Connect where the certificate and private key file are stored on disk, this sample uses the Java Keystore to get the certificate and private key files. This adds a layer of security because the private key and certificate files is not just sitting on the computer and instead is hidden securely away in the Java Keystore. Your IoT Core Thing's [Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) must provide privileges for this sample to connect. Below is a sample policy that can be used on your IoT Core Thing that will allow this sample to run as intended.
(see sample policy)
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iot:Connect"
      ],
      "Resource": [
        "arn:aws:iot:region:account:client/test-*"
      ]
    }
  ]
}
Replace with the following with the data from your AWS account: * ``: The AWS IoT Core region where you created your AWS IoT Core thing you wish to use with this sample. For example `us-east-1`. * ``: Your AWS IoT Core account ID. This is the set of numbers in the top right next to your AWS account name when using the AWS IoT Core website. Note that in a real application, you may want to avoid the use of wildcards in your ClientID or use them selectively. Please follow best practices when working with AWS on production applications using the SDK. Also, for the purposes of this sample, please make sure your policy allows a client ID of `test-*` to connect or use `--client_id ` to send the client ID your policy supports.
## How to run To run the Java keystore connect sample use the following command: ```sh mvn compile exec:java -pl samples/JavaKeystoreConnect -Dexec.mainClass=javakeystoreconnect.JavaKeystoreConnect -Dexec.args='--endpoint --keystore --keystore_password --certificate_alias --certificate_password ' ``` ### How to setup and run To use the certificate and key files provided by AWS IoT Core, you will need to convert them into PKCS#12 format and then import them into your Java keystore. You can convert the certificate and key file to PKCS12 using the following command: ```sh openssl pkcs12 -export -in -inkey -out my-pkcs12-key.p12 -name -password pass: ``` Once you have a PKCS12 certificate and key, you can import it into a Java keystore using the following: ```sh keytool -importkeystore -srckeystore my-pkcs12-key.p12 -destkeystore -srcstoretype pkcs12 -alias -srcstorepass -deststorepass ``` Then you can run the sample using the following command: ```sh mvn compile exec:java -pl samples/JavaKeystoreConnect -Dexec.mainClass=javakeystoreconnect.JavaKeystoreConnect -Dexec.args='--endpoint --keystore --keystore_password --certificate_alias --certificate_password ' ```