sun.security.krb5.Asn1Exception Java Examples

The following examples show how to use sun.security.krb5.Asn1Exception. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: jdk8u60   Author: chenghanpeng   File: KRBPriv.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes an KRBPriv object.
 * @return byte array of encoded EncAPRepPart 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 temp, bytes;
    temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(pvno));
    bytes = new DerOutputStream();
    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)0x03), encPart.asn1Encode());
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    bytes = new DerOutputStream();
    bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x15), temp);
    return bytes.toByteArray();
}
 
Example #2
Source Project: jdk8u60   Author: chenghanpeng   File: AuthorizationDataEntry.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance of AuthorizationDataEntry.
 * @param encoding a single DER-encoded value.
 */
public AuthorizationDataEntry(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der;
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    der = encoding.getData().getDerValue();
    if ((der.getTag() & (byte) 0x1F) == (byte) 0x00) {
        adType = der.getData().getBigInteger().intValue();
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    der = encoding.getData().getDerValue();
    if ((der.getTag() & (byte) 0x1F) == (byte) 0x01) {
        adData = der.getData().getOctetString();
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    if (encoding.getData().available() > 0) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
}
 
Example #3
Source Project: jdk8u60   Author: chenghanpeng   File: Ticket.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a Ticket object.
 * @return byte array of encoded ticket 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();
    DerValue der[] = new DerValue[4];
    temp.putInteger(BigInteger.valueOf(tkt_vno));
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), sname.getRealm().asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode());
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    DerOutputStream ticket = new DerOutputStream();
    ticket.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x01), temp);
    return ticket.toByteArray();
}
 
Example #4
Source Project: jdk8u60   Author: chenghanpeng   File: KRBSafeBody.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes an KRBSafeBody object.
 * @return the byte array of encoded KRBSafeBody 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.putOctetString(userData);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    if (timestamp != null)
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), timestamp.asn1Encode());
    if (usec != null) {
        temp = new DerOutputStream();
        temp.putInteger(BigInteger.valueOf(usec.intValue()));
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), temp);
    }
    if (seqNumber != null) {
        temp = new DerOutputStream();
        // encode as an unsigned integer (UInt32)
        temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
    }
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sAddress.asn1Encode());
    if (rAddress != null)
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #5
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: KRBPriv.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes an KRBPriv object.
 * @return byte array of encoded EncAPRepPart 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 temp, bytes;
    temp = new DerOutputStream();
    temp.putInteger(BigInteger.valueOf(pvno));
    bytes = new DerOutputStream();
    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)0x03), encPart.asn1Encode());
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    bytes = new DerOutputStream();
    bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x15), temp);
    return bytes.toByteArray();
}
 
Example #6
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: KerberosTime.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse (unmarshal) a kerberostime from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains
 *             one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicates if this data field is optional
 * @return an instance of KerberosTime.
 *
 */
public static KerberosTime parse(
        DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F)!= explicitTag))
        return null;
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    else {
        DerValue subDer = der.getData().getDerValue();
        Date temp = subDer.getGeneralizedTime();
        return new KerberosTime(temp.getTime(), 0);
    }
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: PAData.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a PAData object.
 * @param encoding a Der-encoded data.
 * @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 PAData(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der = null;
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x01) {
        this.pADataType = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x02) {
        this.pADataValue = der.getData().getOctetString();
    }
    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #8
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: PAData.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(pADataType);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_PATYPE), temp);
    temp = new DerOutputStream();
    temp.putOctetString(pADataValue);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_PAVALUE), temp);

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Ticket.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initializes a Ticket 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.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */

