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

<channel>
	<title>unitstep.net &#187; CHAP</title>
	<atom:link href="http://unitstep.net/blog/category/chap/feed/" rel="self" type="application/rss+xml" />
	<link>http://unitstep.net</link>
	<description>the home of peter chng</description>
	<pubDate>Sun, 05 Oct 2008 17:42:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Password salting and the modified Challenge-Response system</title>
		<link>http://unitstep.net/blog/2008/04/28/password-salting-and-the-modified-challenge-response-system/</link>
		<comments>http://unitstep.net/blog/2008/04/28/password-salting-and-the-modified-challenge-response-system/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 01:12:42 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[CHAP]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[authentication]]></category>

		<category><![CDATA[chap-php]]></category>

		<category><![CDATA[login]]></category>

		<category><![CDATA[passwords]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[challenge-response]]></category>

		<category><![CDATA[salting]]></category>

		<guid isPermaLink="false">http://unitstep.net/?p=312</guid>
		<description><![CDATA[Since I released my demo/example modified Challenge-Response Ajax PHP Login System about a month ago (which was based on ideas from Paul Johnston), I&#8217;ve been receiving some questions about why salting was not incorporated into the system.  In particular, there was a discussion at a Dutch-language forums, which I somewhat understood after Google translation. [...]]]></description>
			<content:encoded><![CDATA[<p>Since I released my demo/example <a href="/blog/2008/03/29/a-challenge-response-ajax-php-login-system/">modified Challenge-Response Ajax <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> Login System</a> about a month ago (which was based on ideas from <a href="http://pajhome.org.uk/crypt/md5/auth.html">Paul Johnston</a>), I&#8217;ve been receiving some questions about why <a href="http://en.wikipedia.org/wiki/Salt_(cryptography)">salting</a> was not incorporated into the system.  In particular, there was a <a href="http://gathering.tweakers.net/forum/list_messages/1284731///salt">discussion</a> at a Dutch-language forums, which I somewhat understood after <a href="http://www.google.com/translate?u=http%3A%2F%2Fgathering.tweakers.net%2Fforum%2Flist_messages%2F1284731%2F%2F%2Fsalt&#038;langpair=nl%7Cen&#038;hl=en&#038;ie=UTF8">Google translation</a>. </p>
<p>Here, I&#8217;ll try to address some of these concerns and answer some questions.</p>
<h3>Salt of the earth</h3>
<p>To understand why salting is used, we must first understand exactly what it is.  Just like regular salt, in cryptography, salting is used to alter the &#8220;taste&#8221; or output of some process. </p>
<p>In the case of password storage, most people would realize that you should <em>never</em> store lists of users&#8217; passwords in plaintext, because if that data is ever compromised, attackers will gain access not only the compromised accounts but could potentially use the passwords to gain access to user accounts on other services/sites.  This is because people often reuse the same passwords across multiple account/services.</p>
<p>The easiest way to avoid this is to store the <em>hash</em> of the password.  A hash is a one-way function, that is, once you compute the hash of a value, you cannot obtain the original from just the hashed value.  Some typical hash functions are MD5 or the more secure family of SHA hash functions.</p>
<p>However, this still doesn&#8217;t fully conceal passwords.  If an attacker were to obtain the list of hashed passwords, they could try a dictionary-based attack to discover the original inputs.  This involves hashing common words to see if they hash to the correct value.  Since people often use common words or combinations of such, a dictionary-based attack has the advantage of having far fewer combinations that the attacker needs to try compared to a true brute-force attack.</p>
<h3>Adding variability</h3>
<p>This problem can be mitigated by salting, which basically amounts to combining the password with additional input before passing it into the hash function.  This alters the end output from the hash function so that a dictionary-based attack cannot be used, <strong>provided the salt is kept a secret</strong>.  A comparison example:</p>
<pre><code>Without salting:
hash(A) -&gt; B;

With salting:
hash (A + S) -&gt; C;</code></pre>
<p>In the first example, salting was not used before hashing.  Assuming the value &#8216;A&#8217; is a common word or phrase, an attacker can use a dictionary-attack to determine what the value of &#8216;A&#8217; was. (I.E. what value hashes to the value of &#8216;C&#8217;)</p>
<p>With salting, things become more difficult.  If the attacker does not know the value of the salt (S), they cannot use a dictionary-based attack because the actual input will not be a common word or phrase.  Instead, they must try all values in the dictionary <em>with</em> all possible values of the salt.  In fact, every bit of the added salt value doubles the number of computations in a dictionary-based attack.  The important point to retain here is the <strong>salt value must be kept a secret</strong> in order to obtain this benefit.</p>
<p>One other benefit of salting is to ensure that two accounts with the same password don&#8217;t produce the same hash.  This can be accomplished by making different accounts have different salts.  The obvious benefit of this is to decrease the information leakage from the hashes, as otherwise, equivalent hashes would infer equivalent passwords.</p>
<h3>Salting and the modified Challenge-Response System</h3>
<p>With the <a href="/blog/2008/03/29/a-challenge-response-ajax-php-login-system/">modified challenge-response system</a>, it isn&#8217;t clear to me how salting could be used to improve it.  Here&#8217;s a quick re-cap of how it works:</p>
<blockquote><p>
Signup:</p>
<p>1. Server sends random1<br />
2. Client sends hex_sha1(hex_hmac_sha1(password, random1))</p>
<p>Login:</p>
<p>1. Server sends random1 and random2<br />
2. Client sends hex_hmac_sha1(password, random1) and hex_sha1(hex_hmac_sha1(password, random2))
</p></blockquote>
<p>To login, the user must present two values: One to verify that they know the password, and the second value, which is used to set the response that must be computed for the <em>next login</em>.</p>
<p>Because the client must compute the next response value, it&#8217;s a bit tricky to implement salting in a way that&#8217;s beneficial. </p>
<p>One possible method would be to further hash the second value (<code>hex_sha1(hex_hmac_sha1(password, random1))</code>) with a <strong>server secret</strong> before storing it in the database.  This would complicate things should the database be compromised but not the server secret, since a dictionary attack would become much harder with the extra variability of a server secret.  In this case, the work flow would look something like this:</p>
<h4>Signup</h4>
<ol>
<li>Server sends random1</li>
<li>Client sends hex_sha1(hex_hmac_sha1(password, random1)) [<strong>Let's call this value `hashed_challenge_response` for brevity</strong>]</li>
<li>Server stores hex_hmac_sha1(server_secret, hashed_challenge_response)</li>
</ol>
<h4>Login:</h4>
<ol>
<li>Server sends random1 and random2</li>
<li>Client sends hex_hmac_sha1(password, random1) and hex_sha1(hex_hmac_sha1(password, random2))</li>
<li>Server computes hex_sha1(hex_hmac_sha1(password, random1)) [<strong>Call this `hashed_challenge_response_received`</strong>]</li>
<li>Server checks if hex_hmac_sha1(server_secret, hashed_challenge_response_received) equals the value previously stored.  If so, authentication was successful and a new challenge-response is stored based on the second value received.</li>
</ol>
<p>Note that this method <strong>would not improve the login security anymore</strong>, since an attacker who captured the intermediate traffic of a successful login could still conduct an offline dictionary attack, which this challenge-response system is unfortunately susceptible to.</p>
<p>However, the modified system does benefit from the use of the `random1` and `random2` challenge strings, which are stored alongside the response values.  Since these are random and different for each user (and for each subsequent login), accounts with the same password will not have the same hash-response.  This effectively gives the second lesser benefit of salting.</p>
<p>The modified challenge-response system also suffers from the inability of the server to enforce strong passwords.  Because the initial value sent during registration is a hashed value of the password and a random value, the server cannot be aware of any properties of the password such as its length or composition.  The only aspect that could be enforced server-side would be to make sure the password was not blank!  My suggestion is to (attempt to) enforce password complexity using JavaScript on the client side.  Such rules can obviously be circumvented but are better than nothing.</p>
<h3>Conclusion</h3>
<p>Hopefully I&#8217;ve shed some light on the topic of salting in relation to the modified challenge-response Ajax <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> login system.  I&#8217;m no security expert, so you should not take my advise as scripture.  Please don&#8217;t hesitate to give me your comments or feedback!</p>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/04/28/password-salting-and-the-modified-challenge-response-system/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Challenge-Response Ajax PHP Login System</title>
		<link>http://unitstep.net/blog/2008/03/29/a-challenge-response-ajax-php-login-system/</link>
		<comments>http://unitstep.net/blog/2008/03/29/a-challenge-response-ajax-php-login-system/#comments</comments>
		<pubDate>Sun, 30 Mar 2008 01:53:11 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[CHAP]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[authentication]]></category>

		<category><![CDATA[chap-php]]></category>

		<category><![CDATA[login]]></category>

		<category><![CDATA[passwords]]></category>

		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2008/03/29/a-challenge-response-ajax-php-login-system/</guid>
		<description><![CDATA[A while ago, (okay, a long while ago) I wrote about a way to improve the security of login/authentication with web applications.  The process involved using challenge-response during authentication to prevent passwords from being transmitted in plaintext.  The idea was not mine, but instead the work of a smart fellow named Paul Johnston. [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, (okay, a <em>long</em> while ago) I wrote about <a href="/blog/2006/09/19/using-a-chap-login-system-to-improve-security/">a way to improve the security</a> of login/authentication with web applications.  The process involved using challenge-response during authentication to prevent passwords from being transmitted in plaintext.  The <a href="http://pajhome.org.uk/crypt/md5/auth.html">idea was not mine</a>, but instead the work of a smart fellow named <a href="http://pajhome.org.uk/">Paul Johnston</a>.   At the time, I &#8220;hoped to present an actual implementation&#8221; sometime in the future, but never got around to it.  I finally had some time and decided to put together a working example using <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> and JavaScript. </p>
<h3>Download the source</h3>
<p>Please feel free to download and try out the first public release of the CHAP-PHP login system.  The zip file has the full source and provides an example how to implement the system both on the client and server side.</p>
<div class="download">
<a class="icon" href='http://unitstep.net/wordpress/wp-content/uploads/2008/03/chap-php-051.zip' title='CHAP-PHP-0.5.1'>Download CHAP-PHP-0.5.1</a>
</div>
<p>The same demo available in the zip file is also <a href="/projects/CHAP-PHP/src/demo/index.php">available here</a>.</p>
<h3>Improving authentication security with Challenge-Response</h3>
<p>Challenge-Response is the basis for many authentication systems.  In such a situation, a server may have to authenticate a user by verifying their credentials, usually in the form of a password.  However, transmitting plaintext passwords over connections that are not secure can lead to compromises.  In such a situation, <dfn>challenge-response</dfn> may be used.  This usually involves the server sending a <strong>random challenge</strong> string to the client, which must then produce an appropriate <strong>response</strong> that can only be computed using the challenge and the password.  This response is then sent to the server, which can then verify if the right password was used to generate it.  The response is usually computed by hashing a value that depends on the challenge and the password, thus it is not possible to obtain the password from the response, which might have been sniffed on an insecure connection. </p>
<p>However, such a traditional challenge-response has the downside that the plaintext password (or a password-equivalent) must be known to the server at some point.  Paul Johnston came up with <a href="http://pajhome.org.uk/crypt/md5/auth.html">an idea for an alternative system</a> a while ago that overcomes these shortcomings.  (Though it is not free from weaknesses itself)  It is this &#8220;Alternative System&#8221; that the above release is based upon.  Here is a quick explanation of the system, adapted from Johnston&#8217;s site:</p>
<blockquote cite="http://pajhome.org.uk/crypt/md5/auth.html"><p>
Signup:</p>
<p>   1. Server sends random1<br />
   2. Client sends hex_sha1(hex_hmac_sha1(password, random1))</p>
<p>Login:</p>
<p>   1. Server sends random1 and random2<br />
   2. Client sends hex_hmac_sha1(password, random1) and hex_sha1(hex_hmac_sha1(password, random2))
</p></blockquote>
<p>During registration, the value sent by the client is stored.  During login, the user must present a value <em>that when hashed</em> produces the value provided at registration.  Because of the non-reversibility property of hashes, knowing the value passed during registration does not allow an attacker to login.  The only way to produce the valid response is to know the actual plaintext password, which is never transmitted or known by the server.  In this system, challenges are linked to a user and must be stored, since it must be known what challenge was used to produce the response.</p>
<p>The second random challenge (random2) and the second value sent by the client during login are used to prevent replay attacks.  Upon successful login, the second value provided by the client becomes the next response, equivalent to the value first provided during registration.  Thus, for the next login, the value that is sent must hash to equal this value.  This also means that the challenges are updated/changed each time a login is successful.  This has the unfortunate downside of revealing when a user has logged in, since the challenge presented at login will be different.  (Challenges must be publicly available)</p>
<p>For a more thorough explanation, I suggest that you <a href="http://pajhome.org.uk/crypt/md5/auth.html">read Johnston&#8217;s article on the subject</a>.</p>
<h3>Getting it to work</h3>
<p>Understanding the process above leads to the conclusion that user-login is now a two-stage process.  Since the challenges are tied to a user, the username must first be known to the server in order to retrieve the challenge for that user.  The client can then use the challenge to produce the response to send to the server for authentication.</p>
<p>Having a two-stage login form would be very unfriendly to users.  Thus, the main challenge is to make it <em>appear</em> as if nothing out of the ordinary is happening.  This is where Ajax comes into play.  When the form is submitted, the event is prevented from occurring normally.  Instead, the username is first retrieved from the form and sent to the server via an Ajax call in order to retrieve the associated challenge.  Once the challenge is received, the appropriate responses are computed, inserted into the form and then the form is submitted.</p>
<p>The current system also works in the case that JavaScript is not enabled/available on the client side.  In this case, challenge-response will not be available, since JavaScript is used to compute the responses.  The server-side <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> scripts infer that JavaScript <em>was not</em> enabled on the client-side if proper challenge-responses are not received, and thus treat the password as plaintext.  In this case, passwords are transmitted in plaintext.  With this code, you have the choice of allowing this &#8220;insecure&#8221; login to proceed or not.</p>
<p>Note that the CHAP-PHP is more of a module than a full-fledged system, since it&#8217;s not intended to be used on its own but instead as part of some application.  It might be a bit confusing if you&#8217;re a non-developer, but I&#8217;ve tried to make it as straightforward and simple as possible so that it will be easy to integrate with existing code bases/frameworks/sites. </p>
<p>Please don&#8217;t hesitate to <a href="/contact">contact me</a> with your questions, comments or suggestions.</p>
<h3>Disclaimer and warning</h3>
<p>You should not use this as the basis for authentication for sensitive data/websites.  I am not a security expert.  At this point, this is more of a proof-of-concept then something concrete.  It is intended to be the starting point for perhaps something more secure and to show that there are alternatives for more secure authentication when SSL is not available.</p>
<h4>Revision History</h4>
<ul class="note less">
<li>0.5 - First Public Release - 2008-03-29</li>
<li>0.5.1 - Fixed file-based storage to be more robust - 2008-03-30</li>
</ul>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2008/03/29/a-challenge-response-ajax-php-login-system/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using a CHAP login system to improve security</title>
		<link>http://unitstep.net/blog/2006/09/19/using-a-chap-login-system-to-improve-security/</link>
		<comments>http://unitstep.net/blog/2006/09/19/using-a-chap-login-system-to-improve-security/#comments</comments>
		<pubDate>Wed, 20 Sep 2006 02:24:51 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[CHAP]]></category>

		<category><![CDATA[authentication]]></category>

		<category><![CDATA[login]]></category>

		<category><![CDATA[passwords]]></category>

		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://unitstep.net/blog/2006/09/19/using-a-chap-login-system-to-improve-security/</guid>
		<description><![CDATA[After reading this article (which was linked off Digg), I was surprised to find that many commercial and popular sites were still sending login and password information in plaintext over unencrypted channels as part of their authentication system.  Most login forms use the POST HTTP method to submit information to the server, and while [...]]]></description>
			<content:encoded><![CDATA[<p>After reading <a href="http://blogs.ittoolbox.com/security/investigator/archives/look-at-all-of-these-passwords-11240">this article</a> (which was <a href="http://digg.com/security/Look_At_All_These_Passwords">linked off Digg</a>), I was surprised to find that many commercial and popular sites were still sending login and password information in plaintext over unencrypted channels as part of their authentication system.  Most login forms use the POST <acronym class="uttInitialism" title="HyperText Transfer Protocol">HTTP</acronym> method to submit information to the server, and while this doesn&#8217;t reveal the contents in the <acronym class="uttInitialism" title="Uniform Resource Locator">URL</acronym> as a GET request would, the information is easily available if one looks at the <acronym class="uttInitialism" title="HyperText Transfer Protocol">HTTP</acronym> headers - and if the passwords are submitted in plaintext (or a simple encoding such as base-64 is used), then it&#8217;s trivial for someone sniffing packets to obtain your password and hence your account credentials.</p>
<p>While this lack of security surprised me, what further surprised me were the number of people throwing their arms up, and saying, &#8220;<i class="quote">Oh well, this is unpreventable when you&#8217;re not using SSL (https) for your client-server connection</i>&#8220;.  Contrary to popular belief, <strong>it is possible</strong> to implement a login or authentication system that doesn&#8217;t transmit passwords in plaintext and thus is more secure over unencrypted channels - it&#8217;s called a <abbr title="Challenge-Handshake Authentication Protocol">CHAP</abbr> login system, and it vastly improves security.</p>
<h3>They&#8217;re listening</h3>
<p>The basic problem with communication over the Internet is that it is inherently insecure.  Eavesdropping is quite easy, especially if one has knowledge of how the packets or traffic are being sent from a host to a server and vice-versa - this has to do with how most of the networks that comprise the Internet are setup.  This presents a problem during the process of <dfn>authentication</dfn>, that is, determining that a user really is who they purport to be.  </p>
<p>Authentication usually takes the form of a user providing <dfn>credentials</dfn>, that is, a set of information that proves their identity.  For most applications, this consists of a <dfn>username-password</dfn> combination, which provides both the identity (username) and proof (password).  The password is proof of the user&#8217;s identity since it is supposed to be kept a secret.  But, if the password is transmitted over insecure channels, how can it be kept a secret?</p>
<h3>CHAP and Digest Access Authentication</h3>
<p>This is where CHAP (Challenge-Response Authentication Protocol) comes into play.  Despite my main focus being on web applications (built using server-side scripting languages), methods like this such as <dfn>Digest Access Authentication</dfn> have been around for some time.  Digest Access Authentication is a function provided by the web server itself (though the client browser must support the method as well), and is a way to password-protect resources (i.e., certain web pages or directories) so that only certain users can access it.   The previous <dfn>Basic Authentication Scheme</dfn>, merely transmitted both the login and username after encoding in base-64, providing no protection whatsoever from sniffing.</p>
<h3>Hash functions</h3>
<p>So, how does it work?  At the heart of CHAP are functions known as <dfn>hash functions</dfn> .  Ideal hash functions are <dfn>one-way</dfn>, that is, if one knows the output of the function, it is impossible to determine the input.  One output could potentially correspond to an infinite number of inputs.  How can this be so? Think of functions involving modular arithmetic - if I tell you that the remainder of a division was 3, can you come up with a definitive answer as to what the intial two inputs were?  It could have been <code>15 mod 4</code>, but it could have just as easily have been <code>16 mod 13</code> .  Actual hash functions are more complicated than this.</p>
<p>Another important property is that different inputs should produce different outputs - the previous example did not illustrate this.  To some extent, this property can only be idealized, since the output from hash functions are usually strings with limited lengths, and thus there are only a finite number of outputs while there are usually an infinite number of inputs.  Thus, a good hash function should try to avoid these <dfn>collisions</dfn>, that is, when two inputs produce the same output, and should definitely make it hard to intentionally produce collisions.</p>
<h3>Bringing it together</h3>
<p>Perhaps you can see how hash functions would be ideal in this situation.  For example, a password, once put through the hash, would produce an output that could still be used for authentication, but it would be impossible to go from this back to the original password.  But, CHAP takes it one step further.</p>
<p>When a user wants to authenticate, the server first generates and issues a random challenge string to the client.  The client then combines this with the password using <a href="http://en.wikipedia.org/wiki/HMAC">HMAC</a>, (a cryptographically proper way to combine information with a key/password), then feeds this result into a hash function.  The output from the hash function is then submitted to the server.  When the server receives this string, it also does the same computation (since it keeps hold of the challenge string and also has the user&#8217;s password), and compares this with what it received from the client.  If the two match, then authentication was successful and the user can be given access!</p>
<p>How is this better than transmitting the password in plaintext?  Let&#8217;s say someone, named <cite>Eve</cite>, is sniffing the traffic from client to server.  What information would she get?  Well, first, she&#8217;d get the challenge string issued from the server to the client.  Then, she&#8217;d get the output from the hash function sent from client to server.  Why can she not derive the password from this?  Because hash functions are one-way, there is no way to go back original input data - which contained the password combined with the challenge string. </p>
<h3>Hold on, partner</h3>
<p>While this sounds simply, there are many implementation issues.  Firstly, the client must have access to hash functions.  For the most part, this is trivial, as the client application is usually a web browser, and most web browsers support JavaScript, which can be used to implement several popular hash functions.  See <a href="http://pajhome.org.uk/crypt/md5/index.html">Paul Johnston&#8217;s excellent page on cryptography in JavaScript</a> for more details.</p>
<p>Another important point is that the challenge strings issued by the server must be random and must not be reused.  If they were reused, our attacker Eve could sniff the output from the client&#8217;s hash function and just re-send that to trick the authentication scheme as the same challenge string and password fed into a given hash function will always produce the same output.  Therefore, there must be a way to keep track of the challenge strings used or at least make it very unlikely for the same challenge string to be used more than once.</p>
<p>Also, the technique is not totally secure. (But what is?)  An attacker could capture the output from the client&#8217;s hash function and using brute force attacks (trying almost every combination), attempt to guess the user&#8217;s password, by trying to find out what would produce the hash function&#8217;s output.  This has the added danger that the attacker doesn&#8217;t need to communicate with the server for this sort of attack, negating any server-side lockout protection that may be in place.  A remedy for this, is of course, strong passwords, but not a lot of people use them. </p>
<p>Additionally, a multi-user system would need to keep track of challenges issued to each user, instead of relying on the client to tell the server what challenge was issued to it.  This must be done since mutiple users could be authentication at or around the same time, so the server would need to know what challenges were issued to which user.  If the usernames and passwords are stored in a table, this could easily be done by adding another column for the challenge.</p>
<p>The tricky part here is that now the server needs to know the username <em>before</em> it can issue the challenge.  This could be done in a two-step process, but might be confusing to some users.  Here is where I think Ajax could come into play - using Ajax techniques, you would be able to accomplish this two-step process using a normal form and mask it to appear as a regular one-step login process.</p>
<p>Another issue that needs to be dealt with is that the way this system has been currently described, the passwords are stored in plaintext on the server.  This is a big no-no, as if the server is compromised, the attacker now has a plethora of username/password combinations.  Since users often re-use passwords across many different sites (despite warnings not to), some of which may have sensitive financial information, this could lead to more complicated matters, such as identity theft.  One solution is to store a hash of the password plus a <a href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29">salt value</a>, and then also adjust the client-side method for computation of the challenge-password hash accordingly.  This doesn&#8217;t improve the security of the system, but it does prevent passwords from being discovered should the server be compromised.</p>
<p>Another problem is what occurs when the client doesn&#8217;t have JavaScript enabled.  You could simply disallow logins, or &#8220;downgrade&#8221; the system to submit plaintext authentication creditials in this case.  This wouldn&#8217;t be hard to do.</p>
<h3>All this talk, but no action</h3>
<p>So far, all I&#8217;ve done is given a few examples of how a CHAP system might work - I&#8217;m definitely no expert on this subject.  In a later article, I hope to present an actual implementation, (using <acronym class="uttInitialism" title="PHP: Hypertext Preprocessor">PHP</acronym> and MySQL on the server side and JavaScript on the client side) and also deal with how to track the login session - stay tuned.  If I&#8217;ve piqued your interest, please don&#8217;t hesistate to check out the references below.</p>
<h3>References</h3>
<ol class="less note">
<li><a href="http://pajhome.org.uk/crypt/md5/">Paul Johnstonâ€™s page on JavaScript Cryptography</a> - an all-around excellent resource</li>
<li><a href="http://simon.incutio.com/archive/2003/04/20/javascriptMD5">Simon Willison on MD5 in JavaScript</a></li>
<li><a href="http://httpd.apache.org/docs/2.0/mod/mod_auth_digest.html">Apache Module: mod_auth_digest</a></li>
</ol>
<hr/>Copyright &copy; 2008 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2006/09/19/using-a-chap-login-system-to-improve-security/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
