import-log: better stripped key logging

This commit is contained in:
Vincent Breitmoser 2014-06-06 17:29:39 +02:00
parent 118225d7d2
commit c36b311d5f
4 changed files with 43 additions and 17 deletions

View File

@ -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),
;

View File

@ -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())) {

View File

@ -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)
});
}
}

View File

@ -535,7 +535,7 @@
<string name="msg_ip_insert_subkeys">Inserting subkeys</string>
<string name="msg_ip_preserving_secret">Preserving available secret key</string>
<string name="msg_ip_reinsert_secret">Re-inserting secret key</string>
<string name="msg_ip_success">Successfully inserted secret keyring</string>
<string name="msg_ip_success">Successfully inserted public keyring</string>
<string name="msg_ip_trust_retrieve">Retrieving trusted keys</string>
<string name="msg_ip_trust_using">Using %s trusted keys</string>
<string name="msg_ip_trust_using_sec">Secret key available, self certificates are trusted</string>
@ -556,6 +556,7 @@
<string name="msg_is_io_excption">Error encoding keyring</string>
<string name="msg_is_subkey_nonexistent">Subkey %s unavailable in public key</string>
<string name="msg_is_subkey_ok">Marked %s as available</string>
<string name="msg_is_subkey_stripped">Marked %s as stripped</string>
<string name="msg_is_success">Successfully inserted secret keyring</string>
</resources>