title: Restlet javax.net.ssl.SSLHandshakeException: null cert chain
body: <p>I am testing SSL communication between client and server locally.
  So I generated certificate using OpenSSL commands. Added this certificate in cacert file. Also generated .p12 file.</p>
  
  <p>I am using the same .p12 file in server and client.
  This is the server code</p>
  
  <pre><code>Server server = component.getServers().add(Protocol.HTTPS, port);
  Series&lt;Parameter&gt; params = server.getContext().getParameters();
  
  params.add("keystorePath", ".p12 file path");
  params.add("keystoreType", "PKCS12");
  params.add("needClientAuthentication","true");
  
  component.getDefaultHost().attach("", "/AA"), new AAClass());
  component.start();
  </code></pre>
  
  <p>And this is client code:</p>
  
  <pre><code>Client client = trustAllCerts();
  clientResource = new ClientResource(url);
  clientResource.setNext(client);
  try{
        clientText = clientResource.post"");
   }
   catch(ResourceException e){
      e.printStackTrace();
   }
  
  public Client trustAllCerts() {
      Client client = null;
      try {
          client = new Client(new Context(), Protocol.HTTPS);
          Context context = client.getContext();
  
  
          final SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
          context.getAttributes().put("sslContextFactory", new SslContextFactory() {
              public void init(Series&lt;Parameter&gt; parameters) {
  
              }
  
              public SSLContext createSslContext() {
                  return sslContext;
              }
          });
          TrustManager tm = new X509TrustManager() {
              public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
              }
  
              public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
              }
  
              public X509Certificate[] getAcceptedIssuers() {
                  return null;
              }
          };
          context.getAttributes().put("hostnameVerifier", new HostnameVerifier() {                
              @Override
              public boolean verify(String arg0, SSLSession arg1) {
                  return true;
              }
  
          });         
  
          sslContext.init(null, new TrustManager[] { tm }, null);         
  
      } catch (KeyManagementException e) {
          LOGGER.error("Exception in Key Management" + e);
      } catch (NoSuchAlgorithmException e) {
          LOGGER.error("Exception in Algorithm Used" + e);
      }
      return client;
  }
  </code></pre>
  
  <p>I am getting following exception:</p>
  
  <pre><code>Restlet-1299242, fatal error: 42: null cert chain
  javax.net.ssl.SSLHandshakeException: null cert chain
  %% Invalidated:  [Session-25, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256]
  Restlet-1299242, SEND TLSv1.2 ALERT:  fatal, description = bad_certificate
  Restlet-1299242, WRITE: TLSv1.2 Alert, length = 2
  Restlet-1299242, fatal: engine already closed.  Rethrowing javax.net.ssl.SSLHandshakeException: null cert chain
  Restlet-1299242, called closeInbound()
  Restlet-1299242, fatal: engine already closed.  Rethrowing javax.net.ssl.SSLException: Inbound closed before receiving peer's close_notify: possible truncation attack?
  Restlet-1299242, called closeOutbound()
  Restlet-1299242, closeOutboundInternal()
  </code></pre>
  
  <p>I tried to add keystore and truststore using System.setProperty() but it didn't work.</p>
  
  <p>Please help. Thanks in advance.</p>