<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Simplest method to Implement 2 Way Authentication using SSL &#8211; Example With Source Code Available	</title>
	<atom:link href="https://www.opencodez.com/java/implement-2-way-authentication-using-ssl.htm/feed" rel="self" type="application/rss+xml" />
	<link>https://www.opencodez.com/java/implement-2-way-authentication-using-ssl.htm</link>
	<description>develope &#124; share &#124; reuse</description>
	<lastBuildDate>Fri, 06 Aug 2021 05:49:57 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<!--Theme by MyThemeShop.com-->
	<item>
		<title>
		By: imran		</title>
		<link>https://www.opencodez.com/java/implement-2-way-authentication-using-ssl.htm/comment-page-1#comment-103558</link>

		<dc:creator><![CDATA[imran]]></dc:creator>
		<pubDate>Fri, 06 Aug 2021 05:49:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.opencodez.com/?p=2496#comment-103558</guid>

					<description><![CDATA[Hi Pavan,

I have two distinct projects both on tomcat. Here, when I add a self-signed server certificate in the server.xml it works fine.
But I am trying to configure 2 Way Authentication with the below configuration.
Server.xml (Server)



System Properties set in the eclipse as below (Client):

-Djavax.net.debug=all 
-Djavax.net.ssl.trustStore=/Users/imran.inamdar/work/Local/SPClient.jks 
-Djavax.net.ssl.trustStorePassword=storeit 
-Djavax.net.ssl.keyStore=/Users/imran.inamdar/work/Local/SPClient.jks 
-Djavax.net.ssl.keyStorePassword=storeit
	
Error on Tomcat Console  on Eclipse (Client):

javax.net.ssl&#124;DEBUG&#124;2A&#124;http-nio-9090-exec-3&#124;2021-08-06 11:10:43.240 IST&#124;Alert.java:238&#124;Received alert message (
&quot;Alert&quot;: {
  &quot;level&quot;      : &quot;fatal&quot;,
  &quot;description&quot;: &quot;bad_certificate&quot;
}
)
javax.net.ssl&#124;ERROR&#124;2A&#124;http-nio-9090-exec-3&#124;2021-08-06 11:10:43.242 IST&#124;TransportContext.java:361&#124;Fatal (BAD_CERTIFICATE): Received fatal alert: bad_certificate (
&quot;throwable&quot; : {
  javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate
  
Error on Tomcat Console  on Eclipse (Server):
javax.net.ssl&#124;DEBUG&#124;22&#124;https-jsse-nio-7443-exec-5&#124;2021-08-06 11:10:43.228 IST&#124;CertificateMessage.java:1177&#124;Consuming client Certificate handshake message (
&quot;Certificate&quot;: {
  &quot;certificate_request_context&quot;: &quot;&quot;,
  &quot;certificate_list&quot;: [  
]
}
)
javax.net.ssl&#124;ERROR&#124;22&#124;https-jsse-nio-7443-exec-5&#124;2021-08-06 11:10:43.231 IST&#124;TransportContext.java:361&#124;Fatal (BAD_CERTIFICATE): Empty client certificate chain (
&quot;throwable&quot; : {
  javax.net.ssl.SSLHandshakeException: Empty client certificate chain
  	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
  	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
  	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:356)
  	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:312)
  	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:303)

