/*     */ public void putBitString(byte[] paramArrayOfByte) /*     */ throws IOException
       /*     */ {
   /* 238 */ write(3);
   /* 239 */ putLength(paramArrayOfByte.length + 1);
   /* 240 */ write(0);
   /* 241 */ write(paramArrayOfByte);
   /*     */ }
Exemple #2
0
  /**
   * Returns the ASN.1 encoding of this object.
   *
   * @return the ASN.1 encoding.
   * @exception IOException if error occurs when constructing its ASN.1 encoding.
   */
  public byte[] getEncoded() throws NoSuchAlgorithmException, IOException {
    if (this.encoded != null) return this.encoded.clone();

    DerOutputStream out = new DerOutputStream();
    DerOutputStream tmp = new DerOutputStream();

    DerOutputStream tmp2 = new DerOutputStream();
    // encode encryption algorithm
    AlgorithmId algid = AlgorithmId.get(digestAlgorithmName);
    algid.encode(tmp2);

    // encode digest data
    tmp2.putOctetString(digest);

    tmp.write(DerValue.tag_Sequence, tmp2);

    // encode salt
    tmp.putOctetString(macSalt);

    // encode iterations
    tmp.putInteger(iterations);

    // wrap everything into a SEQUENCE
    out.write(DerValue.tag_Sequence, tmp);
    this.encoded = out.toByteArray();

    return this.encoded.clone();
  }
 /*     */ public void write(byte paramByte, DerOutputStream paramDerOutputStream)
     /*     */ throws IOException
       /*     */ {
   /*  93 */ write(paramByte);
   /*  94 */ putLength(paramDerOutputStream.count);
   /*  95 */ write(paramDerOutputStream.buf, 0, paramDerOutputStream.count);
   /*     */ }
  /**
   * Encode the CertPath using PKIPATH format.
   *
   * @return a byte array containing the binary encoding of the PkiPath object
   * @exception CertificateEncodingException if an exception occurs
   */
  private byte[] encodePKIPATH() throws CertificateEncodingException {

    ListIterator<X509Certificate> li = certs.listIterator(certs.size());
    try {
      DerOutputStream bytes = new DerOutputStream();
      // encode certs in reverse order (trust anchor to target)
      // according to PkiPath format
      while (li.hasPrevious()) {
        X509Certificate cert = li.previous();
        // check for duplicate cert
        if (certs.lastIndexOf(cert) != certs.indexOf(cert)) {
          throw new CertificateEncodingException("Duplicate Certificate");
        }
        // get encoded certificates
        byte[] encoded = cert.getEncoded();
        bytes.write(encoded);
      }

      // Wrap the data in a SEQUENCE
      DerOutputStream derout = new DerOutputStream();
      derout.write(DerValue.tag_SequenceOf, bytes);
      return derout.toByteArray();

    } catch (IOException ioe) {
      throw new CertificateEncodingException("IOException encoding " + "PkiPath data: " + ioe, ioe);
    }
  }
 /*     */ public void putInteger(BigInteger paramBigInteger) /*     */ throws IOException
       /*     */ {
   /* 164 */ write(2);
   /* 165 */ byte[] arrayOfByte = paramBigInteger.toByteArray();
   /* 166 */ putLength(arrayOfByte.length);
   /* 167 */ write(arrayOfByte, 0, arrayOfByte.length);
   /*     */ }
Exemple #6
0
  /**
   * Returns the encoded SPNEGO token Note: inserts the required CHOICE tags
   *
   * @return the encoded token
   * @exception GSSException
   */
  byte[] getEncoded() throws IOException, GSSException {

    // get the token encoded value
    DerOutputStream token = new DerOutputStream();
    token.write(encode());

    // now insert the CHOICE
    switch (tokenType) {
      case NEG_TOKEN_INIT_ID:
        // Insert CHOICE of Negotiation Token
        DerOutputStream initToken = new DerOutputStream();
        initToken.write(
            DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) NEG_TOKEN_INIT_ID), token);
        return initToken.toByteArray();

      case NEG_TOKEN_TARG_ID:
        // Insert CHOICE of Negotiation Token
        DerOutputStream targToken = new DerOutputStream();
        targToken.write(
            DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) NEG_TOKEN_TARG_ID), token);
        return targToken.toByteArray();
      default:
        return token.toByteArray();
    }
  }
