blob: 179a8a7bafeeb29a665bfd5ad71e2e68a0494bd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}
}
}
|