code cleanup and plurals in import log entries

closes #698
This commit is contained in:
Vincent Breitmoser 2014-06-28 19:00:44 +02:00
parent b7b22beafc
commit d6a2875816
9 changed files with 140 additions and 154 deletions

View File

@ -33,7 +33,6 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.PGPSignature; import org.spongycastle.openpgp.PGPSignature;
import org.spongycastle.openpgp.PGPSignatureGenerator; import org.spongycastle.openpgp.PGPSignatureGenerator;
import org.spongycastle.openpgp.PGPSignatureSubpacketGenerator; import org.spongycastle.openpgp.PGPSignatureSubpacketGenerator;
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
import org.spongycastle.openpgp.PGPUtil; import org.spongycastle.openpgp.PGPUtil;
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor; import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.spongycastle.openpgp.operator.PBESecretKeyEncryptor; import org.spongycastle.openpgp.operator.PBESecretKeyEncryptor;
@ -51,7 +50,6 @@ import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType;
import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Primes; import org.sufficientlysecure.keychain.util.Primes;
import java.io.IOException; import java.io.IOException;
@ -65,7 +63,6 @@ import java.security.SignatureException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
/** /**
@ -268,18 +265,18 @@ public class PgpKeyOperation {
// 4a. For each subkey change, generate new subkey binding certificate // 4a. For each subkey change, generate new subkey binding certificate
for (SaveKeyringParcel.SubkeyChange change : saveParcel.changeSubKeys) { for (SaveKeyringParcel.SubkeyChange change : saveParcel.changeSubKeys) {
log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_CHANGE, log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_CHANGE,
new String[]{PgpKeyHelper.convertKeyIdToHex(change.mKeyId)}, indent); indent, PgpKeyHelper.convertKeyIdToHex(change.mKeyId));
PGPSecretKey sKey = sKR.getSecretKey(change.mKeyId); PGPSecretKey sKey = sKR.getSecretKey(change.mKeyId);
if (sKey == null) { if (sKey == null) {
log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_MISSING, log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_MISSING,
new String[]{PgpKeyHelper.convertKeyIdToHex(change.mKeyId)}, indent + 1); indent + 1, PgpKeyHelper.convertKeyIdToHex(change.mKeyId));
return null; return null;
} }
PGPPublicKey pKey = sKey.getPublicKey(); PGPPublicKey pKey = sKey.getPublicKey();
if (change.mExpiry != null && new Date(change.mExpiry).before(new Date())) { if (change.mExpiry != null && new Date(change.mExpiry).before(new Date())) {
log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_PAST_EXPIRY, log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_PAST_EXPIRY,
new String[]{PgpKeyHelper.convertKeyIdToHex(change.mKeyId)}, indent + 1); indent + 1, PgpKeyHelper.convertKeyIdToHex(change.mKeyId));
return null; return null;
} }
@ -293,11 +290,11 @@ public class PgpKeyOperation {
// 4b. For each subkey revocation, generate new subkey revocation certificate // 4b. For each subkey revocation, generate new subkey revocation certificate
for (long revocation : saveParcel.revokeSubKeys) { for (long revocation : saveParcel.revokeSubKeys) {
log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_REVOKE, log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_REVOKE,
new String[] { PgpKeyHelper.convertKeyIdToHex(revocation) }, indent); indent, PgpKeyHelper.convertKeyIdToHex(revocation));
PGPSecretKey sKey = sKR.getSecretKey(revocation); PGPSecretKey sKey = sKR.getSecretKey(revocation);
if (sKey == null) { if (sKey == null) {
log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_MISSING, log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_MISSING,
new String[] { PgpKeyHelper.convertKeyIdToHex(revocation) }, indent+1); indent+1, PgpKeyHelper.convertKeyIdToHex(revocation));
return null; return null;
} }
PGPPublicKey pKey = sKey.getPublicKey(); PGPPublicKey pKey = sKey.getPublicKey();
@ -321,7 +318,7 @@ public class PgpKeyOperation {
log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_NEW, indent); log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_NEW, indent);
PGPSecretKey sKey = createKey(add.mAlgorithm, add.mKeysize, passphrase, false); PGPSecretKey sKey = createKey(add.mAlgorithm, add.mKeysize, passphrase, false);
log.add(LogLevel.DEBUG, LogType.MSG_MF_SUBKEY_NEW_ID, log.add(LogLevel.DEBUG, LogType.MSG_MF_SUBKEY_NEW_ID,
new String[] { PgpKeyHelper.convertKeyIdToHex(sKey.getKeyID()) }, indent+1); indent+1, PgpKeyHelper.convertKeyIdToHex(sKey.getKeyID()));
PGPPublicKey pKey = sKey.getPublicKey(); PGPPublicKey pKey = sKey.getPublicKey();
PGPSignature cert = generateSubkeyBindingSignature(masterPublicKey, masterPrivateKey, PGPSignature cert = generateSubkeyBindingSignature(masterPublicKey, masterPrivateKey,

View File

@ -207,7 +207,7 @@ public class UncachedKeyRing {
public UncachedKeyRing canonicalize(OperationLog log, int indent) { public UncachedKeyRing canonicalize(OperationLog log, int indent) {
log.add(LogLevel.START, isSecret() ? LogType.MSG_KC_SECRET : LogType.MSG_KC_PUBLIC, log.add(LogLevel.START, isSecret() ? LogType.MSG_KC_SECRET : LogType.MSG_KC_PUBLIC,
new String[]{PgpKeyHelper.convertKeyIdToHex(getMasterKeyId())}, indent); indent, PgpKeyHelper.convertKeyIdToHex(getMasterKeyId()));
indent += 1; indent += 1;
final Date now = new Date(); final Date now = new Date();
@ -220,7 +220,7 @@ public class UncachedKeyRing {
{ {
log.add(LogLevel.DEBUG, LogType.MSG_KC_MASTER, log.add(LogLevel.DEBUG, LogType.MSG_KC_MASTER,
new String[]{PgpKeyHelper.convertKeyIdToHex(masterKey.getKeyID())}, indent); indent, PgpKeyHelper.convertKeyIdToHex(masterKey.getKeyID()));
indent += 1; indent += 1;
PGPPublicKey modified = masterKey; PGPPublicKey modified = masterKey;
@ -240,9 +240,7 @@ public class UncachedKeyRing {
if (type != PGPSignature.KEY_REVOCATION) { if (type != PGPSignature.KEY_REVOCATION) {
// Unknown type, just remove // Unknown type, just remove
log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TYPE, new String[]{ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TYPE, indent, "0x" + Integer.toString(type, 16));
"0x" + Integer.toString(type, 16)
}, indent);
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
badCerts += 1; badCerts += 1;
continue; continue;
@ -250,7 +248,7 @@ public class UncachedKeyRing {
if (cert.getCreationTime().after(now)) { if (cert.getCreationTime().after(now)) {
// Creation date in the future? No way! // Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TIME, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TIME, indent);
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
badCerts += 1; badCerts += 1;
continue; continue;
@ -258,7 +256,7 @@ public class UncachedKeyRing {
if (cert.isLocal()) { if (cert.isLocal()) {
// Creation date in the future? No way! // Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_LOCAL, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_LOCAL, indent);
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
badCerts += 1; badCerts += 1;
continue; continue;
@ -267,13 +265,13 @@ public class UncachedKeyRing {
try { try {
cert.init(masterKey); cert.init(masterKey);
if (!cert.verifySignature(masterKey)) { if (!cert.verifySignature(masterKey)) {
log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD, indent);
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
badCerts += 1; badCerts += 1;
continue; continue;
} }
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {
log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_ERR, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_ERR, indent);
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
badCerts += 1; badCerts += 1;
continue; continue;
@ -286,12 +284,12 @@ public class UncachedKeyRing {
} else if (revocation.getCreationTime().before(zert.getCreationTime())) { } else if (revocation.getCreationTime().before(zert.getCreationTime())) {
modified = PGPPublicKey.removeCertification(modified, revocation); modified = PGPPublicKey.removeCertification(modified, revocation);
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, null, indent); log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, indent);
revocation = zert; revocation = zert;
} else { } else {
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, null, indent); log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, indent);
} }
} }
@ -312,16 +310,14 @@ public class UncachedKeyRing {
&& type != PGPSignature.POSITIVE_CERTIFICATION && type != PGPSignature.POSITIVE_CERTIFICATION
&& type != PGPSignature.CERTIFICATION_REVOCATION) { && type != PGPSignature.CERTIFICATION_REVOCATION) {
log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_TYPE, log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_TYPE,
new String[] { indent, "0x" + Integer.toString(zert.getSignatureType(), 16));
"0x" + Integer.toString(zert.getSignatureType(), 16)
}, indent);
modified = PGPPublicKey.removeCertification(modified, userId, zert); modified = PGPPublicKey.removeCertification(modified, userId, zert);
badCerts += 1; badCerts += 1;
} }
if (cert.getCreationTime().after(now)) { if (cert.getCreationTime().after(now)) {
// Creation date in the future? No way! // Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TIME, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TIME, indent);
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
badCerts += 1; badCerts += 1;
continue; continue;
@ -329,7 +325,7 @@ public class UncachedKeyRing {
if (cert.isLocal()) { if (cert.isLocal()) {
// Creation date in the future? No way! // Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_LOCAL, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_LOCAL, indent);
modified = PGPPublicKey.removeCertification(modified, zert); modified = PGPPublicKey.removeCertification(modified, zert);
badCerts += 1; badCerts += 1;
continue; continue;
@ -340,7 +336,7 @@ public class UncachedKeyRing {
// never mind any further for public keys, but remove them from secret ones // never mind any further for public keys, but remove them from secret ones
if (isSecret()) { if (isSecret()) {
log.add(LogLevel.WARN, LogType.MSG_KC_UID_FOREIGN, log.add(LogLevel.WARN, LogType.MSG_KC_UID_FOREIGN,
new String[] { PgpKeyHelper.convertKeyIdToHex(certId) }, indent); indent, PgpKeyHelper.convertKeyIdToHex(certId));
modified = PGPPublicKey.removeCertification(modified, userId, zert); modified = PGPPublicKey.removeCertification(modified, userId, zert);
badCerts += 1; badCerts += 1;
} }
@ -352,14 +348,14 @@ public class UncachedKeyRing {
cert.init(masterKey); cert.init(masterKey);
if (!cert.verifySignature(masterKey, userId)) { if (!cert.verifySignature(masterKey, userId)) {
log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD, log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD,
new String[] { userId }, indent); indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, zert); modified = PGPPublicKey.removeCertification(modified, userId, zert);
badCerts += 1; badCerts += 1;
continue; continue;
} }
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {
log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_ERR, log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_ERR,
new String[] { userId }, indent); indent, userId);
modified = PGPPublicKey.removeCertification(modified, userId, zert); modified = PGPPublicKey.removeCertification(modified, userId, zert);
badCerts += 1; badCerts += 1;
continue; continue;
@ -376,13 +372,13 @@ public class UncachedKeyRing {
modified = PGPPublicKey.removeCertification(modified, userId, selfCert); modified = PGPPublicKey.removeCertification(modified, userId, selfCert);
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP, log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP,
new String[] { userId }, indent); indent, userId);
selfCert = zert; selfCert = zert;
} else { } else {
modified = PGPPublicKey.removeCertification(modified, userId, zert); modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP, log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP,
new String[] { userId }, indent); indent, userId);
} }
// If there is a revocation certificate, and it's older than this, drop it // If there is a revocation certificate, and it's older than this, drop it
if (revocation != null if (revocation != null
@ -391,7 +387,7 @@ public class UncachedKeyRing {
revocation = null; revocation = null;
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_OLD, log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_OLD,
new String[] { userId }, indent); indent, userId);
} }
break; break;
@ -401,7 +397,7 @@ public class UncachedKeyRing {
modified = PGPPublicKey.removeCertification(modified, userId, zert); modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_OLD, log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_OLD,
new String[] { userId }, indent); indent, userId);
continue; continue;
} }
// first revocation? remember it. // first revocation? remember it.
@ -412,13 +408,13 @@ public class UncachedKeyRing {
modified = PGPPublicKey.removeCertification(modified, userId, revocation); modified = PGPPublicKey.removeCertification(modified, userId, revocation);
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_DUP, log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_DUP,
new String[] { userId }, indent); indent, userId);
revocation = zert; revocation = zert;
} else { } else {
modified = PGPPublicKey.removeCertification(modified, userId, zert); modified = PGPPublicKey.removeCertification(modified, userId, zert);
redundantCerts += 1; redundantCerts += 1;
log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_DUP, log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_REVOKE_DUP,
new String[] { userId }, indent); indent, userId);
} }
break; break;
@ -430,13 +426,13 @@ public class UncachedKeyRing {
if (selfCert == null && revocation == null) { if (selfCert == null && revocation == null) {
modified = PGPPublicKey.removeCertification(modified, userId); modified = PGPPublicKey.removeCertification(modified, userId);
log.add(LogLevel.ERROR, LogType.MSG_KC_UID_REVOKE_DUP, log.add(LogLevel.ERROR, LogType.MSG_KC_UID_REVOKE_DUP,
new String[] { userId }, indent); indent, userId);
} }
} }
// If NO user ids remain, error out! // If NO user ids remain, error out!
if (!modified.getUserIDs().hasNext()) { if (!modified.getUserIDs().hasNext()) {
log.add(LogLevel.ERROR, LogType.MSG_KC_FATAL_NO_UID, null, indent); log.add(LogLevel.ERROR, LogType.MSG_KC_FATAL_NO_UID, indent);
return null; return null;
} }
@ -453,7 +449,7 @@ public class UncachedKeyRing {
continue; continue;
} }
log.add(LogLevel.DEBUG, LogType.MSG_KC_SUB, log.add(LogLevel.DEBUG, LogType.MSG_KC_SUB,
new String[]{PgpKeyHelper.convertKeyIdToHex(key.getKeyID())}, indent); indent, PgpKeyHelper.convertKeyIdToHex(key.getKeyID()));
indent += 1; indent += 1;
// A subkey needs exactly one subkey binding certificate, and optionally one revocation // A subkey needs exactly one subkey binding certificate, and optionally one revocation
// certificate. // certificate.
@ -468,29 +464,27 @@ public class UncachedKeyRing {
// filter out bad key types... // filter out bad key types...
if (cert.getKeyId() != masterKey.getKeyID()) { if (cert.getKeyId() != masterKey.getKeyID()) {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_KEYID, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_KEYID, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
if (type != PGPSignature.SUBKEY_BINDING && type != PGPSignature.SUBKEY_REVOCATION) { if (type != PGPSignature.SUBKEY_BINDING && type != PGPSignature.SUBKEY_REVOCATION) {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_TYPE, new String[]{ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_TYPE, indent, "0x" + Integer.toString(type, 16));
"0x" + Integer.toString(type, 16)
}, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
if (cert.getCreationTime().after(now)) { if (cert.getCreationTime().after(now)) {
// Creation date in the future? No way! // Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_TIME, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_TIME, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
if (cert.isLocal()) { if (cert.isLocal()) {
// Creation date in the future? No way! // Creation date in the future? No way!
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_LOCAL, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_LOCAL, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
@ -501,12 +495,12 @@ public class UncachedKeyRing {
try { try {
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, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_ERR, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_ERR, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
@ -526,19 +520,19 @@ public class UncachedKeyRing {
if (subsig.verifySignature(masterKey, key)) { if (subsig.verifySignature(masterKey, key)) {
ok = true; ok = true;
} else { } else {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_BAD, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_BAD, indent);
badCerts += 1; badCerts += 1;
continue uids; continue uids;
} }
} }
} }
if (!ok) { if (!ok) {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_NONE, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_NONE, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
} catch (Exception e) { } catch (Exception e) {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_BAD_ERR, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_BAD_ERR, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
@ -565,12 +559,12 @@ public class UncachedKeyRing {
try { try {
cert.init(masterKey); cert.init(masterKey);
if (!cert.verifySignature(key)) { if (!cert.verifySignature(key)) {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_REVOKE_BAD, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_REVOKE_BAD, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {
log.add(LogLevel.WARN, LogType.MSG_KC_SUB_REVOKE_BAD_ERR, null, indent); log.add(LogLevel.WARN, LogType.MSG_KC_SUB_REVOKE_BAD_ERR, indent);
badCerts += 1; badCerts += 1;
continue; continue;
} }
@ -591,7 +585,7 @@ public class UncachedKeyRing {
ring = replacePublicKey(ring, modified); ring = replacePublicKey(ring, modified);
log.add(LogLevel.ERROR, LogType.MSG_KC_SUB_NO_CERT, log.add(LogLevel.ERROR, LogType.MSG_KC_SUB_NO_CERT,
new String[]{ PgpKeyHelper.convertKeyIdToHex(key.getKeyID()) }, indent); indent, PgpKeyHelper.convertKeyIdToHex(key.getKeyID()));
indent -= 1; indent -= 1;
continue; continue;
} }
@ -608,17 +602,17 @@ public class UncachedKeyRing {
} }
if (badCerts > 0 && redundantCerts > 0) { if (badCerts > 0 && redundantCerts > 0) {
// multi plural would make this complex, just leaving this as is...
log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS_BAD_AND_RED, log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS_BAD_AND_RED,
new String[] { Integer.toString(badCerts), indent, Integer.toString(badCerts), Integer.toString(redundantCerts));
Integer.toString(redundantCerts) }, indent);
} else if (badCerts > 0) { } else if (badCerts > 0) {
log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS_BAD, log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS_BAD,
new String[] { Integer.toString(badCerts) }, indent); indent, badCerts);
} else if (redundantCerts > 0) { } else if (redundantCerts > 0) {
log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS_REDUNDANT, log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS_REDUNDANT,
new String[] { Integer.toString(redundantCerts) }, indent); indent, redundantCerts);
} else { } else {
log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS, null, indent); log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS, indent);
} }
return new UncachedKeyRing(ring, true); return new UncachedKeyRing(ring, true);
@ -638,13 +632,13 @@ public class UncachedKeyRing {
public UncachedKeyRing merge(UncachedKeyRing other, OperationLog log, int indent) { public UncachedKeyRing merge(UncachedKeyRing other, OperationLog log, int indent) {
log.add(LogLevel.DEBUG, isSecret() ? LogType.MSG_MG_SECRET : LogType.MSG_MG_PUBLIC, log.add(LogLevel.DEBUG, isSecret() ? LogType.MSG_MG_SECRET : LogType.MSG_MG_PUBLIC,
new String[]{ PgpKeyHelper.convertKeyIdToHex(getMasterKeyId()) }, indent); indent, PgpKeyHelper.convertKeyIdToHex(getMasterKeyId()));
indent += 1; indent += 1;
long masterKeyId = other.getMasterKeyId(); long masterKeyId = other.getMasterKeyId();
if (getMasterKeyId() != masterKeyId) { if (getMasterKeyId() != masterKeyId) {
log.add(LogLevel.ERROR, LogType.MSG_MG_HETEROGENEOUS, null, indent); log.add(LogLevel.ERROR, LogType.MSG_MG_HETEROGENEOUS, indent);
return null; return null;
} }
@ -683,7 +677,7 @@ public class UncachedKeyRing {
final PGPPublicKey resultKey = result.getPublicKey(key.getKeyID()); final PGPPublicKey resultKey = result.getPublicKey(key.getKeyID());
if (resultKey == null) { if (resultKey == null) {
log.add(LogLevel.DEBUG, LogType.MSG_MG_NEW_SUBKEY, null, indent); log.add(LogLevel.DEBUG, LogType.MSG_MG_NEW_SUBKEY, indent);
result = replacePublicKey(result, key); result = replacePublicKey(result, key);
continue; continue;
} }
@ -751,12 +745,12 @@ public class UncachedKeyRing {
} }
log.add(LogLevel.DEBUG, LogType.MSG_MG_FOUND_NEW, log.add(LogLevel.DEBUG, LogType.MSG_MG_FOUND_NEW,
new String[] { Integer.toString(newCerts) }, indent); indent, Integer.toString(newCerts));
return new UncachedKeyRing(result); return new UncachedKeyRing(result);
} catch (IOException e) { } catch (IOException e) {
log.add(LogLevel.ERROR, LogType.MSG_MG_FATAL_ENCODE, null, indent); log.add(LogLevel.ERROR, LogType.MSG_MG_FATAL_ENCODE, indent);
return null; return null;
} }

View File

@ -165,10 +165,10 @@ public class KeychainDatabase extends SQLiteOpenHelper {
// make sure this is only done once, on the first instance! // make sure this is only done once, on the first instance!
boolean iAmIt = false; boolean iAmIt = false;
synchronized(apgHack) { synchronized(KeychainDatabase.class) {
if(!apgHack) { if(!KeychainDatabase.apgHack) {
iAmIt = true; iAmIt = true;
apgHack = true; KeychainDatabase.apgHack = true;
} }
} }
// if it's us, do the import // if it's us, do the import
@ -206,6 +206,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
try { try {
db.execSQL("ALTER TABLE keys ADD COLUMN has_secret BOOLEAN"); db.execSQL("ALTER TABLE keys ADD COLUMN has_secret BOOLEAN");
} catch (Exception e) { } catch (Exception e) {
// never mind, the column probably already existed
} }
} }
} }
@ -261,8 +262,8 @@ public class KeychainDatabase extends SQLiteOpenHelper {
cursor = db.rawQuery("SELECT key_ring_data FROM key_rings WHERE type = 1 OR EXISTS (" cursor = db.rawQuery("SELECT key_ring_data FROM key_rings WHERE type = 1 OR EXISTS ("
+ " SELECT 1 FROM key_rings d2 WHERE key_rings.master_key_id = d2.master_key_id" + " SELECT 1 FROM key_rings d2 WHERE key_rings.master_key_id = d2.master_key_id"
+ " AND d2.type = 1) ORDER BY type ASC", null); + " AND d2.type = 1) ORDER BY type ASC", null);
Log.d(Constants.TAG, "Importing " + cursor.getCount() + " secret keyrings from apg.db...");
if (cursor != null) { if (cursor != null) {
Log.d(Constants.TAG, "Importing " + cursor.getCount() + " secret keyrings from apg.db...");
for (int i = 0; i < cursor.getCount(); i++) { for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i); cursor.moveToPosition(i);
byte[] data = cursor.getBlob(0); byte[] data = cursor.getBlob(0);
@ -285,8 +286,8 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ " SELECT 1 FROM key_rings d2 WHERE key_rings.master_key_id = d2.master_key_id AND" + " SELECT 1 FROM key_rings d2 WHERE key_rings.master_key_id = d2.master_key_id AND"
+ " d2.type = 1)) DESC, type DESC", null); + " d2.type = 1)) DESC, type DESC", null);
// import from old database // import from old database
Log.d(Constants.TAG, "Importing " + cursor.getCount() + " keyrings from apg.db...");
if (cursor != null) { if (cursor != null) {
Log.d(Constants.TAG, "Importing " + cursor.getCount() + " keyrings from apg.db...");
for (int i = 0; i < cursor.getCount(); i++) { for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i); cursor.moveToPosition(i);
byte[] data = cursor.getBlob(0); byte[] data = cursor.getBlob(0);

View File

@ -116,12 +116,12 @@ public class ProviderHelper {
public void log(LogLevel level, LogType type) { public void log(LogLevel level, LogType type) {
if(mLog != null) { if(mLog != null) {
mLog.add(level, type, null, mIndent); mLog.add(level, type, mIndent);
} }
} }
public void log(LogLevel level, LogType type, String[] parameters) { public void log(LogLevel level, LogType type, Object... parameters) {
if(mLog != null) { if(mLog != null) {
mLog.add(level, type, parameters, mIndent); mLog.add(level, type, mIndent, parameters);
} }
} }
@ -320,9 +320,9 @@ 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())) {
long keyId = key.getKeyId(); long keyId = key.getKeyId();
log(LogLevel.DEBUG, keyId == masterKeyId ? LogType.MSG_IP_MASTER : LogType.MSG_IP_SUBKEY, new String[]{ log(LogLevel.DEBUG, keyId == masterKeyId ? LogType.MSG_IP_MASTER : LogType.MSG_IP_SUBKEY,
PgpKeyHelper.convertKeyIdToHex(keyId) PgpKeyHelper.convertKeyIdToHex(keyId)
}); );
mIndent += 1; mIndent += 1;
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
@ -343,36 +343,36 @@ public class ProviderHelper {
if (c) { if (c) {
if (e) { if (e) {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_CES log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_CES
: LogType.MSG_IP_MASTER_FLAGS_CEX, null); : LogType.MSG_IP_MASTER_FLAGS_CEX);
} else { } else {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_CXS log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_CXS
: LogType.MSG_IP_MASTER_FLAGS_CXX, null); : LogType.MSG_IP_MASTER_FLAGS_CXX);
} }
} else { } else {
if (e) { if (e) {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_XES log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_XES
: LogType.MSG_IP_MASTER_FLAGS_XEX, null); : LogType.MSG_IP_MASTER_FLAGS_XEX);
} else { } else {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_XXS log(LogLevel.DEBUG, s ? LogType.MSG_IP_MASTER_FLAGS_XXS
: LogType.MSG_IP_MASTER_FLAGS_XXX, null); : LogType.MSG_IP_MASTER_FLAGS_XXX);
} }
} }
} else { } else {
if (c) { if (c) {
if (e) { if (e) {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_CES log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_CES
: LogType.MSG_IP_SUBKEY_FLAGS_CEX, null); : LogType.MSG_IP_SUBKEY_FLAGS_CEX);
} else { } else {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_CXS log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_CXS
: LogType.MSG_IP_SUBKEY_FLAGS_CXX, null); : LogType.MSG_IP_SUBKEY_FLAGS_CXX);
} }
} else { } else {
if (e) { if (e) {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XES log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XES
: LogType.MSG_IP_SUBKEY_FLAGS_XEX, null); : LogType.MSG_IP_SUBKEY_FLAGS_XEX);
} else { } else {
log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XXS log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XXS
: LogType.MSG_IP_SUBKEY_FLAGS_XXX, null); : LogType.MSG_IP_SUBKEY_FLAGS_XXX);
} }
} }
} }
@ -385,11 +385,11 @@ public class ProviderHelper {
if (key.isExpired()) { if (key.isExpired()) {
log(LogLevel.DEBUG, keyId == masterKeyId ? log(LogLevel.DEBUG, keyId == masterKeyId ?
LogType.MSG_IP_MASTER_EXPIRED : LogType.MSG_IP_SUBKEY_EXPIRED, LogType.MSG_IP_MASTER_EXPIRED : LogType.MSG_IP_SUBKEY_EXPIRED,
new String[]{ expiryDate.toString() }); expiryDate.toString());
} else { } else {
log(LogLevel.DEBUG, keyId == masterKeyId ? log(LogLevel.DEBUG, keyId == masterKeyId ?
LogType.MSG_IP_MASTER_EXPIRES : LogType.MSG_IP_SUBKEY_EXPIRES, LogType.MSG_IP_MASTER_EXPIRES : LogType.MSG_IP_SUBKEY_EXPIRES,
new String[] { expiryDate.toString() }); expiryDate.toString());
} }
} }
@ -405,9 +405,7 @@ public class ProviderHelper {
// classify and order user ids. primary are moved to the front, revoked to the back, // classify and order user ids. primary are moved to the front, revoked to the back,
// otherwise the order in the keyfile is preserved. // otherwise the order in the keyfile is preserved.
log(LogLevel.INFO, LogType.MSG_IP_UID_CLASSIFYING, new String[]{ log(LogLevel.INFO, LogType.MSG_IP_UID_CLASSIFYING, trustedKeys.size());
Integer.toString(trustedKeys.size())
});
mIndent += 1; mIndent += 1;
List<UserIdItem> uids = new ArrayList<UserIdItem>(); List<UserIdItem> uids = new ArrayList<UserIdItem>();
for (String userId : new IterableIterator<String>( for (String userId : new IterableIterator<String>(
@ -418,7 +416,7 @@ public class ProviderHelper {
int unknownCerts = 0; int unknownCerts = 0;
log(LogLevel.INFO, LogType.MSG_IP_UID_PROCESSING, new String[]{ userId }); log(LogLevel.INFO, LogType.MSG_IP_UID_PROCESSING, userId);
mIndent += 1; mIndent += 1;
// look through signatures for this specific key // look through signatures for this specific key
for (WrappedSignature cert : new IterableIterator<WrappedSignature>( for (WrappedSignature cert : new IterableIterator<WrappedSignature>(
@ -447,10 +445,10 @@ public class ProviderHelper {
cert.init(trustedKey); cert.init(trustedKey);
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,
PgpKeyHelper.convertKeyIdToHexShort(trustedKey.getKeyId()), PgpKeyHelper.convertKeyIdToHexShort(trustedKey.getKeyId()),
trustedKey.getPrimaryUserId() trustedKey.getPrimaryUserId()
}); );
} else { } else {
log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_BAD); log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_BAD);
} }
@ -459,16 +457,13 @@ public class ProviderHelper {
unknownCerts += 1; unknownCerts += 1;
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {
log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_ERROR, new String[]{ log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_ERROR,
PgpKeyHelper.convertKeyIdToHex(cert.getKeyId()) PgpKeyHelper.convertKeyIdToHex(cert.getKeyId()));
});
} }
} }
if (unknownCerts > 0) { if (unknownCerts > 0) {
log(LogLevel.DEBUG, LogType.MSG_IP_UID_CERTS_UNKNOWN, new String[]{ log(LogLevel.DEBUG, LogType.MSG_IP_UID_CERTS_UNKNOWN, unknownCerts);
Integer.toString(unknownCerts)
});
} }
mIndent -= 1; mIndent -= 1;
@ -574,8 +569,7 @@ public class ProviderHelper {
} }
long masterKeyId = keyRing.getMasterKeyId(); long masterKeyId = keyRing.getMasterKeyId();
log(LogLevel.START, LogType.MSG_IS, log(LogLevel.START, LogType.MSG_IS, PgpKeyHelper.convertKeyIdToHex(masterKeyId));
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
mIndent += 1; mIndent += 1;
try { try {
@ -625,18 +619,18 @@ public class ProviderHelper {
int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?", int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?",
new String[]{Long.toString(id)}); new String[]{Long.toString(id)});
if (upd == 1) { if (upd == 1) {
log(LogLevel.DEBUG, LogType.MSG_IS_SUBKEY_OK, new String[]{ log(LogLevel.DEBUG, LogType.MSG_IS_SUBKEY_OK,
PgpKeyHelper.convertKeyIdToHex(id) PgpKeyHelper.convertKeyIdToHex(id)
}); );
} else { } else {
log(LogLevel.WARN, LogType.MSG_IS_SUBKEY_NONEXISTENT, new String[]{ log(LogLevel.WARN, LogType.MSG_IS_SUBKEY_NONEXISTENT,
PgpKeyHelper.convertKeyIdToHex(id) PgpKeyHelper.convertKeyIdToHex(id)
}); );
} }
} else { } else {
log(LogLevel.INFO, LogType.MSG_IS_SUBKEY_STRIPPED, new String[]{ log(LogLevel.INFO, LogType.MSG_IS_SUBKEY_STRIPPED,
PgpKeyHelper.convertKeyIdToHex(id) PgpKeyHelper.convertKeyIdToHex(id)
}); );
} }
} }
mIndent -= 1; mIndent -= 1;
@ -654,8 +648,6 @@ public class ProviderHelper {
} }
@Deprecated
public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) { public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) {
return savePublicKeyRing(keyRing, new NullProgressable()); return savePublicKeyRing(keyRing, new NullProgressable());
} }
@ -669,8 +661,7 @@ public class ProviderHelper {
try { try {
long masterKeyId = publicRing.getMasterKeyId(); long masterKeyId = publicRing.getMasterKeyId();
log(LogLevel.START, LogType.MSG_IP, log(LogLevel.START, LogType.MSG_IP, PgpKeyHelper.convertKeyIdToHex(masterKeyId));
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
mIndent += 1; mIndent += 1;
// If there is an old keyring, merge it // If there is an old keyring, merge it
@ -694,7 +685,7 @@ public class ProviderHelper {
// Early breakout if nothing changed // Early breakout if nothing changed
if (Arrays.hashCode(publicRing.getEncoded()) if (Arrays.hashCode(publicRing.getEncoded())
== Arrays.hashCode(oldPublicRing.getEncoded())) { == Arrays.hashCode(oldPublicRing.getEncoded())) {
log(LogLevel.OK, LogType.MSG_IP_SUCCESS_IDENTICAL, null); log(LogLevel.OK, LogType.MSG_IP_SUCCESS_IDENTICAL);
return new SaveKeyringResult(SaveKeyringResult.RESULT_OK, mLog); return new SaveKeyringResult(SaveKeyringResult.RESULT_OK, mLog);
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
@ -754,8 +745,7 @@ public class ProviderHelper {
try { try {
long masterKeyId = secretRing.getMasterKeyId(); long masterKeyId = secretRing.getMasterKeyId();
log(LogLevel.START, LogType.MSG_IS, log(LogLevel.START, LogType.MSG_IS, PgpKeyHelper.convertKeyIdToHex(masterKeyId));
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
mIndent += 1; mIndent += 1;
// If there is an old secret key, merge it. // If there is an old secret key, merge it.
@ -780,7 +770,7 @@ public class ProviderHelper {
if (Arrays.hashCode(secretRing.getEncoded()) if (Arrays.hashCode(secretRing.getEncoded())
== Arrays.hashCode(oldSecretRing.getEncoded())) { == Arrays.hashCode(oldSecretRing.getEncoded())) {
log(LogLevel.OK, LogType.MSG_IS_SUCCESS_IDENTICAL, log(LogLevel.OK, LogType.MSG_IS_SUCCESS_IDENTICAL,
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) }); PgpKeyHelper.convertKeyIdToHex(masterKeyId) );
return new SaveKeyringResult(SaveKeyringResult.RESULT_OK, mLog); return new SaveKeyringResult(SaveKeyringResult.RESULT_OK, mLog);
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
@ -812,7 +802,7 @@ public class ProviderHelper {
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
log(LogLevel.DEBUG, LogType.MSG_IS_PUBRING_GENERATE, null); log(LogLevel.DEBUG, LogType.MSG_IS_PUBRING_GENERATE);
publicRing = secretRing.extractPublicKeyRing(); publicRing = secretRing.extractPublicKeyRing();
} }
@ -833,7 +823,7 @@ public class ProviderHelper {
return new SaveKeyringResult(result, mLog); return new SaveKeyringResult(result, mLog);
} catch (IOException e) { } catch (IOException e) {
log(LogLevel.ERROR, LogType.MSG_IS_FAIL_IO_EXC, null); log(LogLevel.ERROR, LogType.MSG_IS_FAIL_IO_EXC);
return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog); return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
} finally { } finally {
mIndent -= 1; mIndent -= 1;
@ -841,21 +831,6 @@ public class ProviderHelper {
} }
/**
* Saves (or updates) a pair of public and secret KeyRings in the database
*/
@Deprecated // scheduled for deletion after merge with new-edit branch
public void savePairedKeyRing(UncachedKeyRing pubRing, UncachedKeyRing secRing) throws IOException {
long masterKeyId = pubRing.getMasterKeyId();
// delete secret keyring (so it isn't unnecessarily saved by public-savePublicKeyRing below)
mContentResolver.delete(KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId)), null, null);
// save public keyring
internalSavePublicKeyRing(pubRing, null, true);
internalSaveSecretKeyRing(secRing);
}
/** /**
* Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing
*/ */

View File

@ -59,23 +59,23 @@ public class OperationResultParcel implements Parcelable {
public static class LogEntryParcel implements Parcelable { public static class LogEntryParcel implements Parcelable {
public final LogLevel mLevel; public final LogLevel mLevel;
public final LogType mType; public final LogType mType;
public final String[] mParameters; public final Object[] mParameters;
public final int mIndent; public final int mIndent;
public LogEntryParcel(LogLevel level, LogType type, String[] parameters, int indent) { public LogEntryParcel(LogLevel level, LogType type, int indent, Object... parameters) {
mLevel = level; mLevel = level;
mType = type; mType = type;
mParameters = parameters; mParameters = parameters;
mIndent = indent; mIndent = indent;
} }
public LogEntryParcel(LogLevel level, LogType type, String[] parameters) { public LogEntryParcel(LogLevel level, LogType type, Object... parameters) {
this(level, type, parameters, 0); this(level, type, 0, parameters);
} }
public LogEntryParcel(Parcel source) { public LogEntryParcel(Parcel source) {
mLevel = LogLevel.values()[source.readInt()]; mLevel = LogLevel.values()[source.readInt()];
mType = LogType.values()[source.readInt()]; mType = LogType.values()[source.readInt()];
mParameters = source.createStringArray(); mParameters = (Object[]) source.readSerializable();
mIndent = source.readInt(); mIndent = source.readInt();
} }
@ -88,7 +88,7 @@ public class OperationResultParcel implements Parcelable {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mLevel.ordinal()); dest.writeInt(mLevel.ordinal());
dest.writeInt(mType.ordinal()); dest.writeInt(mType.ordinal());
dest.writeStringArray(mParameters); dest.writeSerializable(mParameters);
dest.writeInt(mIndent); dest.writeInt(mIndent);
} }
@ -164,8 +164,8 @@ public class OperationResultParcel implements Parcelable {
MSG_IP_UID_CERT_BAD (R.string.msg_ip_uid_cert_bad), MSG_IP_UID_CERT_BAD (R.string.msg_ip_uid_cert_bad),
MSG_IP_UID_CERT_ERROR (R.string.msg_ip_uid_cert_error), MSG_IP_UID_CERT_ERROR (R.string.msg_ip_uid_cert_error),
MSG_IP_UID_CERT_GOOD (R.string.msg_ip_uid_cert_good), MSG_IP_UID_CERT_GOOD (R.string.msg_ip_uid_cert_good),
MSG_IP_UID_CERTS_UNKNOWN (R.string.msg_ip_uid_certs_unknown), MSG_IP_UID_CERTS_UNKNOWN (R.plurals.msg_ip_uid_certs_unknown),
MSG_IP_UID_CLASSIFYING (R.string.msg_ip_uid_classifying), MSG_IP_UID_CLASSIFYING (R.plurals.msg_ip_uid_classifying),
MSG_IP_UID_REORDER(R.string.msg_ip_uid_reorder), MSG_IP_UID_REORDER(R.string.msg_ip_uid_reorder),
MSG_IP_UID_PROCESSING (R.string.msg_ip_uid_processing), MSG_IP_UID_PROCESSING (R.string.msg_ip_uid_processing),
MSG_IP_UID_REVOKED (R.string.msg_ip_uid_revoked), MSG_IP_UID_REVOKED (R.string.msg_ip_uid_revoked),
@ -209,9 +209,9 @@ public class OperationResultParcel implements Parcelable {
MSG_KC_SUB_REVOKE_BAD_ERR (R.string.msg_kc_sub_revoke_bad_err), MSG_KC_SUB_REVOKE_BAD_ERR (R.string.msg_kc_sub_revoke_bad_err),
MSG_KC_SUB_REVOKE_BAD (R.string.msg_kc_sub_revoke_bad), MSG_KC_SUB_REVOKE_BAD (R.string.msg_kc_sub_revoke_bad),
MSG_KC_SUB_REVOKE_DUP (R.string.msg_kc_sub_revoke_dup), MSG_KC_SUB_REVOKE_DUP (R.string.msg_kc_sub_revoke_dup),
MSG_KC_SUCCESS_BAD (R.string.msg_kc_success_bad), MSG_KC_SUCCESS_BAD (R.plurals.msg_kc_success_bad),
MSG_KC_SUCCESS_BAD_AND_RED (R.string.msg_kc_success_bad_and_red), MSG_KC_SUCCESS_BAD_AND_RED (R.string.msg_kc_success_bad_and_red),
MSG_KC_SUCCESS_REDUNDANT (R.string.msg_kc_success_redundant), MSG_KC_SUCCESS_REDUNDANT (R.plurals.msg_kc_success_redundant),
MSG_KC_SUCCESS (R.string.msg_kc_success), MSG_KC_SUCCESS (R.string.msg_kc_success),
MSG_KC_UID_BAD_ERR (R.string.msg_kc_uid_bad_err), MSG_KC_UID_BAD_ERR (R.string.msg_kc_uid_bad_err),
MSG_KC_UID_BAD_LOCAL (R.string.msg_kc_uid_bad_local), MSG_KC_UID_BAD_LOCAL (R.string.msg_kc_uid_bad_local),
@ -296,13 +296,13 @@ public class OperationResultParcel implements Parcelable {
public static class OperationLog extends ArrayList<LogEntryParcel> { public static class OperationLog extends ArrayList<LogEntryParcel> {
/// Simple convenience method /// Simple convenience method
public void add(LogLevel level, LogType type, String[] parameters, int indent) { public void add(LogLevel level, LogType type, int indent, Object... parameters) {
Log.d(Constants.TAG, type.toString()); Log.d(Constants.TAG, type.toString());
add(new OperationResultParcel.LogEntryParcel(level, type, parameters, indent)); add(new OperationResultParcel.LogEntryParcel(level, type, indent, parameters));
} }
public void add(LogLevel level, LogType type, int indent) { public void add(LogLevel level, LogType type, int indent) {
add(new OperationResultParcel.LogEntryParcel(level, type, null, indent)); add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null));
} }
public boolean containsWarnings() { public boolean containsWarnings() {

View File

@ -390,9 +390,6 @@ public class ImportKeysActivity extends ActionBarActivity {
/** /**
* Scroll ViewPager left and right * Scroll ViewPager left and right
*
* @param event
* @return
*/ */
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
@ -432,7 +429,7 @@ public class ImportKeysActivity extends ActionBarActivity {
// get returned data bundle // get returned data bundle
Bundle returnData = message.getData(); Bundle returnData = message.getData();
final ImportResult result = final ImportResult result =
returnData.<ImportResult>getParcelable(KeychainIntentService.RESULT); returnData.getParcelable(KeychainIntentService.RESULT);
int resultType = result.getResult(); int resultType = result.getResult();

View File

@ -35,6 +35,7 @@ import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper; import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader;
@ -79,6 +80,7 @@ public class ImportKeysListFragment extends ListFragment implements
public ArrayList<ParcelableKeyRing> getSelectedData() { public ArrayList<ParcelableKeyRing> getSelectedData() {
ArrayList<ParcelableKeyRing> result = new ArrayList<ParcelableKeyRing>(); ArrayList<ParcelableKeyRing> result = new ArrayList<ParcelableKeyRing>();
for (ImportKeysListEntry entry : getSelectedEntries()) { for (ImportKeysListEntry entry : getSelectedEntries()) {
Log.d(Constants.TAG, "code" + Integer.toString(entry.hashCode()));
result.add(mCachedKeyData.get(entry.hashCode())); result.add(mCachedKeyData.get(entry.hashCode()));
} }
return result; return result;

View File

@ -173,7 +173,14 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener
ih = (ItemHolder) convertView.getTag(); ih = (ItemHolder) convertView.getTag();
} }
ih.mText.setText(getResources().getString(entry.mType.getMsgId(), (Object[]) entry.mParameters)); // special case: first parameter may be a quantity
if (entry.mParameters != null && entry.mParameters.length > 0
&& entry.mParameters[0] instanceof Integer) {
ih.mText.setText(getResources().getQuantityString(entry.mType.getMsgId(),
(Integer) entry.mParameters[0], entry.mParameters));
} else {
ih.mText.setText(getResources().getString(entry.mType.getMsgId(), entry.mParameters));
}
ih.mText.setTextColor(entry.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK); ih.mText.setTextColor(entry.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK);
convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0); convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0);
switch (entry.mLevel) { switch (entry.mLevel) {

View File

@ -388,19 +388,19 @@
<!-- Import result toast --> <!-- Import result toast -->
<plurals name="import_keys_added_and_updated_1"> <plurals name="import_keys_added_and_updated_1">
<item quantity="one">Successfully added %1$d key</item> <item quantity="one">Successfully imported key</item>
<item quantity="other">Successfully added %1$d keys</item> <item quantity="other">Successfully imported %1$d keys</item>
</plurals> </plurals>
<plurals name="import_keys_added_and_updated_2"> <plurals name="import_keys_added_and_updated_2">
<item quantity="one"> and updated %1$d key%2$s.</item> <item quantity="one"> and updated key%2$s.</item>
<item quantity="other"> and updated %1$d keys%2$s.</item> <item quantity="other"> and updated %1$d keys%2$s.</item>
</plurals> </plurals>
<plurals name="import_keys_added"> <plurals name="import_keys_added">
<item quantity="one">Successfully added %1$d key%2$s.</item> <item quantity="one">Successfully imported key%2$s.</item>
<item quantity="other">Successfully added %1$d keys%2$s.</item> <item quantity="other">Successfully imported %1$d keys%2$s.</item>
</plurals> </plurals>
<plurals name="import_keys_updated"> <plurals name="import_keys_updated">
<item quantity="one">Successfully updated %1$d key%2$s.</item> <item quantity="one">Successfully updated key%2$s.</item>
<item quantity="other">Successfully updated %1$d keys%2$s.</item> <item quantity="other">Successfully updated %1$d keys%2$s.</item>
</plurals> </plurals>
<string name="import_view_log">View Log</string> <string name="import_view_log">View Log</string>
@ -542,8 +542,15 @@
<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">User id is certified by %1$s (%2$s)</string> <string name="msg_ip_uid_cert_good">User id is certified by %1$s (%2$s)</string>
<string name="msg_ip_uid_certs_unknown">Ignoring %s certificates from unknown pubkeys</string> <plurals name="msg_ip_uid_certs_unknown">
<string name="msg_ip_uid_classifying">Classifying user ids, using %s trusted signatures</string> <item quantity="one">Ignoring one certificate issued by an unknown public key</item>
<item quantity="other">Ignoring %s certificates issued by unknown public keys</item>
</plurals>
<plurals name="msg_ip_uid_classifying">
<item quantity="zero">Classifying user ids (no trusted keys available)</item>
<item quantity="one">Classifying user ids (using one trusted key)</item>
<item quantity="other">Classifying user ids (using %s trusted keys)</item>
</plurals>
<string name="msg_ip_uid_reorder">Re-ordering user ids</string> <string name="msg_ip_uid_reorder">Re-ordering user ids</string>
<string name="msg_ip_uid_processing">Processing user id %s</string> <string name="msg_ip_uid_processing">Processing user id %s</string>
<string name="msg_ip_uid_revoked">User id is revoked</string> <string name="msg_ip_uid_revoked">User id is revoked</string>
@ -588,9 +595,15 @@
<string name="msg_kc_sub_revoke_bad">Removing bad subkey revocation certificate</string> <string name="msg_kc_sub_revoke_bad">Removing bad subkey revocation certificate</string>
<string name="msg_kc_sub_revoke_dup">Removing redundant subkey revocation certificate</string> <string name="msg_kc_sub_revoke_dup">Removing redundant subkey revocation certificate</string>
<string name="msg_kc_success">Keyring canonicalization successful, no changes</string> <string name="msg_kc_success">Keyring canonicalization successful, no changes</string>
<string name="msg_kc_success_bad">Keyring canonicalization successful, removed %s erroneous certificates</string> <plurals name="msg_kc_success_bad">
<item quantity="one">Keyring canonicalization successful, removed one erroneous certificate</item>
<item quantity="other">Keyring canonicalization successful, removed %d erroneous certificates</item>
</plurals>
<string name="msg_kc_success_bad_and_red">Keyring canonicalization successful, removed %1$s erroneous and %2$s redundant certificates</string> <string name="msg_kc_success_bad_and_red">Keyring canonicalization successful, removed %1$s erroneous and %2$s redundant certificates</string>
<string name="msg_kc_success_redundant">Keyring canonicalization successful, removed %s redundant certificates</string> <plurals name="msg_kc_success_redundant">
<item quantity="one">Keyring canonicalization successful, removed one redundant certificate</item>
<item quantity="other">Keyring canonicalization successful, removed %d redundant certificates</item>
</plurals>
<string name="msg_kc_uid_bad_err">Removing bad self certificate for user id %s</string> <string name="msg_kc_uid_bad_err">Removing bad self certificate for user id %s</string>
<string name="msg_kc_uid_bad_local">Removing user id certificate with "local" flag</string> <string name="msg_kc_uid_bad_local">Removing user id certificate with "local" flag</string>
<string name="msg_kc_uid_bad_time">Removing user id with future timestamp</string> <string name="msg_kc_uid_bad_time">Removing user id with future timestamp</string>