I got the same exception using cacerts and using OpenSSL too.]]></description>
			<content:encoded><![CDATA[<p>Hi Pavan,</p>
<p>I have two distinct projects both on tomcat. Here, when I add a self-signed server certificate in the server.xml it works fine.<br />
But I am trying to configure 2 Way Authentication with the below configuration.<br />
Server.xml (Server)</p>
<p>System Properties set in the eclipse as below (Client):</p>
<p>-Djavax.net.debug=all<br />
-Djavax.net.ssl.trustStore=/Users/imran.inamdar/work/Local/SPClient.jks<br />
-Djavax.net.ssl.trustStorePassword=storeit<br />
-Djavax.net.ssl.keyStore=/Users/imran.inamdar/work/Local/SPClient.jks<br />
-Djavax.net.ssl.keyStorePassword=storeit</p>
<p>Error on Tomcat Console  on Eclipse (Client):</p>
<p>javax.net.ssl|DEBUG|2A|http-nio-9090-exec-3|2021-08-06 11:10:43.240 IST|Alert.java:238|Received alert message (<br />
&#8220;Alert&#8221;: {<br />
  &#8220;level&#8221;      : &#8220;fatal&#8221;,<br />
  &#8220;description&#8221;: &#8220;bad_certificate&#8221;<br />
}<br />
)<br />
javax.net.ssl|ERROR|2A|http-nio-9090-exec-3|2021-08-06 11:10:43.242 IST|TransportContext.java:361|Fatal (BAD_CERTIFICATE): Received fatal alert: bad_certificate (<br />
&#8220;throwable&#8221; : {<br />
  javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate</p>
<p>Error on Tomcat Console  on Eclipse (Server):<br />
javax.net.ssl|DEBUG|22|https-jsse-nio-7443-exec-5|2021-08-06 11:10:43.228 IST|CertificateMessage.java:1177|Consuming client Certificate handshake message (<br />
&#8220;Certificate&#8221;: {<br />
  &#8220;certificate_request_context&#8221;: &#8220;&#8221;,<br />
  &#8220;certificate_list&#8221;: [<br />
]<br />
}<br />
)<br />
javax.net.ssl|ERROR|22|https-jsse-nio-7443-exec-5|2021-08-06 11:10:43.231 IST|TransportContext.java:361|Fatal (BAD_CERTIFICATE): Empty client certificate chain (<br />
&#8220;throwable&#8221; : {<br />
  javax.net.ssl.SSLHandshakeException: Empty client certificate chain<br />
  	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)<br />
  	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)<br />
  	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:356)<br />
  	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:312)<br />
  	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:303)</p>
<p>I got the same exception using cacerts and using OpenSSL too.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Steve		</title>
		<link>https://www.opencodez.com/java/implement-2-way-authentication-using-ssl.htm/comment-page-1#comment-98509</link>

		<dc:creator><![CDATA[Steve]]></dc:creator>
		<pubDate>Mon, 19 Oct 2020 15:05:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.opencodez.com/?p=2496#comment-98509</guid>

					<description><![CDATA[looks very simple.  but may you explain why the keystore and truststore are set to the same shown in your config:
like on Tomcat:
 keystoreFile=&quot;C:\core-jks\MyServer.jks&quot;
 ...
 truststoreFile=&quot;C:\core-jks\MyServer.jks&quot;

and on client:

 System.setProperty(&quot;javax.net.ssl.trustStore&quot;, &quot;c://core-jks//MyClient.jks&quot;);
....
 System.setProperty(&quot;javax.net.ssl.keyStore&quot;,  &quot;c://core-jks//MyClient.jks&quot;);

shouldn&#039;t the trust store be the &quot;cacerts&quot;? 

Thanks.]]></description>
			<content:encoded><![CDATA[<p>looks very simple.  but may you explain why the keystore and truststore are set to the same shown in your config:<br />
like on Tomcat:<br />
 keystoreFile=&#8221;C:\core-jks\MyServer.jks&#8221;<br />
 &#8230;<br />
 truststoreFile=&#8221;C:\core-jks\MyServer.jks&#8221;</p>
<p>and on client:</p>
<p> System.setProperty(&#8220;javax.net.ssl.trustStore&#8221;, &#8220;c://core-jks//MyClient.jks&#8221;);<br />
&#8230;.<br />
 System.setProperty(&#8220;javax.net.ssl.keyStore&#8221;,  &#8220;c://core-jks//MyClient.jks&#8221;);</p>
<p>shouldn&#8217;t the trust store be the &#8220;cacerts&#8221;? </p>
<p>Thanks.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mahesh		</title>
		<link>https://www.opencodez.com/java/implement-2-way-authentication-using-ssl.htm/comment-page-1#comment-98331</link>

		<dc:creator><![CDATA[Mahesh]]></dc:creator>
		<pubDate>Fri, 02 Oct 2020 17:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.opencodez.com/?p=2496#comment-98331</guid>

					<description><![CDATA[hi Pavan,
Where we need to configure connector, is it already configured in code or do we need to do explicitely?
Can i use Sprint Boot for this code to run?

Getting this error.

2020-10-02 13:07:50.261 ERROR 18348 --- [           main] o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boo]]></description>
			<content:encoded><![CDATA[<p>hi Pavan,<br />
Where we need to configure connector, is it already configured in code or do we need to do explicitely?<br />
Can i use Sprint Boot for this code to run?</p>
<p>Getting this error.</p>
<p>2020-10-02 13:07:50.261 ERROR 18348 &#8212; [           main] o.s.boot.SpringApplication               : Application startup failed</p>
<p>java.lang.IllegalStateException: Failed to execute CommandLineRunner<br />
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boo</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: John Smith		</title>
		<link>https://www.opencodez.com/java/implement-2-way-authentication-using-ssl.htm/comment-page-1#comment-98136</link>

		<dc:creator><![CDATA[John Smith]]></dc:creator>
		<pubDate>Mon, 14 Sep 2020 13:26:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.opencodez.com/?p=2496#comment-98136</guid>

					<description><![CDATA[Hi Pavan:

I am getting the following error:

java.lang.IllegalStateException: Failed to execute CommandLineRunner
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	at com.opencodez.SslClientApplication.main(SslClientApplication.java:41) [classes/:na]
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for &quot;https://localhost:8443/ssl-server-0.0.1-SNAPSHOT/hello&quot;: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:312) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at com.opencodez.HttpClient.run(HttpClient.java:24) ~[classes/:na]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	... 6 common frames omitted
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.8.0_121]
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) ~[na:1.8.0_121]
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_121]
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_121]
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_121]
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_121]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_121]
	at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_121]
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668) ~[na:1.8.0_121]
	at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173) ~[na:1.8.0_121]
	at sun.net.NetworkClient.doConnect(NetworkClient.java:180) ~[na:1.8.0_121]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) ~[na:1.8.0_121]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) ~[na:1.8.0_121]
	at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264) ~[na:1.8.0_121]
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367) ~[na:1.8.0_121]
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) ~[na:1.8.0_121]
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138) ~[na:1.8.0_121]
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032) ~[na:1.8.0_121]
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) ~[na:1.8.0_121]
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) ~[na:1.8.0_121]
	at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:652) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	... 10 common frames omitted

