From f461d6b1d83604d6752ac97128403ff2a34ddec4 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 29 Sep 2015 20:20:26 +0200 Subject: decryptverify: add trivial detection of pgp ascii-armored data --- .../keychain/pgp/PgpDecryptVerifyOperation.java | 35 ++++++++++++++++++++-- .../keychain/operations/ExportTest.java | 3 ++ 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index 36b4f5e1e..055f84b4d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -535,14 +535,14 @@ public class PgpDecryptVerifyOperation extends BaseOperation 0) { // Log.d(Constants.TAG, "read bytes: " + length); if (out != null) { @@ -595,7 +596,13 @@ public class PgpDecryptVerifyOperation extends BaseOperation firstBytes.length ? firstBytes.length : length); + } + alreadyWritten += length; + if (wholeSize > 0) { long progress = 100 * alreadyWritten / wholeSize; // stop at 100% for wrong file sizes... @@ -607,6 +614,17 @@ public class PgpDecryptVerifyOperation extends BaseOperation= needle.length() + static boolean matchesPrefix(byte[] data, String needle) { + byte[] needleBytes = needle.getBytes(); + for (int i = 0; i < needle.length(); i++) { + if (data[i] != needleBytes[i]) { + return false; + } + } + return true; + } + } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/ExportTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/ExportTest.java index 4d4915e8d..e88dc95fc 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/ExportTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/ExportTest.java @@ -354,6 +354,9 @@ public class ExportTest { "backup_" + KeyFormattingUtils.convertKeyIdToHex(mStaticRing1.getMasterKeyId()) + ".pub.asc", result.getDecryptionMetadata().getFilename()); + assertEquals("mime type for pgp keys must be correctly detected", + "application/pgp-keys", result.getDecryptionMetadata().getMimeType()); + TestingUtils.assertArrayEqualsPrefix("exported data must start with ascii armor header", "-----BEGIN PGP PUBLIC KEY BLOCK-----\n".getBytes(), result.getOutputBytes()); TestingUtils.assertArrayEqualsSuffix("exported data must end with ascii armor header", -- cgit v1.2.3