
Signature
Eric Sosman
esosman@ieee-dot-org.invalid
> Make sure dispose() is used. You might even go so far
> as to set a timer and call dispose() yourself if the user
> hasn't called it within T milliseconds.
>
> But I doubt any such mechanism -- not even finalize() --
> will be much protection against a determined snoop. After
Brian Goetz's essential /Java Concurrency in Practice/ explains that
finalize() immediately puts you into a concurrent-programming situation. He
recommends finally {} blocks. He also refers the reader to
<http://www.hpl.hp.com/personal/Hans_Boehm/misc_slides/java_finalizers.pdf>
for details on how tricky it is to get finalize() right.
Even before runFinalizersOnExit() was deprecated it was already "inherently
unsafe", as the Javadocs describe it.
Use finally {}.

Signature
Lew
>> I am writing a security related application and I want to make sure
>> that some critical data is wiped after it is finished with. I have
[quoted text clipped - 8 lines]
>
> Make sure dispose() is used.
I try. One thought is "It is a sackable offence not to use dispose",
but even then someone is going to slip up somewhere.
>You might even go so far
>as to set a timer and call dispose() yourself if the user
>hasn't called it within T milliseconds.
Probably not practical, but I will have a look at it.
> But I doubt any such mechanism -- not even finalize() --
>will be much protection against a determined snoop.
Agreed, there is no 100% security - all you can do is to make it more
difficult.
>After all, it's not (very) important what was in the process' memory
>at the moment it exited, but what's in memory or swap while
>the process is running.
What is in swap space is not my problem luckily. The OS team are
scratching their heads over that one.
>If the Bad Guy runs your classes in a JVM which itself is running
>under a debugger, or even if he can just cause the JVM to dump
>core, he's got your data even if the very next thing you do is wipe it.
Not my data, his own data. I am talking about wiping things like
passphrases and entropy.
Thaks for the ideas,
rossum
Lew - 24 Nov 2007 17:13 GMT
> Not my data, his own data. I am talking about wiping things like
> passphrases and entropy.
I don't know about entropy, but you shouldn't store a passphrase in memory
anyway, even during a program run. The program should forget the passphrase
pretty near immediately.

Signature
Lew
Daniel Pitts - 24 Nov 2007 18:23 GMT
>>> I am writing a security related application and I want to make sure
>>> that some critical data is wiped after it is finished with. I have
[quoted text clipped - 9 lines]
> I try. One thought is "It is a sackable offence not to use dispose",
> but even then someone is going to slip up somewhere.
Alternatively, you could "invert" your API a little bit. The only way to
retrieve a secure resource would be to call a method that allocates it,
calls a call-back, and then disposes it:
public void executeSecure(SecureOperation operation) {
SecureResource resource = createResource();
try {
operation.perform(resource);
} finally {
resource.dispose();
}
}
Note, that in the event of a system or application crash, dispose may
never be called.
Also note, that at any time, the used memory could be written to a swap
file. If that happens, it may never get overwritten. Typically,
programs that deal with sensitive data lock their memory so that it
can't be swapped out. I don't think you can do that in Java, so if it is
truly that sensitive, you might need to go into native code.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
rossum - 24 Nov 2007 20:42 GMT
>>>> I am writing a security related application and I want to make sure
>>>> that some critical data is wiped after it is finished with. I have
[quoted text clipped - 21 lines]
> }
>}
Good thinking, that will work for some of my interface.
>Note, that in the event of a system or application crash, dispose may
>never be called.
[quoted text clipped - 4 lines]
>can't be swapped out. I don't think you can do that in Java, so if it is
>truly that sensitive, you might need to go into native code.
Luckily, that is a problem for the OS team, not for me :)
Thanks for the suggestion,
rossum