2020-09-14 09:13:05.873  INFO 14088 --- [           main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@54a7079e: startup date [Mon Sep 14 09:10:41 EDT 2020]; root of context hierarchy
2020-09-14 09:13:05.874  INFO 14088 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown


These are my steps:


step 1:
server certificate:
keytool -genkey -alias MyServer -keyalg RSA -validity 1825 -keystore &quot;MyServer.jks&quot; -storetype JKS -dname &quot;CN=myserver.com,OU=MyCompany Name,O=My Organization,L=My Location,ST=My State,C=My Country Short Code&quot;  

step 2:
keytool -exportcert -alias MyServer -keystore MyServer.jks -file MyServer.cer

step 3:

client certificate:
keytool -genkey -alias MyClient -keyalg RSA -validity 1825 -keystore MyClient.jks -storetype JKS 
-dname &quot;CN=client.com,OU=Client Company,O=Client,L=CLient Location,ST=Client State,C=Client Country Short Code&quot;

step 4:
keytool -exportcert -alias MyClient -keystore MyClient.jks -file MyClientPublic.cer

step 5:
--Add Server certificate to client truststore
C:\JDK-1.8.0.x64\jre\lib\security&#062;keytool -importcert -alias MyServer -keystore MyClient.jks -file MyServer.cer

step 6:
--Add client certificate to server truststore
C:\JDK-1.8.0.x64\jre\lib\security&#062;keytool -importcert -alias MyClient -keystore MyServer.jks -file MyClientPublic.cer

step 7:
https://localhost:8443/ssl-server-0.0.1-SNAPSHOT/hello]]></description>
			<content:encoded><![CDATA[<p>Hi Pavan:</p>
<p>I am getting the following error:</p>
<p>java.lang.IllegalStateException: Failed to execute CommandLineRunner<br />
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	at com.opencodez.SslClientApplication.main(SslClientApplication.java:41) [classes/:na]<br />
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for &#8220;https://localhost:8443/ssl-server-0.0.1-SNAPSHOT/hello&#8221;: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect<br />
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:312) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at com.opencodez.HttpClient.run(HttpClient.java:24) ~[classes/:na]<br />
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	&#8230; 6 common frames omitted<br />
Caused by: java.net.ConnectException: Connection refused: connect<br />
	at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.8.0_121]<br />
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) ~[na:1.8.0_121]<br />
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_121]<br />
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_121]<br />
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_121]<br />
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_121]<br />
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_121]<br />
	at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_121]<br />
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668) ~[na:1.8.0_121]<br />
	at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173) ~[na:1.8.0_121]<br />
	at sun.net.NetworkClient.doConnect(NetworkClient.java:180) ~[na:1.8.0_121]<br />
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) ~[na:1.8.0_121]<br />
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) ~[na:1.8.0_121]<br />
	at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264) ~[na:1.8.0_121]<br />
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367) ~[na:1.8.0_121]<br />
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) ~[na:1.8.0_121]<br />
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138) ~[na:1.8.0_121]<br />
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032) ~[na:1.8.0_121]<br />
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) ~[na:1.8.0_121]<br />
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) ~[na:1.8.0_121]<br />
	at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:652) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	&#8230; 10 common frames omitted</p>
