3 ms·
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 cop
by saurik 7y ago
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.
- java-man 7y agoSo 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-allocate-vs-bytebuffer-allocatedirect https://stackoverflow.com/questions/5670862/bytebuffer-alloc... ?
- MarkSweep 7y agoIn .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.
- rurban 7y agoJava 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.
- java-man 7y agoThis is interesting. Could you explain this please?