title: android self-signed certificate wont work
body: <p>Recently I made a self-singed certificate in Apache web server using this tutorial:</p>
  
  <p><a href="http://theheat.dk/blog/?p=1023&amp;cpage=1" rel="nofollow">http://theheat.dk/blog/?p=1023&amp;cpage=1</a></p>
  
  <p>Web service require certificate to open. in browser everything goes well. I imported certificates and site will open.</p>
  
  <p>I made BKS file from rootCA.crt, client.crt, winter fell.crt, But no one works.<br>
  In Android I get</p>
  
  <blockquote>
    <p>SSL3_GET_CLIENT_CERTIFICATE:peer did not return a certificate No CAs
    known to server for verification?</p>
  </blockquote>
  
  <p>error message in apache log.</p>
  
  <p>It seems my problem is about combination of certificates to send to server! in browser I use client and rootCA, How can I combine them to send to webserver?</p>
  
  <p>My code:</p>
  
  <pre><code>  try {
          DefaultHttpClient httpclient = new MyHttpClient(getApplicationContext());
          HttpGet get = new HttpGet("https://xxx.xxx.xxx.xxx/index.php");
  
          try {
              HttpResponse response = httpclient.execute(get);
          } catch (ClientProtocolException e) {
              System.out.println(e.getMessage());
          } catch (IOException e) {
              System.out.println(e.getMessage());
          }
          return "OK";
  
  
      } catch (Exception err) {
          return "Err";
      }
  </code></pre>
  
  <p>And </p>
  
  <pre><code>public class MyHttpClient extends DefaultHttpClient {
  
  final Context context;
  
  public MyHttpClient(Context context) {
      this.context = context;
  }
  
  @Override
  protected ClientConnectionManager createClientConnectionManager() {
      SchemeRegistry registry = new SchemeRegistry();
      // Register for port 443 our SSLSocketFactory with our keystore
      // to the ConnectionManager
      registry.register(new Scheme("https", newSslSocketFactory(), 443));
      return new SingleClientConnManager(getParams(), registry);
  }
  
  private SSLSocketFactory newSslSocketFactory() {
      try {
          // Get an instance of the Bouncy Castle KeyStore format
          KeyStore trusted = KeyStore.getInstance("BKS");
          // Get the raw resource, which contains the keystore with
          // your trusted certificates (root and any intermediate certs)
          InputStream in = context.getResources().openRawResource(R.raw.comb);
          try {
              // Initialize the keystore with the provided trusted certificates
              // Also provide the password of the keystore
              trusted.load(in, "mysecret".toCharArray());
          } finally {
              in.close();
          }
  
          // Pass the keystore to the SSLSocketFactory. The factory is responsible
          // for the verification of the server certificate.
          SSLSocketFactory sf = new SSLSocketFactory(trusted);
          // Hostname verification from certificate
          // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
          //sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
          HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  
          return sf;
      } catch (Exception e) {
          throw new AssertionError(e);
      }
  }
  </code></pre>
  
  <p>Your helps really appreciated!</p>