title: Android app to connect to AWS IoT using X.509 certificate
body: <p>I am writing an Android application to connect a sensor to an AWS IoT service.</p>
  
  <p>I have been provided with the X.509 certificate, a pair of public-private key, <code>clientEndpoint</code>, etc.</p>
  
  <p>I am trying to follow the AWS's Sample code (<a href="https://github.com/awslabs/aws-sdk-android-samples/blob/master/AndroidPubSub/README.md" rel="nofollow noreferrer">see here</a>).</p>
  
  <p>The instructions are clear, but I don't want to generate the certificate and the keys (I already have them).</p>
  
  <p>Below is the code snippet:</p>
  
  <pre class="lang-java prettyprint-override"><code>// Create a new private key and certificate. This call
  // creates both on the server and returns them to the
  // device.
  CreateKeysAndCertificateRequest createKeysAndCertificateRequest = new CreateKeysAndCertificateRequest();
  createKeysAndCertificateRequest.setSetAsActive(true);
  final CreateKeysAndCertificateResult createKeysAndCertificateResult;
  createKeysAndCertificateResult = mIotAndroidClient.createKeysAndCertificate(createKeysAndCertificateRequest);
  Log.i(LOG_TAG,"Cert ID: " +createKeysAndCertificateResult.getCertificateId() +" created.");
  
  // store in keystore for use in MQTT client
  // saved as alias "default" so a new certificate isn't
  // generated each run of this application
  AWSIotKeystoreHelper.saveCertificateAndPrivateKey(certificateId,createKeysAndCertificateResult.getCertificatePem(),createKeysAndCertificateResult.getKeyPair().getPrivateKey(),
  keystorePath, keystoreName, keystorePassword);
  // load keystore from file into memory to pass on
  // connection
  clientKeyStore = AWSIotKeystoreHelper.getIotKeystore(certificateId,keystorePath, keystoreName, keystorePassword);
  </code></pre>
  
  <p>How can I use the existing certificates files instead of generating new certificate and keys?</p>
  
  <p>Thank you</p>