/* Parse the encoded bytes */
  private void parse(DerValue val) throws IOException, CertificateException {
    if (val.tag != DerValue.tag_Sequence) {
      throw new IOException("Sequence tag missing for X509CertificatePair");
    }

    while (val.data != null && val.data.available() != 0) {
      DerValue opt = val.data.getDerValue();
      short tag = (byte) (opt.tag & 0x01f);
      switch (tag) {
        case TAG_FORWARD:
          if (opt.isContextSpecific() && opt.isConstructed()) {
            if (forward != null) {
              throw new IOException("Duplicate forward " + "certificate in X509CertificatePair");
            }
            opt = opt.data.getDerValue();
            forward = X509Factory.intern(new X509CertImpl(opt.toByteArray()));
          }
          break;
        case TAG_REVERSE:
          if (opt.isContextSpecific() && opt.isConstructed()) {
            if (reverse != null) {
              throw new IOException("Duplicate reverse " + "certificate in X509CertificatePair");
            }
            opt = opt.data.getDerValue();
            reverse = X509Factory.intern(new X509CertImpl(opt.toByteArray()));
          }
          break;
        default:
          throw new IOException("Invalid encoding of " + "X509CertificatePair");
      }
    }
    if (forward == null && reverse == null) {
      throw new CertificateException("at least one of certificate pair " + "must be non-null");
    }
  }
 /*     */ private void construct(DerValue paramDerValue) throws IOException /*     */ {
   /*  72 */ if (paramDerValue.tag != 48) {
     /*  73 */ throw new IOException(
         "Invalid encoded CertificateValidity, starting sequence tag missing.");
     /*     */ }
   /*     */
   /*  77 */ if (paramDerValue.data.available() == 0) {
     /*  78 */ throw new IOException("No data encoded for CertificateValidity");
     /*     */ }
   /*  80 */ DerInputStream localDerInputStream = new DerInputStream(paramDerValue.toByteArray());
   /*  81 */ DerValue[] arrayOfDerValue = localDerInputStream.getSequence(2);
   /*  82 */ if (arrayOfDerValue.length != 2) {
     /*  83 */ throw new IOException("Invalid encoding for CertificateValidity");
     /*     */ }
   /*  85 */ if (arrayOfDerValue[0].tag == 23)
     /*  86 */ this.notBefore = paramDerValue.data.getUTCTime();
   /*  87 */ else if (arrayOfDerValue[0].tag == 24)
     /*  88 */ this.notBefore = paramDerValue.data.getGeneralizedTime();
   /*     */ else {
     /*  90 */ throw new IOException("Invalid encoding for CertificateValidity");
     /*     */ }
   /*     */
   /*  93 */ if (arrayOfDerValue[1].tag == 23)
     /*  94 */ this.notAfter = paramDerValue.data.getUTCTime();
   /*  95 */ else if (arrayOfDerValue[1].tag == 24)
     /*  96 */ this.notAfter = paramDerValue.data.getGeneralizedTime();
   /*     */ else /*  98 */ throw new IOException("Invalid encoding for CertificateValidity");
   /*     */ }
Beispiel #3
0
  @SuppressWarnings("deprecation")
  private byte[] extractKeyData(DerInputStream stream)
      throws IOException, NoSuchAlgorithmException, CertificateException {
    byte[] returnValue = null;
    DerValue[] safeBags = stream.getSequence(2);
    int count = safeBags.length;

    /*
     * Spin over the SafeBags.
     */
    for (int i = 0; i < count; i++) {
      ObjectIdentifier bagId;
      DerInputStream sbi;
      DerValue bagValue;
      Object bagItem = null;

      sbi = safeBags[i].toDerInputStream();
      bagId = sbi.getOID();
      bagValue = sbi.getDerValue();
      if (!bagValue.isContextSpecific((byte) 0)) {
        throw new IOException("unsupported PKCS12 bag value type " + bagValue.tag);
      }
      bagValue = bagValue.data.getDerValue();
      if (bagId.equals(PKCS8ShroudedKeyBag_OID)) {
        // got what we were looking for.  Return it.
        returnValue = bagValue.toByteArray();
      } else {
        // log error message for "unsupported PKCS12 bag type"
        System.out.println("Unsupported bag type '" + bagId + "'");
      }
    }

    return returnValue;
  }
Beispiel #4
0
 /** Construct a key from its components. Used by the RSAKeyFactory and the RSAKeyPairGenerator. */
 RSAPrivateCrtKeyImpl(
     BigInteger n,
     BigInteger e,
     BigInteger d,
     BigInteger p,
     BigInteger q,
     BigInteger pe,
     BigInteger qe,
     BigInteger coeff)
     throws InvalidKeyException {
   this.n = n;
   this.e = e;
   this.d = d;
   this.p = p;
   this.q = q;
   this.pe = pe;
   this.qe = qe;
   this.coeff = coeff;
   RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
   // generate the encoding
   algid = rsaId;
   try {
     DerOutputStream out = new DerOutputStream();
     out.putInteger(0); // version must be 0
     out.putInteger(n);
     out.putInteger(e);
     out.putInteger(d);
     out.putInteger(p);
     out.putInteger(q);
     out.putInteger(pe);
     out.putInteger(qe);
     out.putInteger(coeff);
     DerValue val = new DerValue(DerValue.tag_Sequence, out.toByteArray());
     key = val.toByteArray();
   } catch (IOException exc) {
     // should never occur
     throw new InvalidKeyException(exc);
   }
 }
Beispiel #5
0
 /*
  * parse Algorithm Parameters
  */
 private AlgorithmParameters parseAlgParameters(DerInputStream in) throws IOException {
   AlgorithmParameters algParams = null;
   try {
     DerValue params;
     if (in.available() == 0) {
       params = null;
     } else {
       params = in.getDerValue();
       if (params.tag == DerValue.tag_Null) {
         params = null;
       }
     }
     if (params != null) {
       algParams = AlgorithmParameters.getInstance("PBE");
       algParams.init(params.toByteArray());
     }
   } catch (Exception e) {
     IOException ioe = new IOException("parseAlgParameters failed: " + e.getMessage());
     ioe.initCause(e);
     throw ioe;
   }
   return algParams;
 }