<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Bits and Bytes &#187; TLS</title>
	<atom:link href="http://pa55word.wordpress.com/category/tls/feed/" rel="self" type="application/rss+xml" />
	<link>http://pa55word.wordpress.com</link>
	<description>This blog is to compile the technical programming how to do's into one place in web</description>
	<lastBuildDate>Wed, 21 Jan 2009 11:48:28 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='pa55word.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/5f580b89025f635fe56532dc7947e24b?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Bits and Bytes &#187; TLS</title>
		<link>http://pa55word.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pa55word.wordpress.com/osd.xml" title="Bits and Bytes" />
		<item>
		<title>Cool Java Secure Socket Resources</title>
		<link>http://pa55word.wordpress.com/2007/11/23/cool-java-secure-socket-resources/</link>
		<comments>http://pa55word.wordpress.com/2007/11/23/cool-java-secure-socket-resources/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 14:02:23 +0000</pubDate>
		<dc:creator>sun</dc:creator>
				<category><![CDATA[TLS]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">http://pa55word.wordpress.com/2007/11/23/cool-java-secure-socket-resources/</guid>
		<description><![CDATA[ http://java.sun.com/docs/books/tutorial/networking/sockets/index.html
http://www.ibm.com/developerworks/edu/j-dw-javajsse-i.html
You require a free ibm id for this above.
http://www.ddj.com/java/184404478?pgno=1 
I will be adding more later.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pa55word.wordpress.com&blog=1492994&post=10&subd=pa55word&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p> <a HREF="http://java.sun.com/docs/books/tutorial/networking/sockets/index.html">http://java.sun.com/docs/books/tutorial/networking/sockets/index.html</a></p>
<p><a HREF="http://www.ibm.com/developerworks/edu/j-dw-javajsse-i.html">http://www.ibm.com/developerworks/edu/j-dw-javajsse-i.html</a></p>
<p>You require a free ibm id for this above.</p>
<p><a HREF="http://www.ddj.com/java/184404478?pgno=1">http://www.ddj.com/java/184404478?pgno=1 </a></p>
<p>I will be adding more later.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pa55word.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pa55word.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pa55word.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pa55word.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pa55word.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pa55word.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pa55word.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pa55word.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pa55word.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pa55word.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pa55word.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pa55word.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pa55word.wordpress.com&blog=1492994&post=10&subd=pa55word&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pa55word.wordpress.com/2007/11/23/cool-java-secure-socket-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dfd33724157102562bd013251affe66?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sunray</media:title>
		</media:content>
	</item>
		<item>
		<title>Secure Sockets in Java</title>
		<link>http://pa55word.wordpress.com/2007/11/23/secure-sockets-in-java/</link>
		<comments>http://pa55word.wordpress.com/2007/11/23/secure-sockets-in-java/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 13:56:17 +0000</pubDate>
		<dc:creator>sun</dc:creator>
				<category><![CDATA[TLS]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://pa55word.wordpress.com/2007/11/23/secure-sockets-in-java/</guid>
		<description><![CDATA[ In plain words secure sockets using javax.net.ssl package.
We need secure socket to connect to an ip and port with security. Thus Secure Socket is like a door which we need to go inside apartment whose address is its ip and door number is the port. Now how to we open the door. We need keys.
Certificates are keys which is verified and signed by some authority(Certifying Authority [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pa55word.wordpress.com&blog=1492994&post=8&subd=pa55word&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p> In plain words secure sockets using javax.net.ssl package.</p>
<p>We need secure socket to connect to an ip and port with security. Thus Secure Socket is like a door which we need to go inside apartment whose address is its ip and door number is the port. Now how to we open the door. We need keys.</p>
<p>Certificates are keys which is verified and signed by some authority(Certifying Authority &#8211; CA) as good keys.</p>
<p>Now we have more than one key. So we use a keystore. Its like key-rings holding all your keys in one place. KeyStore Class can be used to represent a certificate in java. You upload your keystore made by java keytool into this object.</p>
<p>KeyManagerFactory class does the job of managing your key ring. Give that to your SSLContextClass and from that you can get the SSLSocketFactory. Using SSLSocketFactory we finally get our SSLSocket.</p>
<p>That much code in place the problem of how to trust others keys which they(servers) send to verify themselves while communicating comes up. We will put those keys in another keystore and call it our trust store. Again put the trust store in a KeyStore object and put it a TrustManagerFactory and give it to the context.</p>
<p>Of-course the question how to get keystore and truststore with certificates is still there. <a TITLE="Quick and easy certificates for TLS" HREF="http://pa55word.wordpress.com/2007/11/23/quick-and-easy-certificates-for-tls/">Click this link for that.</a></p>
<p>The folowing method creates a secure socket with client authentication.</p>
<blockquote><p>public SSLSocket createSecureSocket(String keyStore, String keyStorePwd, String trustStore,<br />
String trustStorePwd) throws IOException {<br />
// create 2 JKS keystores for keystore and truststore<br />
KeyStore clientKeyStore = null;<br />
KeyStore clientTrustStore = null;<br />
try {<br />
clientKeyStore = KeyStore.getInstance( &#8220;JKS&#8221;);<br />
clientTrustStore = KeyStore.getInstance( &#8220;JKS&#8221;) ;<br />
} catch (KeyStoreException e) {<br />
e.printStackTrace();<br />
}<br />
//convert keystore pwd into char array and load the client keystore made with keytool into<br />
//one keystore object.<br />
char[] keyStorePwdArray = keyStorePwd.toCharArray();<br />
try {<br />
clientKeyStore.load(new FileInputStream(keyStore), keyStorePwdArray);<br />
} catch (NoSuchAlgorithmException e1) {<br />
e1.printStackTrace();<br />
} catch (CertificateException e1) {<br />
e1.printStackTrace();<br />
}<br />
//convert truststore pwd into char array and load the client truststore made with keytool into<br />
//other keystore object.<br />
char[] trustStorePwdArray = trustStorePwd.toCharArray();<br />
try {<br />
clientTrustStore.load(new FileInputStream(trustStore), trustStorePwdArray);<br />
} catch (NoSuchAlgorithmException e1) {<br />
e1.printStackTrace();<br />
} catch (CertificateException e1) {<br />
e1.printStackTrace();<br />
}<br />
// create the key manager and trust manager factories.<br />
KeyManagerFactory kmf = null;<br />
TrustManagerFactory tmf = null;<br />
try {<br />
kmf = KeyManagerFactory.getInstance( &#8220;SunX509&#8243; );<br />
tmf = TrustManagerFactory.getInstance(&#8220;SunX509&#8243;);<br />
} catch (NoSuchAlgorithmException e) {<br />
e.printStackTrace();<br />
}<br />
//load client keystore and pwd to key manager factory.<br />
try {<br />
kmf.init(clientKeyStore, keyStorePwdArray);<br />
} catch (KeyStoreException e1) {<br />
e1.printStackTrace();<br />
} catch (NoSuchAlgorithmException e1) {<br />
e1.printStackTrace();<br />
} catch (UnrecoverableKeyException e1) {<br />
e1.printStackTrace();<br />
}<br />
// load client truststore into trust manager factory.<br />
try {<br />
tmf.init(clientTrustStore);<br />
} catch (KeyStoreException e) {<br />
e.printStackTrace();<br />
}<br />
// create sslcontext object and load both the facotries into it.<br />
SSLContext ctx=null;<br />
try {<br />
ctx = SSLContext.getInstance( &#8220;TLS&#8221; );<br />
} catch (NoSuchAlgorithmException e) {<br />
e.printStackTrace();<br />
}<br />
try {<br />
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);<br />
} catch (KeyManagementException e) {<br />
e.printStackTrace();<br />
}<br />
// Get our socket factory from context and then get the socket.<br />
SSLSocketFactory factory = ctx.getSocketFactory();<br />
SSLSocket socket = (SSLSocket)factory.createSocket();<br />
return socket;<br />
}<em><br />
</em><em><br />
</em></p>
</blockquote>
<p>Now we need to open a connection.<br />
socket.connect(new InetSocketAddress(&#8220;localhost&#8221;, 9999),10000000);<br />
or<br />
SSLSocketFactory sf = sslContext.getSocketFactory();<br />
Socket socket = sf.createSocket(host, port);</p>
<p>To create a server socket use the same method but use servers keystore and truststore.<br />
Get the context object ctx.<br />
SSLServerSocketFactory ssf = ctx.getServerSocketFactory();<br />
ServerSocket ss = ssf.createServerSocket( 6660 );</p>
<p>Note : If you are really bothered by the numerous try catch statements just put the code in one try block and write catch statements at the end. I write really good <br />
system.out.printlns in catch blocks during the first attempt just to know where I am going wrong. Later I combine them.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pa55word.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pa55word.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pa55word.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pa55word.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pa55word.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pa55word.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pa55word.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pa55word.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pa55word.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pa55word.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pa55word.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pa55word.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pa55word.wordpress.com&blog=1492994&post=8&subd=pa55word&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pa55word.wordpress.com/2007/11/23/secure-sockets-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dfd33724157102562bd013251affe66?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sunray</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick and easy certificates for TLS</title>
		<link>http://pa55word.wordpress.com/2007/11/23/quick-and-easy-certificates-for-tls/</link>
		<comments>http://pa55word.wordpress.com/2007/11/23/quick-and-easy-certificates-for-tls/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 13:50:57 +0000</pubDate>
		<dc:creator>sun</dc:creator>
				<category><![CDATA[TLS]]></category>
		<category><![CDATA[certificates]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[keystore]]></category>
		<category><![CDATA[keytool]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://pa55word.wordpress.com/2007/11/23/quick-and-easy-certificates-for-tls/</guid>
		<description><![CDATA[When urgently you need some keystores and truststores to test out some security related java code this is a useful bat file to have. Copy the code below and create a bat file. run it and you got your stuff.
keytool -genkey -alias serverkeys -keyalg RSA -keystore server.k
eystore -storepass 123456 -keypass 123456 -dname &#8220;CN=localhost, OU=MYOU, O=MYORG, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pa55word.wordpress.com&blog=1492994&post=9&subd=pa55word&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When urgently you need some keystores and truststores to test out some security related java code this is a useful bat file to have. Copy the code below and create a bat file. run it and you got your stuff.</p>
<blockquote><p><em>keytool -genkey -alias serverkeys -keyalg RSA -keystore server.k<br />
eystore -storepass 123456 -keypass 123456 -dname &#8220;CN=localhost, OU=MYOU, O=MYORG, L=MYCITY, ST=M<br />
YSTATE, C=MY&#8221;</em></p>
<p><em><br />
keytool -export -alias serverkeys -keystore server.keystore -stor<br />
epass 123456 -file server.cer</em></p>
<p><em><br />
keytool -genkey -alias clientkeys  -keyalg RSA -keystore client.k<br />
eystore -storepass 123456 -keypass 123456 -dname &#8220;CN=localhost, OU=MYOU, O=MYORG, L=MYCITY, S=MY<br />
STATE, C=MY&#8221;</em></p>
<p><em><br />
keytool -export -alias clientkeys -keystore client.keystore -stor<br />
epass 123456 -file client.cer</em></p>
<p><em><br />
keytool -import -v -keystore client.truststore  -storepass 123456<br />
-file server.cer</em></p>
<p><em><br />
keytool -import -v -keystore server.truststore  -storepass 123456<br />
-file client.cer</em></p></blockquote>
<p>It generates a keystore called  server.keystore with password 123456. Then it creates server certificate server.cer.</p>
<p>Then it  generates a keystore called  client.keystore with password 123456. Creates a client certificate named client.cer</p>
<p>Next it imports server certificate into client truststore and client certificate into server truststore.</p>
<p>These are self signed certificates. Good for internal use. You can use open ssl<br />
and create certificates. But this bat file is short and sweet for immediate use.<br />
When you paste it you do have to be careful about keywords not getting split up like wordpress does.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pa55word.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pa55word.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pa55word.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pa55word.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pa55word.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pa55word.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pa55word.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pa55word.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pa55word.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pa55word.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pa55word.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pa55word.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pa55word.wordpress.com&blog=1492994&post=9&subd=pa55word&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://pa55word.wordpress.com/2007/11/23/quick-and-easy-certificates-for-tls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dfd33724157102562bd013251affe66?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sunray</media:title>
		</media:content>
	</item>
	</channel>
</rss>