summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/blinkt/openvpn/core/PasswordCache.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/de/blinkt/openvpn/core/PasswordCache.java')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/PasswordCache.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/PasswordCache.java b/app/src/main/java/de/blinkt/openvpn/core/PasswordCache.java
new file mode 100644
index 00000000..179a8a7b
--- /dev/null
+++ b/app/src/main/java/de/blinkt/openvpn/core/PasswordCache.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012-2016 Arne Schwabe
+ * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
+ */
+
+package de.blinkt.openvpn.core;
+
+import java.util.UUID;
+
+/**
+ * Created by arne on 15.12.16.
+ */
+
+public class PasswordCache {
+ public static final int PCKS12ORCERTPASSWORD = 2;
+ public static final int AUTHPASSWORD = 3;
+ private static PasswordCache mInstance;
+ final private UUID mUuid;
+ private String mKeyOrPkcs12Password;
+ private String mAuthPassword;
+
+ private PasswordCache(UUID uuid) {
+ mUuid = uuid;
+ }
+
+ public static PasswordCache getInstance(UUID uuid) {
+ if (mInstance == null || !mInstance.mUuid.equals(uuid)) {
+ mInstance = new PasswordCache(uuid);
+ }
+ return mInstance;
+ }
+
+ public static String getPKCS12orCertificatePassword(UUID uuid, boolean resetPw) {
+ String pwcopy = getInstance(uuid).mKeyOrPkcs12Password;
+ if (resetPw)
+ getInstance(uuid).mKeyOrPkcs12Password = null;
+ return pwcopy;
+ }
+
+
+ public static String getAuthPassword(UUID uuid, boolean resetPW) {
+ String pwcopy = getInstance(uuid).mAuthPassword;
+ if (resetPW)
+ getInstance(uuid).mAuthPassword = null;
+ return pwcopy;
+ }
+
+ public static void setCachedPassword(String uuid, int type, String password) {
+ PasswordCache instance = getInstance(UUID.fromString(uuid));
+ switch (type) {
+ case PCKS12ORCERTPASSWORD:
+ instance.mKeyOrPkcs12Password = password;
+ break;
+ case AUTHPASSWORD:
+ instance.mAuthPassword = password;
+ break;
+ }
+ }
+
+
+}