mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
import-log: better stripped key logging
This commit is contained in:
parent
118225d7d2
commit
c36b311d5f
@ -123,6 +123,7 @@ public class OperationResultParcel implements Parcelable {
|
|||||||
MSG_IS_IO_EXCPTION (R.string.msg_is_io_excption),
|
MSG_IS_IO_EXCPTION (R.string.msg_is_io_excption),
|
||||||
MSG_IS_SUBKEY_NONEXISTENT (R.string.msg_is_subkey_nonexistent),
|
MSG_IS_SUBKEY_NONEXISTENT (R.string.msg_is_subkey_nonexistent),
|
||||||
MSG_IS_SUBKEY_OK (R.string.msg_is_subkey_ok),
|
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),
|
MSG_IS_SUCCESS (R.string.msg_is_success),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -149,13 +150,13 @@ public class UncachedKeyRing {
|
|||||||
aos.close();
|
aos.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Long> getAvailableSubkeys() {
|
public HashSet<Long> getAvailableSubkeys() {
|
||||||
if(!isSecret()) {
|
if(!isSecret()) {
|
||||||
throw new RuntimeException("Tried to find available subkeys from non-secret keys. " +
|
throw new RuntimeException("Tried to find available subkeys from non-secret keys. " +
|
||||||
"This is a programming error and should never happen!");
|
"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
|
// then, mark exactly the keys we have available
|
||||||
for (PGPSecretKey sub : new IterableIterator<PGPSecretKey>(
|
for (PGPSecretKey sub : new IterableIterator<PGPSecretKey>(
|
||||||
((PGPSecretKeyRing) mRing).getSecretKeys())) {
|
((PGPSecretKeyRing) mRing).getSecretKeys())) {
|
||||||
|
@ -68,7 +68,7 @@ public class ProviderHelper {
|
|||||||
private int mIndent;
|
private int mIndent;
|
||||||
|
|
||||||
public ProviderHelper(Context context) {
|
public ProviderHelper(Context context) {
|
||||||
this(context, null, 0);
|
this(context, new ArrayList<OperationResultParcel.LogEntryParcel>(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProviderHelper(Context context, ArrayList<OperationResultParcel.LogEntryParcel> log,
|
public ProviderHelper(Context context, ArrayList<OperationResultParcel.LogEntryParcel> log,
|
||||||
@ -96,10 +96,14 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void log(LogLevel level, LogType type) {
|
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) {
|
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!
|
// 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();
|
long masterKeyId = masterKey.getKeyId();
|
||||||
log(LogLevel.INFO, LogType.MSG_IP_IMPORTING,
|
log(LogLevel.INFO, LogType.MSG_IP_IMPORTING,
|
||||||
new String[]{Long.toString(masterKeyId)});
|
new String[]{Long.toString(masterKeyId)});
|
||||||
|
mIndent += 1;
|
||||||
|
|
||||||
// IF there is a secret key, preserve it!
|
// IF there is a secret key, preserve it!
|
||||||
UncachedKeyRing secretRing;
|
UncachedKeyRing secretRing;
|
||||||
@ -301,7 +306,7 @@ public class ProviderHelper {
|
|||||||
int rank = 0;
|
int rank = 0;
|
||||||
for (UncachedPublicKey key : new IterableIterator<UncachedPublicKey>(keyRing.getPublicKeys())) {
|
for (UncachedPublicKey key : new IterableIterator<UncachedPublicKey>(keyRing.getPublicKeys())) {
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_INSERT_SUBKEY, new String[] {
|
log(LogLevel.DEBUG, LogType.MSG_IP_INSERT_SUBKEY, new String[] {
|
||||||
PgpKeyHelper.convertKeyIdToHex(masterKeyId)
|
PgpKeyHelper.convertKeyIdToHex(key.getKeyId())
|
||||||
});
|
});
|
||||||
operations.add(buildPublicKeyOperations(masterKeyId, key, rank));
|
operations.add(buildPublicKeyOperations(masterKeyId, key, rank));
|
||||||
++rank;
|
++rank;
|
||||||
@ -433,10 +438,19 @@ public class ProviderHelper {
|
|||||||
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_IO_EXC);
|
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) {
|
} catch (RemoteException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_REMOTE_EX);
|
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) {
|
} catch (OperationApplicationException e) {
|
||||||
log(LogLevel.ERROR, LogType.MSG_IP_FAIL_OP_EX);
|
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)
|
// Save the saved keyring (if any)
|
||||||
@ -448,6 +462,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log(LogLevel.INFO, LogType.MSG_IP_SUCCESS);
|
log(LogLevel.INFO, LogType.MSG_IP_SUCCESS);
|
||||||
|
mIndent -= 1;
|
||||||
return new OperationResultParcel(0, mLog);
|
return new OperationResultParcel(0, mLog);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -513,17 +528,25 @@ public class ProviderHelper {
|
|||||||
// then, mark exactly the keys we have available
|
// then, mark exactly the keys we have available
|
||||||
log(LogLevel.INFO, LogType.MSG_IS_IMPORTING_SUBKEYS);
|
log(LogLevel.INFO, LogType.MSG_IS_IMPORTING_SUBKEYS);
|
||||||
mIndent += 1;
|
mIndent += 1;
|
||||||
for (Long sub : new IterableIterator<Long>(keyRing.getAvailableSubkeys().iterator())) {
|
Set<Long> available = keyRing.getAvailableSubkeys();
|
||||||
int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?", new String[] {
|
for (UncachedPublicKey sub :
|
||||||
Long.toString(sub)
|
new IterableIterator<UncachedPublicKey>(keyRing.getPublicKeys())) {
|
||||||
});
|
long id = sub.getKeyId();
|
||||||
if(upd == 0) {
|
if(available.contains(id)) {
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IS_SUBKEY_OK, new String[] {
|
int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?",
|
||||||
PgpKeyHelper.convertKeyIdToHex(sub)
|
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 {
|
} else {
|
||||||
log(LogLevel.WARN, LogType.MSG_IS_SUBKEY_NONEXISTENT, new String[] {
|
log(LogLevel.INFO, LogType.MSG_IS_SUBKEY_STRIPPED, new String[]{
|
||||||
PgpKeyHelper.convertKeyIdToHex(sub)
|
PgpKeyHelper.convertKeyIdToHex(id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -535,7 +535,7 @@
|
|||||||
<string name="msg_ip_insert_subkeys">Inserting subkeys</string>
|
<string name="msg_ip_insert_subkeys">Inserting subkeys</string>
|
||||||
<string name="msg_ip_preserving_secret">Preserving available secret key</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_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_retrieve">Retrieving trusted keys</string>
|
||||||
<string name="msg_ip_trust_using">Using %s 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>
|
<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_io_excption">Error encoding keyring</string>
|
||||||
<string name="msg_is_subkey_nonexistent">Subkey %s unavailable in public key</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_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>
|
<string name="msg_is_success">Successfully inserted secret keyring</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user