apply fixPgpMessage to plaintext/armored decrypt input
This commit is contained in:
@@ -21,6 +21,7 @@ package org.sufficientlysecure.keychain.pgp;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
@@ -116,32 +117,27 @@ public class PgpHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPgpContent(CharSequence input) {
|
public static String getPgpContent(@NonNull CharSequence input) {
|
||||||
// only decrypt if clipboard content is available and a pgp message or cleartext signature
|
Log.dEscaped(Constants.TAG, "input: " + input);
|
||||||
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()) {
|
||||||
|
String text = matcher.group(1);
|
||||||
|
text = fixPgpMessage(text);
|
||||||
|
|
||||||
|
Log.dEscaped(Constants.TAG, "input fixed: " + text);
|
||||||
|
return text;
|
||||||
|
} else {
|
||||||
|
matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(input);
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
String text = matcher.group(1);
|
String text = matcher.group(1);
|
||||||
text = fixPgpMessage(text);
|
text = fixPgpCleartextSignature(text);
|
||||||
|
|
||||||
Log.dEscaped(Constants.TAG, "input fixed: " + text);
|
Log.dEscaped(Constants.TAG, "input fixed: " + text);
|
||||||
return text;
|
return text;
|
||||||
} else {
|
} else {
|
||||||
matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(input);
|
return null;
|
||||||
if (matcher.matches()) {
|
|
||||||
String text = matcher.group(1);
|
|
||||||
text = fixPgpCleartextSignature(text);
|
|
||||||
|
|
||||||
Log.dEscaped(Constants.TAG, "input fixed: " + text);
|
|
||||||
return text;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,13 +29,14 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
import org.sufficientlysecure.keychain.intents.OpenKeychainIntents;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
||||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||||
|
|
||||||
@@ -93,7 +94,9 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||||
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
Uri uri = readToTempFile(text);
|
Uri uri = readToTempFile(text);
|
||||||
uris.add(uri);
|
if (uri != null) {
|
||||||
|
uris.add(uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -105,7 +108,9 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
} else if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||||
for (String text : intent.getStringArrayListExtra(Intent.EXTRA_TEXT)) {
|
for (String text : intent.getStringArrayListExtra(Intent.EXTRA_TEXT)) {
|
||||||
Uri uri = readToTempFile(text);
|
Uri uri = readToTempFile(text);
|
||||||
uris.add(uri);
|
if (uri != null) {
|
||||||
|
uris.add(uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +144,9 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
String text = clip.getItemAt(0).coerceToText(this).toString();
|
String text = clip.getItemAt(0).coerceToText(this).toString();
|
||||||
uri = readToTempFile(text);
|
uri = readToTempFile(text);
|
||||||
}
|
}
|
||||||
uris.add(uri);
|
if (uri != null) {
|
||||||
|
uris.add(uri);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -170,9 +177,17 @@ public class DecryptActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri readToTempFile(String text) throws IOException {
|
@Nullable public Uri readToTempFile(String text) throws IOException {
|
||||||
Uri tempFile = TemporaryStorageProvider.createFile(this);
|
Uri tempFile = TemporaryStorageProvider.createFile(this);
|
||||||
OutputStream outStream = getContentResolver().openOutputStream(tempFile);
|
OutputStream outStream = getContentResolver().openOutputStream(tempFile);
|
||||||
|
|
||||||
|
// clean up ascii armored message, fixing newlines and stuff
|
||||||
|
String cleanedText = PgpHelper.getPgpContent(text);
|
||||||
|
if (cleanedText == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if cleanup didn't work, just try the raw data
|
||||||
outStream.write(text.getBytes());
|
outStream.write(text.getBytes());
|
||||||
outStream.close();
|
outStream.close();
|
||||||
return tempFile;
|
return tempFile;
|
||||||
|
|||||||
Reference in New Issue
Block a user