From d795f8d4e240877861ab993608fb7f5aed0a2042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 27 Aug 2014 19:28:33 +0200 Subject: [PATCH] Strip out duplicate user ids --- .../keychain/pgp/UncachedKeyRing.java | 16 +++++++++++++--- .../keychain/service/OperationResultParcel.java | 1 + OpenKeychain/src/main/res/values-es/strings.xml | 2 +- OpenKeychain/src/main/res/values-fr/strings.xml | 2 +- OpenKeychain/src/main/res/values-it/strings.xml | 2 +- OpenKeychain/src/main/res/values-ja/strings.xml | 2 +- OpenKeychain/src/main/res/values/strings.xml | 3 ++- 7 files changed, 20 insertions(+), 8 deletions(-) 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 424420e72..9fa737be4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -37,7 +37,6 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; -import org.sufficientlysecure.keychain.service.OperationResults; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; @@ -46,6 +45,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Date; @@ -339,7 +339,17 @@ public class UncachedKeyRing { } } + ArrayList processedUserIds = new ArrayList(); for (String userId : new IterableIterator(masterKey.getUserIDs())) { + // check for duplicate user ids + if (processedUserIds.contains(userId)) { + log.add(LogLevel.WARN, LogType.MSG_KC_UID_DUP, + indent, userId); + // strip out the first found user id with this name + modified = PGPPublicKey.removeCertification(modified, userId); + } + processedUserIds.add(userId); + PGPSignature selfCert = null; revocation = null; @@ -416,13 +426,13 @@ public class UncachedKeyRing { if (selfCert == null) { selfCert = zert; } else if (selfCert.getCreationTime().before(cert.getCreationTime())) { - log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP, + log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_CERT_DUP, indent, userId); modified = PGPPublicKey.removeCertification(modified, userId, selfCert); redundantCerts += 1; selfCert = zert; } else { - log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_DUP, + log.add(LogLevel.DEBUG, LogType.MSG_KC_UID_CERT_DUP, indent, userId); modified = PGPPublicKey.removeCertification(modified, userId, zert); redundantCerts += 1; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java index ddc456e34..a08ee3091 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java @@ -323,6 +323,7 @@ public class OperationResultParcel implements Parcelable { MSG_KC_UID_BAD_TIME (R.string.msg_kc_uid_bad_time), MSG_KC_UID_BAD_TYPE (R.string.msg_kc_uid_bad_type), MSG_KC_UID_BAD (R.string.msg_kc_uid_bad), + MSG_KC_UID_CERT_DUP (R.string.msg_kc_uid_cert_dup), MSG_KC_UID_DUP (R.string.msg_kc_uid_dup), MSG_KC_UID_FOREIGN (R.string.msg_kc_uid_foreign), MSG_KC_UID_NO_CERT (R.string.msg_kc_uid_no_cert), diff --git a/OpenKeychain/src/main/res/values-es/strings.xml b/OpenKeychain/src/main/res/values-es/strings.xml index 9266950d2..e2b2d2e73 100644 --- a/OpenKeychain/src/main/res/values-es/strings.xml +++ b/OpenKeychain/src/main/res/values-es/strings.xml @@ -563,7 +563,7 @@ Eliminando identidad de usuario con marca de tiempo futura Eliminando certificado de identidad de usuario, de tipo desconocido (%s) Eliminando auto-certificado defectuoso para la identidad de usuario \"%s\" - Eliminando auto-certificado desactualizado para el identificador de usuario \"%s\" + Eliminando auto-certificado desactualizado para el identificador de usuario \"%s\" Eliminando certificado ajeno de identidad de usuario por %s Eliminando certificado redundate de revocación para la identidad de usuario \"%s\" Eliminando certificado desactualizado de revocación para la identidad de usuario \"%s\" diff --git a/OpenKeychain/src/main/res/values-fr/strings.xml b/OpenKeychain/src/main/res/values-fr/strings.xml index 4ac578ba8..de1506665 100644 --- a/OpenKeychain/src/main/res/values-fr/strings.xml +++ b/OpenKeychain/src/main/res/values-fr/strings.xml @@ -563,7 +563,7 @@ Suppression de l\'ID d\'utilisateur ayant une estampille temporelle dans le futur Suppression du certificat d\'ID d\'utilisateur de type inconnu (%s) Suppression du mauvais auto-certificat pour l\'ID d\'utilisateur « %s » - Suppression de l\'auto-certificat périmé pour l\'ID d\'utilisateur « %s » + Suppression de l\'auto-certificat périmé pour l\'ID d\'utilisateur « %s » Suppression du certificat étranger d\'ID d\'utilisateur par %s Suppression du certificat de révocation redondant pour l\'ID d\'utilisateur « %s » Suppression du certificat de révocation périmé pour l\'ID d\'utilisateur « %s » diff --git a/OpenKeychain/src/main/res/values-it/strings.xml b/OpenKeychain/src/main/res/values-it/strings.xml index 9a21a642b..b5cbfd2f5 100644 --- a/OpenKeychain/src/main/res/values-it/strings.xml +++ b/OpenKeychain/src/main/res/values-it/strings.xml @@ -563,7 +563,7 @@ Rimozione ID utente con marca temporale futura Rimozione certificato ID utente di tipo sconosciuto (%s) Rimozione autocertificazione corrotta per ID utente \"%s\" - Rimozione autocertificazione scaduta per ID utente \"%s\" + Rimozione autocertificazione scaduta per ID utente \"%s\" Rimozione certificato ID utente estraneo di %s Rimozione certificato di revoca ridondante per ID utente \"%s\" Rimozione certificato di revoca scaduto per ID utente \"%s\" diff --git a/OpenKeychain/src/main/res/values-ja/strings.xml b/OpenKeychain/src/main/res/values-ja/strings.xml index 724abeab4..6dfe65312 100644 --- a/OpenKeychain/src/main/res/values-ja/strings.xml +++ b/OpenKeychain/src/main/res/values-ja/strings.xml @@ -546,7 +546,7 @@ 未来にタイムスタンプがあるユーザIDを破棄中 不明な型 (%s) でのユーザID検証を破棄中 ユーザID \"%s\" による問題のある自己検証を破棄中 - 期限の切れたユーザID \"%s\" による自己検証を破棄中 + 期限の切れたユーザID \"%s\" による自己検証を破棄中 %s によって検証されている外部ユーザIDを破棄中 ユーザID \"%s\" による重複した破棄証明を破棄中 ユーザID \"%s\" による期限切れ破棄証明を破棄中 diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index d8c73bd9e..418004721 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -611,12 +611,13 @@ Removing user id with future timestamp Removing user id certificate of unknown type (%s) Removing bad self certificate for user id "%s" - Removing outdated self certificate for user id "%s" + Removing outdated self certificate for user id "%s" Removing foreign user id certificate by %s Removing redundant revocation certificate for user id "%s" Removing outdated revocation certificate for user id "%s" No valid self-certificate found for user id %s, removing from ring Removing invalid user id %s + Removing duplicate user id "%s". The secret key contained two of them. This may result in missing certifications! Merging into public keyring %s