corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
pajamas..
php and javascript advanced md5 authentication system
The connexion between "pajamas", which is an acronym for "php and javascript advanced md5 authentication system" and an actual pair of "Pyjamas" is that when you feel secure, you sleep better. Of course the words sound identical, too.
pajamas began as an attempt to create a more secure login using client-side hashing, which is one-way encryption, and as a demonstration, mainly for other web-coders, to two enormous security holes in all-too-common existence..
The first exists when folk use "public" browsers. Often the username and password are stored on the machine, and can be re-used, even by accident, by other members of the public. Clearly this presents a problem, and one which, for some reason, most people like to forget and/or ignore. Probably, like me, they realized it would need to be done with JavaScript, and then ran in the opposite direction.
The second hole is more obvious, and that is the plain text password travelling freely across the wires. This one has received more worldwide attention, but it's still ignored in most php web applications. There are literally hundreds of articles out there describing how to store a user's password using all manner of weird and wonderful algorithms, to protect it from "unauthorised database access", or "unauthorised server access", and yet still expecting the password to arrive in plain text. GUYS!
If your database isn't secure you are in trouble. Same for your filesystem. These are places over which you have control. The place where you certainly don't have control, ever, is the internet. And the moment that packet of data leaves the user's presumably safe environment it's fair game. Its contents could be stored on any one of the many nodes between server and client, dubious proxy "servers" could scan it, on poorly configured servers (most) passwords will show up on other server's referrer logs, etc. There it is, your plain-text password, travelling around the internet in a bundle of other useful plain text information, like the URL of the so-called secure login page, probably your username. No! This is insane!
pajamas takes an entirely different approach. The password is securely hashed before being sent over the wires. Now, not only is interception no longer a problem (it's impossible to retrieve the password from the hash in the given time-frame, even a very much longer time-frame), but public browsers can't save or cache it, either*, being a one-shot mish-mash of your password and some random generated string. Each time you login, it's completely different.
With pajamas, the only places the password ever exists in the clear are in your presumably secure server environment, and the presumably secure user's brain. This password is only protecting access to this server's content; ergo, breaching the web server breaches the user's "protected" data, anyway. To my reckoning, it would be considerably more difficult to compromise a modern web server and get root, than it is to search some log for the phrase "password".
Which strategy is best? You decide.
Since its birth back in 2004, pajamas spent quite a long time lying fairly dormant, yet working away quietly in the background as a highly useful authentication script. More recently, pajamas has grown into a rather neat modular authentication system, and the old "pj" module has essentially become one of its plug-ins. There's also a "plain" plugin that retains many of the good features of pj, but without the client-side hashing, for situations where JavaScript isn't available (On The Moon, maybe!). pj's client-side hashing is made possible with the excellent JavaScript functions provided by Paul Johnston's javascript MD5 code.
You can enjoy my wee "protected" image gallery, and try-out pajamas at the same time, here. If you'd like to ask questions, give feedback, enlighten me, etc, you can do that at the bottom.
The default module on corz.org uses HMAC-SHA256 over HTTPS. The browser signs a fresh server challenge using Web Crypto. See the SHA256 setup example.
There is also a sha1 pajamas plug-in called "shaggie", which is currently available only inside my other packages (e.g. the distro machine), feel free to download and play around with it; get back to me if you find any issues, thanks.
Here's the current pajamas code..
(of course, most of the good stuff is inside the modules!)
At least, this is the expected behaviour - currently, as far as I know, Opera saves the *typed* password, rather than the *sent* password, effectively defeating all forms of client-side password hashing strategy, dudes! - I've figured out a way around this, by the way, which will hopefully hit the code stage for my upcoming "shaggie" pajamas module. Take it easy!
I've just finished the first version of my "pajamas security module", which you simply include() wherever you need security. think plug-in authentication, something like this..
<!-- usual header here -->
include($root.'/inc/pj.php');
if (!auth_user()) die();
<!-- your secure page here -->
at that point, pajamas will either create the special password form and get the user login or else, if the user is already authorised, continue your page, it's pretty neat. the module returns a global variable you can check, too, if you don't want the page to just die after the form. (ie for a footer, or "security message", or something)
I've been testing it at my site admin page, where it's working beautifully (it sure feels good knowing my raw password isn't flying over the wires every time I login, which is a lot) and I plan to release it for a small fee (because this place really has got to start paying for itself soon!), but I'd like a few folk to beta test the module on different servers and setups before it goes on full release (and in truth, I haven't coded my PayPal automation yet)
If you're interested, mail me, and you can play with it, give me some feedback, and get a free license!
for now..
;o)
alexander - 15.05.05 2:43 pm
Very nice!
I dont understand half of it but it looks great
Noticed that one can reset the logout timer by reloading the page, any way to work around that?
Can this easily be implemented as an script that is included on every page on wish to have secured?
/alexander
corz - 15.05.05 3:31 pm
The reset for each page load is just a preference, it's on a hair-trigger for the demo! you only get 30 seconds to look at the pics, too!
As to the "included on every page" secure area thing, see my previous post!
;o)
corz - 20.05.05 1:45 pm
Thanks for all the interest!
I have enough testers now, so if all goes to plan, the module (which I affectionately call "pj") will be released to the masses sometime within the next couple of weeks.
for now..
;o)
Jack White - 21.05.05 9:01 am
I'll be waiting for that!
Cheers, Jack
Alexnader - 24.05.05 9:30 pm
Hi!
Noticed that even if you fail 10 times you can visit another page, then go back to the loginscreen again and if you enter the correct password you are allowed to enter. Is there any way to build that posibility away perhaps.
Anyway, very great script. I will try to write down some tips and ideas of improvement within a few days and send it over to you.
/alexander
G Funk - 30.05.05 11:48 pm
From what I can gather in my limited understanding of security, in order for this to work, you have to have the password exposed in plain text on the server end, be it in a text file, php script, database, etc. Would it be feasible to store the password in an md5 hash on the server, and have the client pass the hash of the combination of the key and the hashed password like
calcMD5(random_string + calcMD5(loginpass.value))
and then use the same logic on the server to compare it, or is it somehow less secure to do this?
corz - 31.05.05 11:00 am
Well G Funk, it's a mind-bender, that's for sure!
At first glance it seems reasonable to store the password as an MD5 on the server, but in reality, all we have done is replaced the password with an MD5 of itself. In other words, you could authenticate by simply knowing the MD5, just as easily as you can by knowing the actual password. When I first put pajamas together, I wrestled with this for some time!
The only "weakness" with the current pajamas implementation is that your password is visible to someone if they have access to your raw filesystem, and if they have that, no amount of authentication will stop them getting your goodies, will it? pajamas isn't designed to protect you from unscrupulous hosting admins!
Probably the best place to put your password is in a database, and I'm considering adding a small database function to the module for this very purpose, but even then, you need to store a database password somewhere...
There's not really a big problem with keeping passwords inside php scripts, phpmyadmin, phpbb, nuke, etc, all keep their passwords inside php files, and mostly have their users send them in plain text over the wire, too!
With any authentication system, you need the original "raw" password to exist somewhere, the philosophy behind the pajamas approach is that it only exists in places where we have 100% control, namely, our brain and the web server, and nowhere inbetween, NOT in the browser, and NOT in the wires connecting it to the server. For a great many situations, this is the ideal approach.
;o)
ps.. alexander, the current behaviour is by design, but it would be very simple to have it your way. Is this really what we want? I guess could make it optional.
Alexander - 31.05.05 10:07 pm
Hi!
I have emailed over some comments and things on the script now.
Yes that I think would be great :) perhaps some temp IPban on anyone who fails X times, could be nice. But I dont know how hard that is to write.
/alexander.
corz - 01.06.05 8:11 pm
I got them! I've incorporated your absolute_luser facility into the module and I've jotted down the edits required to get your version to act this way, they will be in your inbox shortly. You can see it working already on my own admin page (link above).
Thanks for the contributions! As interior designers say, "I like what you've done with it!". I'll follow your example of a modularised logout button, and may even do that with all pj's "html" output, allowing the user to slot the parts in wherever they need, there will be preferences for these things, of course. (I like stuff to plug-in!)
By default, though, the module will come out-of-the-box as a plug-in authentication system, handling all aspects automatically with one simple include on your page, with lots of alternative behaviour configurable in the prefs.
Welcome to the comments facility!
Thanks.
I've just finished the first version of my "pajamas security module", which you simply include() wherever you need security. think plug-in authentication, something like this..
at that point, pajamas will either create the special password form and get the user login or else, if the user is already authorised, continue your page, it's pretty neat. the module returns a global variable you can check, too, if you don't want the page to just die after the form. (ie for a footer, or "security message", or something)
I've been testing it at my site admin page, where it's working beautifully (it sure feels good knowing my raw password isn't flying over the wires every time I login, which is a lot) and I plan to release it for a small fee (because this place really has got to start paying for itself soon!), but I'd like a few folk to beta test the module on different servers and setups before it goes on full release (and in truth, I haven't coded my PayPal automation yet)
If you're interested, mail me, and you can play with it, give me some feedback, and get a free license!
for now..
;o)
Very nice!
I dont understand half of it but it looks great
Noticed that one can reset the logout timer by reloading the page, any way to work around that?
Can this easily be implemented as an script that is included on every page on wish to have secured?
/alexander
The reset for each page load is just a preference, it's on a hair-trigger for the demo! you only get 30 seconds to look at the pics, too!
As to the "included on every page" secure area thing, see my previous post!
;o)
Thanks for all the interest!
I have enough testers now, so if all goes to plan, the module (which I affectionately call "pj") will be released to the masses sometime within the next couple of weeks.
for now..
;o)
I'll be waiting for that!
Cheers, Jack
Hi!
Noticed that even if you fail 10 times you can visit another page, then go back to the loginscreen again and if you enter the correct password you are allowed to enter. Is there any way to build that posibility away perhaps.
Anyway, very great script. I will try to write down some tips and ideas of improvement within a few days and send it over to you.
/alexander
From what I can gather in my limited understanding of security, in order for this to work, you have to have the password exposed in plain text on the server end, be it in a text file, php script, database, etc. Would it be feasible to store the password in an md5 hash on the server, and have the client pass the hash of the combination of the key and the hashed password like
Well G Funk, it's a mind-bender, that's for sure!
At first glance it seems reasonable to store the password as an MD5 on the server, but in reality, all we have done is replaced the password with an MD5 of itself. In other words, you could authenticate by simply knowing the MD5, just as easily as you can by knowing the actual password. When I first put pajamas together, I wrestled with this for some time!
The only "weakness" with the current pajamas implementation is that your password is visible to someone if they have access to your raw filesystem, and if they have that, no amount of authentication will stop them getting your goodies, will it? pajamas isn't designed to protect you from unscrupulous hosting admins!
Probably the best place to put your password is in a database, and I'm considering adding a small database function to the module for this very purpose, but even then, you need to store a database password somewhere...
There's not really a big problem with keeping passwords inside php scripts, phpmyadmin, phpbb, nuke, etc, all keep their passwords inside php files, and mostly have their users send them in plain text over the wire, too!
With any authentication system, you need the original "raw" password to exist somewhere, the philosophy behind the pajamas approach is that it only exists in places where we have 100% control, namely, our brain and the web server, and nowhere inbetween, NOT in the browser, and NOT in the wires connecting it to the server. For a great many situations, this is the ideal approach.
;o)
ps.. alexander, the current behaviour is by design, but it would be very simple to have it your way. Is this really what we want? I guess could make it optional.
Hi!
I have emailed over some comments and things on the script now.
Yes that I think would be great :) perhaps some temp IPban on anyone who fails X times, could be nice. But I dont know how hard that is to write.
/alexander.
I got them! I've incorporated your absolute_luser facility into the module and I've jotted down the edits required to get your version to act this way, they will be in your inbox shortly. You can see it working already on my own admin page (link above).
Thanks for the contributions! As interior designers say, "I like what you've done with it!". I'll follow your example of a modularised logout button, and may even do that with all pj's "html" output, allowing the user to slot the parts in wherever they need, there will be preferences for these things, of course. (I like stuff to plug-in!)
By default, though, the module will come out-of-the-box as a plug-in authentication system, handling all aspects automatically with one simple include on your page, with lots of alternative behaviour configurable in the prefs.
for now..
;o)