<p>2020-09-14 09:13:05.873  INFO 14088 &#8212; [           main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@54a7079e: startup date [Mon Sep 14 09:10:41 EDT 2020]; root of context hierarchy<br />
2020-09-14 09:13:05.874  INFO 14088 &#8212; [           main] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown</p>
<p>These are my steps:</p>
<p>step 1:<br />
server certificate:<br />
keytool -genkey -alias MyServer -keyalg RSA -validity 1825 -keystore &#8220;MyServer.jks&#8221; -storetype JKS -dname &#8220;CN=myserver.com,OU=MyCompany Name,O=My Organization,L=My Location,ST=My State,C=My Country Short Code&#8221;  </p>
<p>step 2:<br />
keytool -exportcert -alias MyServer -keystore MyServer.jks -file MyServer.cer</p>
<p>step 3:</p>
<p>client certificate:<br />
keytool -genkey -alias MyClient -keyalg RSA -validity 1825 -keystore MyClient.jks -storetype JKS<br />
-dname &#8220;CN=client.com,OU=Client Company,O=Client,L=CLient Location,ST=Client State,C=Client Country Short Code&#8221;</p>
<p>step 4:<br />
keytool -exportcert -alias MyClient -keystore MyClient.jks -file MyClientPublic.cer</p>
<p>step 5:<br />
&#8211;Add Server certificate to client truststore<br />
C:\JDK-1.8.0.x64\jre\lib\security&gt;keytool -importcert -alias MyServer -keystore MyClient.jks -file MyServer.cer</p>
<p>step 6:<br />
&#8211;Add client certificate to server truststore<br />
C:\JDK-1.8.0.x64\jre\lib\security&gt;keytool -importcert -alias MyClient -keystore MyServer.jks -file MyClientPublic.cer</p>
<p>step 7:<br />
<a href="https://localhost:8443/ssl-server-0.0.1-SNAPSHOT/hello" rel="nofollow ugc">https://localhost:8443/ssl-server-0.0.1-SNAPSHOT/hello</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: John Smith		</title>
		<link>https://www.opencodez.com/java/implement-2-way-authentication-using-ssl.htm/comment-page-1#comment-98135</link>

		<dc:creator><![CDATA[John Smith]]></dc:creator>
		<pubDate>Mon, 14 Sep 2020 13:16:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.opencodez.com/?p=2496#comment-98135</guid>

					<description><![CDATA[I am able to run the server but when I run the client I get the following error:

Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for &quot;https://localhost:8443/ssl-server-0.0.1-SNAPSHOT/hello&quot;: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:312) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at com.opencodez.HttpClient.run(HttpClient.java:24) ~[classes/:na]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
	... 6 common frames omitted
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.8.0_121]
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) ~[na:1.8.0_121]
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_121]
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_121]
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_121]
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_121]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_121]


