reject keys with duplicate subkeys altogether

closes #870
This commit is contained in:
Vincent Breitmoser 2014-09-23 01:35:49 +02:00
parent 3759d74ac8
commit 9d9d71f3db
3 changed files with 17 additions and 1 deletions

View File

@ -51,6 +51,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -529,12 +530,25 @@ public class UncachedKeyRing {
} }
// Keep track of ids we encountered so far
Set<Long> knownIds = new HashSet<Long>();
// Process all keys // Process all keys
for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(ring.getPublicKeys())) { for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(ring.getPublicKeys())) {
// Don't care about the master key here, that one gets special treatment above // Make sure this is not a duplicate, avoid undefined behavior!
if (knownIds.contains(key.getKeyID())) {
log.add(LogType.MSG_KC_ERROR_DUP_KEY, indent,
KeyFormattingUtils.convertKeyIdToHex(key.getKeyID()));
return null;
}
// Add the key id to known
knownIds.add(key.getKeyID());
// Don't care about the master key any further, that one gets special treatment above
if (key.isMasterKey()) { if (key.isMasterKey()) {
continue; continue;
} }
log.add(LogType.MSG_KC_SUB, log.add(LogType.MSG_KC_SUB,
indent, KeyFormattingUtils.convertKeyIdToHex(key.getKeyID())); indent, KeyFormattingUtils.convertKeyIdToHex(key.getKeyID()));
indent += 1; indent += 1;

View File

@ -316,6 +316,7 @@ public abstract class OperationResult implements Parcelable {
MSG_KC_ERROR_V3 (LogLevel.ERROR, R.string.msg_kc_error_v3), MSG_KC_ERROR_V3 (LogLevel.ERROR, R.string.msg_kc_error_v3),
MSG_KC_ERROR_NO_UID (LogLevel.ERROR, R.string.msg_kc_error_no_uid), MSG_KC_ERROR_NO_UID (LogLevel.ERROR, R.string.msg_kc_error_no_uid),
MSG_KC_ERROR_MASTER_ALGO (LogLevel.ERROR, R.string.msg_kc_error_master_algo), MSG_KC_ERROR_MASTER_ALGO (LogLevel.ERROR, R.string.msg_kc_error_master_algo),
MSG_KC_ERROR_DUP_KEY (LogLevel.ERROR, R.string.msg_kc_error_dup_key),
MSG_KC_MASTER (LogLevel.DEBUG, R.string.msg_kc_master), MSG_KC_MASTER (LogLevel.DEBUG, R.string.msg_kc_master),
MSG_KC_REVOKE_BAD_ERR (LogLevel.WARN, R.string.msg_kc_revoke_bad_err), MSG_KC_REVOKE_BAD_ERR (LogLevel.WARN, R.string.msg_kc_revoke_bad_err),
MSG_KC_REVOKE_BAD_LOCAL (LogLevel.WARN, R.string.msg_kc_revoke_bad_local), MSG_KC_REVOKE_BAD_LOCAL (LogLevel.WARN, R.string.msg_kc_revoke_bad_local),

View File

@ -643,6 +643,7 @@
<string name="msg_kc_error_v3">"This is an OpenPGP version 3 key, which has been deprecated and is no longer supported!"</string> <string name="msg_kc_error_v3">"This is an OpenPGP version 3 key, which has been deprecated and is no longer supported!"</string>
<string name="msg_kc_error_no_uid">"Keyring has no valid user ids!"</string> <string name="msg_kc_error_no_uid">"Keyring has no valid user ids!"</string>
<string name="msg_kc_error_master_algo">"The master key uses an unknown (%s) algorithm!"</string> <string name="msg_kc_error_master_algo">"The master key uses an unknown (%s) algorithm!"</string>
<string name="msg_kc_error_dup_key">"Subkey %s occurs twice in keyring. Keyring is malformed, not importing!"</string>
<string name="msg_kc_master">"Processing master key"</string> <string name="msg_kc_master">"Processing master key"</string>
<string name="msg_kc_revoke_bad_err">"Removing bad keyring revocation certificate"</string> <string name="msg_kc_revoke_bad_err">"Removing bad keyring revocation certificate"</string>
<string name="msg_kc_revoke_bad_local">"Removing keyring revocation certificate with "local" flag"</string> <string name="msg_kc_revoke_bad_local">"Removing keyring revocation certificate with "local" flag"</string>