KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > KeyPairRefreshThread


1 import whisper.PrivateKey;
2
3 /** Thread that attempts to keep the user's KeyPair in real memory.
4 * A single instance of KeyPairRefreshThread is spawned by the main window.
5 * This thread simpley reads the private key of the KeyPair every 1 minute.
6 * </p><p>
7 * By constantly accessing the KeyPair, it reduces the chance of the KeyPair being placed in
8 * virtual memory / swap file - ie stored on the hard drive. Most OSs swap memory that has not been
9 * accessed recently to the hard drive. This would mean the keypair, including the private key in unencrypted form,
10 * would stored on the hard drive. We cannot rely on the user disabling virtual memory when using secuirty applications, or on using a OS that encrypts the swap file, or securely wiping the swap file on shutdown.
11 * </p><p>
12 * Due to the uncontrolable and unpredictable nature of virtual memory, this thread is not guarenteed to achive its aim. An OS encrypted swap file or to disable virtual memory is still the best option.*/

13 public final class KeyPairRefreshThread extends Thread JavaDoc{
14     
15     private static final int ONE_MINUTE=1000;
16     
17     /** Creates a new KeyPairRefreshThread, which is a low-priority daemon thread.*/
18     public KeyPairRefreshThread(){
19         super("Key Pair Refresh Thread");
20         setDaemon(true);
21         setPriority(Thread.MIN_PRIORITY);
22     }
23     
24     /** Reads the private key every minute.*/
25     public void run(){
26         try{
27             while( !isInterrupted() ){
28                 sleep(ONE_MINUTE);
29                 if(isInterrupted()){
30                     return;
31                 }
32                 if(WhisperIM.KEYPAIR!=null){
33                     WhisperIM.KEYPAIR.privateKey().getD();
34                     int i=WhisperIM.MainWindow.keycachekey[0];
35                 }
36                 if(isInterrupted()){
37                     return;
38                 }
39             }
40         }
41         catch(Exception JavaDoc e){ // e.g. if thread is interrupted whilst sleeping
42
return; // stop running
43
}
44     }
45 }
Popular Tags