Program: 8365
Project: 8365
Buggy source:
/** 
 * "Canonicalizes" a public key, removing inconsistencies in the process. This variant can be applied to public keyrings only. More specifically: - Remove all non-verifying self-certificates - Remove all "future" self-certificates - Remove all certificates flagged as "local" - Remove all certificates which are superseded by a newer one on the same target, including revocations with later re-certifications. - Remove all certificates of unknown type: - key revocation signatures on the master key - subkey binding signatures for subkeys - certifications and certification revocations for user ids - If a subkey retains no valid subkey binding certificate, remove it - If a user id retains no valid self certificate, remove it - If the key is a secret key, remove all certificates by foreign keys - If no valid user id remains, log an error and return null This operation writes an OperationLog which can be used as part of a OperationResultParcel.
 * @return A canonicalized key, or null on fatal error
 */
@SuppressWarnings("String_Node_Str") public UncachedKeyRing canonicalize(OperationLog log,int indent){
  log.add(LogLevel.START,isSecret() ? LogType.MSG_KC_SECRET : LogType.MSG_KC_PUBLIC,indent,PgpKeyHelper.convertKeyIdToHex(getMasterKeyId()));
  indent+=1;
  final Date now=new Date();
  int redundantCerts=0, badCerts=0;
  PGPKeyRing ring=mRing;
  PGPPublicKey masterKey=mRing.getPublicKey();
  final long masterKeyId=masterKey.getKeyID();
{
    log.add(LogLevel.DEBUG,LogType.MSG_KC_MASTER,indent,PgpKeyHelper.convertKeyIdToHex(masterKey.getKeyID()));
    indent+=1;
    PGPPublicKey modified=masterKey;
    PGPSignature revocation=null;
    for (    PGPSignature zert : new IterableIterator<PGPSignature>(masterKey.getSignatures())) {
      int type=zert.getSignatureType();
      if (type == PGPSignature.NO_CERTIFICATION || type == PGPSignature.DEFAULT_CERTIFICATION || type == PGPSignature.CASUAL_CERTIFICATION || type == PGPSignature.POSITIVE_CERTIFICATION || type == PGPSignature.CERTIFICATION_REVOCATION) {
        continue;
      }
      WrappedSignature cert=new WrappedSignature(zert);
      if (type != PGPSignature.KEY_REVOCATION) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_TYPE,indent,"String_Node_Str" + Integer.toString(type,16));
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      if (cert.getCreationTime().after(now)) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_TIME,indent);
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      if (cert.isLocal()) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_LOCAL,indent);
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      try {
        cert.init(masterKey);
        if (!cert.verifySignature(masterKey)) {
          log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD,indent);
          modified=PGPPublicKey.removeCertification(modified,zert);
          badCerts+=1;
          continue;
        }
      }
 catch (      PgpGeneralException e) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_ERR,indent);
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      if (revocation == null) {
        revocation=zert;
      }
 else       if (revocation.getCreationTime().before(zert.getCreationTime())) {
        modified=PGPPublicKey.removeCertification(modified,revocation);
        redundantCerts+=1;
        log.add(LogLevel.INFO,LogType.MSG_KC_REVOKE_DUP,indent);
        revocation=zert;
      }
 else {
        modified=PGPPublicKey.removeCertification(modified,zert);
        redundantCerts+=1;
        log.add(LogLevel.INFO,LogType.MSG_KC_REVOKE_DUP,indent);
      }
    }
    for (    String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
      PGPSignature selfCert=null;
      revocation=null;
      for (      PGPSignature zert : new IterableIterator<PGPSignature>(masterKey.getSignaturesForID(userId))) {
        WrappedSignature cert=new WrappedSignature(zert);
        long certId=cert.getKeyId();
        int type=zert.getSignatureType();
        if (type != PGPSignature.DEFAULT_CERTIFICATION && type != PGPSignature.NO_CERTIFICATION && type != PGPSignature.CASUAL_CERTIFICATION && type != PGPSignature.POSITIVE_CERTIFICATION && type != PGPSignature.CERTIFICATION_REVOCATION) {
          log.add(LogLevel.WARN,LogType.MSG_KC_UID_BAD_TYPE,indent,"String_Node_Str" + Integer.toString(zert.getSignatureType(),16));
          modified=PGPPublicKey.removeCertification(modified,userId,zert);
          badCerts+=1;
        }
        if (cert.getCreationTime().after(now)) {
          log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_TIME,indent);
          modified=PGPPublicKey.removeCertification(modified,zert);
          badCerts+=1;
          continue;
        }
        if (cert.isLocal()) {
          log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_LOCAL,indent);
          modified=PGPPublicKey.removeCertification(modified,zert);
          badCerts+=1;
          continue;
        }
        if (certId != masterKeyId) {
          if (isSecret()) {
            log.add(LogLevel.WARN,LogType.MSG_KC_UID_FOREIGN,indent,PgpKeyHelper.convertKeyIdToHex(certId));
            modified=PGPPublicKey.removeCertification(modified,userId,zert);
            badCerts+=1;
          }
          continue;
        }
        try {
          cert.init(masterKey);
          if (!cert.verifySignature(masterKey,userId)) {
            log.add(LogLevel.WARN,LogType.MSG_KC_UID_BAD,indent,userId);
            modified=PGPPublicKey.removeCertification(modified,userId,zert);
            badCerts+=1;
            continue;
          }
        }
 catch (        PgpGeneralException e) {
          log.add(LogLevel.WARN,LogType.MSG_KC_UID_BAD_ERR,indent,userId);
          modified=PGPPublicKey.removeCertification(modified,userId,zert);
          badCerts+=1;
          continue;
        }
