-
-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Proton Pass importer #1438
base: master
Are you sure you want to change the base?
Add Proton Pass importer #1438
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this! I'd like to see a couple of touch-ups before we merge this.
Also, a couple of general style notes:
{
goes at the end of the line, not on a new line.- Because we prefix private fields with an underscore, there's almost never a need to access them through
this
. - Please leave out trivial comments like
// Unzip
and// Read file
. - Insert a space where appropriate. So, not
if(true){
, butif (true) {
.
@@ -44,6 +44,7 @@ public abstract class DatabaseImporter { | |||
_importers.add(new Definition("Google Authenticator", GoogleAuthImporter.class, R.string.importer_help_google_authenticator, true)); | |||
_importers.add(new Definition("Microsoft Authenticator", MicrosoftAuthImporter.class, R.string.importer_help_microsoft_authenticator, true)); | |||
_importers.add(new Definition("Plain text", GoogleAuthUriImporter.class, R.string.importer_help_plain_text, false)); | |||
_importers.add(new Definition("Proton Pass", ProtonPassImporter.class, R.string.importer_help_proton_pass, true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your importer does not support reading directly from the Proton Pass' internal storage, so the boolean at the end should be false
.
@Override | ||
protected State read(InputStream stream, boolean isInternal) throws DatabaseImporterException { | ||
// Unzip | ||
ZipInputStream zis = new ZipInputStream(stream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap this in a try-with-resources statement.
BufferedReader br = new BufferedReader(new InputStreamReader(zis)); | ||
StringBuilder json = new StringBuilder(); | ||
String line; | ||
while((line = br.readLine()) != null){ | ||
json.append(line); | ||
} | ||
br.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this block with IOUtils.readAll
.
br.close(); | ||
|
||
// Parse JSON | ||
JSONTokener tokener = new JSONTokener(json.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can instantiate a JSONObject
from the string directly, no need for a JSONTokener
.
@@ -506,6 +506,7 @@ | |||
<string name="importer_help_authy">Supply a copy of <b>/data/data/com.authy.authy/shared_prefs/com.authy.storage.tokens.authenticator.xml</b>, located in the internal storage directory of Authy.</string> | |||
<string name="importer_help_andotp">Supply an andOTP export/backup file.</string> | |||
<string name="importer_help_bitwarden">Supply a Bitwarden export/backup file. Encrypted files are not supported.</string> | |||
<string name="importer_help_proton_pass">Supply a Proton pass export/backup zip. Encrypted files are not supported.</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Supply a Proton Pass export ZIP containing a JSON file. Encrypted files are not supported."
} | ||
|
||
//Json not found | ||
throw new DatabaseImporterException("Invalid proton zip file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Unable to find \"Proton Pass/data.json\" in the ZIP file."
return null; | ||
} | ||
|
||
Uri toptURI = Uri.parse(content.getString("totpUri")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GoogleAuthInfo.parseUri
has an overload that takes a string.
JSONObject item = items.getJSONObject(j); | ||
|
||
try{ | ||
VaultEntry entry = this.fromItem(item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To stay a bit more consistent with the other importers, please rename fromItem
to convertItem
.
Check whether it's a TOTP item here instead of returning null from fromItem
. Catch all possible exceptions inside convertItem
and wrap them in a DatabaseImporterEntryException
there.
No description provided.