private void init(DerValue encoding) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    DerValue der;
    DerValue subDer;
    if (((encoding.getTag() & (byte)0x1F) != Krb5.KRB_TKT)
        || (encoding.isApplication() != true)
        || (encoding.isConstructed() != true))
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    der = encoding.getData().getDerValue();
    if (der.getTag() != DerValue.tag_Sequence)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) != (byte)0x00)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    tkt_vno = subDer.getData().getBigInteger().intValue();
    if (tkt_vno != Krb5.TICKET_VNO)
        throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    Realm srealm = Realm.parse(der.getData(), (byte)0x01, false);
    sname = PrincipalName.parse(der.getData(), (byte)0x02, false, srealm);
    encPart = EncryptedData.parse(der.getData(), (byte)0x03, false);
    if (der.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #10
Source Project: dragonwell8_jdk   Author: alibaba   File: Ticket.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initializes a Ticket 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.
 * @exception RealmException if an error occurs while parsing a Realm object.
 */

private void init(DerValue encoding) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    DerValue der;
    DerValue subDer;
    if (((encoding.getTag() & (byte)0x1F) != Krb5.KRB_TKT)
        || (encoding.isApplication() != true)
        || (encoding.isConstructed() != true))
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    der = encoding.getData().getDerValue();
    if (der.getTag() != DerValue.tag_Sequence)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) != (byte)0x00)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    tkt_vno = subDer.getData().getBigInteger().intValue();
    if (tkt_vno != Krb5.TICKET_VNO)
        throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    Realm srealm = Realm.parse(der.getData(), (byte)0x01, false);
    sname = PrincipalName.parse(der.getData(), (byte)0x02, false, srealm);
    encPart = EncryptedData.parse(der.getData(), (byte)0x03, false);
    if (der.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #11
Source Project: openjdk-8   Author: bpupadhyaya   File: KRBError.java    License: GNU General Public License v2.0 6 votes vote down vote up
public KRBError(
                APOptions new_apOptions,
                KerberosTime new_cTime,
                Integer new_cuSec,
                KerberosTime new_sTime,
                Integer new_suSec,
                int new_errorCode,
                PrincipalName new_cname,
                PrincipalName new_sname,
                String new_eText,
                byte[] new_eData
                    ) throws IOException, Asn1Exception {
    pvno = Krb5.PVNO;
    msgType = Krb5.KRB_ERROR;
    cTime = new_cTime;
    cuSec = new_cuSec;
    sTime = new_sTime;
    suSec = new_suSec;
    errorCode = new_errorCode;
    cname = new_cname;
    sname = new_sname;
    eText = new_eText;
    eData = new_eData;

    parseEData(eData);
}
 
Example #12
Source Project: openjdk-8-source   Author: keerath   File: KRBSafe.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes an KRBSafe object.
 * @return byte array of encoded KRBSafe 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 temp = new DerOutputStream();
    DerOutputStream bytes = 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), safeBody.asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), cksum.asn1Encode());
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    bytes = new DerOutputStream();
    bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x14), temp);
    return bytes.toByteArray();
}
 
Example #13
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: KRBError.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Try parsing the data as a sequence of PA-DATA.
 * @param data the data block
 */
private void parsePAData(byte[] data)
        throws IOException, Asn1Exception {
    DerValue derPA = new DerValue(data);
    List<PAData> paList = new ArrayList<>();
    while (derPA.data.available() > 0) {
        // read the PA-DATA
        DerValue tmp = derPA.data.getDerValue();
        PAData pa_data = new PAData(tmp);
        paList.add(pa_data);
        if (DEBUG) {
            System.out.println(pa_data);
        }
    }
    pa = paList.toArray(new PAData[paList.size()]);
}
 
Example #14
Source Project: jdk8u_jdk   Author: JetBrains   File: KerberosTime.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static long toKerberosTime(String time) throws Asn1Exception {
    // ASN.1 GeneralizedTime format:

    // "19700101000000Z"
    //  |   | | | | | |
    //  0   4 6 8 | | |
    //           10 | |
    //             12 |
    //               14

    if (time.length() != 15)
        throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT);
    if (time.charAt(14) != 'Z')
        throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT);
    int year = Integer.parseInt(time.substring(0, 4));
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.clear(); // so that millisecond is zero
    calendar.set(year,
                 Integer.parseInt(time.substring(4, 6)) - 1,
                 Integer.parseInt(time.substring(6, 8)),
                 Integer.parseInt(time.substring(8, 10)),
                 Integer.parseInt(time.substring(10, 12)),
                 Integer.parseInt(time.substring(12, 14)));
    return calendar.getTimeInMillis();
}
 