switch (type) {
case PGPSignature.DEFAULT_CERTIFICATION:
case PGPSignature.NO_CERTIFICATION:
case PGPSignature.CASUAL_CERTIFICATION:
case PGPSignature.POSITIVE_CERTIFICATION:
          if (selfCert == null) {
            selfCert=zert;
          }
 else           if (selfCert.getCreationTime().before(cert.getCreationTime())) {
            modified=PGPPublicKey.removeCertification(modified,userId,selfCert);
            redundantCerts+=1;
            log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_DUP,indent,userId);
            selfCert=zert;
          }
 else {
            modified=PGPPublicKey.removeCertification(modified,userId,zert);
            redundantCerts+=1;
            log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_DUP,indent,userId);
          }
        if (revocation != null && revocation.getCreationTime().before(selfCert.getCreationTime())) {
          modified=PGPPublicKey.removeCertification(modified,userId,revocation);
          revocation=null;
          redundantCerts+=1;
          log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_OLD,indent,userId);
        }
      break;
case PGPSignature.CERTIFICATION_REVOCATION:
    if (selfCert != null && selfCert.getCreationTime().after(zert.getCreationTime())) {
      modified=PGPPublicKey.removeCertification(modified,userId,zert);
      redundantCerts+=1;
      log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_OLD,indent,userId);
      continue;
    }
  if (revocation == null) {
    revocation=zert;
  }
 else   if (revocation.getCreationTime().before(cert.getCreationTime())) {
    modified=PGPPublicKey.removeCertification(modified,userId,revocation);
    redundantCerts+=1;
    log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_DUP,indent,userId);
    revocation=zert;
  }
 else {
    modified=PGPPublicKey.removeCertification(modified,userId,zert);
    redundantCerts+=1;
    log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_DUP,indent,userId);
  }
break;
}
}
if (selfCert == null && revocation == null) {
modified=PGPPublicKey.removeCertification(modified,userId);
log.add(LogLevel.ERROR,LogType.MSG_KC_UID_REVOKE_DUP,indent,userId);
}
}
if (!modified.getUserIDs().hasNext()) {
log.add(LogLevel.ERROR,LogType.MSG_KC_FATAL_NO_UID,indent);
return null;
}
ring=replacePublicKey(ring,modified);
indent-=1;
}
for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(ring.getPublicKeys())) {
if (key.isMasterKey()) {
continue;
}
log.add(LogLevel.DEBUG,LogType.MSG_KC_SUB,indent,PgpKeyHelper.convertKeyIdToHex(key.getKeyID()));
indent+=1;
PGPPublicKey modified=key;
PGPSignature selfCert=null, revocation=null;
uids: for (PGPSignature zert : new IterableIterator<PGPSignature>(key.getSignatures())) {
modified=PGPPublicKey.removeCertification(modified,zert);
WrappedSignature cert=new WrappedSignature(zert);
int type=cert.getSignatureType();
if (cert.getKeyId() != masterKey.getKeyID()) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_KEYID,indent);
badCerts+=1;
continue;
}
if (type != PGPSignature.SUBKEY_BINDING && type != PGPSignature.SUBKEY_REVOCATION) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_TYPE,indent,"String_Node_Str" + Integer.toString(type,16));
badCerts+=1;
continue;
}
if (cert.getCreationTime().after(now)) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_TIME,indent);
badCerts+=1;
continue;
}
if (cert.isLocal()) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_LOCAL,indent);
badCerts+=1;
continue;
}
if (type == PGPSignature.SUBKEY_BINDING) {
try {
cert.init(masterKey);
if (!cert.verifySignature(masterKey,key)) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD,indent);
badCerts+=1;
continue;
}
}
 catch (PgpGeneralException e) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_ERR,indent);
