Strip out duplicate user ids

This commit is contained in:
Dominik Schürmann 2014-08-27 19:28:33 +02:00
parent 12a5b2174f
commit d795f8d4e2
7 changed files with 20 additions and 8 deletions

View File

@ -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<String> processedUserIds = new ArrayList<String>();
for (String userId : new IterableIterator<String>(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;

View File

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

View File

@ -563,7 +563,7 @@
<string name="msg_kc_uid_bad_time">Eliminando identidad de usuario con marca de tiempo futura</string>
<string name="msg_kc_uid_bad_type">Eliminando certificado de identidad de usuario, de tipo desconocido (%s)</string>
<string name="msg_kc_uid_bad">Eliminando auto-certificado defectuoso para la identidad de usuario \"%s\"</string>
<string name="msg_kc_uid_dup">Eliminando auto-certificado desactualizado para el identificador de usuario \"%s\"</string>
<string name="msg_kc_uid_cert_dup">Eliminando auto-certificado desactualizado para el identificador de usuario \"%s\"</string>
<string name="msg_kc_uid_foreign">Eliminando certificado ajeno de identidad de usuario por %s</string>
<string name="msg_kc_uid_revoke_dup">Eliminando certificado redundate de revocación para la identidad de usuario \"%s\"</string>
<string name="msg_kc_uid_revoke_old">Eliminando certificado desactualizado de revocación para la identidad de usuario \"%s\"</string>

View File

@ -563,7 +563,7 @@
<string name="msg_kc_uid_bad_time">Suppression de l\'ID d\'utilisateur ayant une estampille temporelle dans le futur</string>
<string name="msg_kc_uid_bad_type">Suppression du certificat d\'ID d\'utilisateur de type inconnu (%s)</string>
<string name="msg_kc_uid_bad">Suppression du mauvais auto-certificat pour l\'ID d\'utilisateur « %s »</string>
<string name="msg_kc_uid_dup">Suppression de l\'auto-certificat périmé pour l\'ID d\'utilisateur « %s »</string>
<string name="msg_kc_uid_cert_dup">Suppression de l\'auto-certificat périmé pour l\'ID d\'utilisateur « %s »</string>
<string name="msg_kc_uid_foreign">Suppression du certificat étranger d\'ID d\'utilisateur par %s</string>
<string name="msg_kc_uid_revoke_dup">Suppression du certificat de révocation redondant pour l\'ID d\'utilisateur « %s »</string>
<string name="msg_kc_uid_revoke_old">Suppression du certificat de révocation périmé pour l\'ID d\'utilisateur « %s »</string>

View File

@ -563,7 +563,7 @@
<string name="msg_kc_uid_bad_time">Rimozione ID utente con marca temporale futura</string>
<string name="msg_kc_uid_bad_type">Rimozione certificato ID utente di tipo sconosciuto (%s)</string>
<string name="msg_kc_uid_bad">Rimozione autocertificazione corrotta per ID utente \"%s\"</string>
<string name="msg_kc_uid_dup">Rimozione autocertificazione scaduta per ID utente \"%s\"</string>
<string name="msg_kc_uid_cert_dup">Rimozione autocertificazione scaduta per ID utente \"%s\"</string>
<string name="msg_kc_uid_foreign">Rimozione certificato ID utente estraneo di %s</string>
<string name="msg_kc_uid_revoke_dup">Rimozione certificato di revoca ridondante per ID utente \"%s\"</string>
<string name="msg_kc_uid_revoke_old">Rimozione certificato di revoca scaduto per ID utente \"%s\"</string>

View File

@ -546,7 +546,7 @@
<string name="msg_kc_uid_bad_time">未来にタイムスタンプがあるユーザIDを破棄中</string>
<string name="msg_kc_uid_bad_type">不明な型 (%s) でのユーザID検証を破棄中</string>
<string name="msg_kc_uid_bad">ユーザID \"%s\" による問題のある自己検証を破棄中</string>
<string name="msg_kc_uid_dup">期限の切れたユーザID \"%s\" による自己検証を破棄中</string>
<string name="msg_kc_uid_cert_dup">期限の切れたユーザID \"%s\" による自己検証を破棄中</string>
<string name="msg_kc_uid_foreign">%s によって検証されている外部ユーザIDを破棄中</string>
<string name="msg_kc_uid_revoke_dup">ユーザID \"%s\" による重複した破棄証明を破棄中</string>
<string name="msg_kc_uid_revoke_old">ユーザID \"%s\" による期限切れ破棄証明を破棄中</string>

View File

@ -611,12 +611,13 @@
<string name="msg_kc_uid_bad_time">Removing user id with future timestamp</string>
<string name="msg_kc_uid_bad_type">Removing user id certificate of unknown type (%s)</string>
<string name="msg_kc_uid_bad">Removing bad self certificate for user id "%s"</string>
<string name="msg_kc_uid_dup">Removing outdated self certificate for user id "%s"</string>
<string name="msg_kc_uid_cert_dup">Removing outdated self certificate for user id "%s"</string>
<string name="msg_kc_uid_foreign">Removing foreign user id certificate by %s</string>
<string name="msg_kc_uid_revoke_dup">Removing redundant revocation certificate for user id "%s"</string>
<string name="msg_kc_uid_revoke_old">Removing outdated revocation certificate for user id "%s"</string>
<string name="msg_kc_uid_no_cert">No valid self-certificate found for user id %s, removing from ring</string>
<string name="msg_kc_uid_remove">Removing invalid user id %s</string>
<string name="msg_kc_uid_dup">Removing duplicate user id "%s". The secret key contained two of them. This may result in missing certifications!</string>
<!-- Keyring merging log entries -->
<string name="msg_mg_public">Merging into public keyring %s</string>