mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-14 12:55:08 -05:00
import-log: minor improvements
This commit is contained in:
parent
dae503284f
commit
e4a7d4f6e5
@ -127,9 +127,7 @@ public class PgpImportExport {
|
|||||||
|
|
||||||
updateProgress(R.string.progress_importing, 0, 100);
|
updateProgress(R.string.progress_importing, 0, 100);
|
||||||
|
|
||||||
int newKeys = 0;
|
int newKeys = 0, oldKeys = 0, badKeys = 0;
|
||||||
int oldKeys = 0;
|
|
||||||
int badKeys = 0;
|
|
||||||
|
|
||||||
int position = 0;
|
int position = 0;
|
||||||
for (ParcelableKeyRing entry : entries) {
|
for (ParcelableKeyRing entry : entries) {
|
||||||
@ -147,7 +145,12 @@ public class PgpImportExport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(key);
|
SaveKeyringResult result;
|
||||||
|
if (key.isSecret()) {
|
||||||
|
result = mProviderHelper.saveSecretKeyRing(key);
|
||||||
|
} else {
|
||||||
|
result = mProviderHelper.savePublicKeyRing(key);
|
||||||
|
}
|
||||||
if (!result.success()) {
|
if (!result.success()) {
|
||||||
badKeys += 1;
|
badKeys += 1;
|
||||||
} else if (result.updated()) {
|
} else if (result.updated()) {
|
||||||
|
@ -416,9 +416,6 @@ public class UncachedKeyRing {
|
|||||||
cert.init(masterKey);
|
cert.init(masterKey);
|
||||||
if (!cert.verifySignature(masterKey, key)) {
|
if (!cert.verifySignature(masterKey, key)) {
|
||||||
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD, null, indent);
|
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD, null, indent);
|
||||||
log.add(LogLevel.WARN, LogType.MSG_KC_SUB, new String[] {
|
|
||||||
cert.getCreationTime().toString()
|
|
||||||
}, indent);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} catch (PgpGeneralException e) {
|
} catch (PgpGeneralException e) {
|
||||||
|
@ -296,20 +296,14 @@ public class ProviderHelper {
|
|||||||
secretRing = null;
|
secretRing = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
ArrayList<ContentProviderOperation> operations;
|
||||||
int deleted = mContentResolver.delete(
|
|
||||||
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
|
||||||
if (deleted > 0) {
|
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
|
|
||||||
result |= SaveKeyringResult.UPDATED;
|
|
||||||
} else {
|
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_FAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
log(LogLevel.DEBUG, LogType.MSG_IP_PREPARE);
|
||||||
|
mIndent += 1;
|
||||||
|
|
||||||
// save all keys and userIds included in keyRing object in database
|
// save all keys and userIds included in keyRing object in database
|
||||||
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
|
operations = new ArrayList<ContentProviderOperation>();
|
||||||
|
|
||||||
log(LogLevel.INFO, LogType.MSG_IP_INSERT_KEYRING);
|
log(LogLevel.INFO, LogType.MSG_IP_INSERT_KEYRING);
|
||||||
{ // insert keyring
|
{ // insert keyring
|
||||||
@ -382,7 +376,7 @@ public class ProviderHelper {
|
|||||||
if (expiryDate != null) {
|
if (expiryDate != null) {
|
||||||
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
||||||
if (key.isExpired()) {
|
if (key.isExpired()) {
|
||||||
log(LogLevel.INFO, LogType.MSG_IP_SUBKEY_EXPIRED, new String[] {
|
log(LogLevel.DEBUG, LogType.MSG_IP_SUBKEY_EXPIRED, new String[]{
|
||||||
expiryDate.toString()
|
expiryDate.toString()
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -453,7 +447,7 @@ public class ProviderHelper {
|
|||||||
item.isPrimary = cert.isPrimaryUserId();
|
item.isPrimary = cert.isPrimaryUserId();
|
||||||
if (cert.isRevocation()) {
|
if (cert.isRevocation()) {
|
||||||
item.isRevoked = true;
|
item.isRevoked = true;
|
||||||
log(LogLevel.INFO, LogType.MSG_IP_UID_REVOKED);
|
log(LogLevel.DEBUG, LogType.MSG_IP_UID_REVOKED);
|
||||||
} else {
|
} else {
|
||||||
item.isRevoked = false;
|
item.isRevoked = false;
|
||||||
}
|
}
|
||||||
@ -467,7 +461,8 @@ public class ProviderHelper {
|
|||||||
if (cert.verifySignature(masterKey, userId)) {
|
if (cert.verifySignature(masterKey, userId)) {
|
||||||
item.trustedCerts.add(cert);
|
item.trustedCerts.add(cert);
|
||||||
log(LogLevel.INFO, LogType.MSG_IP_UID_CERT_GOOD, new String[] {
|
log(LogLevel.INFO, LogType.MSG_IP_UID_CERT_GOOD, new String[] {
|
||||||
PgpKeyHelper.convertKeyIdToHex(trustedKey.getKeyId())
|
PgpKeyHelper.convertKeyIdToHexShort(trustedKey.getKeyId()),
|
||||||
|
trustedKey.getPrimaryUserId()
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_BAD);
|
log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_BAD);
|
||||||
@ -517,25 +512,30 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_APPLY_BATCH);
|
log(LogLevel.DEBUG, LogType.MSG_IP_PREPARE_SUCCESS);
|
||||||
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
mIndent -= 1;
|
||||||
|
|
||||||
} 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);
|
Log.e(Constants.TAG, "IOException during import", e);
|
||||||
mIndent -= 1;
|
mIndent -= 1;
|
||||||
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, 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 SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, 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 SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||||
|
int deleted = mContentResolver.delete(
|
||||||
|
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
|
||||||
|
if (deleted > 0) {
|
||||||
|
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
|
||||||
|
result |= SaveKeyringResult.UPDATED;
|
||||||
|
} else {
|
||||||
|
log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
log(LogLevel.DEBUG, LogType.MSG_IP_APPLY_BATCH);
|
||||||
|
mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
|
||||||
|
|
||||||
// Save the saved keyring (if any)
|
// Save the saved keyring (if any)
|
||||||
if (secretRing != null) {
|
if (secretRing != null) {
|
||||||
log(LogLevel.DEBUG, LogType.MSG_IP_REINSERT_SECRET);
|
log(LogLevel.DEBUG, LogType.MSG_IP_REINSERT_SECRET);
|
||||||
@ -549,6 +549,18 @@ public class ProviderHelper {
|
|||||||
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
||||||
return new SaveKeyringResult(result, mLog);
|
return new SaveKeyringResult(result, 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 SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, 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 SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class UserIdItem implements Comparable<UserIdItem> {
|
private static class UserIdItem implements Comparable<UserIdItem> {
|
||||||
@ -575,18 +587,23 @@ public class ProviderHelper {
|
|||||||
/**
|
/**
|
||||||
* Saves a PGPSecretKeyRing in the DB. This will only work if a corresponding public keyring
|
* Saves a PGPSecretKeyRing in the DB. This will only work if a corresponding public keyring
|
||||||
* is already in the database!
|
* is already in the database!
|
||||||
|
*
|
||||||
|
* TODO allow adding secret keys where no public key exists (ie, consolidate keys)
|
||||||
*/
|
*/
|
||||||
public OperationResultParcel saveSecretKeyRing(UncachedKeyRing keyRing) {
|
public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing keyRing) {
|
||||||
|
|
||||||
|
if (!keyRing.isSecret()) {
|
||||||
|
log(LogLevel.ERROR, LogType.MSG_IS_BAD_TYPE_PUBLIC);
|
||||||
|
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
||||||
|
}
|
||||||
|
|
||||||
long masterKeyId = keyRing.getMasterKeyId();
|
long masterKeyId = keyRing.getMasterKeyId();
|
||||||
log(LogLevel.START, LogType.MSG_IS,
|
log(LogLevel.START, LogType.MSG_IS,
|
||||||
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
|
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
|
||||||
mIndent += 1;
|
mIndent += 1;
|
||||||
|
|
||||||
if (!keyRing.isSecret()) {
|
// IF this is successful, it's a secret key
|
||||||
log(LogLevel.ERROR, LogType.MSG_IS_BAD_TYPE_PUBLIC);
|
int result = SaveKeyringResult.SAVED_SECRET;
|
||||||
return new OperationResultParcel(1, mLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
// save secret keyring
|
// save secret keyring
|
||||||
try {
|
try {
|
||||||
@ -599,7 +616,7 @@ public class ProviderHelper {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "Failed to encode key!", e);
|
Log.e(Constants.TAG, "Failed to encode key!", e);
|
||||||
log(LogLevel.ERROR, LogType.MSG_IS_IO_EXCPTION);
|
log(LogLevel.ERROR, LogType.MSG_IS_IO_EXCPTION);
|
||||||
return new OperationResultParcel(1, mLog);
|
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -643,7 +660,7 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log(LogLevel.OK, LogType.MSG_IS_SUCCESS);
|
log(LogLevel.OK, LogType.MSG_IS_SUCCESS);
|
||||||
return new OperationResultParcel(0, mLog);
|
return new SaveKeyringResult(result, mLog);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,8 @@ public class OperationResultParcel implements Parcelable {
|
|||||||
MSG_IP_FAIL_REMOTE_EX (R.string.msg_ip_fail_remote_ex),
|
MSG_IP_FAIL_REMOTE_EX (R.string.msg_ip_fail_remote_ex),
|
||||||
MSG_IP_INSERT_KEYRING (R.string.msg_ip_insert_keyring),
|
MSG_IP_INSERT_KEYRING (R.string.msg_ip_insert_keyring),
|
||||||
MSG_IP_INSERT_SUBKEYS (R.string.msg_ip_insert_subkeys),
|
MSG_IP_INSERT_SUBKEYS (R.string.msg_ip_insert_subkeys),
|
||||||
|
MSG_IP_PREPARE (R.string.msg_ip_prepare),
|
||||||
|
MSG_IP_PREPARE_SUCCESS(R.string.msg_ip_prepare_success),
|
||||||
MSG_IP_PRESERVING_SECRET (R.string.msg_ip_preserving_secret),
|
MSG_IP_PRESERVING_SECRET (R.string.msg_ip_preserving_secret),
|
||||||
MSG_IP_REINSERT_SECRET (R.string.msg_ip_reinsert_secret),
|
MSG_IP_REINSERT_SECRET (R.string.msg_ip_reinsert_secret),
|
||||||
MSG_IP_SUBKEY (R.string.msg_ip_subkey),
|
MSG_IP_SUBKEY (R.string.msg_ip_subkey),
|
||||||
|
@ -516,6 +516,8 @@
|
|||||||
<string name="msg_ip">Importing public keyring %s</string>
|
<string name="msg_ip">Importing public keyring %s</string>
|
||||||
<string name="msg_ip_insert_keyring">Inserting keyring data</string>
|
<string name="msg_ip_insert_keyring">Inserting keyring data</string>
|
||||||
<string name="msg_ip_insert_subkeys">Inserting subkeys</string>
|
<string name="msg_ip_insert_subkeys">Inserting subkeys</string>
|
||||||
|
<string name="msg_ip_prepare">Preparing database operations</string>
|
||||||
|
<string name="msg_ip_prepare_success">OK</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_subkey">Processing subkey %s</string>
|
<string name="msg_ip_subkey">Processing subkey %s</string>
|
||||||
<string name="msg_ip_subkey_expired">Subkey expired on %s</string>
|
<string name="msg_ip_subkey_expired">Subkey expired on %s</string>
|
||||||
@ -536,7 +538,7 @@
|
|||||||
<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_uid_cert_bad">Encountered bad certificate!</string>
|
<string name="msg_ip_uid_cert_bad">Encountered bad certificate!</string>
|
||||||
<string name="msg_ip_uid_cert_error">Error processing certificate!</string>
|
<string name="msg_ip_uid_cert_error">Error processing certificate!</string>
|
||||||
<string name="msg_ip_uid_cert_good">Found good certificate from %s</string>
|
<string name="msg_ip_uid_cert_good">Found good certificate from %2$s (%2$s)</string>
|
||||||
<string name="msg_ip_uid_certs_unknown">Ignored %s certificates from unknown pubkeys</string>
|
<string name="msg_ip_uid_certs_unknown">Ignored %s certificates from unknown pubkeys</string>
|
||||||
<string name="msg_ip_uid_classifying">Classifying user ids</string>
|
<string name="msg_ip_uid_classifying">Classifying user ids</string>
|
||||||
<string name="msg_ip_uid_insert">Inserting user ids</string>
|
<string name="msg_ip_uid_insert">Inserting user ids</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user