Thread: [Jamwiki-devel] Question about code fragment
Brought to you by:
wrh2
From: <jam...@li...> - 2013-03-10 18:56:55
|
Hi, I stumbled about JAMWiki not using any salt for password hashing and wanted to start a request about it. Than I figured JIRA exists and found JAMWIKI-36 ... So now I'm trying to take care about it. While crawling through the code, to get an image about who's using what, when and why I saw org.jamwiki.utils.Encryption.bytes2String(byte[]) and am wondering, what's the concrete intention behind it? I see what it does and from it's usage I see what's it currently expected to do. But to achieve the very same much simpler code would be sufficient. [1] So I fear there's something else "implied", which I don't see ... Anybody out there able to answer my question? Best regards, Peter [1]: 'new String(byteData, "US-ASCII")' or 'new String(byteData)' because simply casting byte to char is only valid for the very optimistic assumption every provided byte value represents a valid US-ASCII (or system default charset) character. The concrete question that came up to me is: what, if this method just returns a hex string representation of 'byte[]'? OTOH than Encryption.decrypt64(String) might break ... |
From: <jam...@li...> - 2013-03-10 19:14:34
|
I think the Encryption.bytes2String method can be killed - if I had to guess that's probably just very old code and no one noticed the possible cleanup. One caveat if you're looking into the password salts is to ensure that any change will work for existing installations (or with an upgrade process). I haven't looked at that issue in a long time, but as I recall there was no easy way to upgrade existing installations to support password salts using Java 5, but the new encryption methods in Java 6 made it possible. With JAMWiki 2.0 dropping support for Java 5 it should now be feasible to support password salts and upgrades, although it has been so long since I looked at the issue that I don't remember what the specific issues requiring a new Java version were. Let me know if you run into any problems as this was one of the items I had on the TODO list once Java 5 support was dropped. Ryan On 3/10/2013 11:56 AM, jam...@li... wrote: > Hi, > > I stumbled about JAMWiki not using any salt for password hashing and > wanted to start a request about it. Than I figured JIRA exists and > found JAMWIKI-36 ... So now I'm trying to take care about it. > > While crawling through the code, to get an image about who's using > what, when and why I saw > > org.jamwiki.utils.Encryption.bytes2String(byte[]) > > and am wondering, what's the concrete intention behind it? I see what > it does and from it's usage I see what's it currently expected to > do. But to achieve the very same much simpler code would be > sufficient. [1] So I fear there's something else "implied", which I > don't see ... > > Anybody out there able to answer my question? > > Best regards, Peter > > [1]: 'new String(byteData, "US-ASCII")' or 'new String(byteData)' > because simply casting byte to char is only valid for the very > optimistic assumption every provided byte value represents a valid > US-ASCII (or system default charset) character. > > The concrete question that came up to me is: what, if this method > just returns a hex string representation of 'byte[]'? OTOH than > Encryption.decrypt64(String) might break ... |
From: Peter P. <pit...@us...> - 2013-03-16 23:46:20
Attachments:
jamwiki_password_salt.zip
|
Hi, Am 10.03.2013 um 20:14 schrieb jam...@li...: > I think the Encryption.bytes2String method can be killed - if I had to > guess that's probably just very old code and no one noticed the possible > cleanup. Did a SVN history search and the code came already with import from VQwiki. Cleaned it up, because I think it's useless and even more: dangerous. "new String()" is dangerous the very same way, but does not obfuscate this; So I preferred it for now, until I found a way to rearrange this stuff as a whole thing. > One caveat if you're looking into the password salts is to ensure that > any change will work for existing installations (or with an upgrade > process). I gave my very best. There's a small upgrade necessity, but I'll explain below. > I haven't looked at that issue in a long time, but as I > recall there was no easy way to upgrade existing installations to > support password salts using Java 5, I actually had and have no idea, why salts for passwords should be a matter of Java version, whether 1.4, 5, 6 or 7. I implemented salts without any known binding to used Java version. I created a comprehensive patch, which hopefully covers all relevant locations. I'll attach it to this mail. If this list blocks it, I'll upload it to some web space and share the link. The reason behind this is, I'd like to avoid committing an unchecked patch to my branch, that has to be reverted. "Unchecked" in the sense I'd like to have at least a second, even better third, opinion on the proposal for change. So it would be nice if someone could apply this patch to a local export of the sources and test if every thing works well; for me it does. Maybe someone can even test if an already existing installation still works ... After the necessary small upgrade. The details and my thoughts are in "README.md", contained in the mentioned attachment. So ... Feedback time :-) -- Best regards, Peter |
From: Ryan H. <rya...@gm...> - 2013-03-18 04:25:46
|
On 3/16/2013 4:46 PM, Peter Palmreuther wrote: > So it would be nice if someone could apply this patch to a local > export of the sources and test if every thing works well; for me it > does. Maybe someone can even test if an already existing installation > still works ... After the necessary small upgrade. I haven't tried running your code yet, but reading through the patch and approach it makes sense and looks fairly elegant. I can add the code to automatically detect an upgrade and increase the password field size in the database if you'd like - I'm looking into possibly using Flyway for schema management in 2.0, but until that happens a schema change is a simple matter of modifying UpgradeServlet and DatabaseUpgrades. With respect to the specific issue that I thought required Java 6, looking at http://jira.jamwiki.org/browse/JAMWIKI-36 I think that may have been related to the Jasypt library that is mentioned in the comments, but I don't recall specifically - I have vivid memories of working on this issue in the basement of the LA Cathedral while my girlfriend rehearsed for a Christmas concert, but I probably should have written down some notes as well :) I'll get your changes running locally in the next couple of days and let you know if I encounter any problems. If you'd like to commit it to a branch please go ahead. Thanks for working on this - it will be a nice security improvement that I know several people have wanted. Ryan |
From: Ryan H. <rya...@gm...> - 2013-03-19 06:10:00
|
Hi Peter, On 3/16/2013 4:46 PM, Peter Palmreuther wrote: > So it would be nice if someone could apply this patch to a local > export of the sources and test if every thing works well; for me it > does. Maybe someone can even test if an already existing installation > still works ... After the necessary small upgrade. After updating the column size to 150 characters I ran your patch locally without issue - it used my old password without issue (unsalted), and after updating to a new password used the new password with salt. When you're ready to merge this I can do a larger test with some of the test sites I have. Ryan |
From: Peter P. <pit...@us...> - 2013-03-20 05:39:52
|
Hi Ryan, Am 19.03.2013 um 07:09 schrieb Ryan Holliday <rya...@gm...>: > Hi Peter, > > On 3/16/2013 4:46 PM, Peter Palmreuther wrote: >> So it would be nice if someone could apply this patch to a local >> export of the sources and test if every thing works well; for me it >> does. Maybe someone can even test if an already existing installation >> still works ... After the necessary small upgrade. > > After updating the column size to 150 characters I ran your patch > locally without issue - it used my old password without issue > (unsalted), and after updating to a new password used the new password > with salt. When you're ready to merge this I can do a larger test with > some of the test sites I have. Thanks for the good news. I'm ready to commit, it's just matter of merging my local separate branch into SVN. You should see the message on jamwiki-commit in a few minutes. Thanks for testing, Peter PS: I assume you saw the password with salt in your database as well, after changing it? |
From: Peter P. <pit...@us...> - 2013-03-20 21:16:40
|
Hi Ryan, Am 19.03.2013 um 07:09 schrieb Ryan Holliday <rya...@gm...>: > On 3/16/2013 4:46 PM, Peter Palmreuther wrote: >> So it would be nice if someone could apply this patch to a local >> export of the sources and test if every thing works well; for me it >> does. Maybe someone can even test if an already existing installation >> still works ... After the necessary small upgrade. > > After updating the column size to 150 characters I ran your patch > locally without issue - it used my old password without issue > (unsalted), and after updating to a new password used the new password > with salt. When you're ready to merge this I can do a larger test with > some of the test sites I have. I've got another request: I saw the "encrypt64" method in Encryption, and for keeping things with introducing the salt I simply used existing infrastructure. After salting work I had some time and energy to inspect the other infrastructure elements. I couldn't see the reason behind DES encrypting password hash ... Does anybody know the rational behind applying a DES encryption to SHA-512 hash of the password with a not so secret key? In the end this makes the encrypted password 96 bytes, while directly Base64 encoding the hash would only require 56 bytes. This way the added salt (8) and hashing algorithm (7) and delimiters (3) would sum up to 74 bytes, which would fit into the current column size. It would make up updating a little more complex, as I'd need to write a DES decrypting routine, but that's not a big deal at all. It's just a matter of: is it OK? I don't know about enough real world installations and number of users that need to get migrated their data. The positive would be a less complex code with same security level, finally raised by enabling salting password once they're changed by their users. What's your opinion? -- Regards, Peter |
From: Ryan H. <rya...@gm...> - 2013-03-20 21:51:02
|
Hi Peter, On 3/20/2013 2:16 PM, Peter Palmreuther wrote: > Does anybody know the rational behind applying a DES encryption to > SHA-512 hash of the password with a not so secret key? It looks to me like the extra encryption is just a remnant from the original VQWiki code that never got removed - it's there in revision 1 of Encryption.java. So long as the SHA algorithm is applied with a random salt then I think the password is sufficiently secure without the need for any additional processing. Provided it's backwards compatible with 1.2.x (or later) and doesn't open any security holes please feel free to make whatever cleanups you think are necessary. Ryan |
From: Ryan H. <rya...@gm...> - 2013-03-22 05:55:37
|
Hi Peter, > I'm ready to commit, it's just matter of merging my local separate branch into SVN. > You should see the message on jamwiki-commit in a few minutes. I should be able to get your code merged and also add the needed upgrade code for modifying the database column size this weekend. You had mentioned possibly removing the extraneous 64 bit encoding step, so if that will make the database schema change unnecessary let me know and I'll hold off on putting the changes in trunk for now while we work out the details. Ryan |
From: Peter P. <pit...@us...> - 2013-03-22 06:34:10
|
Hi Ryan, Am 22.03.2013 um 06:55 schrieb Ryan Holliday <rya...@gm...>: > Hi Peter, > >> I'm ready to commit, it's just matter of merging my local separate branch into SVN. >> You should see the message on jamwiki-commit in a few minutes. > > I should be able to get your code merged and also add the needed upgrade > code for modifying the database column size this weekend. You had > mentioned possibly removing the extraneous 64 bit encoding step, so if > that will make the database schema change unnecessary let me know and > I'll hold off on putting the changes in trunk for now while we work out > the details. Please hold off the merge, I'm working on reverting the superfluous encryption step, exactly to make the DB upgrade unnecessary. I'll report back shortly. -- Regards, Peter |