Re: Package Proposal: Auth_HMAC
| From: | Jesus M. Castagnetto | Date: | Thu, 24 Apr 2003 17:39:31 +0000 |
| Subject: | Re: Package Proposal: Auth_HMAC | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-15478@lists.php.net to get a copy of this message | ||
Davey,
--- Davey <davey@pixelated-dreams.com> wrote:
> OK, I've been working on a new login system for my CMS these last few
> weeks, and I now believe I have *the* strongest non-SSL login ever.
>
> basically, *every* time the login form is generate, a random hash is
> generated (currently $hash = md5(uniqid(nt_rand(),1));), this is split
> into two halves and stored in $_SESSION.
>
> The hash is output both in the HTML login form (hidden elements, removed
> with JS) and the JS used with this for client side data-checking.
>
> When the user submits the form, JS MD5 hashes the username and password,
> appending one half of the hash onto each. this mean 1/3 of the
> username/password hash is unique to each request, and that part is
> identifiable as supposed to be coming from that client
>
> that means anyone packet sniffing must grab the username/password hash,
> remove the last 16chars of each to get the username/password, and also
> get their SID, then catch the login of that *same* user again (hashes
> change upon login too, same hashes won't work twice), grab the new
> hashes and submit it from their SID all before that user does so.
>
> HMAC works similarly but it uses a single 128bit hash, I use 2x64bit hash
That is only true if you are using MD5. In general, it depends on the actual
hashing algorithm you are using. If you look at the HMAC test vectors from RFC
2202, you can use SHA1, so the actual output digest will be longer when using
SHA1 (for example).
You can see the examples in 'Message/misc/rfc2202_testvectors.php'
> in the 'CVS' version, it a hidden element defaults to non-JS (so PHP
> assumes no client-side data-checking and no MD5 etc) with JS changing
> the value of a hidden input if JS is enabled.
>
> This means it'll work with non-JS capable browsers but it won't be as
> secure (although I can still do some source integrity checking cause the
> two hashes are available from the form)
>
> I propose moving this to the proper HMAC implementation except with my
> random key instead of the fixed HMAC server key.
I am not sure about your definition of a 'proper' HMAC implementation. The HMAC
RFC (2104) does not dictacte anything about your server key, so in principle
your server can use a codebook approach to create keys with a given lifetime
and that will not repeat, or will repeat after a long period of time.
> I would also consider making it an extension onto the Auth package, and
> implementing by adding another argument to the constructor (optional so
> that current code doesn't break) which would then disregard any current
> set login form set using loginFunction() and use my JS enabled (assuming
> client is JS enabled) form.
>
> Note that there is already a HMAC method in the Message package, whilst
> I've not looked at it, I may be able to use that from that package as it
> is (although thats a dependency) or if it's not quite compatible (I'm
> assuming the dynamic hash might not be compatible) I can simply copy and
> paste and make the small (I would assume) changes that are needed. (thus
> voiding the dependency too)
You can use your approach w/ PEAR::Message, there are factory methods as well
as static methods, depending on whether you just want the digest or you want to
get an object. BTW, you can pass an array as the data payload, and tell the
method how to serialize the information before hashing it, so your
username/password/whatever can easily be done.
> Any comments/suggestions on this would be welcome.
>
> I will try to clean up my code and implement HMAC within the next couple
> of days or so and show it to you all.
>
> - Davey
The PEAR::Message class also has fallback methods in case the installation does
not have mhash, in that case you can do HMAC with MD5 and SHA1 only, if you
have mhash, you can use *any* of mhash's hashing algorithms.
Cheers.
=====
--- Jesus M. Castagnetto (jcastagnetto@yahoo.com)
Research:
http://metallo.scripps.edu/
Personal: http://www.castagnetto.org/
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com