I changed the password to &quot;changeit&quot; instead of &quot;password&quot; and I changed SslClientApplication.java in client project to:

		System.setProperty(&quot;javax.net.debug&quot;, &quot;all&quot;);
		System.setProperty(&quot;jdk.tls.client.protocols&quot;, &quot;TLSv1.2&quot;);
		System.setProperty(&quot;https.protocols&quot;, &quot;TLSv1.2&quot;);
		System.setProperty(&quot;javax.net.ssl.trustStore&quot;, &quot;c://core-jks//MyClient.jks&quot;);
		System.setProperty(&quot;javax.net.ssl.trustStorePassword&quot;, &quot;changeit&quot;);
		System.setProperty(&quot;javax.net.ssl.keyStore&quot;,  &quot;c://core-jks//MyClient.jks&quot;);
		System.setProperty(&quot;javax.net.ssl.keyStorePassword&quot;, &quot;changeit&quot;);


Here are my certificate steps:


step 1:
server certificate:
keytool -genkey -alias MyServer -keyalg RSA -validity 1825 -keystore &quot;MyServer.jks&quot; -storetype JKS -dname &quot;CN=myserver.com,OU=MyCompany Name,O=My Organization,L=My Location,ST=My State,C=My Country Short Code&quot;  

step 2:
keytool -exportcert -alias MyServer -keystore MyServer.jks -file MyServer.cer

step 3:

client certificate:
keytool -genkey -alias MyClient -keyalg RSA -validity 1825 -keystore MyClient.jks -storetype JKS 
-dname &quot;CN=client.com,OU=Client Company,O=Client,L=CLient Location,ST=Client State,C=Client Country Short Code&quot;

step 4:
keytool -exportcert -alias MyClient -keystore MyClient.jks -file MyClientPublic.cer

step 5:
--Add Server certificate to client truststore
C:\JDK-1.8.0.x64\jre\lib\security&#062;keytool -importcert -alias MyServer -keystore MyClient.jks -file MyServer.cer

step 6:
--Add client certificate to server truststore
C:\JDK-1.8.0.x64\jre\lib\security&#062;keytool -importcert -alias MyClient -keystore MyServer.jks -file MyClientPublic.cer]]></description>
			<content:encoded><![CDATA[<p>I am able to run the server but when I run the client I get the following error:</p>
<p>Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for &#8220;https://localhost:8443/ssl-server-0.0.1-SNAPSHOT/hello&#8221;: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect<br />
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:312) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]<br />
	at com.opencodez.HttpClient.run(HttpClient.java:24) ~[classes/:na]<br />
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]<br />
	&#8230; 6 common frames omitted<br />
Caused by: java.net.ConnectException: Connection refused: connect<br />
	at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.8.0_121]<br />
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) ~[na:1.8.0_121]<br />
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_121]<br />
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_121]<br />
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_121]<br />
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_121]<br />
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_121]</p>
<p>I changed the password to &#8220;changeit&#8221; instead of &#8220;password&#8221; and I changed SslClientApplication.java in client project to:</p>
<p>		System.setProperty(&#8220;javax.net.debug&#8221;, &#8220;all&#8221;);<br />
		System.setProperty(&#8220;jdk.tls.client.protocols&#8221;, &#8220;TLSv1.2&#8221;);<br />
		System.setProperty(&#8220;https.protocols&#8221;, &#8220;TLSv1.2&#8221;);<br />
		System.setProperty(&#8220;javax.net.ssl.trustStore&#8221;, &#8220;c://core-jks//MyClient.jks&#8221;);<br />
		System.setProperty(&#8220;javax.net.ssl.trustStorePassword&#8221;, &#8220;changeit&#8221;);<br />
		System.setProperty(&#8220;javax.net.ssl.keyStore&#8221;,  &#8220;c://core-jks//MyClient.jks&#8221;);<br />
		System.setProperty(&#8220;javax.net.ssl.keyStorePassword&#8221;, &#8220;changeit&#8221;);</p>
<p>Here are my certificate steps:</p>
<p>step 1:<br />
server certificate:<br />
keytool -genkey -alias MyServer -keyalg RSA -validity 1825 -keystore &#8220;MyServer.jks&#8221; -storetype JKS -dname &#8220;CN=myserver.com,OU=MyCompany Name,O=My Organization,L=My Location,ST=My State,C=My Country Short Code&#8221;  </p>
<p>step 2:<br />
keytool -exportcert -alias MyServer -keystore MyServer.jks -file MyServer.cer</p>
<p>step 3:</p>
<p>client certificate:<br />
keytool -genkey -alias MyClient -keyalg RSA -validity 1825 -keystore MyClient.jks -storetype JKS<br />
-dname &#8220;CN=client.com,OU=Client Company,O=Client,L=CLient Location,ST=Client State,C=Client Country Short Code&#8221;</p>
<p>step 4:<br />
keytool -exportcert -alias MyClient -keystore MyClient.jks -file MyClientPublic.cer</p>
<p>step 5:<br />
&#8211;Add Server certificate to client truststore<br />
C:\JDK-1.8.0.x64\jre\lib\security&gt;keytool -importcert -alias MyServer -keystore MyClient.jks -file MyServer.cer</p>
<p>step 6:<br />
&#8211;Add client certificate to server truststore<br />
C:\JDK-1.8.0.x64\jre\lib\security&gt;keytool -importcert -alias MyClient -keystore MyServer.jks -file MyClientPublic.cer</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 64/67 objects using disk
Page Caching using disk: enhanced 
Database Caching 1/15 queries in 0.005 seconds using disk

Served from: www.opencodez.com @ 2026-05-23 02:21:39 by W3 Total Cache
-->