badCerts+=1;
continue;
}
if (zert.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.KEY_FLAGS)) {
int flags=((KeyFlags)zert.getHashedSubPackets().getSubpacket(SignatureSubpacketTags.KEY_FLAGS)).getFlags();
if ((flags & PGPKeyFlags.CAN_SIGN) == PGPKeyFlags.CAN_SIGN) {
try {
  PGPSignatureList list=zert.getUnhashedSubPackets().getEmbeddedSignatures();
  boolean ok=false;
  for (int i=0; i < list.size(); i++) {
    WrappedSignature subsig=new WrappedSignature(list.get(i));
    if (subsig.getSignatureType() == PGPSignature.PRIMARYKEY_BINDING) {
      subsig.init(key);
      if (subsig.verifySignature(masterKey,key)) {
        ok=true;
      }
 else {
        log.add(LogLevel.WARN,LogType.MSG_KC_SUB_PRIMARY_BAD,indent);
        badCerts+=1;
        continue uids;
      }
    }
  }
  if (!ok) {
    log.add(LogLevel.WARN,LogType.MSG_KC_SUB_PRIMARY_NONE,indent);
    badCerts+=1;
    continue;
  }
}
 catch (Exception e) {
  log.add(LogLevel.WARN,LogType.MSG_KC_SUB_PRIMARY_BAD_ERR,indent);
  badCerts+=1;
  continue;
}
}
}
if (selfCert != null && selfCert.getCreationTime().before(cert.getCreationTime())) {
log.add(LogLevel.DEBUG,LogType.MSG_KC_SUB_DUP,indent);
redundantCerts+=1;
continue;
}
selfCert=zert;
if (revocation != null && selfCert.getCreationTime().after(revocation.getCreationTime())) {
revocation=null;
}
}
 else {
try {
cert.init(masterKey);
if (!cert.verifySignature(key)) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_REVOKE_BAD,indent);
badCerts+=1;
continue;
}
}
 catch (PgpGeneralException e) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_REVOKE_BAD_ERR,indent);
badCerts+=1;
continue;
}
if (selfCert != null && selfCert.getCreationTime().after(cert.getCreationTime())) {
log.add(LogLevel.DEBUG,LogType.MSG_KC_SUB_REVOKE_DUP,indent);
redundantCerts+=1;
continue;
}
revocation=zert;
}
}
if (selfCert == null) {
ring=replacePublicKey(ring,modified);
log.add(LogLevel.ERROR,LogType.MSG_KC_SUB_NO_CERT,indent,PgpKeyHelper.convertKeyIdToHex(key.getKeyID()));
indent-=1;
continue;
}
modified=PGPPublicKey.addCertification(modified,selfCert);
if (revocation != null) {
modified=PGPPublicKey.addCertification(modified,revocation);
}
ring=replacePublicKey(ring,modified);
indent-=1;
}
if (badCerts > 0 && redundantCerts > 0) {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS_BAD_AND_RED,indent,Integer.toString(badCerts),Integer.toString(redundantCerts));
}
 else if (badCerts > 0) {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS_BAD,indent,badCerts);
}
 else if (redundantCerts > 0) {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS_REDUNDANT,indent,redundantCerts);
}
 else {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS,indent);
}
return new UncachedKeyRing(ring,true);
}