Exemple #7
0
  /** Get the encoding of the key. */
  public synchronized byte[] getEncoded() {
    if (this.encodedKey == null) {
      try {
        DerOutputStream algid = new DerOutputStream();

        // store oid in algid
        algid.putOID(new ObjectIdentifier(DH_data));

        // encode parameters
        DerOutputStream params = new DerOutputStream();
        params.putInteger(this.p);
        params.putInteger(this.g);
        if (this.l != 0) params.putInteger(this.l);
        // wrap parameters into SEQUENCE
        DerValue paramSequence = new DerValue(DerValue.tag_Sequence, params.toByteArray());
        // store parameter SEQUENCE in algid
        algid.putDerValue(paramSequence);

        // wrap algid into SEQUENCE, and store it in key encoding
        DerOutputStream tmpDerKey = new DerOutputStream();
        tmpDerKey.write(DerValue.tag_Sequence, algid);

        // store key data
        tmpDerKey.putBitString(this.key);

        // wrap algid and key into SEQUENCE
        DerOutputStream derKey = new DerOutputStream();
        derKey.write(DerValue.tag_Sequence, tmpDerKey);
        this.encodedKey = derKey.toByteArray();
      } catch (IOException e) {
        return null;
      }
    }
    return (byte[]) this.encodedKey.clone();
  }
 /*     */ private void writeString(String paramString1, byte paramByte, String paramString2)
     /*     */ throws IOException
       /*     */ {
   /* 454 */ byte[] arrayOfByte = paramString1.getBytes(paramString2);
   /* 455 */ write(paramByte);
   /* 456 */ putLength(arrayOfByte.length);
   /* 457 */ write(arrayOfByte);
   /*     */ }
 /*     */ public void putUnalignedBitString(BitArray paramBitArray) /*     */ throws IOException
       /*     */ {
   /* 251 */ byte[] arrayOfByte = paramBitArray.toByteArray();
   /*     */
   /* 253 */ write(3);
   /* 254 */ putLength(arrayOfByte.length + 1);
   /* 255 */ write(arrayOfByte.length * 8 - paramBitArray.length());
   /* 256 */ write(arrayOfByte);
   /*     */ }
 /**
  * Write the PolicyInformation to the DerOutputStream.
  *
  * @param out the DerOutputStream to write the extension to.
  * @exception IOException on encoding errors.
  */
 public void encode(DerOutputStream out) throws IOException {
   DerOutputStream tmp = new DerOutputStream();
   policyIdentifier.encode(tmp);
   if (!policyQualifiers.isEmpty()) {
     DerOutputStream tmp2 = new DerOutputStream();
     for (PolicyQualifierInfo pq : policyQualifiers) {
       tmp2.write(pq.getEncoded());
     }
     tmp.write(DerValue.tag_Sequence, tmp2);
   }
   out.write(DerValue.tag_Sequence, tmp);
 }
 /*     */ public byte[] asn1Encode() /*     */ throws Asn1Exception, IOException /*     */ {
   /* 104 */ DerOutputStream localDerOutputStream1 = new DerOutputStream();
   /* 105 */ DerOutputStream localDerOutputStream2 = new DerOutputStream();
   /* 106 */ localDerOutputStream1.write(
       DerValue.createTag((byte) -128, true, (byte) 0), this.pATimeStamp.asn1Encode());
   /* 107 */ if (this.pAUSec != null) {
     /* 108 */ localDerOutputStream2 = new DerOutputStream();
     /* 109 */ localDerOutputStream2.putInteger(BigInteger.valueOf(this.pAUSec.intValue()));
     /* 110 */ localDerOutputStream1.write(
         DerValue.createTag((byte) -128, true, (byte) 1), localDerOutputStream2);
     /*     */ }
   /* 112 */ localDerOutputStream2 = new DerOutputStream();
   /* 113 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1);
   /* 114 */ return localDerOutputStream2.toByteArray();
   /*     */ }
