News for hackers. Stuff that matters.
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @09:45AM (#20242416)
RAM encryption is a feature in my password manager (java):

https://github.com/andy-goryachev/PasswordSafe/blob/master/s...

Curiously, RAM encryption, and its relative - clearing secrets from memory when not in use - cannot be added to the Bouncycastle library because they use java BigInteger (unless reflection is used of course).

Re:SSH gets protection against side-channel attacks by kjeetgill on Friday June 21, 2019 @01:00PM (#20244295)
You can't treat memory, even arrays, as singular memory locations in Java. Stuff moves around because collectors are cimpacting.. If you want to "write in place" in Java you need to either use a non-moving garbage collector, use sun.misc.Unsafe to read write memory directly, or mayyyyyybe take advantage of humongous allocations (arrays big enough that the JVM won't move them).
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @02:19PM (#20245043)
Direct ByteBuffer?
Re:SSH gets protection against side-channel attacks by the8472 on Friday June 21, 2019 @03:40PM (#20245701)
Yes, a direct byte buffer wrapped in class that ensures you can never copy the data somewhere else. That would also require cryptographic routines that can operate on bytebuffers or varhandles, which is quite an obstacle since many crypto libraries consume keys as byte[].
Re:SSH gets protection against side-channel attacks by sjwright on Friday June 21, 2019 @10:27AM (#20242754)
How do you guarantee actual clearing of physical memory in a garbage collected VM?
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @10:51AM (#20242967)
by explicitly clearing it when an operation is finished.

example:

https://github.com/andy-goryachev/PasswordSafe/blob/master/s...

byte[] key = generateKey(); try { // sensitive operation } finally { Crypto.zero(key); }

once the operation finishes, the memory is cleared (and possibly subject to gc)

the problem is that some java classes, for instance BigInteger, are not designed for cryptographic operations - it's underlying arrays are not easily accessible (save for reflection).

Re:SSH gets protection against side-channel attacks by saurik on Friday June 21, 2019 @11:23AM (#20243300)
In that code, after generateKey, during the sensitive operation, the system might need to do a garbage collection, at which point this array might have been copied to a different location in memory before your call to zero. You have to also "pin" (afaik this is the usual terminology for this) that array to a fixed location (which would then have to be a feature of that runtime and garbage collector) after allocating it but before generating the key.
Re:SSH gets protection against side-channel attacks by rurban on Saturday June 22, 2019 @10:14AM (#20249657)
Java also has no mfence or clflush support, so crypto.zero would never be secure. It might overwrite the key in the store buffer only, but not on the heap immediately, so prone to sidechannel attacks.
Re:SSH gets protection against side-channel attacks by java-man on Tuesday June 25, 2019 @11:26AM (#20275165)
This is interesting. Could you explain this please?
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @11:33AM (#20243390)
So what you are saying is that JVM copying surviving object between generational pools might expose secrets in memory?

A very good point, thank you.

What could be done to mitigate this? Direct ByteBuffer per

https://stackoverflow.com/questions/5670862/bytebuffer-alloc...

?

Re:SSH gets protection against side-channel attacks by MarkSweep on Friday June 21, 2019 @06:17PM (#20246728)
In .NET you can pin memory in the GC heap, either using something like the fixed expression in C# or GCHandle. A quick Googleing did not turn up something usable directly by Java, except ByteBuffer.
Re:SSH gets protection against side-channel attacks by pstrateman on Friday June 21, 2019 @11:13AM (#20243213)
That operation is almost certainly optimized out.
Re:SSH gets protection against side-channel attacks by java-man on Friday June 21, 2019 @11:34AM (#20243405)
Would you elaborate please?
Re:SSH gets protection against side-channel attacks by pstrateman on Saturday June 22, 2019 @01:24PM (#20250674)
The compiler will see that your operation does nothing and simply not do it.
Re:SSH gets protection against side-channel attacks by java-man on Sunday June 23, 2019 @12:35AM (#20253325)
What I mean was: do you know this to be the case for JVM 8 later? This is an interesting subject. Was there a study or a paper you can refer me to?
Re:SSH gets protection against side-channel attacks by pstrateman on Sunday June 23, 2019 @04:11PM (#20258368)
JVM 8 isn't an implementation, it's a specification.

Assuming you mean oracles implementation, it's likely that it is.

https://www.sjoerdlangkemper.nl/2016/05/22/should-passwords-... http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buf... https://man.openbsd.org/explicit_bzero.3

Re:SSH gets protection against side-channel attacks by java-man on Sunday June 23, 2019 @04:32PM (#20258482)
Thank you. I was hoping for a more definitive answer, may be a reference to an explicit test involving memory dump analysis.
Re:SSH gets protection against side-channel attacks by marvin-83 on Friday June 21, 2019 @11:55AM (#20243620)
I believe he is referring to compiler optimisation which removes wasteful or extraneous operations. I don't write in Java though, so can't comment more than that.