Fixed version (ground truth):
/** 
 * "Canonicalizes" a public key, removing inconsistencies in the process. This variant can be applied to public keyrings only. More specifically: - Remove all non-verifying self-certificates - Remove all "future" self-certificates - Remove all certificates flagged as "local" - Remove all certificates which are superseded by a newer one on the same target, including revocations with later re-certifications. - Remove all certificates of unknown type: - key revocation signatures on the master key - subkey binding signatures for subkeys - certifications and certification revocations for user ids - If a subkey retains no valid subkey binding certificate, remove it - If a user id retains no valid self certificate, remove it - If the key is a secret key, remove all certificates by foreign keys - If no valid user id remains, log an error and return null This operation writes an OperationLog which can be used as part of a OperationResultParcel.
 * @return A canonicalized key, or null on fatal error
 */
@SuppressWarnings("String_Node_Str") public UncachedKeyRing canonicalize(OperationLog log,int indent){
  log.add(LogLevel.START,isSecret() ? LogType.MSG_KC_SECRET : LogType.MSG_KC_PUBLIC,indent,PgpKeyHelper.convertKeyIdToHex(getMasterKeyId()));
  indent+=1;
  final Date now=new Date();
  int redundantCerts=0, badCerts=0;
  PGPKeyRing ring=mRing;
  PGPPublicKey masterKey=mRing.getPublicKey();
  final long masterKeyId=masterKey.getKeyID();
{
    log.add(LogLevel.DEBUG,LogType.MSG_KC_MASTER,indent,PgpKeyHelper.convertKeyIdToHex(masterKey.getKeyID()));
    indent+=1;
    PGPPublicKey modified=masterKey;
    PGPSignature revocation=null;
    for (    PGPSignature zert : new IterableIterator<PGPSignature>(masterKey.getSignatures())) {
      int type=zert.getSignatureType();
      if (type == PGPSignature.NO_CERTIFICATION || type == PGPSignature.DEFAULT_CERTIFICATION || type == PGPSignature.CASUAL_CERTIFICATION || type == PGPSignature.POSITIVE_CERTIFICATION || type == PGPSignature.CERTIFICATION_REVOCATION) {
        continue;
      }
      WrappedSignature cert=new WrappedSignature(zert);
      if (type != PGPSignature.KEY_REVOCATION) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_TYPE,indent,"String_Node_Str" + Integer.toString(type,16));
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      if (cert.getCreationTime().after(now)) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_TIME,indent);
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      if (cert.isLocal()) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_LOCAL,indent);
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      try {
        cert.init(masterKey);
        if (!cert.verifySignature(masterKey)) {
          log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD,indent);
          modified=PGPPublicKey.removeCertification(modified,zert);
          badCerts+=1;
          continue;
        }
      }
 catch (      PgpGeneralException e) {
        log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_ERR,indent);
        modified=PGPPublicKey.removeCertification(modified,zert);
        badCerts+=1;
        continue;
      }
      if (revocation == null) {
        revocation=zert;
      }
 else       if (revocation.getCreationTime().before(zert.getCreationTime())) {
        modified=PGPPublicKey.removeCertification(modified,revocation);
        redundantCerts+=1;
        log.add(LogLevel.INFO,LogType.MSG_KC_REVOKE_DUP,indent);
        revocation=zert;
      }
 else {
        modified=PGPPublicKey.removeCertification(modified,zert);
        redundantCerts+=1;
        log.add(LogLevel.INFO,LogType.MSG_KC_REVOKE_DUP,indent);
      }
    }
    for (    String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
      PGPSignature selfCert=null;
      revocation=null;
      for (      PGPSignature zert : new IterableIterator<PGPSignature>(masterKey.getSignaturesForID(userId))) {
        WrappedSignature cert=new WrappedSignature(zert);
        long certId=cert.getKeyId();
        int type=zert.getSignatureType();
        if (type != PGPSignature.DEFAULT_CERTIFICATION && type != PGPSignature.NO_CERTIFICATION && type != PGPSignature.CASUAL_CERTIFICATION && type != PGPSignature.POSITIVE_CERTIFICATION && type != PGPSignature.CERTIFICATION_REVOCATION) {
          log.add(LogLevel.WARN,LogType.MSG_KC_UID_BAD_TYPE,indent,"String_Node_Str" + Integer.toString(zert.getSignatureType(),16));
          modified=PGPPublicKey.removeCertification(modified,userId,zert);
          badCerts+=1;
        }
        if (cert.getCreationTime().after(now)) {
          log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_TIME,indent);
          modified=PGPPublicKey.removeCertification(modified,zert);
          badCerts+=1;
          continue;
        }
        if (cert.isLocal()) {
          log.add(LogLevel.WARN,LogType.MSG_KC_REVOKE_BAD_LOCAL,indent);
          modified=PGPPublicKey.removeCertification(modified,zert);
          badCerts+=1;
          continue;
        }
        if (certId != masterKeyId) {
          if (isSecret()) {
            log.add(LogLevel.WARN,LogType.MSG_KC_UID_FOREIGN,indent,PgpKeyHelper.convertKeyIdToHex(certId));
            modified=PGPPublicKey.removeCertification(modified,userId,zert);
            badCerts+=1;
          }
          continue;
        }
        try {
          cert.init(masterKey);
          if (!cert.verifySignature(masterKey,userId)) {
            log.add(LogLevel.WARN,LogType.MSG_KC_UID_BAD,indent,userId);
            modified=PGPPublicKey.removeCertification(modified,userId,zert);
            badCerts+=1;
            continue;
          }
        }
 catch (        PgpGeneralException e) {
          log.add(LogLevel.WARN,LogType.MSG_KC_UID_BAD_ERR,indent,userId);
          modified=PGPPublicKey.removeCertification(modified,userId,zert);
          badCerts+=1;
          continue;
        }
switch (type) {
case PGPSignature.DEFAULT_CERTIFICATION:
case PGPSignature.NO_CERTIFICATION:
case PGPSignature.CASUAL_CERTIFICATION:
case PGPSignature.POSITIVE_CERTIFICATION:
          if (selfCert == null) {
            selfCert=zert;
          }
 else           if (selfCert.getCreationTime().before(cert.getCreationTime())) {
            modified=PGPPublicKey.removeCertification(modified,userId,selfCert);
            redundantCerts+=1;
            log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_DUP,indent,userId);
            selfCert=zert;
          }
 else {
            modified=PGPPublicKey.removeCertification(modified,userId,zert);
            redundantCerts+=1;
            log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_DUP,indent,userId);
          }
        if (revocation != null && revocation.getCreationTime().before(selfCert.getCreationTime())) {
          modified=PGPPublicKey.removeCertification(modified,userId,revocation);
          revocation=null;
          redundantCerts+=1;
          log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_OLD,indent,userId);
        }
      break;
