mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 14:32:49 +00:00
Add support for importing a plain text Google Authenticator URI file
This is the "standard" format discussed in #138.
This commit is contained in:
parent
866466d158
commit
8fda6937a5
3 changed files with 93 additions and 45 deletions
|
@ -34,6 +34,7 @@ public abstract class DatabaseImporter {
|
||||||
_importers.put("FreeOTP+", FreeOtpPlusImporter.class);
|
_importers.put("FreeOTP+", FreeOtpPlusImporter.class);
|
||||||
_importers.put("Google Authenticator", GoogleAuthImporter.class);
|
_importers.put("Google Authenticator", GoogleAuthImporter.class);
|
||||||
_importers.put("Microsoft Authenticator", MicrosoftAuthImporter.class);
|
_importers.put("Microsoft Authenticator", MicrosoftAuthImporter.class);
|
||||||
|
_importers.put("Plain text", GoogleAuthUriImporter.class);
|
||||||
_importers.put("Steam", SteamImporter.class);
|
_importers.put("Steam", SteamImporter.class);
|
||||||
_importers.put("TOTP Authenticator", TotpAuthenticatorImporter.class);
|
_importers.put("TOTP Authenticator", TotpAuthenticatorImporter.class);
|
||||||
_importers.put("WinAuth", WinAuthImporter.class);
|
_importers.put("WinAuth", WinAuthImporter.class);
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.beemdevelopment.aegis.importers;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
||||||
|
import com.beemdevelopment.aegis.otp.GoogleAuthInfoException;
|
||||||
|
import com.beemdevelopment.aegis.vault.VaultEntry;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class GoogleAuthUriImporter extends DatabaseImporter {
|
||||||
|
public GoogleAuthUriImporter(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getAppPkgName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getAppSubPath() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GoogleAuthUriImporter.State read(DatabaseImporter.FileReader reader) throws DatabaseImporterException {
|
||||||
|
ArrayList<String> lines = new ArrayList<>();
|
||||||
|
|
||||||
|
try (InputStreamReader streamReader = new InputStreamReader(reader.getStream());
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(streamReader)) {
|
||||||
|
String line;
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
if (!line.isEmpty()) {
|
||||||
|
lines.add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new DatabaseImporterException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GoogleAuthUriImporter.State(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class State extends DatabaseImporter.State {
|
||||||
|
private ArrayList<String> _lines;
|
||||||
|
|
||||||
|
private State(ArrayList<String> lines) {
|
||||||
|
super(false);
|
||||||
|
_lines = lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseImporter.Result convert() {
|
||||||
|
DatabaseImporter.Result result = new DatabaseImporter.Result();
|
||||||
|
|
||||||
|
for (String line : _lines) {
|
||||||
|
try {
|
||||||
|
VaultEntry entry = convertEntry(line);
|
||||||
|
result.addEntry(entry);
|
||||||
|
} catch (DatabaseImporterEntryException e) {
|
||||||
|
result.addError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VaultEntry convertEntry(String line) throws DatabaseImporterEntryException {
|
||||||
|
try {
|
||||||
|
GoogleAuthInfo info = GoogleAuthInfo.parseUri(line);
|
||||||
|
return new VaultEntry(info);
|
||||||
|
} catch (GoogleAuthInfoException e) {
|
||||||
|
throw new DatabaseImporterEntryException(e, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,8 @@
|
||||||
package com.beemdevelopment.aegis.importers;
|
package com.beemdevelopment.aegis.importers;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import com.beemdevelopment.aegis.vault.VaultEntry;
|
|
||||||
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
|
||||||
import com.beemdevelopment.aegis.otp.GoogleAuthInfoException;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import com.beemdevelopment.aegis.vault.VaultEntry;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class WinAuthImporter extends DatabaseImporter {
|
public class WinAuthImporter extends DatabaseImporter {
|
||||||
public WinAuthImporter(Context context) {
|
public WinAuthImporter(Context context) {
|
||||||
|
@ -27,57 +21,29 @@ public class WinAuthImporter extends DatabaseImporter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WinAuthImporter.State read(FileReader reader) throws DatabaseImporterException {
|
public WinAuthImporter.State read(FileReader reader) throws DatabaseImporterException {
|
||||||
ArrayList<String> lines = new ArrayList<>();
|
GoogleAuthUriImporter importer = new GoogleAuthUriImporter(getContext());
|
||||||
|
GoogleAuthUriImporter.State state = importer.read(reader);
|
||||||
try {
|
return new State(state);
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(reader.getStream()));
|
|
||||||
String line;
|
|
||||||
|
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
lines.add(line);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new DatabaseImporterException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new State(lines);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class State extends DatabaseImporter.State {
|
public static class State extends DatabaseImporter.State {
|
||||||
private ArrayList<String> _lines;
|
private GoogleAuthUriImporter.State _state;
|
||||||
|
|
||||||
private State(ArrayList<String> lines) {
|
private State(GoogleAuthUriImporter.State state) {
|
||||||
super(false);
|
super(false);
|
||||||
_lines = lines;
|
_state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result convert() {
|
public Result convert() {
|
||||||
Result result = new Result();
|
Result result = _state.convert();
|
||||||
|
|
||||||
for (String line : _lines) {
|
for (VaultEntry entry : result.getEntries()) {
|
||||||
try {
|
entry.setIssuer(entry.getName());
|
||||||
VaultEntry entry = convertEntry(line);
|
entry.setName("WinAuth");
|
||||||
result.addEntry(entry);
|
|
||||||
} catch (DatabaseImporterEntryException e) {
|
|
||||||
result.addError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static VaultEntry convertEntry(String line) throws DatabaseImporterEntryException {
|
|
||||||
try {
|
|
||||||
GoogleAuthInfo info = GoogleAuthInfo.parseUri(line);
|
|
||||||
VaultEntry vaultEntry = new VaultEntry(info);
|
|
||||||
vaultEntry.setIssuer(vaultEntry.getName());
|
|
||||||
vaultEntry.setName("WinAuth");
|
|
||||||
|
|
||||||
return vaultEntry;
|
|
||||||
} catch (GoogleAuthInfoException e) {
|
|
||||||
throw new DatabaseImporterEntryException(e, line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue