Пример #1
0
  /**
   * Initializes an APRep object.
   *
   * @param encoding a single DER-encoded value.
   * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
   * @exception IOException if an I/O error occurs while reading encoded data.
   * @exception KrbApErrException if the value read from the DER-encoded data stream does not match
   *     the pre-defined value.
   */
  private void init(DerValue encoding) throws Asn1Exception, KrbApErrException, IOException {

    if (((encoding.getTag() & (byte) (0x1F)) != Krb5.KRB_AP_REP)
        || (encoding.isApplication() != true)
        || (encoding.isConstructed() != true)) {
      throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    DerValue der = encoding.getData().getDerValue();
    if (der.getTag() != DerValue.tag_Sequence) {
      throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    DerValue subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
      throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    pvno = subDer.getData().getBigInteger().intValue();
    if (pvno != Krb5.PVNO) {
      throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    }
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x01) {
      throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    msgType = subDer.getData().getBigInteger().intValue();
    if (msgType != Krb5.KRB_AP_REP) {
      throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
    }
    encPart = EncryptedData.parse(der.getData(), (byte) 0x02, false);
    if (der.getData().available() > 0) {
      throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
  }
Пример #2
0
 /**
  * Encodes an APRep object.
  *
  * @return byte array of encoded APRep 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(pvno));
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   temp.putInteger(BigInteger.valueOf(msgType));
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), encPart.asn1Encode());
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   DerOutputStream aprep = new DerOutputStream();
   aprep.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x0F), temp);
   return aprep.toByteArray();
 }