<?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>Dimuthu's Blog &#187; security</title>
	<atom:link href="http://www.dimuthu.org/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 07 Jul 2010 12:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>SOA Summer School From WSO2</title>
		<link>http://www.dimuthu.org/blog/2009/06/15/soa-summer-school-from-wso2/</link>
		<comments>http://www.dimuthu.org/blog/2009/06/15/soa-summer-school-from-wso2/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 03:47:33 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Governance]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[BPM]]></category>
		<category><![CDATA[enterprise]]></category>
		<category><![CDATA[esb]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wso2]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=987</guid>
		<description><![CDATA[Are you curious What SOA is? Or How SOA revolutionize Enterprise technologies in recent times? Here is a great opportunity to you. WSO2 is hosting a SOA Summer School for Free, starting from 18th June. It will enlighten you on different aspects of SOA like SOA in Enterprise, Scalable SOA, SOA with Security, SOA Governance, [...]]]></description>
			<content:encoded><![CDATA[<p>Are you curious What SOA is? Or How SOA  revolutionize Enterprise technologies in recent times? Here is a great opportunity to you.</p>
<p>WSO2 is hosting a SOA Summer School for Free, starting from 18th June. It will enlighten you on different aspects of SOA like SOA in Enterprise, Scalable SOA, SOA with Security, SOA Governance, SOA in ESBS, BPMs and many more.</p>
<p>For more details visit the official page for the WSO2 SOA Summer School in here, <a href="http://wso2.org/training">http://wso2.org/training</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/06/15/soa-summer-school-from-wso2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security Considerations in Firefox When Accessing Different Domains</title>
		<link>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 18:14:57 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[domains]]></category>
		<category><![CDATA[external domains]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=843</guid>
		<description><![CDATA[If you are a web developer you may have experienced that there are many situations that you need to access remote domains for data sources. For an example if you are building a weather mashup, you may like to connect to some weather forecasting services like  http://www.weather.gov or http://weather.cnn.com/weather/forecast.jsp. Mostly these services are very simple, [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a web developer you may have experienced that there are many situations that you need to access remote domains for data sources. For an example if you are building a weather mashup, you may like to connect to some weather forecasting services like  <a href="http://www.weather.gov">http://www.weather.gov</a> or <a href="http://weather.cnn.com/weather/forecast.jsp">http://weather.cnn.com/weather/forecast.jsp</a>. Mostly these services are very simple, so you can build these services from Javascript  itself. (FYI you can use the blog post, I wrote sometime back, <a href="http://www.dimuthu.org/blog/2008/12/11/calling-simple-web-services-from-javascript/">Calling Simple Web Services From Javascript</a>.) But browsers doesn&#8217;t make it this much straight forward.</p>
<p>For an example if you try running the following code, which basically do a simple AJAX call to an external domain,</p>
<pre class="javascript">    <span style="font-style: italic; color: #009900;">// some external domain</span>
    <span style="font-weight: bold; color: #003366;">var</span> url = <span style="color: #3366cc;">"http://test.dimuthu.org"</span>;

    <span style="font-style: italic; color: #009900;">// doing the ajax call</span>
    <span style="font-weight: bold; color: #003366;">var</span> req = <span style="font-weight: bold; color: #003366;">new</span> XMLHttpRequest<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    req.<span style="color: #000066;">open</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"GET"</span>, url, <span style="font-weight: bold; color: #003366;">true</span><span style="color: #66cc66;">)</span>;
    req.<span style="color: #006600;">onreadystatechange</span> = <span style="font-weight: bold; color: #003366;">function</span> <span style="color: #66cc66;">(</span>e<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="font-weight: bold; color: #000066;">if</span> <span style="color: #66cc66;">(</span>req.<span style="color: #006600;">readyState</span> == <span style="color: #cc0000;">4</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
            <span style="font-weight: bold; color: #000066;">if</span><span style="color: #66cc66;">(</span>req.<span style="color: #000066;">status</span> == <span style="color: #cc0000;">200</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
                <span style="color: #000066;">alert</span><span style="color: #66cc66;">(</span>req.<span style="color: #006600;">responseText</span><span style="color: #66cc66;">)</span>;
            <span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">}</span>
    <span style="color: #66cc66;">}</span>

    req.<span style="color: #006600;">send</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">null</span><span style="color: #66cc66;">)</span>;</pre>
<p>You will get a security exception from the Firefox (opera too gives a similar exception).</p>
<pre><span style="color: #ff0000;">uncaught exception: Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)</span></pre>
<p>In order to avoid this, you have do some special work.</p>
<ol>
<li>You need to add the following code before doing any AJAX request to external domains, This will give the script special privileges to access any domain through XMLHttpRequest object.
<pre class="javascript">    <span style="font-weight: bold; color: #000066;">try</span> <span style="color: #66cc66;">{</span>
        netscape.<span style="color: #006600;">security</span>.<span style="color: #006600;">PrivilegeManager</span>.<span style="color: #006600;">enablePrivilege</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"UniversalBrowserRead"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span> <span style="font-weight: bold; color: #000066;">catch</span> <span style="color: #66cc66;">(</span>e<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="color: #000066;">alert</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"Permission UniversalBrowserRead denied."</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span></pre>
</li>
<li> If your script always jump to the exception, you have to configure your browser to allow the above setting. You can do this by going to the &#8220;about:config&#8221; page in Firefox (Just type the &#8220;about:config&#8221; in the url field and hit Enter) where it shows a list of configurations, there you need to set &#8220;signed.applets.codebase_principal_support&#8221; field to &#8220;true&#8221;. By default this field is set to false in Firefox 3.0</li>
</ol>
<p>After you completed above 2 steps, the page will show you an warning message saying that it is asking more privileges, in which the client have to click the &#8220;allow&#8221; button to continue.</p>
<p>This procedure is not much difficult to setup, but still it will be really painful for an average user, so it is better you avoid this as much as possible in your code.</p>
<p>The main reason this special setup is arranged in Firefox (and most of the other browsers) is attackers can run malicious scripts in some page which you trust, (for an example from one of your email message) and send your private data to some other domain that you don&#8217;t know and don&#8217;t trust.</p>
<p>Apart from XMLHttpRequest another famous way of accessing different domains from a web page is using framesets or iframes. using this technique, You can show an external web page inside yours as it is one part of that.</p>
<p>Before Firefox 3.0 and IE 7.0 you were able to change that external page (appearance or the content) according to your need when it is shown in a frame or iframe. This was possible to do by manipulating the DOM of that external page. But with Firefox 3.0 and IE 7.0 it is impossible. That is you still you can show an external page inside your web page, but you can&#8217;t change anything of it even it shows inside your page. Because it doesn&#8217;t allow you to access the DOM of that external page. See this issue is discussed in details at here, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=397828">https://bugzilla.mozilla.org/show_bug.cgi?id=397828</a></p>
<p>With this improvement, you can&#8217;t call the <a href="http://developer.mozilla.org/en/docs/DOM:window.document">window.document</a> if the page of the window is from external domain.</p>
<p>The reason to this limitation is apparent, if you ever thought of modifying external pages and put it in your web page, you will be able feel many security holes in there. You can show some web based email login page in one of iframe, and fool some users. If that web based email application is not changed by the iframe container, it won&#8217;t be a problem, but how it is changed to submit your username, password to the parent site by updating the submit event (onclick attribute) of the DOM of that external page.</p>
<p>In fact Firefox and most of the browsers are trying to protect your from all these security attacks by restricting lot of functionalities of the browsers. They are doing what they can do it in the client side, but you don&#8217;t know what exactly happens in the server side since it is always a black box. The all the restriction mentioned above (i.e. accessing remote services, changing and showing an external web page) can be done in very simple PHP or .NET code in server side. So it is right that you should use the right tools, but more important thing is you are aware of these attacks and you selectively browse web while avoiding them</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/22/security-considerations-in-firefox-when-accessing-different-domains/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sending Encrypted Binary Messages With PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 17:51:04 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Attachment]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[MIME]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[policy]]></category>
		<category><![CDATA[secuirty token]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=797</guid>
		<description><![CDATA[Web services has made the communication between heterogeneous environments (say PHP with .NET  or Java) a reality. It has defines standards for communicate not only with texts but also with binaries. And more importantly you can keep these communication confidential using encrypted messages according to your requirement. In this post, we will look at how [...]]]></description>
			<content:encoded><![CDATA[<p>Web services has made the communication between heterogeneous environments (say PHP with .NET  or Java) a reality. It has defines standards for communicate not only with texts but also with binaries. And more importantly you can keep these communication confidential using encrypted messages according to your requirement. In this post, we will look at how we can implement such a system with PHP in one side.</p>
<p>In web services we can send/receive binary messages in two basic forms.</p>
<ol>
<li>Setting the binary inside the SOAP message. &#8211; Binary should be converted to base64 to make sure the SOAP body contains only texts. Since base64 converted data span longer than the binary data, we call this form as non-optimized way of sending binaries.</li>
<li>Setting the binary outside the SOAP message &#8211; Binary would be sent as a MIME part in the message. And some element inside SOAP body keeps a reference to the binary using the MIME id. MTOM is a standard for referencing the MIME from inside the SOAP body. Since the binary is encoded, this will keep the message optimum with the binaries.</li>
</ol>
<p>In <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> you can use any of these methods as you prefer. Lets forget about the encryption for now. We will check how we can send binaries in both of the above mentioned forms.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// first the request xml. Note tht xop:Include element that is referring the attachment with the id "myid1".</span>
<span style="color: #0000ff;">$reqPayloadString</span> = &lt;&lt;&lt;XML
&lt;ns1:upload xmlns:ns1=<span style="color: #ff0000;">"http://wso2.org/wsfphp/samples/mtom"</span>&gt;
               &lt;ns1:fileName&gt;test.jpg&lt;/ns1:fileName&gt;
               &lt;ns1:image xmlmime:contentType=<span style="color: #ff0000;">"image/jpeg"</span> xmlns:xmlmime=<span style="color: #ff0000;">"http://www.w3.org/2004/06/xmlmime"</span>&gt;
                  &lt;xop:<span style="color: #b1b100;">Include</span> xmlns:xop=<span style="color: #ff0000;">"http://www.w3.org/2004/08/xop/include"</span> href=<span style="color: #ff0000;">"cid:myid1"</span>&gt;&lt;/xop:Include&gt;
               &lt;/ns1:image&gt;
&lt;/ns1:upload&gt;
XML;

try <span style="color: #66cc66;">{</span>
    <span style="color: #0000ff;">$f</span> = <a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"my_binary_file.jpg"</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// here in the attachments option we define the binaries</span>
    <span style="font-style: italic; color: #808080;">// corresponding to the id defined in the above XML</span>
    <span style="color: #0000ff;">$reqMessage</span> = <span style="font-weight: bold; color: #000000;">new</span> WSMessage<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$reqPayloadString</span>,
                                <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/simple_upload_service.php"</span>,
                                      <span style="color: #ff0000;">"action"</span> =&gt; <span style="color: #ff0000;">"http://wso2.org/upload"</span>,
                                      <span style="color: #ff0000;">"attachments"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"myid1"</span> =&gt; <span style="color: #0000ff;">$f</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// creating the WSClient</span>
    <span style="font-style: italic; color: #808080;">// here the option useMTOM will decide whether the</span>
    <span style="font-style: italic; color: #808080;">// attachment is set MTOM or base64</span>
    <span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useWSA"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                                 <span style="color: #ff0000;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// sending the message and retrieving the response</span>
    <span style="color: #0000ff;">$resMessage</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$reqMessage</span><span style="color: #66cc66;">)</span>;

    <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Response = %s <span style="font-weight: bold; color: #000099;">\\</span>n"</span>, <span style="color: #0000ff;">$resMessage</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

<span style="color: #66cc66;">}</span> catch <span style="color: #66cc66;">(</span>Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$e</span> instanceof WSFault<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Soap Fault: %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>, <span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">Reason</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span>
        <a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Message = %s<span style="font-weight: bold; color: #000099;">\\</span>n"</span>,<span style="color: #0000ff;">$e</span>-&gt;<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
    <span style="color: #66cc66;">}</span>
<span style="color: #66cc66;">}</span></pre>
<p>As mentioned in the inline comment we can choose the preferred form of sending binary using the &#8220;useMTOM&#8221; option. if it is true, the binary is set as a MTOM, (referencing from the body) or if it is set false, the binary will be set as a base64 binary within the SOAP body.<br />
To encrypt the message you only need to write few additional lines. First you define your policy that you need to encrypt this message using a WSPolicy object. Then the security token including the service public key and your private key. You need to give these two option as a constructor argument in WSClient. Here is that little additional code you need to write to add the encryption.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">// loading the keys</span>
    <span style="color: #0000ff;">$rec_cert</span> = ws_get_cert_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"receiving_server.cert"</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$pvt_key</span> = ws_get_key_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"my_private_key.pem"</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// here we defines the policies and create WSPolicy object</span>
    <span style="color: #0000ff;">$sec_array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"encrypt"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                       <span style="color: #ff0000;">"algorithmSuite"</span> =&gt; <span style="color: #ff0000;">"Basic256Rsa15"</span>,
                       <span style="color: #ff0000;">"securityTokenReference"</span> =&gt; <span style="color: #ff0000;">"IssuerSerial"</span><span style="color: #66cc66;">)</span>;

    <span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"security"</span> =&gt; <span style="color: #0000ff;">$sec_array</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// defining Security Tokens</span>
    <span style="color: #0000ff;">$sec_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"privateKey"</span> =&gt; <span style="color: #0000ff;">$pvt_key</span>,
                                           <span style="color: #ff0000;">"receiverCertificate"</span> =&gt; <span style="color: #0000ff;">$rec_cert</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">// modifing WSClient with adding WSPolicy and WSSecurityToken object</span>
    <span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useWSA"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                                 <span style="color: #ff0000;">"useMTOM"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                                 <span style="color: #ff0000;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>,
                                 <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>You can implement the receiving side of the message similar to the sending side that we just described above. The most important thing is it doesn&#8217;t need to be written in PHP. It can be a Java code or .NET code.If you already have web services that use encrypted binary messaging, the above php code can be use out of the box to communicate with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/14/sending-encrypted-binary-messages-with-php-web-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Signing SOAP Headers In PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/11/18/signing-soap-headers-in-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/18/signing-soap-headers-in-php-web-services/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 16:27:13 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[message id]]></category>
		<category><![CDATA[sign]]></category>
		<category><![CDATA[signature]]></category>
		<category><![CDATA[ws-addressing]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=638</guid>
		<description><![CDATA[Non-Repudiation and Integrity are two main security issues addressed by signing a message. If you are writing a web service or a service consumer in PHP you can use the WSF/PHP toolkit to sign messages. Here is how you can sign a SOAP request message. // loading the keys $my_cert = ws_get_cert_from_file("client_certificate.cert"); $my_key = ws_get_key_from_file("client_private_key.pem"); [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Non-repudiation">Non-Repudiation</a> and Integrity are two main security issues addressed by signing a message. If you are writing a web service or a service consumer in PHP you can use the <a href="http://wso2.org/projects/wsf/php">WSF/PHP toolkit</a> to sign messages.</p>
<p>Here is how you can sign a SOAP request message.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// loading the keys</span>
<span style="color: #0000ff;">$my_cert</span> = ws_get_cert_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"client_certificate.cert"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$my_key</span> = ws_get_key_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"client_private_key.pem"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$rec_cert</span> = ws_get_cert_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"server_certificate.cert"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// preparing the policy array</span>
<span style="color: #0000ff;">$sec_array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"sign"</span>=&gt;TRUE,
                   <span style="color: #ff0000;">"algorithmSuite"</span> =&gt; <span style="color: #ff0000;">"Basic256Rsa15"</span>,
                   <span style="color: #ff0000;">"securityTokenReference"</span> =&gt; <span style="color: #ff0000;">"IssuerSerial"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"security"</span>=&gt;<span style="color: #0000ff;">$sec_array</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// preparing the security_token</span>
<span style="color: #0000ff;">$sec_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"privateKey"</span> =&gt; <span style="color: #0000ff;">$my_key</span>,
                                       <span style="color: #ff0000;">"certificate"</span> =&gt; <span style="color: #0000ff;">$my_cert</span>,
                                       <span style="color: #ff0000;">"receiverCertificate"</span> =&gt; <span style="color: #0000ff;">$rec_cert</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// create the client using the policy and sec token + option ws-addressing</span>
<span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"useWSA"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                              <span style="color: #ff0000;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>,
                              <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// invoke the request				</span>
<span style="color: #0000ff;">$resMessage</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$reqMessage</span><span style="color: #66cc66;">)</span>;</pre>
<p>Although I&#8217;ve not shown in the above code, you should always wrap the requesting code inside a try/catch block specially when there are security tokens in your message. Because whenever security test is failed the server will send a SOAP fault, and the client is expected to handle that.</p>
<p>Similarity you can write a service that accept only signing messages with the same policy and security tokens. But this time your security token contains the private key and the certificate of the server. And for service you create WSService instance (similarity to  WSClient) and feed these options.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">// loading the keys and create the security token</span>
<span style="color: #0000ff;">$cert</span> = ws_get_cert_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"server_certificate.cert"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$pvt_key</span> = ws_get_key_from_file<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"server_private_key.pem"</span><span style="color: #66cc66;">)</span>

<span style="color: #0000ff;">$sec_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"privateKey"</span> =&gt; <span style="color: #0000ff;">$pvt_key</span>,
                                       <span style="color: #ff0000;">"certificate"</span> =&gt; <span style="color: #0000ff;">$cert</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// policy is declared similar to earlier example</span>

<span style="color: #0000ff;">$sec_array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"sign"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                    <span style="color: #ff0000;">"algorithmSuite"</span> =&gt; <span style="color: #ff0000;">"Basic256Rsa15"</span>,
                    <span style="color: #ff0000;">"securityTokenReference"</span> =&gt; <span style="color: #ff0000;">"KeyIdentifier"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"security"</span>=&gt;<span style="color: #0000ff;">$sec_array</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// create a WSService instance and feed the options</span>
<span style="color: #0000ff;">$svr</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
                           <span style="color: #ff0000;">"actions"</span> =&gt; <span style="color: #0000ff;">$actions</span>,
                           <span style="color: #ff0000;">"policy"</span> =&gt; <span style="color: #0000ff;">$policy</span>,
                           <span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$sec_token</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p>With this code you will only be able to sign the payload of a SOAP request. Payload is what stays inside the soap body part which contain the actual data of your business. So in most of the case, what you want is integrity of your business data, so this will satisfy your need.</p>
<p>But there can be situation you want to sign SOAP headers which are outside the SOAP body. SOAP headers contain meta data of the message. For an example when you sign a message, the SOAP headers could carry the signature information and the certificates.</p>
<p>One example of the use of signing SOAP headers is replay detection. (I&#8217;ve written about<a href="http://www.dimuthu.org/blog/2008/11/17/detect-replay-attacks-in-to-your-php-web-service/"> replay detection on a early blog</a>). in SOAP, replays can be detected using &#8216;message id&#8217;s which are transferred through the WS-addressing SOAP headers. But interceptors can change the message ids and send it as a unique message which will eventually cause to fail the replay detection. But if you sign the &#8216;message id&#8217; (i.e. WS-Addressing headers) the intruders will not be able to do the trick since they can not recreate the signature for the changed content.</p>
<p>Anyway you can not set your requirement to sign the soap headers, just using a PHP array as it has done in the above examples. Rather you have to declare it using a policy file compliant to WS-SecurityPolicy specification. I.e instead of using a PHP array to create a WSPolicy instance like this,</p>
<pre class="php"><span style="color: #0000ff;">$sec_array</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"sign"</span>=&gt;TRUE,
                    <span style="color: #ff0000;">"algorithmSuite"</span> =&gt; <span style="color: #ff0000;">"Basic256Rsa15"</span>,
                    <span style="color: #ff0000;">"securityTokenReference"</span> =&gt; <span style="color: #ff0000;">"IssuerSerial"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"security"</span>=&gt;<span style="color: #0000ff;">$sec_array</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>You can create the WSPolicy instance directly using the policy file,</p>
<pre class="php"><span style="color: #0000ff;">$policy_xml</span> = <a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"policy.xml"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$policy_xml</span><span style="color: #66cc66;">)</span>;</pre>
<p>And inside the policy file, you can declare your requirements, policies. Here is how I say I want to sign all my WS-Addressing headers.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sp:SignedParts</span> <span style="color: #000066;">xmlns:sp</span>=<span style="color: #ff0000;">"http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;sp:Header</span> <span style="color: #000066;">Namespace</span>=<span style="color: #ff0000;">"http://www.w3.org/2005/08/addressing"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/sp:SignedParts<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Note that here the namespace &#8220;http://www.w3.org/2005/08/addressing&#8221; is the namespace used in the Addressing headers. So I instruct to sign headers containing that namespace in order to sign the &#8216;message id&#8217; inside the WS-Addressing headers. You can visit a comlete policy file with the declarations of signed part from <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fsigning%2Fpolicy_file_based%2Fpolicy.xml">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/18/signing-soap-headers-in-php-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect Replay Attacks In to Your PHP Web Service</title>
		<link>http://www.dimuthu.org/blog/2008/11/17/detect-replay-attacks-in-to-your-php-web-service/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/17/detect-replay-attacks-in-to-your-php-web-service/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 17:47:11 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[replay detect]]></category>
		<category><![CDATA[replay detection]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=631</guid>
		<description><![CDATA[Replay attack is a common kind of attack, the hackers are using to break the security of a web service. If you can intercept one soap message while it is transferring through the wire, you can replay that message to the server again and again. Since the original message may have already encrypted, signed and [...]]]></description>
			<content:encoded><![CDATA[<p>Replay attack is a common kind of attack, the hackers are using to break the security of a web service.</p>
<p>If you can intercept one soap message while it is transferring through the wire, you can replay that message to the server again and again. Since the original message may have already encrypted, signed and contain valid authentication credentials the replaying messages will also be able to pass all the security tests and fool the server and do enormous damages to the business. For an example think of replying a soap message that a client is conducting a payment with a e-commerce service. The service may tend to charge the client multiple times for each request which break the integrity of the business.</p>
<p>So it is no doubt when ever you thinking of designing an enterprise web service application, you should give attention to &#8216;Replay Detection&#8217; more seriously.</p>
<p>One solution is you can handle the replay detection inside the business logic itself. If you do this for the above mentioned e-commerce like services, you will keep all the session ids and make sure only one payment is possible for one session. But this may need some really careful design of the application logic.</p>
<p>The other solution is to let your web service framework to handle the &#8216;Replay Detection&#8217;. That will clearly separate the security aspects from the business aspects of your service. And it will give you more flexibility in configuring your security requirements. And the other advantage is it will detect &#8216;Replay Attacks&#8217; well before hitting the business logic, making the web service perform well.</p>
<p><a href="http://wso2.org/projects/wsf/php">WSF/PHP </a>allows you to detect replay attacks using WS-Addressing and WS-Username token headers. WS-Addressing headers contains a message id which can be considered as unique to a soap message and ws-security headers contains created time of the message which can be used to calculate the age of the message and derive its validity.</p>
<p>WSF/PHP provide web service developer a callback with the &#8216;message id&#8217; and the &#8216;message created time&#8217;  per each message. In the callback you can store this message id and created time in a database, and check them against all the incoming soap messages. If it found duplicate entries, you can consider it as a replay attack.</p>
<p>Here is an example draft of the above scenario written using WSF/PHP.</p>
<pre class="php"><span style="font-style: italic; color: #808080;">/* replay detection callback */</span>
<span style="font-weight: bold; color: #000000;">function</span> replay_detect_callback<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$msg_id</span>, <span style="color: #0000ff;">$time_created</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">/* Here is the pseudo code of the logic

    query for the $msg_id and $time_created for the database.
    if already exist
      return FALSE;
    else
      Insert message id and time created to the database
    return TRUE */</span>
<span style="color: #66cc66;">}</span>

<span style="color: #0000ff;">$security_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="font-style: italic; color: #808080;"> </span>
                      <span style="color: #ff0000;">"replayDetectionCallback"</span> =&gt; <span style="color: #ff0000;">"replay_detect_callback"</span>,
                      <span style="color: #ff0000;">"enableReplayDetect"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,<span style="color: #66cc66;">
                      </span><span style="font-style: italic; color: #808080;">/* Other tokens */</span><span style="color: #66cc66;"> </span><span><span style="color: #66cc66;">)</span></span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"securityToken"</span> =&gt; <span style="color: #0000ff;">$security_token</span>,<span style="color: #66cc66;">
                      </span><span style="font-style: italic; color: #808080;">/* Other options*/</span><span style="color: #66cc66;"> </span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></pre>
<p>So if you use this code in the service you can happily detect any replays of an old message and avoid possible damages. But remember this security check will work only if the replaying message contain the same message id and the created time as the original one. It is possible that an intruder not only intercept the message, but also change these fields and replay it in to your server. Such replays will not be detected from this code.</p>
<p>The solution is to sign each SOAP requests. If a client sign a message with his private key, the server can confirm that the message is not altered while it is on the wire. So if intruder replay a signed message, either it will fail the replay detection test (if it is replaying without changing the message id and created time) or it will fail validating the signature (if the message id and the created time is altered).</p>
<p>So if you implement a replay detection test with a signature test, you can eliminate all the replay attacks to your service (at least theoretically <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/17/detect-replay-attacks-in-to-your-php-web-service/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Test Cases Explained</title>
		<link>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 19:27:10 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[phpt]]></category>
		<category><![CDATA[reliable messaging]]></category>
		<category><![CDATA[rm]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[test-suit]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[wsdl generation]]></category>
		<category><![CDATA[wsdl mode]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=594</guid>
		<description><![CDATA[WSO2 WSF/PHP comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the &#8220;src/tests&#8221; directory of WSF/PHP source package. Or you can find the latest test-suite from the SVN location. Here are some aspects covered in the test-suit. Scenario [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a> comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the &#8220;src/tests&#8221; directory of WSF/PHP source package. Or you can find the latest test-suite from <a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">the SVN location</a>.</p>
<p>Here are some aspects covered in the test-suit.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Scenario</td>
<td>Test Cases For Client</td>
<td>Test Cases For Service</td>
</tr>
<tr>
<td>Basic Functionality</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_client*.phpt</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">math_*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/echo_service*.php</a><br />
<a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/math_service.php</a></td>
</tr>
<tr>
<td>Basic Schema Types</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/BasicDataTypes/">BasicDataTypes/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/BasicTypesDoclitBSvc/">services/BasicTypesDoclitBSvc/*.php</a></td>
</tr>
<tr>
<td>Complex Schema Types</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/cmplxDataTypes/">cmplxDataTypes/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/ComplexDataTypesWSvc/">services/ComplexDataTypesWSvc/*.php</a><br />
<a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/ComplexDataTypesBSvc/">services/ComplexDataTypesBSvc/*.php</a></td>
</tr>
<tr>
<td>WSDL/Schema Variations</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/wsdl_mode/">wsdl_mode/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunhttps://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/wsdl_mode/">services/wsdl_mode/*.php</a></td>
</tr>
<tr>
<td>WSDL Generation with Annotations</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/wsdl_generation/">wsdl_generation/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/wsdl_generation/">services/wsdl_generation/*.php</a></td>
</tr>
<tr>
<td>Reliable Messaging</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_rm*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/echo_service_rm*.php</a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_encrypt_client*.phpt</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_signing_client*.phpt</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_timestamp_client*.phpt</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_username_token_client*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">encrypt_service*.php</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">signing_service*.php</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">timestamp_service*.php</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">username_token_service*.php</a></td>
</tr>
<tr>
<td>MTOM</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">mtom_*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/mtom/">samples/mtom/*.php</a></td>
</tr>
</tbody>
</table>
<p>(Note that Here &#8216;*&#8217; is used as a wild card represent 0 or many characters)</p>
<p><strong>Steps to Run Tests</strong></p>
<ul>
<li>First you need to install WSF/PHP correctly. Please read the <a href="http://wso2.org/project/wsf/php/2.0.0/docs/manual_content.html#Installation">WSF/PHP installation manual</a> for that.</li>
<li>You have to have the &#8216;pear&#8217; utility tool comes with PHP. And add this to the PATH environment variable.</li>
<li>Copy the samples and src/tests/samples/services directory (paths are relative to the root directory of the wsf/php package) to the web root directory.</li>
<li>Then go to the src/tests directory and execute the following command.
<pre>pear run-tests -r</pre>
<p>This will execute all the test cases under the &#8216;tests&#8217; directory and finally give a summery of the test results.</li>
<li> You can run individual test cases separately by providing the relative path to the test case from the &#8216;test&#8217; directory. E.g. To run the echo_client.phpt test case, you may type
<pre>pear run-tests samples/echo_client.phpt</pre>
</li>
</ul>
<p>If you like to add test cases for the WSF/PHP scenarios, follow this comprehensive guideline titled <a href="http://wso2.org/library/3579">Writing Simple phpt Test Scripts For PHP Web Services</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Samples Explained</title>
		<link>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 12:20:02 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[beginners]]></category>
		<category><![CDATA[code first]]></category>
		<category><![CDATA[contract first]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[reliable messaging]]></category>
		<category><![CDATA[samples]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=589</guid>
		<description><![CDATA[Here is a simple categorization of the WSF/PHP samples. You can access all the wsf/php samples from http://labs.wso2.org/wsf/php/solutions/samples/index.html. Sample Category Example Client Source Code Example Service Source Code Online Demo Beginners echo_client.php echo_service.php Demo REST echo_client_rest.php echo_service_with_rest.php Demo WSDL Mode (Contract First) wsdl_11_client.php wsdl_11_service.php Demo WSDL Generation (Code First) doclit_client.php doclit_service.php Demo MTOM Attachments mtom_download_client.php [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple categorization of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP </a>samples. You can access all the wsf/php samples from <a href="http://labs.wso2.org/wsf/php/solutions/samples/index.html">http://labs.wso2.org/wsf/php/solutions/samples/index.html</a>.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Sample Category</td>
<td>Example Client Source Code</td>
<td>Example Service Source Code</td>
<td>Online Demo</td>
</tr>
<tr>
<td>Beginners</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client.php">echo_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service.php">echo_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client.php">Demo</a></td>
</tr>
<tr>
<td>REST</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client_rest.php">echo_client_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service_with_rest.php">echo_service_with_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client_rest.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Mode (Contract First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_client.php">wsdl_11_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_service.php">wsdl_11_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_mode/wsdl_11_client.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Generation (Code First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_client.php">doclit_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_service.php">doclit_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_generation/doclit_client.php">Demo</a></td>
</tr>
<tr>
<td>MTOM Attachments</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_client.php">mtom_download_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_service.php">mtom_download_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/mtom/mtom_download_client.php">Demo</a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fclient.php">encryption_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fservice.php">encryption_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/security/encryption/client.php">Demo</a></td>
</tr>
<tr>
<td>Reliable Messaging</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_client_rm.php">echo_client_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_service_rm.php">echo_service_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/reliable/echo_client_rm.php">Demo</a></td>
</tr>
<tr>
<td>Data Services</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsClient.php">CustomerDetailsClient.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsService.php">CustomerDetailsService.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/DataServices/CustomerDetailsClient.php">Demo</a></td>
</tr>
</tbody>
</table>
<p>If you have downloaded the  <a href="http://wso2.org/projects/wsf/php">WSF/PHP binaries or souce code</a> package you can find all these samples, inside the &#8216;samples&#8217; directory</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encrypt and Sign your SOAP messages in PHP</title>
		<link>http://www.dimuthu.org/blog/2008/08/14/encrypt-your-soap-messages-in-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/08/14/encrypt-your-soap-messages-in-php/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 18:02:18 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[encrypt]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[message level security]]></category>
		<category><![CDATA[messages]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sign]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[Transprot level Security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=102</guid>
		<description><![CDATA[When you are developing a Web Service, you have to think about the security aspects of your service seriously. When it comes to security in web services you have two basic choices. Transport level security &#8211; Just SOAP over HTTPS Message level security &#8211; WS-Security See my previous blog comparing Transport level and Message level [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing a Web Service, you have to think about the security aspects of your service seriously. When it comes to security in web services you have two basic choices.</p>
<ol>
<li>Transport level security &#8211; Just SOAP over HTTPS</li>
<li>Message level security &#8211; <a href="http://www.oasis-open.org/specs/index.php#wssv1.1">WS-Security</a></li>
</ol>
<p>See my previous blog <a href="http://www.dimuthu.org/blog/2008/08/14/transport-level-security-vs-message-level-security/">comparing Transport level and Message level security</a>.</p>
<p>If you are satisfied with the security provided by using just &#8216;SOAP over HTTPS&#8217;, you can get the work done by configuring your server (Apache or IIS) to enable ssl. See <a href="http://www.onlamp.com/pub/a/onlamp/2008/03/04/step-by-step-configuring-ssl-under-apache.html">http://www.onlamp.com/pub/a/onlamp/2008/03/04/step-by-step-configuring-ssl-under-apache.html</a> for an step by step guide for configure SSL in your Apache server.</p>
<p>If you want message level security for your application, just use WS-Security. With <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> it is even easier to implement than SOAP over HTTPS method, because you can provide the certificates programatically in PHP and no need to do further configuration.</p>
<p>WSF/PHP provides you two classes in line with <a href="http://wso2.org/project/wsf/php/1.3.2/docs/api_content.html#service">WSService</a> to implement an API to provide WS-Security.</p>
<ol>
<li><a href="http://wso2.org/project/wsf/php/1.3.2/docs/security_api.html#wspolicy">WSPolicy</a> -Let you provide rules that the engine need to follow in securing the message. E.g.
<pre><span style="color: #0000ff;">$policy</span> = <span style="font-weight: bold; color: #000000;">new</span> WSPolicy<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"security"</span>=&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"encrypt"</span> =&gt; <span style="font-weight: bold; color: #000000;">TRUE</span>,
                    <span style="color: #ff0000;">"algorithmSuite"</span> =&gt; <span style="color: #ff0000;">"Basic256Rsa15"</span>,
                    <span style="color: #ff0000;">"securityTokenReference"</span> =&gt; <span style="color: #ff0000;">"IssuerSerial"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>In fact you can load policies from an xml which adheres to the WS-SecurityPolicy specification.</li>
<li> <a href="http://wso2.org/project/wsf/php/1.3.2/docs/security_api.html#ws_security_token">WSSecurityToken</a> &#8211; Keeps the security tokens like certificates, keys, username, passwords which would be used when applying the rules specified in the policy. E.g.
<pre><span style="color: #0000ff;">$sec_token</span> = <span style="font-weight: bold; color: #000000;">new</span> WSSecurityToken<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"privateKey"</span> =&gt; <span style="color: #0000ff;">$pvt_key</span>,
                                       <span style="color: #ff0000;">"receiverCertificate"</span> =&gt; <span style="color: #0000ff;">$pub_key</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
</li>
</ol>
<p>You can see the WS-Security in action on live from <a href="http://labs.wso2.org/wsf/php/samples/security/">http://labs.wso2.org/wsf/php/samples/security/</a> and  <a href="http://labs.wso2.org/wsf/php/source_page_frame.php?src=samples/security">security demo ource codes.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/08/14/encrypt-your-soap-messages-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