Example #15
Source Project: jdk8u60   Author: chenghanpeng   File: PAEncTSEnc.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a PAEncTSEnc object.
 * @param encoding a Der-encoded data.
 * @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 PAEncTSEnc(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der;
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    pATimeStamp = KerberosTime.parse(encoding.getData(), (byte)0x00, false);
    if (encoding.getData().available() > 0) {
        der = encoding.getData().getDerValue();
        if ((der.getTag() & 0x1F) == 0x01) {
            pAUSec = new Integer(der.getData().getBigInteger().intValue());
        }
        else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #16
Source Project: hottub   Author: dsrg-uoft   File: HostAddress.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses (unmarshal) a host address from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
     * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @param data the Der input stream value, which contains one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicates if this data field is optional
 * @return an instance of HostAddress.
 *
 */
public static HostAddress parse(DerInputStream data, byte explicitTag,
                                boolean optional)
    throws Asn1Exception, IOException{
    if ((optional) &&
        (((byte)data.peekByte() & (byte)0x1F) != explicitTag)) {
        return null;
    }
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    else {
        DerValue subDer = der.getData().getDerValue();
        return new HostAddress(subDer);
    }
}
 
Example #17
Source Project: TencentKona-8   Author: Tencent   File: KerberosTime.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static long toKerberosTime(String time) throws Asn1Exception {
    // ASN.1 GeneralizedTime format:

    // "19700101000000Z"
    //  |   | | | | | |
    //  0   4 6 8 | | |
    //           10 | |
    //             12 |
    //               14

    if (time.length() != 15)
        throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT);
    if (time.charAt(14) != 'Z')
        throw new Asn1Exception(Krb5.ASN1_BAD_TIMEFORMAT);
    int year = Integer.parseInt(time.substring(0, 4));
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.clear(); // so that millisecond is zero
    calendar.set(year,
                 Integer.parseInt(time.substring(4, 6)) - 1,
                 Integer.parseInt(time.substring(6, 8)),
                 Integer.parseInt(time.substring(8, 10)),
                 Integer.parseInt(time.substring(10, 12)),
                 Integer.parseInt(time.substring(12, 14)));
    return calendar.getTimeInMillis();
}
 
Example #18
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: ETypeInfo.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #19
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: LastReqEntry.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a LastReqEntry object.
 * @param encoding a Der-encoded data.
 * @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 LastReqEntry(DerValue encoding) throws Asn1Exception, IOException {
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    DerValue der;
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00){
        lrType = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);

    lrValue = KerberosTime.parse(encoding.getData(), (byte)0x01, false);
    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #20
Source Project: dragonwell8_jdk   Author: alibaba   File: PAData.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a PAData object.
 * @param encoding a Der-encoded data.
 * @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 PAData(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der = null;
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x01) {
        this.pADataType = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x02) {
        this.pADataValue = der.getData().getOctetString();
    }
    if (encoding.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #21
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: MethodData.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #22
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TransitedEncoding.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a TransitedEncoding object.
 * @param encoding a Der-encoded data.
 * @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 TransitedEncoding(DerValue encoding) throws Asn1Exception, IOException {
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    DerValue der;
    der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00) {
        trType = der.getData().getBigInteger().intValue();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    der = encoding.getData().getDerValue();

    if ((der.getTag() & 0x1F) == 0x01) {
        contents = der.getData().getOctetString();
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    if (der.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #23
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: Ticket.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes a Ticket object.
 * @return byte array of encoded ticket 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();
    DerValue der[] = new DerValue[4];
    temp.putInteger(BigInteger.valueOf(tkt_vno));
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), sname.getRealm().asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), sname.asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), encPart.asn1Encode());
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    DerOutputStream ticket = new DerOutputStream();
    ticket.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x01), temp);
    return ticket.toByteArray();
}
 
