diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-06-06 17:29:39 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-06-06 17:29:39 +0200 |
commit | c36b311d5f5c2b43ec3f1549d9a059fb0de3bde2 (patch) | |
tree | 2fb6d4c8948c768bf81ef0c876c0c2ca0b8460db /OpenKeychain/src/main/java/org/sufficientlysecure | |
parent | 118225d7d2b6401006352897386a40131c6cd854 (diff) | |
download | open-keychain-c36b311d5f5c2b43ec3f1549d9a059fb0de3bde2.tar.gz open-keychain-c36b311d5f5c2b43ec3f1549d9a059fb0de3bde2.tar.bz2 open-keychain-c36b311d5f5c2b43ec3f1549d9a059fb0de3bde2.zip |
import-log: better stripped key logging
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure')
3 files changed, 41 insertions, 16 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OperationResultParcel.java index ccb4b935c..216e4b497 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OperationResultParcel.java @@ -123,6 +123,7 @@ public class OperationResultParcel implements Parcelable { MSG_IS_IO_EXCPTION (R.string.msg_is_io_excption), MSG_IS_SUBKEY_NONEXISTENT (R.string.msg_is_subkey_nonexistent), MSG_IS_SUBKEY_OK (R.string.msg_is_subkey_ok), + MSG_IS_SUBKEY_STRIPPED (R.string.msg_is_subkey_stripped), MSG_IS_SUCCESS (R.string.msg_is_success), ; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java index 02e5411ca..1264c8c36 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Vector; @@ -149,13 +150,13 @@ public class UncachedKeyRing { aos.close(); } - public ArrayList<Long> getAvailableSubkeys() { + public HashSet<Long> getAvailableSubkeys() { if(!isSecret()) { throw new RuntimeException("Tried to find available subkeys from non-secret keys. " + "This is a programming error and should never happen!"); } - ArrayList<Long> result = new ArrayList<Long>(); + HashSet<Long> result = new HashSet<Long>(); // then, mark exactly the keys we have available for (PGPSecretKey sub : new IterableIterator<PGPSecretKey>( ((PGPSecretKeyRing) mRing).getSecretKeys())) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index b3a08a063..5c8bf6752 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -68,7 +68,7 @@ public class ProviderHelper { private int mIndent; public ProviderHelper(Context context) { - this(context, null, 0); + this(context, new ArrayList<OperationResultParcel.LogEntryParcel>(), 0); } public ProviderHelper(Context context, ArrayList<OperationResultParcel.LogEntryParcel> log, @@ -96,10 +96,14 @@ public class ProviderHelper { } public void log(LogLevel level, LogType type) { - mLog.add(new OperationResultParcel.LogEntryParcel(level, type, null, mIndent)); + if(mLog != null) { + mLog.add(new OperationResultParcel.LogEntryParcel(level, type, null, mIndent)); + } } public void log(LogLevel level, LogType type, String[] parameters) { - mLog.add(new OperationResultParcel.LogEntryParcel(level, type, parameters, mIndent)); + if(mLog != null) { + mLog.add(new OperationResultParcel.LogEntryParcel(level, type, parameters, mIndent)); + } } // If we ever switch to api level 11, we can ditch this whole mess! @@ -258,6 +262,7 @@ public class ProviderHelper { long masterKeyId = masterKey.getKeyId(); log(LogLevel.INFO, LogType.MSG_IP_IMPORTING, new String[]{Long.toString(masterKeyId)}); + mIndent += 1; // IF there is a secret key, preserve it! UncachedKeyRing secretRing; @@ -301,7 +306,7 @@ public class ProviderHelper { int rank = 0; for (UncachedPublicKey key : new IterableIterator<UncachedPublicKey>(keyRing.getPublicKeys())) { log(LogLevel.DEBUG, LogType.MSG_IP_INSERT_SUBKEY, new String[] { - PgpKeyHelper.convertKeyIdToHex(masterKeyId) + PgpKeyHelper.convertKeyIdToHex(key.getKeyId()) }); operations.add(buildPublicKeyOperations(masterKeyId, key, rank)); ++rank; @@ -433,10 +438,19 @@ public class ProviderHelper { mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations); } catch (IOException e) { log(LogLevel.ERROR, LogType.MSG_IP_FAIL_IO_EXC); + Log.e(Constants.TAG, "IOException during import", e); + mIndent -= 1; + return new OperationResultParcel(1, mLog); } catch (RemoteException e) { log(LogLevel.ERROR, LogType.MSG_IP_FAIL_REMOTE_EX); + Log.e(Constants.TAG, "RemoteException during import", e); + mIndent -= 1; + return new OperationResultParcel(1, mLog); } catch (OperationApplicationException e) { log(LogLevel.ERROR, LogType.MSG_IP_FAIL_OP_EX); + Log.e(Constants.TAG, "OperationApplicationException during import", e); + mIndent -= 1; + return new OperationResultParcel(1, mLog); } // Save the saved keyring (if any) @@ -448,6 +462,7 @@ public class ProviderHelper { } log(LogLevel.INFO, LogType.MSG_IP_SUCCESS); + mIndent -= 1; return new OperationResultParcel(0, mLog); } @@ -513,17 +528,25 @@ public class ProviderHelper { // then, mark exactly the keys we have available log(LogLevel.INFO, LogType.MSG_IS_IMPORTING_SUBKEYS); mIndent += 1; - for (Long sub : new IterableIterator<Long>(keyRing.getAvailableSubkeys().iterator())) { - int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?", new String[] { - Long.toString(sub) - }); - if(upd == 0) { - log(LogLevel.DEBUG, LogType.MSG_IS_SUBKEY_OK, new String[] { - PgpKeyHelper.convertKeyIdToHex(sub) - }); + Set<Long> available = keyRing.getAvailableSubkeys(); + for (UncachedPublicKey sub : + new IterableIterator<UncachedPublicKey>(keyRing.getPublicKeys())) { + long id = sub.getKeyId(); + if(available.contains(id)) { + int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?", + new String[] { Long.toString(id) }); + if (upd == 1) { + log(LogLevel.DEBUG, LogType.MSG_IS_SUBKEY_OK, new String[]{ + PgpKeyHelper.convertKeyIdToHex(id) + }); + } else { + log(LogLevel.WARN, LogType.MSG_IS_SUBKEY_NONEXISTENT, new String[]{ + PgpKeyHelper.convertKeyIdToHex(id) + }); + } } else { - log(LogLevel.WARN, LogType.MSG_IS_SUBKEY_NONEXISTENT, new String[] { - PgpKeyHelper.convertKeyIdToHex(sub) + log(LogLevel.INFO, LogType.MSG_IS_SUBKEY_STRIPPED, new String[]{ + PgpKeyHelper.convertKeyIdToHex(id) }); } } |