Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

pedrxd
Copy link

@pedrxd pedrxd commented Jul 24, 2024

No description provided.

Copy link
Member

@alexbakker alexbakker left a 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){, but if (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));
Copy link
Member

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);
Copy link
Member

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.

Comment on lines +52 to +58
BufferedReader br = new BufferedReader(new InputStreamReader(zis));
StringBuilder json = new StringBuilder();
String line;
while((line = br.readLine()) != null){
json.append(line);
}
br.close();
Copy link
Member

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());
Copy link
Member

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>
Copy link
Member

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");
Copy link
Member

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"));
Copy link
Member

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);
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants