aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/thialfihar/android/apg/Apg.java
diff options
context:
space:
mode:
authorThialfihar <thialfihar@gmail.com>2010-05-16 13:17:45 +0000
committerThialfihar <thialfihar@gmail.com>2010-05-16 13:17:45 +0000
commit9855f4d1441ac1e5dc7df19ebd0272e5f94e2aa2 (patch)
tree5bf2a68bc44d433ca62521971d3569bf39f397ad /src/org/thialfihar/android/apg/Apg.java
parentf94af3e4e66c4b0cd184931ec5aa6503764bfb38 (diff)
downloadopen-keychain-9855f4d1441ac1e5dc7df19ebd0272e5f94e2aa2.tar.gz
open-keychain-9855f4d1441ac1e5dc7df19ebd0272e5f94e2aa2.tar.bz2
open-keychain-9855f4d1441ac1e5dc7df19ebd0272e5f94e2aa2.zip
honour the pass phrase cache TTL by running a timer and removing expired cached pass phrases
Diffstat (limited to 'src/org/thialfihar/android/apg/Apg.java')
-rw-r--r--src/org/thialfihar/android/apg/Apg.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java
index a453cdf4a..5071e3d01 100644
--- a/src/org/thialfihar/android/apg/Apg.java
+++ b/src/org/thialfihar/android/apg/Apg.java
@@ -41,6 +41,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Vector;
import java.util.regex.Pattern;
@@ -293,9 +294,26 @@ public class Apg {
if (cpp == null) {
return null;
}
+ // set it again to reset the cache life cycle
+ setCachedPassPhrase(realId, cpp.passPhrase);
return cpp.passPhrase;
}
+ public static void cleanUpCache(int ttl) {
+ long now = new Date().getTime();
+
+ Vector<Long> oldKeys = new Vector<Long>();
+ for (Map.Entry<Long, CachedPassPhrase> pair : mPassPhraseCache.entrySet()) {
+ if ((now - pair.getValue().timestamp) >= 1000 * ttl) {
+ oldKeys.add(pair.getKey());
+ }
+ }
+
+ for (long keyId : oldKeys) {
+ mPassPhraseCache.remove(keyId);
+ }
+ }
+
public static PGPSecretKey createKey(Context context,
int algorithmChoice, int keySize, String passPhrase,
PGPSecretKey masterKey)
@@ -1266,7 +1284,7 @@ public class Apg {
PGPSignatureGenerator signatureGenerator = null;
progress.setProgress(R.string.progress_preparingStreams, 5, 100);
- // encryptFile and compress input file content
+ // encrypt and compress input file content
PGPEncryptedDataGenerator cPk =
new PGPEncryptedDataGenerator(symmetricAlgorithm, true, new SecureRandom(),
new BouncyCastleProvider());