minor layout fixes, replace non breakable spaces if found in an encrypted armored message, as they break the decryption, the HTML representation of GMail introduces them for empty lines ending in a normal space, also adjusted the PGP_MESSAGE regex to allow for spaces after the -----, which seems to be added by some implementations

This commit is contained in:
Thialfihar 2010-04-15 14:37:46 +00:00
parent b8009d6d43
commit acd71a45c0
4 changed files with 19 additions and 9 deletions

View File

@ -29,7 +29,7 @@
android:src="@drawable/encrypted" android:src="@drawable/encrypted"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"/> android:layout_gravity="center_vertical"/>
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"

View File

@ -122,7 +122,7 @@ public class Apg {
protected static Vector<PGPSecretKeyRing> mSecretKeyRings; protected static Vector<PGPSecretKeyRing> mSecretKeyRings;
public static Pattern PGP_MESSAGE = public static Pattern PGP_MESSAGE =
Pattern.compile(".*?(-----BEGIN PGP MESSAGE-----\n.*?-----END PGP MESSAGE-----).*", Pattern.compile(".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
Pattern.DOTALL); Pattern.DOTALL);
protected static boolean mInitialized = false; protected static boolean mInitialized = false;
@ -1135,6 +1135,7 @@ public class Apg {
} }
public static void encrypt(InputStream inStream, OutputStream outStream, public static void encrypt(InputStream inStream, OutputStream outStream,
boolean armored,
long encryptionKeyIds[], long signatureKeyId, long encryptionKeyIds[], long signatureKeyId,
String signaturePassPhrase, String signaturePassPhrase,
ProgressDialogUpdater progress) ProgressDialogUpdater progress)
@ -1142,11 +1143,16 @@ public class Apg {
NoSuchAlgorithmException, SignatureException { NoSuchAlgorithmException, SignatureException {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
ArmoredOutputStream armorOut = new ArmoredOutputStream(outStream); ArmoredOutputStream armorOut = null;
armorOut.setHeader("Version", FULL_VERSION); OutputStream out = null;
OutputStream out = armorOut;
OutputStream encryptOut = null; OutputStream encryptOut = null;
if (armored) {
armorOut = new ArmoredOutputStream(outStream);
armorOut.setHeader("Version", FULL_VERSION);
out = armorOut;
} else {
out = outStream;
}
PGPSecretKey signingKey = null; PGPSecretKey signingKey = null;
PGPSecretKeyRing signingKeyRing = null; PGPSecretKeyRing signingKeyRing = null;
PGPPrivateKey signaturePrivateKey = null; PGPPrivateKey signaturePrivateKey = null;

View File

@ -190,6 +190,8 @@ public class DecryptMessageActivity extends Activity
Matcher matcher = Apg.PGP_MESSAGE.matcher(data); Matcher matcher = Apg.PGP_MESSAGE.matcher(data);
if (matcher.matches()) { if (matcher.matches()) {
data = matcher.group(1); data = matcher.group(1);
// replace non breakable spaces
data = data.replaceAll("\\xa0", " ");
mMessage.setText(data); mMessage.setText(data);
} }
} }
@ -312,8 +314,9 @@ public class DecryptMessageActivity extends Activity
Bundle data = new Bundle(); Bundle data = new Bundle();
Message msg = new Message(); Message msg = new Message();
ByteArrayInputStream in = String messageData = mMessage.getText().toString();
new ByteArrayInputStream(mMessage.getText().toString().getBytes());
ByteArrayInputStream in = new ByteArrayInputStream(messageData.getBytes());
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
try { try {

View File

@ -312,7 +312,8 @@ public class EncryptMessageActivity extends Activity
try { try {
if (mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) { if (mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) {
Apg.encrypt(in, out, mEncryptionKeyIds, mSignatureKeyId, Apg.getPassPhrase(), this); Apg.encrypt(in, out, true, mEncryptionKeyIds, mSignatureKeyId,
Apg.getPassPhrase(), this);
data.putString("message", new String(out.toByteArray())); data.putString("message", new String(out.toByteArray()));
} else { } else {
Apg.sign(in, out, mSignatureKeyId, Apg.getPassPhrase(), this); Apg.sign(in, out, mSignatureKeyId, Apg.getPassPhrase(), this);