Example #24
Source Project: openjdk-8-source   Author: keerath   File: ETypeInfo.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes this object to an OutputStream.
 *
 * @return byte array of the encoded data.
 * @exception IOException if an I/O error occurs while reading encoded data.
 * @exception Asn1Exception on encoding errors.
 */
public byte[] asn1Encode() throws Asn1Exception, IOException {

    DerOutputStream bytes = new DerOutputStream();
    DerOutputStream temp = new DerOutputStream();

    temp.putInteger(etype);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_TYPE), temp);

    if (salt != null) {
        temp = new DerOutputStream();
        if (KerberosString.MSNAME) {
            temp.putOctetString(salt.getBytes("UTF8"));
        } else {
            temp.putOctetString(salt.getBytes());
        }
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
                                    TAG_VALUE), temp);
    }

    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #25
Source Project: TencentKona-8   Author: Tencent   File: KRBError.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Try parsing the data as a sequence of PA-DATA.
 * @param data the data block
 */
private void parsePAData(byte[] data)
        throws IOException, Asn1Exception {
    DerValue derPA = new DerValue(data);
    List<PAData> paList = new ArrayList<>();
    while (derPA.data.available() > 0) {
        // read the PA-DATA
        DerValue tmp = derPA.data.getDerValue();
        PAData pa_data = new PAData(tmp);
        paList.add(pa_data);
        if (DEBUG) {
            System.out.println(pa_data);
        }
    }
    pa = paList.toArray(new PAData[paList.size()]);
}
 
Example #26
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: HostAddresses.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a <code>HostAddresses</code> from a DER input stream.
 * This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception if an Asn1Exception occurs.
 * @param data the Der input stream value, which contains one or more
 * marshaled value.
 * @param explicitTag tag number.
 * @param optional indicates if this data field is optional.
 * @return an instance of <code>HostAddresses</code>.
 */
public static HostAddresses parse(DerInputStream data,
                                  byte explicitTag, boolean optional)
    throws Asn1Exception, IOException {
    if ((optional) &&
        (((byte)data.peekByte() & (byte)0x1F) != explicitTag))
        return null;
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    } else {
        DerValue subDer = der.getData().getDerValue();
        return new HostAddresses(subDer);
    }
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: TransitedEncoding.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes a TransitedEncoding object.
 * @return the byte array of the encoded TransitedEncoding 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(trType));
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    temp = new DerOutputStream();
    temp.putOctetString(contents);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #28
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: LastReqEntry.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encodes an LastReqEntry object.
 * @return the byte array of encoded LastReqEntry 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(lrType);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), lrValue.asn1Encode());
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
 
Example #29
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: KRBError.java    License: GNU General Public License v2.0 5 votes vote down vote up
public KRBError(
                APOptions new_apOptions,
                KerberosTime new_cTime,
                Integer new_cuSec,
                KerberosTime new_sTime,
                Integer new_suSec,
                int new_errorCode,
                PrincipalName new_cname,
                PrincipalName new_sname,
                String new_eText,
                byte[] new_eData,
                Checksum new_eCksum
                    ) throws IOException, Asn1Exception {
    pvno = Krb5.PVNO;
    msgType = Krb5.KRB_ERROR;
    cTime = new_cTime;
    cuSec = new_cuSec;
    sTime = new_sTime;
    suSec = new_suSec;
    errorCode = new_errorCode;
    crealm = new_cname != null ? new_cname.getRealm() : null;
    cname = new_cname;
    sname = new_sname;
    eText = new_eText;
    eData = new_eData;
    eCksum = new_eCksum;

    parseEData(eData);
}
 
Example #30
Source Project: openjdk-8-source   Author: keerath   File: BadKdc.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void go(String... expected)
        throws Exception {
    try {
        go0(expected);
    } catch (BindException be) {
        System.out.println("The random port is used by another process");
    } catch (LoginException le) {
        Throwable cause = le.getCause();
        if (cause instanceof Asn1Exception) {
            System.out.println("Bad packet possibly from another process");
            return;
        }
        throw le;
    }
}