title: Android SSL Certificate Authentication (with the Android KeyChain API) to a WCF Service
body: <p>I have big problems with getting the certificates running under android.
  I have an android client which connects to a WCF-Service.</p>
  
  <p>I think the problem is, that the certificates are not transfered. I get an error message: 
  403 forbidden (in the response). I really hope you can help me. 
  => in my android client</p>
  
  <p>In internet explorer, it works just fine => status 200</p>
  
  <p>I found this article: 
  <a href="http://android-developers.blogspot.de/2012/03/unifying-key-store-access-in-ics.html" rel="nofollow">http://android-developers.blogspot.de/2012/03/unifying-key-store-access-in-ics.html</a> </p>
  
  <p>"A common use of the private key is for SSL client authentication. This can be implemented by using an HttpsURLConnection with a custom X509KeyManager that returns the PrivateKey retrieved from the KeyChain API. The open source Email application for ICS uses KeyChain with an X509ExtendedKeyManager. To learn more, have a look at the source code (in SSLUtils.java)."</p>
  
  <p>I have checked out the SSLUtils class and I am trying to use it. </p>
  
  <p>Here is some code: </p>
  
  <pre><code>private void setHttpsAdvanced() {
      HostAuth ht = new HostAuth();
      ht.mPort = 443;
      ht.mClientCertAlias = "jensZert";
  
      HttpParams params = getHttpParams();
      MyThreadSafeClientConnManager ccm = MyThreadSafeClientConnManager
              .newInstance(params, true, 443);
  
      try {
          MyThreadSafeClientConnManager.makeScheme(true, false,    
                            ht.mClientCertAlias);
  
          ccm.registerClientCert(getApplicationContext(), ht);
          // checkCertificate(ht.mClientCertAlias);
  
      } catch (CertificateException e) {
          Log.d(TAG, e.getMessage());
          e.printStackTrace();
      }
  
      this.httpclient = new DefaultHttpClient(ccm, params);
  
      connectionInfo = this.getConnectionInfo();
  
      this.url = String.format("%1$s://%2$s/%3$s/%4$s",
              connectionInfo.Protocol, connectionInfo.ServerName,
              connectionInfo.WebserviceName, connectionInfo.Path);
  
      httpGet = new HttpGet(url);
  }
  
  
  private String callTheWebserviceCertificate() {
      this.setupClient();
      String result = "";
  
      HttpResponse response = null;
      try {
          response = (HttpResponse) this.httpclient.execute(httpGet);
          result = EntityUtils.toString(response.getEntity());
  
      } catch (ClientProtocolException e) {
  
          e.printStackTrace();
      } catch (IOException e) {
  
          result = e.getMessage() + "\n";
  
          for (StackTraceElement el : e.getStackTrace()) {
              result += el.toString() + "\n";
          }
  
          Log.d(TAG, result);
      }
      return result;
  }
  </code></pre>
  
  <p>greetings,
  jens</p>