blob: ba689fe9bd7c088b52b4303b374950074382f8b9 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package com.zeapo.pwdstore;
import android.net.Uri;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
/**
* A single entry in password store.
*/
public class PasswordEntry {
private static final String[] USERNAME_FIELDS = new String[]{"login", "username"};
private final String extraContent;
private final String password;
private final String username;
private final String totpSecret;
public PasswordEntry(final ByteArrayOutputStream os) throws UnsupportedEncodingException {
this(os.toString("UTF-8"));
}
public PasswordEntry(final String decryptedContent) {
final String[] passContent = decryptedContent.split("\n", 2);
password = passContent[0];
extraContent = passContent.length > 1 ? passContent[1] : "";
username = findUsername();
totpSecret = findTotpSecret(decryptedContent);
}
public String getPassword() {
return password;
}
public String getExtraContent() {
return extraContent;
}
public String getUsername() {
return username;
}
public String getTotpSecret() {
return totpSecret;
}
public boolean hasExtraContent() {
return extraContent.length() != 0;
}
public boolean hasUsername() {
return username != null;
}
public boolean hasTotp() { return totpSecret != null; }
private String findUsername() {
final String[] extraLines = extraContent.split("\n");
for (String line : extraLines) {
for (String field : USERNAME_FIELDS) {
if (line.toLowerCase().startsWith(field + ":")) {
return line.split(": *", 2)[1];
}
}
}
return null;
}
private String findTotpSecret(String decryptedContent) {
for (String line : decryptedContent.split("\n")) {
if (line.startsWith("otpauth://totp/")) {
return Uri.parse(line).getQueryParameter("secret");
}
}
return null;
}
}
|