{"id":27,"date":"2016-05-06T08:48:35","date_gmt":"2016-05-06T08:48:35","guid":{"rendered":"http:\/\/symbioticindia.in\/docu\/?p=27"},"modified":"2016-05-06T08:48:35","modified_gmt":"2016-05-06T08:48:35","slug":"nusoap-http-authentication-and-http-proxy","status":"publish","type":"post","link":"http:\/\/symbioticindia.in\/docu\/2016\/05\/06\/nusoap-http-authentication-and-http-proxy\/","title":{"rendered":"NuSOAP, HTTP Authentication and HTTP Proxy"},"content":{"rendered":"<div id=\"a4j12\"><span style=\"font-size: medium;\"><strong>NuSOAP and HTTP Authentication<\/strong><br \/>\n<\/span><\/div>\n<p><span style=\"font-size: medium;\">\u00a0<\/span><\/p>\n<div id=\"a4j18\"><span style=\"font-size: medium;\"><br \/>\n<\/span><span id=\"zkg20\" style=\"font-size: medium;\">I regularly receive emails from\u00a0 friends messing around with nusoap asking about various features of the library. Most doubts are about HTTP Authentication and\u00a0 HTTP Proxy. Here are my five cents to try and help.<\/p>\n<p>If your webservice server requires http authentication don&#8217;t worry, nusoap includes the method you need : &#8220;setCredentials&#8221;. Here is an example of the simplest case:<\/p>\n<p>$soapclient = new soapclient(&#8220;http:\/\/myserver\/mysoapservice.php&#8221;);<br \/>\n$soapclient-&gt;setCredentials(&#8220;user&#8221;,&#8221;password&#8221;);<\/p>\n<p>I said &#8220;the simplest case&#8221; because &#8220;setCredentials&#8221; is much more complete than this. In this case we are supposing a &#8220;Basic Authentication Type&#8221; (the one that, when set on an http page, pops up a dialog asking for a user\/password pair).We set the<br \/>\nused authentication type with the third parameter of setCredentials, and it can be: &#8220;basic&#8221;,&#8221;digest&#8221; or &#8220;certificate&#8221;, but being &#8220;basic&#8221; the default we&#8217;ve omitted it here. When we input our username and password, their &#8220;username:password&#8221; form gets<br \/>\nbase64 encoded and sent to the server as part of the headers.<br \/>\nBasic Authentication Type uses clear data(base64 is just a content transfer encoding scheme) and is therefore insecure. There are two more http authentication types we can rely on :<\/p>\n<p><\/span><\/p>\n<ul>\n<li><span id=\"zkg21\" style=\"font-size: medium;\">Digest Authentication Type<\/span><\/li>\n<li><span id=\"zkg22\" style=\"font-size: medium;\">Certificate Authentication Type<\/span><\/li>\n<\/ul>\n<p><span id=\"zkg23\" style=\"font-size: medium;\"><br \/>\nOn <a title=\"Wikipedia - Digest Access Authentication\" href=\"http:\/\/en.wikipedia.org\/wiki\/Digest_access_authentication\" target=\"_blank\">Wikipedia<\/a> you will find the following definition for Digest Access Authentication:<br \/>\n&#8220;&#8230;&#8230; allowing user identity to be established securely without having to send a <a title=\"Password\" href=\"http:\/\/en.wikipedia.org\/wiki\/Password\">password<\/a> in <a title=\"Plaintext\" href=\"http:\/\/en.wikipedia.org\/wiki\/Plaintext\">plaintext<\/a> over the network. Digest authentication is basically an application of <a title=\"MD5\" href=\"http:\/\/en.wikipedia.org\/wiki\/MD5\">MD5<\/a>cryptographic hashing with usage of <a title=\"Cryptographic nonce\" href=\"http:\/\/en.wikipedia.org\/wiki\/Cryptographic_nonce\">nonce<\/a> values to prevent <a title=\"Cryptanalysis\" href=\"http:\/\/en.wikipedia.org\/wiki\/Cryptanalysis\">cryptanalysis<\/a>.&#8221;<br \/>\nThis type of authentication implies\u00a0 a sort of handshake between\u00a0 the server and the client, to make sure &#8220;curious&#8221;\u00a0 eyes are not\u00a0 grabbing our\u00a0 sensitive data.<br \/>\nYou tell nusoap to use Digest Authentication by passing &#8220;digest&#8221; as third parameter to &#8220;setCredentials&#8221; and as fourth parameter an array containing the following keys:<\/p>\n<p><\/span><\/p>\n<ul>\n<li><span id=\"zkg24\" style=\"font-size: medium;\">&#8220;realm&#8221;<\/span><\/li>\n<li><span id=\"zkg25\" style=\"font-size: medium;\">&#8220;nonce&#8221;<\/span><\/li>\n<li><span id=\"zkg26\" style=\"font-size: medium;\">&#8220;nc&#8221;<\/span><\/li>\n<li><span id=\"zkg27\" style=\"font-size: medium;\">&#8220;qop&#8221;<\/span><\/li>\n<\/ul>\n<p><span id=\"zkg28\" style=\"font-size: medium;\"><br \/>\n&#8220;realm&#8221; is the authentication realm,&#8221;nonce&#8221; stands for &#8220;number used once&#8221; and is a randomly generated value. Both these two values are retrieved from the server with a first call and are subsequently used for the real authentication process.<br \/>\nBasically we do a simple &#8220;GET&#8221; request to the resource for which the digest authentication is required. We&#8217;ll get back a 401 response from the server, something like this:<\/span><span style=\"font-size: medium;\"><\/p>\n<p><\/span><span id=\"v0lc0\" style=\"font-family: 'Courier New'; font-size: medium;\">HTTP\/1.1 401 Unauthorized<br \/>\nWWW-Authenticate: Digest realm=\u201ddigestedaccess\u201d, nonce=\u201dAb32Hh49iueg78bdg563jsndjk\u201d,<br \/>\nopaque=\u201d0000000000000000\u2033, stale=false, algorithm=MD5, qop=\u201dauth\u201d<\/p>\n<p><span id=\"asa40\"><br \/>\n<span id=\"zkg210\">What we are interested in here are &#8220;realm&#8221;, &#8220;nonce&#8221; and &#8220;qop&#8221; (quality of protection).\u00a0 We&#8217;ll use them in the array we&#8217;ll pass as fourth parameter to &#8220;setCredentials&#8221;.\u00a0 &#8220;nc&#8221; is a counter for how many times the nonce has been used.<br \/>\nThe value &#8220;auth&#8221; for &#8220;qop&#8221; means\u00a0 authentication only(it can also be &#8220;auth-int&#8221;, authentication and integrity).<br \/>\nWith the values we have, out method call will be:<\/p>\n<p><\/span><\/span><\/span><span id=\"zkg20\" style=\"font-size: medium;\">$soapclient-&gt;setCredentials(&#8220;user&#8221;,&#8221;password&#8221;,&#8221;digest&#8221;,<br \/>\narray(<br \/>\n&#8220;realm&#8221;\u00a0 =&gt; &#8220;digestedaccess&#8221;,<br \/>\n&#8220;nonce&#8221;\u00a0 =&gt; <\/span><span id=\"v0lc0\" style=\"font-family: 'Courier New'; font-size: medium;\">\u201dAb32Hh49iueg78bdg563jsndjk\u201d,<br \/>\n&#8220;nc&#8221; \u00a0 \u00a0 \u00a0\u00a0 =&gt; 0,<br \/>\n&#8220;qop&#8221; \u00a0 \u00a0 =&gt; &#8220;auth&#8221;<br \/>\n<\/span><span id=\"zkg20\" style=\"font-size: medium;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 )<br \/>\n&#8220;);<\/span><span style=\"font-size: medium;\"><br \/>\n<\/span><span id=\"v0lc0\" style=\"font-family: 'Courier New'; font-size: medium;\"><span id=\"asa40\"><span id=\"zkg210\"><br \/>\nThe digest authentication type is far more secure that the &#8220;basic&#8221; one, as sensitive data are combined with server generated ones and md5 encoded. md5 is a &#8220;one-way&#8221; hashing algorithm making it difficult to retrieve clear data from the encoded result.<br \/>\nEven more secure is the third authentication method: the Certificate Authentication Type.<br \/>\nThis implies using an ssl client certificate recognized by the server. To fully understand this, we&#8217;ll need to explain the basics of the &#8220;Public Key Infrastructure&#8221;, which is out of the scope of this article. You can find extensive information about it on <a title=\"Wikipedia - Public Key Infrastructure\" href=\"http:\/\/en.wikipedia.org\/wiki\/Public_key_infrastructure\" target=\"_blank\">Wikipedia<\/a> .<br \/>\nIf you want to use this authentication method with nusoap, you need to set &#8220;certificate&#8221; as the third parameter for &#8220;setCredentials&#8221; , and\u00a0 as fifth parameter an array with at least the following keys:<\/p>\n<p><\/span><\/span><\/span><\/p>\n<ul>\n<li><span style=\"font-size: medium;\">&#8220;sslcertfile&#8221;,\u00a0 the ssl certificate file (.pem)<br \/>\n<\/span><\/li>\n<li><span style=\"font-size: medium;\">&#8220;sslkeyfile&#8221;,\u00a0 the ssl key file (.pem) of the above certificate<br \/>\n<\/span><\/li>\n<li><span style=\"font-size: medium;\">&#8220;passphrase&#8221;, the password\/passphrase for the above certificate key<\/span><\/li>\n<li><span style=\"font-size: medium;\">&#8220;cainfofile&#8221; (optional), the Certification Authority certificate file (.pem)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: medium;\"><\/p>\n<p><\/span><\/p>\n<div id=\"pdzy3\">\n<div id=\"pdzy4\"><span style=\"font-size: medium;\">NuSOAP and HTTP Proxy<br \/>\n<\/span><\/div>\n<p><span style=\"font-size: medium;\"><\/p>\n<p><\/span><\/p>\n<div id=\"pdzy11\"><span style=\"font-size: medium;\">This is something I&#8217;ve been asked about a lot of time and honestly don&#8217;t know why, as long as nusoap includes a simple and self documented method for this: setHTTPProxy. Here is a simple example:<\/p>\n<p>$soapclient-&gt;setHTTPProxy(&#8220;http:\/\/proxyhost&#8221;,8080,&#8221;proxy_user&#8221;,&#8221;proxy_password&#8221;);<\/p>\n<p>The second parameter is obviously the proxy port.<br \/>\nThat&#8217;s all.<br \/>\n<\/span><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>NuSOAP and HTTP Authentication \u00a0 I regularly receive emails from\u00a0 friends messing around with nusoap asking about various features of the library. Most doubts are about HTTP Authentication and\u00a0 HTTP Proxy. Here are my five cents to try and help. If your webservice server requires http authentication don&#8217;t worry, nusoap includes the method you need ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"http:\/\/symbioticindia.in\/docu\/2016\/05\/06\/nusoap-http-authentication-and-http-proxy\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-27","post","type-post","status-publish","format-standard","hentry","category-soap"],"_links":{"self":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":1,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":28,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/27\/revisions\/28"}],"wp:attachment":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}