case PGPSignature.CERTIFICATION_REVOCATION:
    if (selfCert != null && selfCert.getCreationTime().after(zert.getCreationTime())) {
      modified=PGPPublicKey.removeCertification(modified,userId,zert);
      redundantCerts+=1;
      log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_OLD,indent,userId);
      continue;
    }
  if (revocation == null) {
    revocation=zert;
  }
 else   if (revocation.getCreationTime().before(cert.getCreationTime())) {
    modified=PGPPublicKey.removeCertification(modified,userId,revocation);
    redundantCerts+=1;
    log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_DUP,indent,userId);
    revocation=zert;
  }
 else {
    modified=PGPPublicKey.removeCertification(modified,userId,zert);
    redundantCerts+=1;
    log.add(LogLevel.DEBUG,LogType.MSG_KC_UID_REVOKE_DUP,indent,userId);
  }
break;
}
}
if (selfCert == null && revocation == null) {
modified=PGPPublicKey.removeCertification(modified,userId);
log.add(LogLevel.ERROR,LogType.MSG_KC_UID_REVOKE_DUP,indent,userId);
}
}
if (!modified.getUserIDs().hasNext()) {
log.add(LogLevel.ERROR,LogType.MSG_KC_FATAL_NO_UID,indent);
return null;
}
ring=replacePublicKey(ring,modified);
indent-=1;
}
for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(ring.getPublicKeys())) {
if (key.isMasterKey()) {
continue;
}
log.add(LogLevel.DEBUG,LogType.MSG_KC_SUB,indent,PgpKeyHelper.convertKeyIdToHex(key.getKeyID()));
indent+=1;
PGPPublicKey modified=key;
PGPSignature selfCert=null, revocation=null;
uids: for (PGPSignature zert : new IterableIterator<PGPSignature>(key.getSignatures())) {
modified=PGPPublicKey.removeCertification(modified,zert);
WrappedSignature cert=new WrappedSignature(zert);
int type=cert.getSignatureType();
if (cert.getKeyId() != masterKey.getKeyID()) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_KEYID,indent);
badCerts+=1;
continue;
}
if (type != PGPSignature.SUBKEY_BINDING && type != PGPSignature.SUBKEY_REVOCATION) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_TYPE,indent,"String_Node_Str" + Integer.toString(type,16));
badCerts+=1;
continue;
}
if (cert.getCreationTime().after(now)) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_TIME,indent);
badCerts+=1;
continue;
}
if (cert.isLocal()) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_LOCAL,indent);
badCerts+=1;
continue;
}
if (type == PGPSignature.SUBKEY_BINDING) {
try {
cert.init(masterKey);
if (!cert.verifySignature(masterKey,key)) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD,indent);
badCerts+=1;
continue;
}
}
 catch (PgpGeneralException e) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_BAD_ERR,indent);
