Fix decrypt/verify from gmail/aosp mail with sharing intent, fix scrolling in decryt screen

This commit is contained in:
Dominik Schürmann 2014-10-01 15:03:53 +02:00
parent e7cbf975ac
commit 42ce3bb0d3
3 changed files with 89 additions and 89 deletions

View File

@ -32,9 +32,7 @@ import org.sufficientlysecure.keychain.service.results.SingletonResult;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import java.io.StreamTokenizer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DecryptTextActivity extends ActionBarActivity { public class DecryptTextActivity extends ActionBarActivity {
@ -58,38 +56,51 @@ public class DecryptTextActivity extends ActionBarActivity {
} }
/** /**
* Fix the message a bit, trailing spaces and newlines break stuff, * Fixing broken PGP MESSAGE Strings coming from GMail/AOSP Mail
* because GMail sends as HTML and such things break ASCII Armor
* TODO: things like "<" and ">" also make problems
* <p/>
* NOTE: Do not use on cleartext signatures, only on ASCII-armored ciphertext,
* it would change the signed message
*/ */
private String fixAsciiArmoredCiphertext(String message) { private String fixPgpMessage(String message) {
// windows newline -> unix newline
message = message.replaceAll("\r\n", "\n");
// Mac OS before X newline -> unix newline
message = message.replaceAll("\r", "\n");
// remove whitespaces before newline
message = message.replaceAll(" +\n", "\n"); message = message.replaceAll(" +\n", "\n");
// only two consecutive newlines are allowed
message = message.replaceAll("\n\n+", "\n\n"); message = message.replaceAll("\n\n+", "\n\n");
message = message.replaceFirst("^\n+", "");
// make sure there'll be exactly one newline at the end
message = message.replaceFirst("\n*$", "\n");
// replace non breakable spaces // replace non breakable spaces
message = message.replaceAll("\\xa0", " "); message = message.replaceAll("\\xa0", " ");
return message; return message;
} }
/**
* Fixing broken PGP SIGNED MESSAGE Strings coming from GMail/AOSP Mail
*/
private String fixPgpCleartextSignature(String message) {
// windows newline -> unix newline
message = message.replaceAll("\r\n", "\n");
// Mac OS before X newline -> unix newline
message = message.replaceAll("\r", "\n");
return message;
}
private String getPgpContent(String input) { private String getPgpContent(String 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 (input != null) {
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 message = matcher.group(1);
message = fixAsciiArmoredCiphertext(message); message = fixPgpMessage(message);
return message; return message;
} else { } else {
matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(input); matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(input);
if (matcher.matches()) { if (matcher.matches()) {
// return cleartext signature String message = matcher.group(1);
return matcher.group(1); message = fixPgpCleartextSignature(message);
return message;
} else { } else {
return null; return null;
} }

View File

@ -23,6 +23,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -181,7 +182,6 @@ public class DecryptTextFragment extends DecryptFragment {
byte[] decryptedMessage = returnData byte[] decryptedMessage = returnData
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES); .getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
mText.setText(new String(decryptedMessage)); mText.setText(new String(decryptedMessage));
mText.setHorizontallyScrolling(false);
pgpResult.createNotify(getActivity()).show(); pgpResult.createNotify(getActivity()).show();

View File

@ -1,51 +1,45 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/decrypt_result_include" /> <include layout="@layout/decrypt_result_include" />
<View <ScrollView
android:id="@+id/status_divider" android:fillViewport="true"
android:layout_height="1dip" android:paddingTop="8dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="?android:attr/listDivider" /> android:scrollbars="vertical"
android:layout_height="0dp"
<LinearLayout android:layout_weight="1">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="4dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">
<TextView <TextView
android:id="@+id/decrypt_text_plaintext" android:id="@+id/decrypt_text_plaintext"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dip" android:layout_height="wrap_content"
android:gravity="top" android:gravity="top"
android:hint="" android:hint=""
android:scrollHorizontally="true"
android:layout_weight="1"
android:textIsSelectable="true" /> android:textIsSelectable="true" />
</ScrollView>
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dip" android:layout_height="1dip"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="?android:attr/listDivider" /> android:background="?android:attr/listDivider" />
<LinearLayout <LinearLayout
android:id="@+id/action_decrypt_share_plaintext" android:id="@+id/action_decrypt_share_plaintext"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:clickable="true" android:clickable="true"
style="@style/SelectableItem" style="@style/SelectableItem"
android:orientation="horizontal"> android:orientation="horizontal">
@ -81,9 +75,4 @@
style="@style/SelectableItem" /> style="@style/SelectableItem" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout>
</ScrollView>