title: Android SSL - No Peer Certificate
body: <p>Whenever this code runs, I get a 'No Peer Certificate' error.</p>
  
  <p>SSL certificate is valid, bought from Namecheap (PositiveSSL). It has the CA crt before it, and opens fine in the Android browser.</p>
  
  <p>HTTP server: nginx</p>
  
  <p><strong>Code:</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public void postData() {
  
  // Add your data
  List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
  
  nameValuePairs.add(new BasicNameValuePair("string", "myfirststring"));
  
  try {
  
     HttpPost post = new HttpPost(new URI("https://example.com/submit"));
      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
      KeyStore trusted = KeyStore.getInstance("BKS");
      trusted.load(null, "".toCharArray());
      SSLSocketFactory sslf = new SSLSocketFactory(trusted);
      sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  
      SchemeRegistry schemeRegistry = new SchemeRegistry();
      schemeRegistry.register(new Scheme ("https", sslf, 443));
      SingleClientConnManager cm = new SingleClientConnManager(post.getParams(),
              schemeRegistry);
  
      HttpClient client = new DefaultHttpClient(cm, post.getParams());
  
      // Execute HTTP Post Request
      @SuppressWarnings("unused")
      HttpResponse result = client.execute(post);
  
  } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      Log.e(TAG,e.getMessage());
      Log.e(TAG,e.toString());
      e.printStackTrace();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      Log.e(TAG,e.getMessage());
      Log.e(TAG,e.toString());
      e.printStackTrace();
  } catch (URISyntaxException e) {
          // TODO Auto-generated catch block
      Log.e(TAG,e.getMessage());
      Log.e(TAG,e.toString());
      e.printStackTrace();
      } catch (KeyStoreException e) {
          // TODO Auto-generated catch block
          Log.e(TAG,e.getMessage());
          Log.e(TAG,e.toString());
          e.printStackTrace();
      } catch (NoSuchAlgorithmException e) {
          // TODO Auto-generated catch block
          Log.e(TAG,e.getMessage());
          Log.e(TAG,e.toString());
          e.printStackTrace();
      } catch (CertificateException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          Log.e(TAG,e.toString());
          Log.e(TAG,e.getMessage());
      } catch (KeyManagementException e) {
          // TODO Auto-generated catch block
          Log.e(TAG,e.getMessage());
          Log.e(TAG,e.toString());
          e.printStackTrace();
      } catch (UnrecoverableKeyException e) {
          // TODO Auto-generated catch block
          Log.e(TAG,e.getMessage());
          Log.e(TAG,e.toString());
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p><strong>Adb logcat</strong>:</p>
  
  <pre><code>01-10 15:44:34.872: E/myfirstapp(572): No peer certificate
  01-10 15:44:34.872: E/myfirstapp(572): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
  01-10 15:44:34.883: W/System.err(572): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
  01-10 15:44:34.883: W/System.err(572):  at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)
  01-10 15:44:34.883: W/System.err(572):  at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
  01-10 15:44:34.908: W/System.err(572):  at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
  01-10 15:44:34.908: W/System.err(572):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
  01-10 15:44:34.908: W/System.err(572):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
  01-10 15:44:34.914: W/System.err(572):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
  01-10 15:44:34.914: W/System.err(572):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
  01-10 15:44:34.914: W/System.err(572):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  01-10 15:44:34.914: W/System.err(572):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  01-10 15:44:34.914: W/System.err(572):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  01-10 15:44:34.933: W/System.err(572):  at com.giggsey.myfirstapp.myfirstappIntent.postData(myfirstappIntent.java:126)
  01-10 15:44:34.933: W/System.err(572):  at com.giggsey.myfirstapp.myfirstappIntent.onReceive(myfirstappIntent.java:77)
  01-10 15:44:34.933: W/System.err(572):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2118)
  01-10 15:44:34.945: W/System.err(572):  at android.app.ActivityThread.access$1500(ActivityThread.java:122)
  01-10 15:44:34.945: W/System.err(572):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  01-10 15:44:34.952: W/System.err(572):  at android.os.Handler.dispatchMessage(Handler.java:99)
  01-10 15:44:34.952: W/System.err(572):  at android.os.Looper.loop(Looper.java:137)
  01-10 15:44:34.962: W/System.err(572):  at android.app.ActivityThread.main(ActivityThread.java:4340)
  01-10 15:44:34.962: W/System.err(572):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-10 15:44:34.962: W/System.err(572):  at java.lang.reflect.Method.invoke(Method.java:511)
  01-10 15:44:34.972: W/System.err(572):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  01-10 15:44:34.972: W/System.err(572):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  01-10 15:44:34.981: W/System.err(572):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>