protected static Date getValidCertDateFromValidityModel(
     ExtendedPKIXParameters paramsPKIX, CertPath certPath, int index) throws AnnotatedException {
   if (paramsPKIX.getValidityModel() == ExtendedPKIXParameters.CHAIN_VALIDITY_MODEL) {
     // if end cert use given signing/encryption/... time
     if (index <= 0) {
       return CertPathValidatorUtilities.getValidDate(paramsPKIX);
       // else use time when previous cert was created
     } else {
       if (index - 1 == 0) {
         DERGeneralizedTime dateOfCertgen = null;
         try {
           byte[] extBytes =
               ((X509Certificate) certPath.getCertificates().get(index - 1))
                   .getExtensionValue(
                       ISISMTTObjectIdentifiers.id_isismtt_at_dateOfCertGen.getId());
           if (extBytes != null) {
             dateOfCertgen = DERGeneralizedTime.getInstance(ASN1Primitive.fromByteArray(extBytes));
           }
         } catch (IOException e) {
           throw new AnnotatedException("Date of cert gen extension could not be read.");
         } catch (IllegalArgumentException e) {
           throw new AnnotatedException("Date of cert gen extension could not be read.");
         }
         if (dateOfCertgen != null) {
           try {
             return dateOfCertgen.getDate();
           } catch (ParseException e) {
             throw new AnnotatedException(
                 "Date from date of cert gen extension could not be parsed.", e);
           }
         }
         return ((X509Certificate) certPath.getCertificates().get(index - 1)).getNotBefore();
       } else {
         return ((X509Certificate) certPath.getCertificates().get(index - 1)).getNotBefore();
       }
     }
   } else {
     return getValidDate(paramsPKIX);
   }
 }
Beispiel #2
0
  private PKIHeader(ASN1Sequence seq) {
    Enumeration en = seq.getObjects();

    pvno = DERInteger.getInstance(en.nextElement());
    sender = GeneralName.getInstance(en.nextElement());
    recipient = GeneralName.getInstance(en.nextElement());

    while (en.hasMoreElements()) {
      ASN1TaggedObject tObj = (ASN1TaggedObject) en.nextElement();

      switch (tObj.getTagNo()) {
        case 0:
          messageTime = DERGeneralizedTime.getInstance(tObj, true);
          break;
        case 1:
          protectionAlg = AlgorithmIdentifier.getInstance(tObj, true);
          break;
        case 2:
          senderKID = ASN1OctetString.getInstance(tObj, true);
          break;
        case 3:
          recipKID = ASN1OctetString.getInstance(tObj, true);
          break;
        case 4:
          transactionID = ASN1OctetString.getInstance(tObj, true);
          break;
        case 5:
          senderNonce = ASN1OctetString.getInstance(tObj, true);
          break;
        case 6:
          recipNonce = ASN1OctetString.getInstance(tObj, true);
          break;
        case 7:
          freeText = PKIFreeText.getInstance(tObj, true);
          break;
        case 8:
          generalInfo = ASN1Sequence.getInstance(tObj, true);
          break;
        default:
          throw new IllegalArgumentException("unknown tag number: " + tObj.getTagNo());
      }
    }
  }
  /**
   * @param obj The ASN.1 object to parse.
   * @return A GeneralizedTimeHoledr instance.
   */
  public static GeneralizedTimeHolder getInstance(Object obj) {

    if (obj instanceof GeneralizedTimeHolder) return (GeneralizedTimeHolder) obj;

    return new GeneralizedTimeHolderImpl(DERGeneralizedTime.getInstance(obj));
  }