badCerts+=1;
continue;
}
if (zert.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.KEY_FLAGS)) {
int flags=((KeyFlags)zert.getHashedSubPackets().getSubpacket(SignatureSubpacketTags.KEY_FLAGS)).getFlags();
if ((flags & PGPKeyFlags.CAN_SIGN) == PGPKeyFlags.CAN_SIGN) {
try {
  PGPSignatureList list=zert.getUnhashedSubPackets().getEmbeddedSignatures();
  boolean ok=false;
  for (int i=0; i < list.size(); i++) {
    WrappedSignature subsig=new WrappedSignature(list.get(i));
    if (subsig.getSignatureType() == PGPSignature.PRIMARYKEY_BINDING) {
      subsig.init(key);
      if (subsig.verifySignature(masterKey,key)) {
        ok=true;
      }
 else {
        log.add(LogLevel.WARN,LogType.MSG_KC_SUB_PRIMARY_BAD,indent);
        badCerts+=1;
        continue uids;
      }
    }
  }
  if (!ok) {
    log.add(LogLevel.WARN,LogType.MSG_KC_SUB_PRIMARY_NONE,indent);
    badCerts+=1;
    continue;
  }
}
 catch (Exception e) {
  log.add(LogLevel.WARN,LogType.MSG_KC_SUB_PRIMARY_BAD_ERR,indent);
  badCerts+=1;
  continue;
}
}
}
if (selfCert != null && selfCert.getCreationTime().before(cert.getCreationTime())) {
log.add(LogLevel.DEBUG,LogType.MSG_KC_SUB_DUP,indent);
redundantCerts+=1;
continue;
}
selfCert=zert;
if (revocation != null && selfCert.getCreationTime().after(revocation.getCreationTime())) {
revocation=null;
}
}
 else {
try {
cert.init(masterKey);
if (!cert.verifySignature(masterKey,key)) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_REVOKE_BAD,indent);
badCerts+=1;
continue;
}
}
 catch (PgpGeneralException e) {
log.add(LogLevel.WARN,LogType.MSG_KC_SUB_REVOKE_BAD_ERR,indent);
badCerts+=1;
continue;
}
if (selfCert != null && selfCert.getCreationTime().after(cert.getCreationTime())) {
log.add(LogLevel.DEBUG,LogType.MSG_KC_SUB_REVOKE_DUP,indent);
redundantCerts+=1;
continue;
}
revocation=zert;
}
}
if (selfCert == null) {
ring=replacePublicKey(ring,modified);
log.add(LogLevel.ERROR,LogType.MSG_KC_SUB_NO_CERT,indent,PgpKeyHelper.convertKeyIdToHex(key.getKeyID()));
indent-=1;
continue;
}
modified=PGPPublicKey.addCertification(modified,selfCert);
if (revocation != null) {
modified=PGPPublicKey.addCertification(modified,revocation);
}
ring=replacePublicKey(ring,modified);
indent-=1;
}
if (badCerts > 0 && redundantCerts > 0) {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS_BAD_AND_RED,indent,Integer.toString(badCerts),Integer.toString(redundantCerts));
}
 else if (badCerts > 0) {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS_BAD,indent,badCerts);
}
 else if (redundantCerts > 0) {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS_REDUNDANT,indent,redundantCerts);
}
 else {
log.add(LogLevel.OK,LogType.MSG_KC_SUCCESS,indent);
}
return new UncachedKeyRing(ring,true);
}