Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 864d1c3c3cd8df4e3a2692faf8776e05 > files > 246

db4o-doc-7.4-2.fc13.i686.rpm

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Using SSL For Client-Server Communication</title>
    <link rel="stylesheet" type="text/css" href="../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Using SSL For Client-Server Communication</h1><script>
//We attach this function to a browser object as a variable so that if multiple of these blocks are
//present on the same page, then they will simply over-write eachother with the same function instead
//of generating a naming collision.
window.WikiCodeFormattingCopyToClipboard = function copyToClipboard(sID){
	var sContent = document.getElementById(sID).innerText;
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", sContent);
	}
	else
	{
		alert("You must enable javascript access to your clipboard for this feature to work. Please referr to your browser documentation or Google search for instructions.");
	}
}
</script>
<P><FONT color=#990000>This topic applies to Java version only</FONT></P>
<P>With the default settings db4o client-server communication is not encrypted and thus can potentially be a dangerous security hole. This can be fixed with a <a href="../pluggable_sockets.html" class="wikiLink">new pluggable socket</a> client/server implementation. Let's look at a simple example - we will use SSL protocol to protect our communication channel.</P>
<P>Basically the task is to create a NativeSocketFactory implementation that will create sockets able to communicate through an encrypted channel. In Java these would be SSLServerSocket and SSLSocket.</P>
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">SecureSocketFactory.java</span></div><div class="fscCode"><pre ID="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Open_Text').style.display='inline';"/><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">/**/</span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_0_62_Open_Text"><span style="color: #008000;">/*</span><span style="color: #008000;"> Copyright (C) 2007  db4objects Inc.  </span><span style="color: #008000; text-decoration: underline;">http://www.db4o.com</span><span style="color: #008000;"> </span><span style="color: #008000;">*/</span></span><span style="color: #000000;">
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/></span><span style="color: #0000FF;">package</span><span style="color: #000000;"> com.db4odoc.ssl;
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/>
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/></span><span style="color: #0000FF;">import</span><span style="color: #000000;"> java.io.IOException;
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/></span><span style="color: #0000FF;">import</span><span style="color: #000000;"> java.net.ServerSocket;
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/></span><span style="color: #0000FF;">import</span><span style="color: #000000;"> java.net.Socket;
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/>
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/></span><span style="color: #0000FF;">import</span><span style="color: #000000;"> javax.net.ssl.SSLContext;
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/>
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/></span><span style="color: #0000FF;">import</span><span style="color: #000000;"> com.db4o.config.NativeSocketFactory;
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/>
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Open_Text').style.display='inline';"/></span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> SecureSocketFactory </span><span style="color: #0000FF;">implements</span><span style="color: #000000;"> NativeSocketFactory </span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_315_865_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>  </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> SSLContext _context;
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Open_Text').style.display='inline';"/>  </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> SecureSocketFactory(SSLContext context) </span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_397_423_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    _context </span><span style="color: #000000;">=</span><span style="color: #000000;"> context;
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>  }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Open_Text').style.display='inline';"/>  </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> ServerSocket createServerSocket(</span><span style="color: #0000FF;">int</span><span style="color: #000000;"> port) </span><span style="color: #0000FF;">throws</span><span style="color: #000000;"> IOException </span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_494_610_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    System.out.println(</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">SERVER on </span><span style="color: #000000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> port);
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> _context.getServerSocketFactory().createServerSocket(port);
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>  }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">25</span><span style="color: #000000;"><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Open_Text').style.display='inline';"/>  </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> Socket createSocket(String hostName, </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> port) </span><span style="color: #0000FF;">throws</span><span style="color: #000000;"> IOException </span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_686_800_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">26</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    System.out.println(</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">CLIENT on </span><span style="color: #000000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> port);
</span><span style="color: #008080;">27</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> _context.getSocketFactory().createSocket(hostName, port);
</span><span style="color: #008080;">28</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>  }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">29</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">30</span><span style="color: #000000;"><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Open_Text').style.display='inline';"/>  </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> Object deepClone(Object context) </span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSecureSocketFactory.Java_SecureSocketFactory.Java_622_53_843_862_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">31</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">;
</span><span style="color: #008080;">32</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>  }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">33</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">34</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>}</span></span></div></pre></div></div>
<P>In order for this class to work correctly we need to provide a correctly initialized SSLContext. For those who are not familiar with Java SSL implementation it is recommended to get acquainted with Java documentation for SSLContext, TrustManager, KeyStore and KeyManagerFactory APIs.</P>
<P>For encryption purposes we will need to create a new keystore. This can be done with the following command:</P>
<P><code>keytool -genkey -keystore SSLcert -storepass password</code></P>
<P>This command creates a file SSLcert, which contains a keystore protected by "password" password. For a test keystore you can provide any answers to the keytool questions and leave the key password the same as the keystore password. For easy access copy the SSLcert file into your projects directory.</P>
<P>Now we are ready to create a SecureSocketFactory</P>
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">SSLSocketsExample.java: <span class="fscMemberName">createSecureSocketFactory</span></span></div><div class="fscCode"><pre ID="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Open_Text').style.display='inline';"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> SecureSocketFactory createSecureSocketFactory() </span><span style="color: #0000FF;">throws</span><span style="color: #000000;"> Exception</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateSecureSocketFactory_1525_77_79_718_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    SSLContext sc;
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    </span><span style="color: #008000;">//</span><span style="color: #008000;">Create a trust manager that does not validate certificate chains</span><span style="color: #008000;">
</span><span style="color: #008080;">05</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">      TrustManager[] trustAllCerts </span><span style="color: #000000;">=</span><span style="color: #000000;"> createTrustManager();
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      </span><span style="color: #008000;">//</span><span style="color: #008000;"> Install the all-trusting trust manager</span><span style="color: #008000;">
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">    sc </span><span style="color: #000000;">=</span><span style="color: #000000;"> SSLContext.getInstance(</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">SSLv3</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    KeyStore ks </span><span style="color: #000000;">=</span><span style="color: #000000;"> KeyStore.getInstance(KEYSTORE_ID);
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      ks.load(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> FileInputStream(KEYSTORE_PATH), </span><span style="color: #0000FF;">null</span><span style="color: #000000;">);
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      KeyManagerFactory kmf </span><span style="color: #000000;">=</span><span style="color: #000000;"> KeyManagerFactory.getInstance( KeyManagerFactory.getDefaultAlgorithm() );
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      kmf.init( ks, KEYSTORE_PASSWORD.toCharArray());
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      sc.init(kmf.getKeyManagers(), trustAllCerts, </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> java.security.SecureRandom());
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> SecureSocketFactory(sc);
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>  }</span></span></div></pre></div></div>
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">SSLSocketsExample.java: <span class="fscMemberName">createTrustManager</span></span></div><div class="fscCode"><pre ID="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Open_Text').style.display='inline';"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> TrustManager[] createTrustManager()</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_50_553_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Open_Text').style.display='inline';"/>    </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> TrustManager[]</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_79_549_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Open_Text').style.display='inline';"/>            </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> X509TrustManager() </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_114_541_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Open_Text').style.display='inline';"/>                </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> java.security.cert.X509Certificate[] getAcceptedIssuers() </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_195_243_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>                }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> checkClientTrusted(
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Open_Text').style.display='inline';"/>                    java.security.cert.X509Certificate[] certs, String authType) </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_369_386_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>                }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> checkServerTrusted(
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Open_Text').style.display='inline';"/>                    java.security.cert.X509Certificate[] certs, String authType) </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_CreateTrustManager_1604_70_512_529_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>                }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>            }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>        }</span></span><span style="color: #000000;">;
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>  }</span></span></div></pre></div></div>
<P>Starting a server and opening client connections with the new socket factory is as simple as usual:</P>
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">SSLSocketsExample.java: <span class="fscMemberName">main</span></span></div><div class="fscCode"><pre ID="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Open_Text').style.display='inline';"/><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> main(String[] args) </span><span style="color: #0000FF;">throws</span><span style="color: #000000;"> Exception </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_56_498_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      </span><span style="color: #008000;">//</span><span style="color: #008000;"> Create a SecureSocketFactory for the SSL context</span><span style="color: #008000;">
</span><span style="color: #008080;">04</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">    socketFactory </span><span style="color: #000000;">=</span><span style="color: #000000;"> createSecureSocketFactory();
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    Configuration config </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4o.newConfiguration();
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    ObjectServer db4oServer </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4o.openServer(config, FILE, PORT,
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        socketFactory);
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    db4oServer.grantAccess(USER, PASSWORD);
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Open_Text').style.display='inline';"/>    </span><span style="color: #0000FF;">try</span><span style="color: #000000;"> </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_350_458_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      storeObjectsRemotely(HOST, PORT, USER, PASSWORD);
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      queryRemoteServer(HOST, PORT, USER, PASSWORD);
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Open_Text').style.display='inline';"/>    }</span></span><span style="color: #000000;"> </span><span style="color: #0000FF;">finally</span><span style="color: #000000;"> </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_Main_1784_56_467_495_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>      db4oServer.close();
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>    }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>  }</span></span></div></pre></div></div>
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">SSLSocketsExample.java: <span class="fscMemberName">storeObjectsRemotely</span></span></div><div class="fscCode"><pre ID="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Open_Text').style.display='inline';"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> storeObjectsRemotely(String host, </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> port,String user,String password) </span><span style="color: #0000FF;">throws</span><span style="color: #000000;"> IOException </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_StoreObjectsRemotely_1842_72_111_378_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    Configuration config </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4o.newConfiguration();
</span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        ObjectContainer client</span><span style="color: #000000;">=</span><span style="color: #000000;">Db4o.openClient(config, </span><span style="color: #000000;">&quot;</span><span style="color: #000000;">localhost</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">,port,user,password, socketFactory);
</span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">Fernando Alonso</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">, </span><span style="color: #000000;">89</span><span style="color: #000000;">);
</span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        client.set(pilot);
</span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        client.close();
</span><span style="color: #008080;">7</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>    }</span></span></div></pre></div></div>
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">SSLSocketsExample.java: <span class="fscMemberName">queryRemoteServer</span></span></div><div class="fscCode"><pre ID="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Open_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Closed_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Closed_Text').style.display='inline';"/><img id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Closed_Text').style.display='none'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Open_Image').style.display='inline'; document.getElementById('..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Open_Text').style.display='inline';"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> queryRemoteServer(String host, </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> port,String user,String password) </span><span style="color: #0000FF;">throws</span><span style="color: #000000;"> IOException </span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="..SslJava.ZipsSSLSocketsExample.Java_SSLSocketsExample.Java_QueryRemoteServer_1916_69_108_344_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>    Configuration config </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4o.newConfiguration();
</span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        ObjectContainer client</span><span style="color: #000000;">=</span><span style="color: #000000;">Db4o.openClient(config, </span><span style="color: #000000;">&quot;</span><span style="color: #000000;">localhost</span><span style="color: #000000;">&quot;</span><span style="color: #000000;">,port,user,password, socketFactory);
</span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        listResult(client.get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(</span><span style="color: #0000FF;">null</span><span style="color: #000000;">, </span><span style="color: #000000;">0</span><span style="color: #000000;">)));
</span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        client.close();
</span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>    }</span></span></div></pre></div></div>
</div>
    </div>
    <div id="footer">
					This revision (2) was last Modified 2007-12-28T04:09:45 by German Viscuso.
				</div>
  </body>
</html>