<?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/"
	>

<channel>
	<title>Engwar &#187; .net</title>
	<atom:link href="http://engwar.com/tags/net/feed" rel="self" type="application/rss+xml" />
	<link>http://engwar.com</link>
	<description>Chintana Wilamuna&#039;s weblog</description>
	<lastBuildDate>Wed, 30 Nov 2011 13:28:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Creating a signed message with .Net WCF</title>
		<link>http://engwar.com/post/636?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-a-signed-message-with-net-wcf</link>
		<comments>http://engwar.com/post/636#comments</comments>
		<pubDate>Sun, 13 Nov 2011 02:59:13 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wcf]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=636</guid>
		<description><![CDATA[A step by step guide to create a signed message with .Net WCF and consume a service secured service written in Java. Service can be implemented in any language as long as it support standard WS-Security standards. In order to &#8230; <a href="http://engwar.com/post/636">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A step by step guide to create a signed message with .Net WCF and consume a service secured service written in Java. Service can be implemented in any language as long as it support standard WS-Security standards. In order to have a service running in minutes and applying security I&#8217;ll be using <a href="http://wso2.com/products/enterprise-service-bus/">WSO2 ESB</a>.</p>
<ol>
<li>Certificates. We&#8217;ll be using two certificates for signing. We&#8217;ll create a private/public keypair in the client side and import the client&#8217;s public key to server. Likewise, we&#8217;ll import server&#8217;s public key to the machine running the client.</li>
<li>First let&#8217;s create a key pair to be used in the client,
<pre>
makecert -r -pe -n "CN=mycert" -sky exchange -sv mycert.pvk mycert.cer
</pre>
<p>This will create a private and public key pair. Next we need to import this into Windows certificate store. In order to do that we need to convert our key pair to PFX format which includes both the private and the public key,</p>
<pre>
pvk2pfx -pvk mycert.pvk -spc mycert.cer -pfx mycert.pfx
</pre>
<p>Now, run mmc and add a certificate snap-in for the Local Computer. Browse into Trusted People and import mycert.pfx. Just click next when it asks for the private key password.
</li>
<li>We have set the certificates for the client. Next we have to extract server&#8217;s public key and import it into Windows certificate store. Since I&#8217;m going to use WSO2 ESB for the server side, we need to extract the public key from the Java keystore that&#8217;s being used by the ESB. Browse to &lt;ESB HOME&gt;\repository\resources\security and give the following command. Java needs to be in your PATH. When prompted type &#8220;wso2carbon&#8221; as the keystore password.
<pre>
keytool -keystore wso2carbon.jks -export -alias localhost -file localhost.cer
</pre>
<p>Import localhost.cer into Trusted People just like before.
</li>
<li>Now we need to import the client&#8217;s public key to the server. Start the ESB by double clicking wso2server.bat. Browse into https://localhost:9443 and login with admin/admin. Click Configure -&gt; Key Stores.
<p><a href="http://engwar.com/wp-content/uploads/2011/11/select-keystore.png"><img src="http://engwar.com/wp-content/uploads/2011/11/select-keystore.png" alt="" title="select-keystore" width="243" height="340" class="aligncenter size-full wp-image-639" /></a></p>
<p> Click Import Cert</p>
<p><a href="http://engwar.com/wp-content/uploads/2011/11/import-cert.png"><img src="http://engwar.com/wp-content/uploads/2011/11/import-cert.png" alt="" title="import-cert" width="242" height="55" class="aligncenter size-full wp-image-640" /></a></p>
<p> and browse and select mycert.cer we just created and click Import.</p>
<p><a href="http://engwar.com/wp-content/uploads/2011/11/browse-cert-and-import.png"><img src="http://engwar.com/wp-content/uploads/2011/11/browse-cert-and-import.png" alt="" title="browse-cert-and-import" width="512" height="115" class="aligncenter size-full wp-image-641" /></a></p>
</li>
<li>We&#8217;re done setting up certificates. Let&#8217;s create a simple secure service. Luckily ESB ships an echo service which when you send a message, echoes it back. Click Main -&gt; List (under Web Services).
<p><a href="http://engwar.com/wp-content/uploads/2011/11/select-list-ws.png"><img src="http://engwar.com/wp-content/uploads/2011/11/select-list-ws.png" alt="" title="select-list-ws" width="244" height="264" class="aligncenter size-full wp-image-642" /></a></p>
<p>Here you see a list of web services. In front of the echo service you&#8217;ll see a link saying &#8220;Unsecured&#8221;. </p>
<p><a href="http://engwar.com/wp-content/uploads/2011/11/unsecured-echo.png"><img src="http://engwar.com/wp-content/uploads/2011/11/unsecured-echo.png" alt="" title="unsecured-echo" width="518" height="54" class="aligncenter size-full wp-image-643" /></a></p>
<p>Click it and select &#8220;yes&#8221; from the drop down to apply security for the echo service.</p>
<p><a href="http://engwar.com/wp-content/uploads/2011/11/enable-security.png"><img src="http://engwar.com/wp-content/uploads/2011/11/enable-security.png" alt="" title="enable-security" width="214" height="67" class="aligncenter size-full wp-image-644" /></a></p>
<p>Here you&#8217;ll see a list of pre-configured security scenarios. We&#8217;ll be using number 2, Non-Repudiation under Basic Scenarios. Select it and click Next.</p>
<p><a href="http://engwar.com/wp-content/uploads/2011/11/select-non-repudiation.png"><img src="http://engwar.com/wp-content/uploads/2011/11/select-non-repudiation.png" alt="" title="select-non-repudiation" width="229" height="136" class="aligncenter size-full wp-image-645" /></a></p>
<p>Select wso2carbon.jks as a trusted keystore and click Finish. Echo service is secured now.</p>
<p><a href="http://engwar.com/wp-content/uploads/2011/11/select-trusted-keystore.png"><img src="http://engwar.com/wp-content/uploads/2011/11/select-trusted-keystore.png" alt="" title="select-trusted-keystore" width="166" height="186" class="aligncenter size-full wp-image-646" /></a>
</li>
<li>We created and setup certificates and now have a secured service. Open up Visual Studio and create a new console application. You can create any kind of project but I&#8217;d prefer to create console apps for testing these type of scenarios.</li>
<li>Add a Service Reference to your project. WSDL file for the service is located at http://localhost:8280/services/echo?wsdl</li>
<li>For the binding that you&#8217;ll be using you have to configure security,
<pre class="prettyprint ">
&lt;security defaultAlgorithmSuite=&quot;Default&quot; authenticationMode=&quot;MutualCertificateDuplex&quot;
    requireDerivedKeys=&quot;false&quot; securityHeaderLayout=&quot;Lax&quot; includeTimestamp=&quot;true&quot;
    keyEntropyMode=&quot;CombinedEntropy&quot; messageProtectionOrder=&quot;SignBeforeEncrypt&quot;
    messageSecurityVersion=&quot;Default&quot; requireSignatureConfirmation=&quot;false&quot;&gt;
&lt;localClientSettings cacheCookies=&quot;true&quot; detectReplays=&quot;true&quot;
    replayCacheSize=&quot;900000&quot; maxClockSkew=&quot;00:05:00&quot; maxCookieCachingTime=&quot;Infinite&quot;
    replayWindow=&quot;00:05:00&quot; sessionKeyRenewalInterval=&quot;10:00:00&quot;
    sessionKeyRolloverInterval=&quot;00:05:00&quot; reconnectTransportOnFailure=&quot;true&quot;
    timestampValidityDuration=&quot;00:05:00&quot; cookieRenewalThresholdPercentage=&quot;60&quot; /&gt;
&lt;localServiceSettings detectReplays=&quot;true&quot; issuedCookieLifetime=&quot;10:00:00&quot;
    maxStatefulNegotiations=&quot;128&quot; replayCacheSize=&quot;900000&quot; maxClockSkew=&quot;00:05:00&quot;
    negotiationTimeout=&quot;00:01:00&quot; replayWindow=&quot;00:05:00&quot; inactivityTimeout=&quot;00:02:00&quot;
    sessionKeyRenewalInterval=&quot;15:00:00&quot; sessionKeyRolloverInterval=&quot;00:05:00&quot;
    reconnectTransportOnFailure=&quot;true&quot; maxPendingSessions=&quot;128&quot;
    maxCachedCookies=&quot;1000&quot; timestampValidityDuration=&quot;00:05:00&quot; /&gt;
&lt;secureConversationBootstrap /&gt;
&lt;/security&gt;
</pre>
</li>
<li>Your actual service should looks like this,
<pre class="prettyprint ">
static void Main(string[] args)
{
    svc.echoPortTypeClient echo = new svc.echoPortTypeClient(&quot;echoHttpSoap11Endpoint&quot;);

    echo.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
       System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine,
       System.Security.Cryptography.X509Certificates.StoreName.TrustedPeople,
       System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName, &quot;localhost&quot;);

    echo.ClientCredentials.ClientCertificate.SetCertificate(
        System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine,
        System.Security.Cryptography.X509Certificates.StoreName.TrustedPeople,
        System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName, &quot;mycert&quot;);

    System.Console.WriteLine(echo.echoString(&quot;hello&quot;));
    System.Console.ReadLine();
}
</pre>
<p>Note that we set the correct service and client certificates. As you can see I&#8217;m using an HTTP endpoint. This is useful to test the messages going through a tool like <a href="http://ws.apache.org/commons/tcpmon/">TCPMon</a>. When you have the scenario working you can just switch to the HTTPS endpoint.
</li>
</ol>
<p>Useful references,</p>
<ul>
<li>Various ways to create private/public keypairs &#8211; <a href="http://code.google.com/apis/apps/articles/sso-keygen.html">http://code.google.com/apis/apps/articles/sso-keygen.html</a></li>
<li>Makecert reference &#8211; <a href="http://msdn.microsoft.com/en-us/library/bfsktky3%28v=VS.100%29.aspx">http://msdn.microsoft.com/en-us/library/bfsktky3%28v=VS.100%29.aspx</a></li>
<li>SecurityBindingElement Authentication Modes &#8211; <a href="http://msdn.microsoft.com/en-us/library/aa751836.aspx">http://msdn.microsoft.com/en-us/library/aa751836.aspx</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/636/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using WSAS business service with .Net trader client</title>
		<link>http://engwar.com/post/264?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-wsas-business-service-with-net-trader-client</link>
		<comments>http://engwar.com/post/264#comments</comments>
		<pubDate>Thu, 11 Feb 2010 06:29:03 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[stonehenge]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=264</guid>
		<description><![CDATA[Stonehenge is an Apache project started to demonstrate interoperability between different Web services platforms. Until we get this into the Stonehenge documentation, this is to record how to configure .Net trader client (a web interface written in .Net and is &#8230; <a href="http://engwar.com/post/264">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://incubator.apache.org/stonehenge/">Stonehenge</a> is an Apache project started to demonstrate interoperability between different Web services platforms. Until we get this into the Stonehenge documentation, this is to record how to configure .Net trader client (a web interface written in .Net and is operating in the presentation layer) to talk to business service written using Java and is hosted in <a href="http://wso2.org/projects/wsas/java">WSAS</a>. Prerequisites and installation steps can be found in the <a href="http://cwiki.apache.org/STONEHENGE/">Stonehenge wiki</a>.</p>
<p>IMO (also I&#8217;ve raised this issue numerous times in the Stonehenge mailing list) problem with .Net WCF code we have now in Stonehenge defines bindings to each and every endpoint. Currently Stonehenge .Net trader client program can talk to business services implemented in .Net, Java (deployed in WSO2 WSAS and <a href="https://metro.dev.java.net/">Sun Metro</a>) and PHP (implemented using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>). Each of these implementations runs on a different port and is having their own URL that they&#8217;re exposing the services. When there is a new implementation of the business service using a different framework, in order to point the .Net trader client program to talk to this new business service we have to add a binding into the trader client configuration with a binding specific to that. This, IMHO, defeats the whole purpose of Web services. When you compare .Net WCF to WSO2 Web services frameworks, in the WSO2 family of open source frameworks for many languages, only need the end point. When you want to talk to a different service with similar semantics, you just change the end point URL and everything else just work. There&#8217;s no &#8220;boilerplate&#8221; configuration necessary. That&#8217;s loose coupling. Anyhoo, back to the steps,</p>
<ol>
<li>Open SQL Management Studio</li>
<li>Connect to your StockTraderDB database</li>
<li>Open up <code>ClientToBs</code> table and make sure <code>DOTNET_CLIENT</code> is using <code>DOTNET_BS</code></li>
<li>Open up <code>Service</code> table and change the URL of <code>DOTNET_BS</code> to <code>http://localhost:9763/services/TradeServiceWsas</code> </li>
<li>Open <code>Web.config</code> in <code><stocktrader>\dotnet\trader_client\Trade</code> and add <code>requireSignatureConfirmation="false"</code> to line 99. After the change the line should look like the following,
<p><code>messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10" requireSignatureConfirmation="false"></code> </li>
<li><a href="http://cwiki.apache.org/STONEHENGE/stonehenge-php-and-wsas-stocktrader-installation-guide.html#StonehengePHPandWSASStocktraderInstallationGuide-wsas">Build WSAS trunk</a></li>
<li>Start WSAS by running <code>&lt;WSAS dir&gt;\bin\wso2server.bat</code>
<li>Import BS.jks and OPS.jks in <code>&lt;stonehenge trunk&gt;\stocktrader\wsas\resources\conf</code>. Go to https://localhost:9443/carbon  and login as admin. Username: admin, password: admin.</li>
<li>Click on Key Stores -&gt; Add New Key Store. For BS.jks password is &#8216;yyy&#8217;. For OPS.jks password is &#8216;password&#8217;.</li>
<li>Start .Net services by running <code>RunServices.bat </code></li>
<li>Login to .Net trader client by going to http://localhost/trade and tryout the operations </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/264/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

