-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protection against RAM attacks #83
Comments
Feel free to throw it over and I'll have a look. |
@ChrisMcKee It doesn't sound like @grzegorzkloc is actively working on such a thing (correct me if I'm wrong), but rather requesting the feature. This sound like its in my wheelhouse and sounded like fun, so I've began taking stab at it. I'm also ensuring the framework methods that I call don't leave a copy of the bytes sitting around for the GC to collect, which makes it more challenging indeed. @ChrisMcKee Question for you: Am I allowed to use the unsafe keyword? Will you accept such a solution? The constraints and requirements seem to be pushing in that direction, and I was wondering if unsafe code blocks were off the table or a deal breaker for you? I will obviously prefer a solution that avoids the use of the unsafe keyword, but it may be the most pragmatic solution. The trick is getting it from a string or SecureString to an array of bytes without the framework making a copy, which I wouldn't be able to zero out... Yeah it probably doesn't make much sense to this without providing a SecureString overload, so expect that. I will look at that branch you mentioned to see what his approach was, and adopt that if its solves the problem to my satisfaction. Heck, it may be that that is already the correct and total solution, and I need not do anything. I don't know yet, I haven't looked. |
The secure string branch 'worked' afaik It's a niche requirement so I'm on the fence when it comes to adding this as an actual part of the library. If you look at the .net dpa library you'll see it leads into the wonderful world of unsafe and the game of playing hide the key / removing from memory. The use case is nearly always wpf apps as with web apps the password has already spent time as a string in the body / serialiser etc. |
Re-reading what @grzegorzkloc said, I realized I totally misinterpreted what they were asking for; they just want an overload that takes an array of bytes, so they can zero it out after hashing and rest easy knowing that the BCrypt library didn't make a copy in memory. Also, they already worked out some code that does this, contrary to what I thought before. I, for one, think this is a good idea; it allows the library to be used in a more secure fashion, and it solves the non-trivial problem of trying to move a string into a byte array without making a copy in memory for the GC to clean up, which might not have made a lot of sense to do at that point anyways. So its a win-win. Now, due to the way BCrypt versioning is handled, adding such an overload without a lot of duplication of code isn't so straight forward, so I would be interested in seeing what grzegorzkloc has. They have a fork but I cannot discern any changes made to it. So @grzegorzkloc lets see what you have. Ignore my previous comments on this thead, I was confused. |
"a more secure fashion"... Really depends on the threat model but as stated prior, other than in wpf where you can buffer keystrokes to secure string from the outset, it's a lot of effort for inconsequential gain (imo). I'd be interested in the use case though. |
Well I suppose you're right. If you are at the point where you're considering the scenario where a threat actor is able to read your ram, you've got bigger problems... |
First of all, thank you for the answer and taking the time to think about my question / suggestion. My suggestion is actually very simple, it would just be an overload of a few methods. Please find an example based on the HashPassword method below:
The advantages of above changes (at least from my point of view) are as follows:
I think the above could work well with a SecureString extension method such as this one (func could be a simple GenerateHash from your library):
Would you be interested in introducing such overloads? |
I can work on adding in byte array based methods similar to the frameworks handling of PBKDF2; these only limit exposure to GC though and in no way provide a guarantee of zero exposure. Array clear is a built in method. ref: |
Thank you very much. I am sure that these changes will be beneficial not only to me but to many other users as well. |
+1 |
I'd replace Just my 2c. |
For sure; it was certainly looking to be the choice. I'll undoubtedly have to tackle the documentation too as realistically this isn't something everyone needs to use and, realistically, I doubt most devs will even consider threat modelling before using something, in which case the standard routes the safest. Just so I don't have to find them every few months and so I don't lose them again when I eventually un-gunk the docs. Secure String ...
|
To be clear by "safest" (because god only knows this is public, and someone will appear with a tinfoil hat on to complain) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Good day,
first of all thank you for a great library, awesome job, much appreciated.
I am using your library in a project where cyber security is vital. In order to comply with some external requirements our software must ensure that the passwords are not stored in RAM longer than they need to. As we don't not have any control over when the GC collects the password string (and the string itself is immutable in memory) it would be a good idea to provide a mechanism to be able to overwrite the password in memory.
Do you think there is a chance for a feature which would include overloaded methods as below:
Above changes would allow users to alter the contents of a password variable (because as you know we cannot do it with a string without using unsafe code) once a hash is generated or verified.
Should you be interested in including such a feature I have a sample code waiting and checked using WinDbg which would provide functionality described above.
Thank you for your time and an awesome piece of code which makes our lives easier.
The text was updated successfully, but these errors were encountered: