From b06e7cd737c9f85c37fb2d17533cc1a2b25715a9 Mon Sep 17 00:00:00 2001 From: William Faulk Date: Wed, 29 Apr 2015 19:59:32 -0400 Subject: Fix Bluetooth share without breaking others --- .../keychain/KeychainApplication.java | 13 +++++ .../keychain/ui/ViewKeyAdvShareFragment.java | 65 ++++++++++++++++++++-- .../keychain/ui/util/KeyFormattingUtils.java | 30 +++++++++- 3 files changed, 99 insertions(+), 9 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java index 710dbf8aa..161979ce3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java @@ -40,6 +40,8 @@ import org.sufficientlysecure.keychain.util.PRNGFixes; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.TlsHelper; +import java.io.File; +import java.io.FilenameFilter; import java.security.Security; import java.util.HashMap; @@ -88,6 +90,17 @@ public class KeychainApplication extends Application { } } + // Clean up leftover Bluetooth Share files + for (File toDelete : this.getExternalCacheDir().listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String filename) { + if (filename.matches("^key-[0-9a-fA-F]{8}\\.pgp\\.asc$")) { + return true; + } + return false; + } + })) { toDelete.delete(); } + brandGlowEffect(getApplicationContext(), getApplicationContext().getResources().getColor(R.color.primary)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 6bd3a9303..4141da202 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -26,6 +26,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.os.FileObserver; import android.support.v4.app.ActivityCompat; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; @@ -54,6 +55,9 @@ import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.NfcHelper; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; import java.io.IOException; @@ -175,11 +179,11 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements boolean toClipboard) { try { String content; + byte[] fingerprintData = (byte[]) providerHelper.getGenericData( + KeyRings.buildUnifiedKeyRingUri(dataUri), + Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); if (fingerprintOnly) { - byte[] data = (byte[]) providerHelper.getGenericData( - KeyRings.buildUnifiedKeyRingUri(dataUri), - Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); - String fingerprint = KeyFormattingUtils.convertFingerprintToHex(data); + String fingerprint = KeyFormattingUtils.convertFingerprintToHex(fingerprintData); if (!toClipboard) { content = Constants.FINGERPRINT_SCHEME + ":" + fingerprint; } else { @@ -213,13 +217,62 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); + String title; if (fingerprintOnly) { title = getResources().getString(R.string.title_share_fingerprint_with); } else { title = getResources().getString(R.string.title_share_key); } - startActivity(Intent.createChooser(sendIntent, title)); + Intent shareChooser = Intent.createChooser(sendIntent, title); + + // Bluetooth Share will convert text/plain sent via EXTRA_TEXT to HTML + // Add replacement extra to send a text/plain file instead. + try { + final File contentFile = new File(getActivity().getExternalCacheDir(), + "key-" + KeyFormattingUtils.getShortKeyIdAsHexFromFingerprint(fingerprintData, false) + + ".pgp.asc"); + FileWriter contentFileWriter = new FileWriter(contentFile, false); + BufferedWriter contentWriter = new BufferedWriter(contentFileWriter); + contentWriter.write(content); + contentWriter.close(); + Uri contentUri = Uri.fromFile(contentFile); + + final Runnable deleteContentFile = new Runnable() { + public void run() { + contentFile.delete(); + } + }; + + // delete the file after Bluetooth Share closes the file + FileObserver tempFileObserver = new FileObserver(contentFile.getAbsolutePath(), + FileObserver.CLOSE_NOWRITE) { + @Override + public void onEvent(int event, String path) { + // Hopefully it will only be opened and then closed by the share process once + getContainer().post(deleteContentFile); + } + }; + tempFileObserver.startWatching(); + + // If it's not complete in 1m, the file was not used; delete it + getContainer().postDelayed(deleteContentFile, 1 * 60 * 1000); + + // create replacement extras inside try{}: + // if file creation fails, just don't add the replacements + Bundle replacements = new Bundle(); + shareChooser.putExtra(Intent.EXTRA_REPLACEMENT_EXTRAS, replacements); + + Bundle bluetoothExtra = new Bundle(sendIntent.getExtras()); + replacements.putBundle("com.android.bluetooth", bluetoothExtra); + + bluetoothExtra.putParcelable(Intent.EXTRA_STREAM, contentUri); + } catch (IOException e) { + Log.e(Constants.TAG, "error creating temporary Bluetooth key share file!", e); + Notify.create(getActivity(), R.string.error_bluetooth_file, Notify.Style.ERROR).show(); + } + + startActivity(shareChooser); } } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); @@ -379,4 +432,4 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } -} \ No newline at end of file +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java index 91a7d361a..0b80b5fe9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java @@ -227,6 +227,14 @@ public class KeyFormattingUtils { return buf.getLong(); } + public static int getShortKeyIdFromFingerprint(byte[] fingerprint) { + ByteBuffer buf = ByteBuffer.wrap(fingerprint); + // skip first 16 bytes of the fingerprint + buf.position(16); + // the last four bytes are the short key id (big endian, which is default order in ByteBuffer) + return buf.getInt(); + } + /** * Convert key id from long to 64 bit hex string *

@@ -238,16 +246,24 @@ public class KeyFormattingUtils { * @return */ public static String convertKeyIdToHex(long keyId) { + return convertKeyIdToHex(keyId, true); + } + + public static String convertKeyIdToHex(long keyId, boolean header) { long upper = keyId >> 32; if (upper == 0) { // this is a short key id - return convertKeyIdToHexShort(keyId); + return convertKeyIdToHexShort(keyId, header); } - return "0x" + convertKeyIdToHex32bit(keyId >> 32) + convertKeyIdToHex32bit(keyId); + return header?"0x":"" + convertKeyIdToHex32bit(keyId >> 32) + convertKeyIdToHex32bit(keyId); } public static String convertKeyIdToHexShort(long keyId) { - return "0x" + convertKeyIdToHex32bit(keyId); + return convertKeyIdToHexShort(keyId, true); + } + + public static String convertKeyIdToHexShort(long keyId, boolean header) { + return header?"0x":"" + convertKeyIdToHex32bit(keyId); } private static String convertKeyIdToHex32bit(long keyId) { @@ -258,6 +274,14 @@ public class KeyFormattingUtils { return hexString; } + public static String getKeyIdAsHexFromFingerprint(byte[] fingerprint, boolean header) { + return convertKeyIdToHex(getKeyIdFromFingerprint(fingerprint), header); + } + + public static String getShortKeyIdAsHexFromFingerprint(byte[] fingerprint, boolean header) { + return convertKeyIdToHex(getShortKeyIdFromFingerprint(fingerprint), header); + } + /** * Makes a human-readable version of a key ID, which is usually 64 bits: lower-case, no * leading 0x, space-separated quartets (for keys whose length in hex is divisible by 4) -- cgit v1.2.3 From 6383d19dd3921220633686e0e8e78d2d961e0aad Mon Sep 17 00:00:00 2001 From: William Faulk Date: Thu, 30 Apr 2015 18:48:25 -0400 Subject: Wrap EXTRA_REPLACEMENT_EXTRAS section so it only runs on Lollipop or greater --- .../keychain/ui/ViewKeyAdvShareFragment.java | 86 +++++++++++----------- 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 4141da202..81720d816 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -228,48 +228,50 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements // Bluetooth Share will convert text/plain sent via EXTRA_TEXT to HTML // Add replacement extra to send a text/plain file instead. - try { - final File contentFile = new File(getActivity().getExternalCacheDir(), - "key-" + KeyFormattingUtils.getShortKeyIdAsHexFromFingerprint(fingerprintData, false) + - ".pgp.asc"); - FileWriter contentFileWriter = new FileWriter(contentFile, false); - BufferedWriter contentWriter = new BufferedWriter(contentFileWriter); - contentWriter.write(content); - contentWriter.close(); - Uri contentUri = Uri.fromFile(contentFile); - - final Runnable deleteContentFile = new Runnable() { - public void run() { - contentFile.delete(); - } - }; - - // delete the file after Bluetooth Share closes the file - FileObserver tempFileObserver = new FileObserver(contentFile.getAbsolutePath(), - FileObserver.CLOSE_NOWRITE) { - @Override - public void onEvent(int event, String path) { - // Hopefully it will only be opened and then closed by the share process once - getContainer().post(deleteContentFile); - } - }; - tempFileObserver.startWatching(); - - // If it's not complete in 1m, the file was not used; delete it - getContainer().postDelayed(deleteContentFile, 1 * 60 * 1000); - - // create replacement extras inside try{}: - // if file creation fails, just don't add the replacements - Bundle replacements = new Bundle(); - shareChooser.putExtra(Intent.EXTRA_REPLACEMENT_EXTRAS, replacements); - - Bundle bluetoothExtra = new Bundle(sendIntent.getExtras()); - replacements.putBundle("com.android.bluetooth", bluetoothExtra); - - bluetoothExtra.putParcelable(Intent.EXTRA_STREAM, contentUri); - } catch (IOException e) { - Log.e(Constants.TAG, "error creating temporary Bluetooth key share file!", e); - Notify.create(getActivity(), R.string.error_bluetooth_file, Notify.Style.ERROR).show(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + try { + final File contentFile = new File(getActivity().getExternalCacheDir(), + "key-" + KeyFormattingUtils.getShortKeyIdAsHexFromFingerprint(fingerprintData, false) + + ".pgp.asc"); + FileWriter contentFileWriter = new FileWriter(contentFile, false); + BufferedWriter contentWriter = new BufferedWriter(contentFileWriter); + contentWriter.write(content); + contentWriter.close(); + Uri contentUri = Uri.fromFile(contentFile); + + final Runnable deleteContentFile = new Runnable() { + public void run() { + contentFile.delete(); + } + }; + + // delete the file after Bluetooth Share closes the file + FileObserver tempFileObserver = new FileObserver(contentFile.getAbsolutePath(), + FileObserver.CLOSE_NOWRITE) { + @Override + public void onEvent(int event, String path) { + // Hopefully it will only be opened and then closed by the share process once + getContainer().post(deleteContentFile); + } + }; + tempFileObserver.startWatching(); + + // If it's not complete in 1m, the file was not used; delete it + getContainer().postDelayed(deleteContentFile, 1 * 60 * 1000); + + // create replacement extras inside try{}: + // if file creation fails, just don't add the replacements + Bundle replacements = new Bundle(); + shareChooser.putExtra(Intent.EXTRA_REPLACEMENT_EXTRAS, replacements); + + Bundle bluetoothExtra = new Bundle(sendIntent.getExtras()); + replacements.putBundle("com.android.bluetooth", bluetoothExtra); + + bluetoothExtra.putParcelable(Intent.EXTRA_STREAM, contentUri); + } catch (IOException e) { + Log.e(Constants.TAG, "error creating temporary Bluetooth key share file!", e); + Notify.create(getActivity(), R.string.error_bluetooth_file, Notify.Style.ERROR).show(); + } } startActivity(shareChooser); -- cgit v1.2.3 From be3e52884f363de83fd058db1e99e55866413ba4 Mon Sep 17 00:00:00 2001 From: William Faulk Date: Mon, 4 May 2015 12:17:06 -0400 Subject: Use primary user ID for filename instead of short key ID --- .../sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 81720d816..bbca45479 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -43,6 +43,8 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; @@ -230,9 +232,10 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements // Add replacement extra to send a text/plain file instead. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { + String primaryUserId = UncachedKeyRing.decodeFromData(content.getBytes()). + getPublicKey().getPrimaryUserIdWithFallback(); final File contentFile = new File(getActivity().getExternalCacheDir(), - "key-" + KeyFormattingUtils.getShortKeyIdAsHexFromFingerprint(fingerprintData, false) + - ".pgp.asc"); + primaryUserId + ".pgp.asc"); FileWriter contentFileWriter = new FileWriter(contentFile, false); BufferedWriter contentWriter = new BufferedWriter(contentFileWriter); contentWriter.write(content); -- cgit v1.2.3 From af1809eebc1ce9caf8de4a23a6ecfc919890e59b Mon Sep 17 00:00:00 2001 From: William Faulk Date: Mon, 4 May 2015 13:58:20 -0400 Subject: Use FILE_EXTENSION constants --- .../org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index bbca45479..6fc2de335 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -235,7 +235,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements String primaryUserId = UncachedKeyRing.decodeFromData(content.getBytes()). getPublicKey().getPrimaryUserIdWithFallback(); final File contentFile = new File(getActivity().getExternalCacheDir(), - primaryUserId + ".pgp.asc"); + primaryUserId + Constants.FILE_EXTENSION_PGP_ALTERNATE + Constants.FILE_EXTENSION_ASC); FileWriter contentFileWriter = new FileWriter(contentFile, false); BufferedWriter contentWriter = new BufferedWriter(contentFileWriter); contentWriter.write(content); -- cgit v1.2.3 From eabc6cd8d45858a5ceaa44270078aba380b69e12 Mon Sep 17 00:00:00 2001 From: William Faulk Date: Mon, 4 May 2015 16:35:05 -0400 Subject: use TemporaryStorageProvider for Bluetooth Share --- .../provider/TemporaryStorageProvider.java | 9 +++-- .../keychain/ui/ViewKeyAdvShareFragment.java | 41 +++++++--------------- 2 files changed, 18 insertions(+), 32 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java index 6dd4a1633..45f806960 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/TemporaryStorageProvider.java @@ -48,6 +48,8 @@ public class TemporaryStorageProvider extends ContentProvider { private static final Uri BASE_URI = Uri.parse("content://org.sufficientlysecure.keychain.tempstorage/"); private static final int DB_VERSION = 2; + private static File cacheDir; + public static Uri createFile(Context context, String targetName) { ContentValues contentValues = new ContentValues(); contentValues.put(COLUMN_NAME, targetName); @@ -90,7 +92,7 @@ public class TemporaryStorageProvider extends ContentProvider { } } - private TemporaryStorageDatabase db; + private static TemporaryStorageDatabase db; private File getFile(Uri uri) throws FileNotFoundException { try { @@ -101,13 +103,14 @@ public class TemporaryStorageProvider extends ContentProvider { } private File getFile(String id) { - return new File(getContext().getCacheDir(), "temp/" + id); + return new File(cacheDir, "temp/" + id); } @Override public boolean onCreate() { db = new TemporaryStorageDatabase(getContext()); - return new File(getContext().getCacheDir(), "temp").mkdirs(); + cacheDir = getContext().getCacheDir(); + return new File(cacheDir, "temp").mkdirs(); } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 6fc2de335..17aca2373 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -26,7 +26,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.os.FileObserver; +import android.os.ParcelFileDescriptor; import android.support.v4.app.ActivityCompat; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; @@ -44,13 +44,13 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; @@ -58,9 +58,9 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.NfcHelper; import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; +import java.io.OutputStreamWriter; import java.io.IOException; +import java.io.FileNotFoundException; public class ViewKeyAdvShareFragment extends LoaderFragment implements @@ -234,33 +234,16 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements try { String primaryUserId = UncachedKeyRing.decodeFromData(content.getBytes()). getPublicKey().getPrimaryUserIdWithFallback(); - final File contentFile = new File(getActivity().getExternalCacheDir(), + + TemporaryStorageProvider shareFileProv = new TemporaryStorageProvider(); + Uri contentUri = TemporaryStorageProvider.createFile(getActivity(), primaryUserId + Constants.FILE_EXTENSION_PGP_ALTERNATE + Constants.FILE_EXTENSION_ASC); - FileWriter contentFileWriter = new FileWriter(contentFile, false); - BufferedWriter contentWriter = new BufferedWriter(contentFileWriter); + + BufferedWriter contentWriter = new BufferedWriter(new OutputStreamWriter( + new ParcelFileDescriptor.AutoCloseOutputStream( + shareFileProv.openFile(contentUri, "w")))); contentWriter.write(content); contentWriter.close(); - Uri contentUri = Uri.fromFile(contentFile); - - final Runnable deleteContentFile = new Runnable() { - public void run() { - contentFile.delete(); - } - }; - - // delete the file after Bluetooth Share closes the file - FileObserver tempFileObserver = new FileObserver(contentFile.getAbsolutePath(), - FileObserver.CLOSE_NOWRITE) { - @Override - public void onEvent(int event, String path) { - // Hopefully it will only be opened and then closed by the share process once - getContainer().post(deleteContentFile); - } - }; - tempFileObserver.startWatching(); - - // If it's not complete in 1m, the file was not used; delete it - getContainer().postDelayed(deleteContentFile, 1 * 60 * 1000); // create replacement extras inside try{}: // if file creation fails, just don't add the replacements @@ -271,7 +254,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements replacements.putBundle("com.android.bluetooth", bluetoothExtra); bluetoothExtra.putParcelable(Intent.EXTRA_STREAM, contentUri); - } catch (IOException e) { + } catch (FileNotFoundException e) { Log.e(Constants.TAG, "error creating temporary Bluetooth key share file!", e); Notify.create(getActivity(), R.string.error_bluetooth_file, Notify.Style.ERROR).show(); } -- cgit v1.2.3 From 44b47e185d351718f105d7247c727c5f4d6bd0a4 Mon Sep 17 00:00:00 2001 From: William Faulk Date: Mon, 4 May 2015 17:09:59 -0400 Subject: use single file extension --- .../org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 17aca2373..fde0f62fd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -237,7 +237,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements TemporaryStorageProvider shareFileProv = new TemporaryStorageProvider(); Uri contentUri = TemporaryStorageProvider.createFile(getActivity(), - primaryUserId + Constants.FILE_EXTENSION_PGP_ALTERNATE + Constants.FILE_EXTENSION_ASC); + primaryUserId + Constants.FILE_EXTENSION_ASC); BufferedWriter contentWriter = new BufferedWriter(new OutputStreamWriter( new ParcelFileDescriptor.AutoCloseOutputStream( -- cgit v1.2.3 From 7e7892ff2ee6c49e6971483b759337dd216a96b7 Mon Sep 17 00:00:00 2001 From: William Faulk Date: Mon, 4 May 2015 17:15:10 -0400 Subject: revert unneeded changes for old temp Bluetooth share file --- .../sufficientlysecure/keychain/KeychainApplication.java | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java index 161979ce3..710dbf8aa 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java @@ -40,8 +40,6 @@ import org.sufficientlysecure.keychain.util.PRNGFixes; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.TlsHelper; -import java.io.File; -import java.io.FilenameFilter; import java.security.Security; import java.util.HashMap; @@ -90,17 +88,6 @@ public class KeychainApplication extends Application { } } - // Clean up leftover Bluetooth Share files - for (File toDelete : this.getExternalCacheDir().listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String filename) { - if (filename.matches("^key-[0-9a-fA-F]{8}\\.pgp\\.asc$")) { - return true; - } - return false; - } - })) { toDelete.delete(); } - brandGlowEffect(getApplicationContext(), getApplicationContext().getResources().getColor(R.color.primary)); -- cgit v1.2.3 From aba9c884ce46237ed0633c5a123860e6af8488bc Mon Sep 17 00:00:00 2001 From: William Faulk Date: Mon, 4 May 2015 17:15:51 -0400 Subject: revert unneeded changes for short key ID --- .../keychain/ui/util/KeyFormattingUtils.java | 30 +++------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java index 0b80b5fe9..91a7d361a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java @@ -227,14 +227,6 @@ public class KeyFormattingUtils { return buf.getLong(); } - public static int getShortKeyIdFromFingerprint(byte[] fingerprint) { - ByteBuffer buf = ByteBuffer.wrap(fingerprint); - // skip first 16 bytes of the fingerprint - buf.position(16); - // the last four bytes are the short key id (big endian, which is default order in ByteBuffer) - return buf.getInt(); - } - /** * Convert key id from long to 64 bit hex string *

@@ -246,24 +238,16 @@ public class KeyFormattingUtils { * @return */ public static String convertKeyIdToHex(long keyId) { - return convertKeyIdToHex(keyId, true); - } - - public static String convertKeyIdToHex(long keyId, boolean header) { long upper = keyId >> 32; if (upper == 0) { // this is a short key id - return convertKeyIdToHexShort(keyId, header); + return convertKeyIdToHexShort(keyId); } - return header?"0x":"" + convertKeyIdToHex32bit(keyId >> 32) + convertKeyIdToHex32bit(keyId); + return "0x" + convertKeyIdToHex32bit(keyId >> 32) + convertKeyIdToHex32bit(keyId); } public static String convertKeyIdToHexShort(long keyId) { - return convertKeyIdToHexShort(keyId, true); - } - - public static String convertKeyIdToHexShort(long keyId, boolean header) { - return header?"0x":"" + convertKeyIdToHex32bit(keyId); + return "0x" + convertKeyIdToHex32bit(keyId); } private static String convertKeyIdToHex32bit(long keyId) { @@ -274,14 +258,6 @@ public class KeyFormattingUtils { return hexString; } - public static String getKeyIdAsHexFromFingerprint(byte[] fingerprint, boolean header) { - return convertKeyIdToHex(getKeyIdFromFingerprint(fingerprint), header); - } - - public static String getShortKeyIdAsHexFromFingerprint(byte[] fingerprint, boolean header) { - return convertKeyIdToHex(getShortKeyIdFromFingerprint(fingerprint), header); - } - /** * Makes a human-readable version of a key ID, which is usually 64 bits: lower-case, no * leading 0x, space-separated quartets (for keys whose length in hex is divisible by 4) -- cgit v1.2.3