mirror of https://github.com/beemdevelopment/Aegis
Merge pull request #1691 from michaelschattgen/feature/proton-importer
Add support for Proton Authenticator exportsmaster
commit
bc600de7ab
@ -0,0 +1,96 @@
|
||||
package com.beemdevelopment.aegis.importers;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
||||
import com.beemdevelopment.aegis.otp.GoogleAuthInfoException;
|
||||
import com.beemdevelopment.aegis.otp.OtpInfo;
|
||||
import com.beemdevelopment.aegis.util.IOUtils;
|
||||
import com.beemdevelopment.aegis.vault.VaultEntry;
|
||||
import com.topjohnwu.superuser.io.SuFile;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ProtonAuthenticatorImporter extends DatabaseImporter {
|
||||
|
||||
public ProtonAuthenticatorImporter(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SuFile getAppPath() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull State read(@NonNull InputStream stream, boolean isInternal) throws DatabaseImporterException {
|
||||
try {
|
||||
String contents = new String(IOUtils.readAll(stream), UTF_8);
|
||||
JSONObject json = new JSONObject(contents);
|
||||
|
||||
return new DecryptedState(json);
|
||||
} catch (JSONException | IOException e) {
|
||||
throw new DatabaseImporterException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DecryptedState extends DatabaseImporter.State {
|
||||
private final JSONObject _json;
|
||||
|
||||
public DecryptedState(@NonNull JSONObject json) {
|
||||
super(false);
|
||||
_json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Result convert() throws DatabaseImporterException {
|
||||
Result result = new Result();
|
||||
|
||||
try {
|
||||
JSONArray entries = _json.getJSONArray("entries");
|
||||
for (int i = 0; i < entries.length(); i++) {
|
||||
JSONObject entry = entries.getJSONObject(i);
|
||||
try {
|
||||
result.addEntry(convertEntry(entry));
|
||||
} catch (DatabaseImporterEntryException e) {
|
||||
result.addError(e);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new DatabaseImporterException(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static @NonNull VaultEntry convertEntry(@NonNull JSONObject entry) throws DatabaseImporterEntryException {
|
||||
try {
|
||||
JSONObject content = entry.getJSONObject("content");
|
||||
String name = content.getString("name");
|
||||
String uriString = content.getString("uri");
|
||||
|
||||
Uri uri = Uri.parse(uriString);
|
||||
try {
|
||||
GoogleAuthInfo info = GoogleAuthInfo.parseUri(uri);
|
||||
OtpInfo otp = info.getOtpInfo();
|
||||
|
||||
return new VaultEntry(otp, name, info.getIssuer());
|
||||
} catch (GoogleAuthInfoException e) {
|
||||
throw new DatabaseImporterEntryException(e, uriString);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new DatabaseImporterEntryException(e, entry.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
{
|
||||
"version": 1,
|
||||
"entries": [
|
||||
{
|
||||
"id": "a19e0019-47e3-4d3b-af63-6dad0cb49e31",
|
||||
"content": {
|
||||
"uri": "otpauth://totp/Deno:Mason?secret=4SJHB4GSD43FZBAI7C2HLRJGPQ&issuer=Deno&algorithm=SHA1&digits=6&period=30",
|
||||
"entry_type": "Totp",
|
||||
"name": "Mason"
|
||||
},
|
||||
"note": null
|
||||
},
|
||||
{
|
||||
"id": "4603c576-5d93-4c7f-8c26-bed6dc4493fc",
|
||||
"content": {
|
||||
"uri": "otpauth://totp/SPDX:James?secret=5OM4WOOGPLQEF6UGN3CPEOOLWU&issuer=SPDX&algorithm=SHA256&digits=7&period=20",
|
||||
"entry_type": "Totp",
|
||||
"name": "James"
|
||||
},
|
||||
"note": null
|
||||
},
|
||||
{
|
||||
"id": "4fae25ae-16ed-4f15-a887-3bbb50b34d5e",
|
||||
"content": {
|
||||
"uri": "otpauth://totp/Airbnb:Elijah?secret=7ELGJSGXNCCTV3O6LKJWYFV2RA&issuer=Airbnb&algorithm=SHA512&digits=8&period=50",
|
||||
"entry_type": "Totp",
|
||||
"name": "Elijah"
|
||||
},
|
||||
"note": null
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue