11 ms·
An interesting point and I wonder if there are thoughts on if the JVM should implement flags that do overwrite before gc (obv worse perf but some cases have use
by gretch 4y ago
An interesting point and I wonder if there are thoughts on if the JVM should implement flags that do overwrite before gc (obv worse perf but some cases have use for it).
Or at the least, let a program implement parts of the gc api and plug it in themselves.
- cogman10 4y agoYou can with the JVM. https://docs.oracle.com/javase/9/docs/api/java/lang/ref/Cleaner.html https://docs.oracle.com/javase/9/docs/api/java/lang/ref/Clea... However, the issue isn't so much that doing that, rather it's that GC will potentially never collect the memory. In the JVM, the GC primarily runs when enough allocations happen. It's not on some timer. So the concern would then be having a password sitting in memory for hours (or even days) on end.
- lukev 4y agoThere are definitely mechanisms to do this in the JVM, such as the `finalize` method or in more recent versions, the `java.lang.ref.Cleaner` class. However, using them correctly in the context of memory leakage and safety is non-intuitive and is definitely a bit tricky.
- dwaite 4y agoTypically you would be using something like JCE for these sensitive functions, and a JCE implementation could be written (potentially with VM support) to have such functionality. These also can do things like zero out binary data/keys after use. This wouldn't help once you create your own objects however, e.g. JSON parse from a decrypted block.