Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions PGPAuth/src/main/java/org/lf_net/pgpunlocker/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public void close() {
}
}

public void doActionOnServerWithFeedback(String action, String server, String keyAPG) {
String ret = doActionOnServer(action, server, keyAPG);
public void doActionOnServerWithFeedback(String action, String server, String keyAPG, String openPGPKey) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename to openPGPKeyID everywhere

This way its is clearer what that variable is ^^

String ret = doActionOnServer(action, server, keyAPG, openPGPKey);
_guiHelper.showUserFeedback(ret);
}

public String doActionOnServer(String action, String server, String keyAPG) {
public String doActionOnServer(String action, String server, String keyAPG, String openPGPKey) {
if (server == "" || !URLUtil.isValidUrl(server)) {
if (server == "") {
return _context.getString(R.string.no_server_set);
Expand Down Expand Up @@ -106,10 +106,16 @@ public String doActionOnServer(String action, String server, String keyAPG) {
Intent intent = new Intent();
intent.setAction(OpenPgpApi.ACTION_SIGN);
intent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
if (!openPGPKey.isEmpty()) {
intent.putExtra(OpenPgpApi.EXTRA_KEY_ID, openPGPKey);
}
intent.putExtra("PGPAuth_SIGNDATA", request);

try {
sendOpenKeychainIntent(intent);
if (openPGPKey.isEmpty()) {
openPGPKey = intent.getStringExtra(OpenPgpApi.EXTRA_KEY_ID);
}
} catch (Exception e) {
return e.getLocalizedMessage();
}
Expand Down
44 changes: 38 additions & 6 deletions PGPAuth/src/main/java/org/lf_net/pgpunlocker/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ public class Server {
String _name;
String _url;
String _apgKey;
String _openpgpgKey;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgpg? Looks like a nice combination of PGP and GPG, but please only use one ^^
I would prefer PGP

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reuse apgKey? (did we have that question before :O )

boolean _saveKey;

public Server(String name, String url) {
this(name, url, "");
this(name, url, "", "", false);
}

public Server(String name, String url, String apgKey) {
public Server(String name, String url, String apgKey, String openpgpgKey, boolean saveKey) {
_name = name;
_url = url;
_apgKey = apgKey;
_openpgpgKey = openpgpgKey;
_saveKey = saveKey;
}

public String name() {
Expand All @@ -35,6 +39,14 @@ public String apgKey() {
return _apgKey;
}

public String openpgpgKey() {
return _openpgpgKey;
}

public boolean saveKey() {
return _saveKey;
}

public void setName(String name) {
_name = name;
}
Expand All @@ -47,6 +59,18 @@ public void setApgKey(String apgKey) {
_apgKey = apgKey;
}

public void setOpenpgpgKey(String openpgpgKey) {
_openpgpgKey = openpgpgKey;
}

public void keepKey() {
_saveKey = true;
}

public void forgetKey() {
_saveKey = false;
}

public boolean isEmpty() {
return _name == "" && _url == "";
}
Expand All @@ -59,8 +83,8 @@ public static Server deserialize(String serialized) {
return new Server(parts[0], parts[1]);
}

if (parts.length == 3) {
return new Server(parts[0], parts[1], parts[2]);
if (parts.length == 5) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not change things in this function. It is only here to support config loading for configs generated by older versions of the app

return new Server(parts[0], parts[1], parts[2], parts[3], Boolean.parseBoolean(parts[4]));
}

return null;
Expand All @@ -73,6 +97,10 @@ public JSONObject serializeJSON() {
ret.put("name", _name);
ret.put("url", _url);
ret.put("apgKey", _apgKey);
if (saveKey()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use private variables where possible, as function calls are slower in most languages.

ret.put("openpgpgKey", _openpgpgKey);
}
ret.put("saveKey", _saveKey);
} catch (JSONException e) {
// should not happen as we just serialize a bunch of strings
return null;
Expand All @@ -86,8 +114,12 @@ public static Server deserializeJSON(JSONObject obj) throws JSONException {
String name = obj.getString("name");
String url = obj.getString("url");
String apgKey = obj.getString("apgKey");

return new Server(name, url, apgKey);
boolean saveTheKey = obj.getBoolean("saveKey");
String openpgpgKey = "";
if (saveTheKey) {
openpgpgKey = obj.getString("openpgpgKey");
}
return new Server(name, url, apgKey, openpgpgKey, saveTheKey);
} catch (JSONException e) {
// should not happen as we just serialize a bunch of strings
throw e;
Expand Down