title: Mule : javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
body: <p>I have a mule project which uses outbound connection to my local tomcat server over HTTPS (TLS) using self signed cert. When I execute the flow, I get following exception </p>
  
  <p><strong>Mule HTTP Connector</strong></p>
  
  <pre><code>&lt;http:request-config name="SP2" host="my_fqdn" port="38443" doc:name="SP Request Configuration" protocol="HTTPS" &gt;
      &lt;tls:context&gt;
          &lt;tls:trust-store path="/temp/temp1.keystore.jks" password="changeit" type="jks"/&gt;
      &lt;/tls:context&gt;
  &lt;/http:request-config&gt;
  </code></pre>
  
  <p><strong>Error From Mule Flow</strong></p>
  
  <pre><code>javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
  at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397) ~[?:1.7.0_67]
  at org.mule.module.http.internal.domain.request.ClientConnection.getClientCertificate(ClientConnection.java:67) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.mule.module.http.internal.listener.HttpRequestToMuleEvent.transform(HttpRequestToMuleEvent.java:63) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.mule.module.http.internal.listener.DefaultHttpListener.createEvent(DefaultHttpListener.java:165) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.mule.module.http.internal.listener.DefaultHttpListener.access$000(DefaultHttpListener.java:39) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.mule.module.http.internal.listener.DefaultHttpListener$1.handleRequest(DefaultHttpListener.java:124) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.mule.module.http.internal.listener.grizzly.GrizzlyRequestDispatcherFilter.handleRead(GrizzlyRequestDispatcherFilter.java:83) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) ~[grizzly-framework-2.3.21.jar:2.3.21]
  at org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy.run0(ExecutorPerServerAddressIOStrategy.java:102) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy.access$100(ExecutorPerServerAddressIOStrategy.java:30) ~[mule-module-http-3.7.2.jar:3.7.2]
  at org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy$WorkerThreadRunnable.run(ExecutorPerServerAddressIOStrategy.java:125) ~[mule-module-http-3.7.2.jar:3.7.2]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_67]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_67]
  at java.lang.Thread.run(Thread.java:745) [?:1.7.0_67]
  </code></pre>
  
  <p>Normally this means that my trust store is not set correctly. In my case, I have the trust store setup in the Mule's TLS context. As I am still getting the error, I am thinking that Mule is somehow not honoring my TLS context setup. </p>
  
  <p>Additionally, I setup a test program inside the Anypoint Studio in the same project as where my Mule flow was executing.</p>
  
  <pre><code>System.setProperty("javax.net.ssl.trustStore","/temp/temp1.keystore.jks");
  System.setProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType());
  System.setProperty("javax.net.ssl.trustStorePassword","changeit");
  
  SocketFactory sslContext = (SSLSocketFactory) SSLSocketFactory.getDefault();
  SSLSocket sslSocket = (SSLSocket) sslContext.createSocket("my_fqdn",38443);
  SSLSession sslSession = sslSocket.getSession();
  sslSession.getPeerCertificates();
  </code></pre>
  
  <p>In the above mentioned Java code, if I were to not set the trust store properly, I get the "peer not authenticated" error. However when I set the trust store as mentioned then the program executes without any error. Finally I tried passing the trust store as JVM args but that also did not work.</p>
  
  <p>So I am clueless about why mule is acting this way. Does anyone know how to solve this?</p>