title: I have a keystore file, how do I provide keyManagers to sslContext in Android app?
body: <p>UPDATE: As for my original question, it turns out that call to java.security.KeyStore.getCertificate(alias) does actually return X509Certiciate. That wasn't the issue though.</p>
  
  <p>(Bear with me please, I'm new to this certificate stuff.)</p>
  
  <p>I managed to connect to my (self-signed) SSL-enabled server, as long as I don't require authenticated clients. When I do require clientAuth my app yields <em>"routines:SSL3_READ_BYTES:sslv3 alert handshake failure (external/openssl/ssl/s3_pkt.c"...</em> (also described <a href="https://stackoverflow.com/questions/13525445/ssl-client-authentication-in-android-4-x">here</a>)... For some the cure was to switch from BKS to PKCS12, that did not work for me.</p>
  
  <p>So now I am trying to implement my own <code>X509KeyManager</code> (as suggested <a href="http://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html" rel="noreferrer">here</a>), to hand it to <code>sslContext.init([keyManager], trustManagers, null)</code>.</p>
  
  <p>If I understand it correctly the sslContext will ask my keyManager(s) for either a certificate chain and/or a private key for a given alias. (Whenever it asks what alias to choose I provide my hard-coded one.)</p>
  
  <p>But according to the <code>X509KeyManager</code> interface I am supposed to return <code>X509Certificate</code>. <strong>How do I create one using the keystore?</strong>  </p>