Cleanup and fix decrypt activity

This commit is contained in:
Dominik Schürmann 2014-10-07 17:35:12 +02:00
parent a150c0f480
commit f4c8c47ac2

View File

@ -21,6 +21,7 @@ package org.sufficientlysecure.keychain.ui;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
@ -78,29 +79,41 @@ public class DecryptTextActivity extends ActionBarActivity {
/** /**
* Fixing broken PGP SIGNED MESSAGE Strings coming from GMail/AOSP Mail * Fixing broken PGP SIGNED MESSAGE Strings coming from GMail/AOSP Mail
*/ */
private String fixPgpCleartextSignature(String message) { private String fixPgpCleartextSignature(CharSequence input) {
// windows newline -> unix newline if (!TextUtils.isEmpty(input)) {
message = message.replaceAll("\r\n", "\n"); String text = input.toString();
// Mac OS before X newline -> unix newline
message = message.replaceAll("\r", "\n");
return message; // windows newline -> unix newline
text = text.replaceAll("\r\n", "\n");
// Mac OS before X newline -> unix newline
text = text.replaceAll("\r", "\n");
return text;
} else {
return null;
}
} }
private String getPgpContent(String input) { private String getPgpContent(CharSequence input) {
// only decrypt if clipboard content is available and a pgp message or cleartext signature // only decrypt if clipboard content is available and a pgp message or cleartext signature
if (input != null) { if (!TextUtils.isEmpty(input)) {
Log.dEscaped(Constants.TAG, "input: " + input);
Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(input); Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(input);
if (matcher.matches()) { if (matcher.matches()) {
String message = matcher.group(1); String text = matcher.group(1);
message = fixPgpMessage(message); text = fixPgpMessage(text);
return message;
Log.dEscaped(Constants.TAG, "input fixed: " + text);
return text;
} else { } else {
matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(input); matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(input);
if (matcher.matches()) { if (matcher.matches()) {
String message = matcher.group(1); String text = matcher.group(1);
message = fixPgpCleartextSignature(message); text = fixPgpCleartextSignature(text);
return message;
Log.dEscaped(Constants.TAG, "input fixed: " + text);
return text;
} else { } else {
return null; return null;
} }
@ -125,14 +138,13 @@ public class DecryptTextActivity extends ActionBarActivity {
} }
if (Intent.ACTION_SEND.equals(action) && type != null) { if (Intent.ACTION_SEND.equals(action) && type != null) {
Log.logDebugBundle(extras, "extras"); Log.d(Constants.TAG, "ACTION_SEND");
Log.logDebugBundle(extras, "SEND extras");
// When sending to Keychain Decrypt via share menu // When sending to Keychain Decrypt via share menu
if ("text/plain".equals(type)) { if ("text/plain".equals(type)) {
String sharedText = extras.getString(Intent.EXTRA_TEXT); String sharedText = extras.getString(Intent.EXTRA_TEXT);
Log.dEscaped(Constants.TAG, "sharedText incoming: " + sharedText);
sharedText = getPgpContent(sharedText); sharedText = getPgpContent(sharedText);
Log.dEscaped(Constants.TAG, "sharedText fixed: " + sharedText);
if (sharedText != null) { if (sharedText != null) {
loadFragment(savedInstanceState, sharedText); loadFragment(savedInstanceState, sharedText);
@ -143,7 +155,7 @@ public class DecryptTextActivity extends ActionBarActivity {
Log.e(Constants.TAG, "ACTION_SEND received non-plaintext, this should not happen in this activity!"); Log.e(Constants.TAG, "ACTION_SEND received non-plaintext, this should not happen in this activity!");
} }
} else if (ACTION_DECRYPT_TEXT.equals(action)) { } else if (ACTION_DECRYPT_TEXT.equals(action)) {
Log.d(Constants.TAG, "ACTION_DECRYPT_TEXT textData not null, matching text..."); Log.d(Constants.TAG, "ACTION_DECRYPT_TEXT");
String extraText = extras.getString(EXTRA_TEXT); String extraText = extras.getString(EXTRA_TEXT);
extraText = getPgpContent(extraText); extraText = getPgpContent(extraText);
@ -157,9 +169,9 @@ public class DecryptTextActivity extends ActionBarActivity {
Log.d(Constants.TAG, "ACTION_DECRYPT_FROM_CLIPBOARD"); Log.d(Constants.TAG, "ACTION_DECRYPT_FROM_CLIPBOARD");
CharSequence clipboardText = ClipboardReflection.getClipboardText(this); CharSequence clipboardText = ClipboardReflection.getClipboardText(this);
String text = getPgpContent(clipboardText);
if (clipboardText != null) { if (text != null) {
String text = getPgpContent(clipboardText.toString());
loadFragment(savedInstanceState, text); loadFragment(savedInstanceState, text);
} else { } else {
returnInvalidResult(); returnInvalidResult();