Exemple #12
0
  /**
   * Encodes an MethodData object.
   *
   * @return the byte array of encoded MethodData object.
   * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
   * @exception IOException if an I/O error occurs while reading encoded data.
   */
  public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(methodType));
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
    if (methodData != null) {
      temp = new DerOutputStream();
      temp.putOctetString(methodData);
      bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
  }
 /*     */ public void putTag(byte paramByte1, boolean paramBoolean, byte paramByte2) /*     */ {
   /* 560 */ int i = (byte) (paramByte1 | paramByte2);
   /* 561 */ if (paramBoolean) {
     /* 562 */ i = (byte) (i | 0x20);
     /*     */ }
   /* 564 */ write(i);
   /*     */ }
 /*     */ private void putIntegerContents(int paramInt) throws IOException /*     */ {
   /* 189 */ byte[] arrayOfByte = new byte[4];
   /* 190 */ int i = 0;
   /*     */
   /* 194 */ arrayOfByte[3] = ((byte) (paramInt & 0xFF));
   /* 195 */ arrayOfByte[2] = ((byte) ((paramInt & 0xFF00) >>> 8));
   /* 196 */ arrayOfByte[1] = ((byte) ((paramInt & 0xFF0000) >>> 16));
   /* 197 */ arrayOfByte[0] = ((byte) ((paramInt & 0xFF000000) >>> 24));
   /*     */
   /* 202 */ if (arrayOfByte[0] == -1)
   /*     */ {
     /* 206 */ for (j = 0;
         (j < 3) && /* 207 */ (arrayOfByte[j] == -1) && ((arrayOfByte[(j + 1)] & 0x80) == 128);
         j++)
     /*     */ {
       /* 209 */ i++;
       /*     */ }
     /*     */
     /*     */ }
   /* 213 */ else if (arrayOfByte[0] == 0)
   /*     */ {
     /* 217 */ for (j = 0;
         (j < 3) && /* 218 */ (arrayOfByte[j] == 0) && ((arrayOfByte[(j + 1)] & 0x80) == 0);
         j++)
     /*     */ {
       /* 220 */ i++;
       /*     */ }
     /*     */
     /*     */ }
   /*     */
   /* 226 */ putLength(4 - i);
   /* 227 */ for (int j = i; j < 4; j++) /* 228 */ write(arrayOfByte[j]);
   /*     */ }
 /**
  * Encodes a <code>PrincipalName</code> object. Note that only the type and names are encoded. To
  * encode the realm, call getRealm().asn1Encode().
  *
  * @return the byte array of the encoded PrncipalName object.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 public byte[] asn1Encode() throws Asn1Exception, IOException {
   DerOutputStream bytes = new DerOutputStream();
   DerOutputStream temp = new DerOutputStream();
   BigInteger bint = BigInteger.valueOf(this.nameType);
   temp.putInteger(bint);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   DerValue der[] = new DerValue[nameStrings.length];
   for (int i = 0; i < nameStrings.length; i++) {
     der[i] = new KerberosString(nameStrings[i]).toDerValue();
   }
   temp.putSequence(der);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   return temp.toByteArray();
 }
  /**
   * Encode the policy set to the output stream.
   *
   * @param out the DerOutputStream to encode the data to.
   */
  public void encode(DerOutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();

    for (int i = 0; i < ids.size(); i++) {
      ids.elementAt(i).encode(tmp);
    }
    out.write(DerValue.tag_Sequence, tmp);
  }
  /* Translate to encoded bytes */
  private void emit(DerOutputStream out) throws IOException, CertificateEncodingException {
    DerOutputStream tagged = new DerOutputStream();

    if (forward != null) {
      DerOutputStream tmp = new DerOutputStream();
      tmp.putDerValue(new DerValue(forward.getEncoded()));
      tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FORWARD), tmp);
    }

    if (reverse != null) {
      DerOutputStream tmp = new DerOutputStream();
      tmp.putDerValue(new DerValue(reverse.getEncoded()));
      tagged.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_REVERSE), tmp);
    }

    out.write(DerValue.tag_Sequence, tagged);
  }
 /*     */ public void putSet(DerValue[] paramArrayOfDerValue) /*     */ throws IOException
       /*     */ {
   /* 318 */ DerOutputStream localDerOutputStream = new DerOutputStream();
   /*     */
   /* 321 */ for (int i = 0; i < paramArrayOfDerValue.length; i++) {
     /* 322 */ paramArrayOfDerValue[i].encode(localDerOutputStream);
     /*     */ }
   /* 324 */ write((byte) 49, localDerOutputStream);
   /*     */ }
 /*     */ private void putTime(Date paramDate, byte paramByte) /*     */ throws IOException
       /*     */ {
   /* 493 */ TimeZone localTimeZone = TimeZone.getTimeZone("GMT");
   /* 494 */ String str = null;
   /*     */
   /* 496 */ if (paramByte == 23) {
     /* 497 */ str = "yyMMddHHmmss'Z'";
     /*     */ } else {
     /* 499 */ paramByte = 24;
     /* 500 */ str = "yyyyMMddHHmmss'Z'";
     /*     */ }
   /*     */
   /* 503 */ SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(str, Locale.US);
   /* 504 */ localSimpleDateFormat.setTimeZone(localTimeZone);
   /* 505 */ byte[] arrayOfByte = localSimpleDateFormat.format(paramDate).getBytes("ISO-8859-1");
   /*     */
   /* 511 */ write(paramByte);
   /* 512 */ putLength(arrayOfByte.length);
   /* 513 */ write(arrayOfByte);
   /*     */ }
 // Encode this extension value
 private void encodeThis() throws IOException {
   if (accessDescriptions.isEmpty()) {
     this.extensionValue = null;
   } else {
     DerOutputStream ads = new DerOutputStream();
     for (AccessDescription accessDescription : accessDescriptions) {
       accessDescription.encode(ads);
     }
     DerOutputStream seq = new DerOutputStream();
     seq.write(DerValue.tag_Sequence, ads);
     this.extensionValue = seq.toByteArray();
   }
 }
  // Encode this extension value.
  private void encodeThis() throws IOException {
    if (certPolicies == null || certPolicies.isEmpty()) {
      this.extensionValue = null;
    } else {
      DerOutputStream os = new DerOutputStream();
      DerOutputStream tmp = new DerOutputStream();

      for (PolicyInformation info : certPolicies) {
        info.encode(tmp);
      }

      os.write(DerValue.tag_Sequence, tmp);
      this.extensionValue = os.toByteArray();
    }
  }
 /*     */ public void encode(OutputStream paramOutputStream) /*     */ throws IOException
       /*     */ {
   /* 151 */ if ((this.notBefore == null) || (this.notAfter == null)) {
     /* 152 */ throw new IOException("CertAttrSet:CertificateValidity: null values to encode.\n");
     /*     */ }
   /*     */
   /* 155 */ DerOutputStream localDerOutputStream1 = new DerOutputStream();
   /*     */
   /* 157 */ if (this.notBefore.getTime() < 2524636800000L)
     /* 158 */ localDerOutputStream1.putUTCTime(this.notBefore);
   /*     */ else {
     /* 160 */ localDerOutputStream1.putGeneralizedTime(this.notBefore);
     /*     */ }
   /* 162 */ if (this.notAfter.getTime() < 2524636800000L)
     /* 163 */ localDerOutputStream1.putUTCTime(this.notAfter);
   /*     */ else {
     /* 165 */ localDerOutputStream1.putGeneralizedTime(this.notAfter);
     /*     */ }
   /* 167 */ DerOutputStream localDerOutputStream2 = new DerOutputStream();
   /* 168 */ localDerOutputStream2.write((byte) 48, localDerOutputStream1);
   /*     */
   /* 170 */ paramOutputStream.write(localDerOutputStream2.toByteArray());
   /*     */ }
 /*     */ private void putOrderedSet(
     byte paramByte, DerEncoder[] paramArrayOfDerEncoder, Comparator<byte[]> paramComparator)
     /*     */ throws IOException
       /*     */ {
   /* 375 */ DerOutputStream[] arrayOfDerOutputStream =
       new DerOutputStream[paramArrayOfDerEncoder.length];
   /*     */
   /* 377 */ for (int i = 0; i < paramArrayOfDerEncoder.length; i++) {
     /* 378 */ arrayOfDerOutputStream[i] = new DerOutputStream();
     /* 379 */ paramArrayOfDerEncoder[i].derEncode(arrayOfDerOutputStream[i]);
     /*     */ }
   /*     */
   /* 383 */ byte[][] arrayOfByte = new byte[arrayOfDerOutputStream.length][];
   /* 384 */ for (int j = 0; j < arrayOfDerOutputStream.length; j++) {
     /* 385 */ arrayOfByte[j] = arrayOfDerOutputStream[j].toByteArray();
     /*     */ }
   /* 387 */ Arrays.sort(arrayOfByte, paramComparator);
   /*     */
   /* 389 */ DerOutputStream localDerOutputStream = new DerOutputStream();
   /* 390 */ for (int k = 0; k < arrayOfDerOutputStream.length; k++) {
     /* 391 */ localDerOutputStream.write(arrayOfByte[k]);
     /*     */ }
   /* 393 */ write(paramByte, localDerOutputStream);
   /*     */ }
 /*     */ public void putNull() /*     */ throws IOException /*     */ {
   /* 283 */ write(5);
   /* 284 */ putLength(0);
   /*     */ }
 /*     */ public void putInteger(int paramInt) /*     */ throws IOException /*     */ {
   /* 183 */ write(2);
   /* 184 */ putIntegerContents(paramInt);
   /*     */ }
 /*     */ public void putEnumerated(int paramInt) /*     */ throws IOException /*     */ {
   /* 154 */ write(10);
   /* 155 */ putIntegerContents(paramInt);
   /*     */ }
 /*     */ public void putBoolean(boolean paramBoolean) /*     */ throws IOException /*     */ {
   /* 140 */ write(1);
   /* 141 */ putLength(1);
   /* 142 */ if (paramBoolean) /* 143 */ write(255);
   /*     */ else /* 145 */ write(0);
   /*     */ }
 /*     */ public void writeImplicit(byte paramByte, DerOutputStream paramDerOutputStream)
     /*     */ throws IOException
       /*     */ {
   /* 117 */ write(paramByte);
   /* 118 */ write(paramDerOutputStream.buf, 1, paramDerOutputStream.count - 1);
   /*     */ }
 /*     */ public void putLength(int paramInt) /*     */ throws IOException /*     */ {
   /* 523 */ if (paramInt < 128) {
     /* 524 */ write((byte) paramInt);
     /*     */ }
   /* 526 */ else if (paramInt < 256) {
     /* 527 */ write(-127);
     /* 528 */ write((byte) paramInt);
     /*     */ }
   /* 530 */ else if (paramInt < 65536) {
     /* 531 */ write(-126);
     /* 532 */ write((byte) (paramInt >> 8));
     /* 533 */ write((byte) paramInt);
     /*     */ }
   /* 535 */ else if (paramInt < 16777216) {
     /* 536 */ write(-125);
     /* 537 */ write((byte) (paramInt >> 16));
     /* 538 */ write((byte) (paramInt >> 8));
     /* 539 */ write((byte) paramInt);
     /*     */ }
   /*     */ else {
     /* 542 */ write(-124);
     /* 543 */ write((byte) (paramInt >> 24));
     /* 544 */ write((byte) (paramInt >> 16));
     /* 545 */ write((byte) (paramInt >> 8));
     /* 546 */ write((byte) paramInt);
     /*     */ }
   /*     */ }
 /*     */ public void write(byte paramByte, byte[] paramArrayOfByte) /*     */ throws IOException
       /*     */ {
   /*  78 */ write(paramByte);
   /*  79 */ putLength(paramArrayOfByte.length);
   /*  80 */ write(paramArrayOfByte, 0, paramArrayOfByte.length);
   /*     */ }