sun.security.krb5.RealmException Java Examples

The following examples show how to use sun.security.krb5.RealmException. 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 File: Ticket.java    From TencentKona-8 with 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 #2
Source File: Ticket.java    From jdk8u60 with 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 #3
Source File: Ticket.java    From dragonwell8_jdk with 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 #4
Source File: Ticket.java    From openjdk-jdk8u with 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 #5
Source File: KRBSafe.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes an KRBSafe 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 RealmException if an error occurs while parsing a Realm object.
 * @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,
RealmException, KrbApErrException, IOException {
    DerValue der, subDer;
    if (((encoding.getTag() & (byte)0x1F) != (byte)0x14)
        || (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() & 0x1F) == 0x00) {
        pvno = subDer.getData().getBigInteger().intValue();
        if (pvno != Krb5.PVNO)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x01) {
        msgType = subDer.getData().getBigInteger().intValue();
        if (msgType != Krb5.KRB_SAFE)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
    }

    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    safeBody = KRBSafeBody.parse(der.getData(), (byte)0x02, false);
    cksum = Checksum.parse(der.getData(), (byte)0x03, false);
    if (der.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #6
Source File: KRBSafe.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes an KRBSafe 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 RealmException if an error occurs while parsing a Realm object.
 * @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,
RealmException, KrbApErrException, IOException {
    DerValue der, subDer;
    if (((encoding.getTag() & (byte)0x1F) != (byte)0x14)
        || (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() & 0x1F) == 0x00) {
        pvno = subDer.getData().getBigInteger().intValue();
        if (pvno != Krb5.PVNO)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x01) {
        msgType = subDer.getData().getBigInteger().intValue();
        if (msgType != Krb5.KRB_SAFE)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
    }

    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    safeBody = KRBSafeBody.parse(der.getData(), (byte)0x02, false);
    cksum = Checksum.parse(der.getData(), (byte)0x03, false);
    if (der.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #7
Source File: Ticket.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a Ticket 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 indicate if this data field is optional
 * @return an instance of Ticket.
 */
public static Ticket parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException, RealmException, KrbApErrException {
    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 Ticket(subDer);
    }
}
 
Example #8
Source File: Ticket.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a Ticket 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 indicate if this data field is optional
 * @return an instance of Ticket.
 */
public static Ticket parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException, RealmException, KrbApErrException {
    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 Ticket(subDer);
    }
}
 
Example #9
Source File: Ticket.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a Ticket 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 indicate if this data field is optional
 * @return an instance of Ticket.
 */
public static Ticket parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException, RealmException, KrbApErrException {
    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 Ticket(subDer);
    }
}
 
Example #10
Source File: KRBSafe.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes an KRBSafe 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 RealmException if an error occurs while parsing a Realm object.
 * @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,
RealmException, KrbApErrException, IOException {
    DerValue der, subDer;
    if (((encoding.getTag() & (byte)0x1F) != (byte)0x14)
        || (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() & 0x1F) == 0x00) {
        pvno = subDer.getData().getBigInteger().intValue();
        if (pvno != Krb5.PVNO)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    }
    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x01) {
        msgType = subDer.getData().getBigInteger().intValue();
        if (msgType != Krb5.KRB_SAFE)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
    }

    else
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    safeBody = KRBSafeBody.parse(der.getData(), (byte)0x02, false);
    cksum = Checksum.parse(der.getData(), (byte)0x03, false);
    if (der.getData().available() > 0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #11
Source File: Ticket.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse (unmarshal) a Ticket 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 indicate if this data field is optional
 * @return an instance of Ticket.
 */
public static Ticket parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException, RealmException, KrbApErrException {
    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 Ticket(subDer);
    }
}
 
Example #12
Source File: ASRep.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public ASRep(DerValue encoding) throws Asn1Exception,
        RealmException, KrbApErrException, IOException {
    init(encoding);
}
 
Example #13
Source File: ASRep.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public ASRep(byte[] data) throws Asn1Exception,
        RealmException, KrbApErrException, IOException {
    init(new DerValue(data));
}
 
Example #14
Source File: ASRep.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void init(DerValue encoding) throws Asn1Exception,
        RealmException, KrbApErrException, IOException {
    init(encoding, Krb5.KRB_AS_REP);
}
 
Example #15
Source File: KRBError.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public KRBError(byte[] data) throws Asn1Exception,
        RealmException, KrbApErrException, IOException {
    init(new DerValue(data));
    parseEData(eData);
}
 
Example #16
Source File: EncKrbCredPart.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initializes an EncKrbCredPart 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 RealmException if an error occurs while parsing a Realm object.
 */
private void init(DerValue encoding) throws Asn1Exception,
        IOException, RealmException {
    DerValue der, subDer;
    //may not be the correct error code for a tag
    //mismatch on an encrypted structure
    nonce = null;
    timeStamp = null;
    usec = null;
    sAddress = null;
    rAddress = null;
    if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1D)
            || (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) {
        DerValue derValues[] = subDer.getData().getSequence(1);
        ticketInfo = new KrbCredInfo[derValues.length];
        for (int i = 0; i < derValues.length; i++) {
            ticketInfo[i] = new KrbCredInfo(derValues[i]);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    if (der.getData().available() > 0) {
        if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x01) {
            subDer = der.getData().getDerValue();
            nonce = new Integer(subDer.getData().getBigInteger().intValue());
        }
    }
    if (der.getData().available() > 0) {
        timeStamp = KerberosTime.parse(der.getData(), (byte) 0x02, true);
    }
    if (der.getData().available() > 0) {
        if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x03) {
            subDer = der.getData().getDerValue();
            usec = new Integer(subDer.getData().getBigInteger().intValue());
        }
    }
    if (der.getData().available() > 0) {
        sAddress = HostAddress.parse(der.getData(), (byte) 0x04, true);
    }
    if (der.getData().available() > 0) {
        rAddress = HostAddresses.parse(der.getData(), (byte) 0x05, true);
    }
    if (der.getData().available() > 0) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
}
 
Example #17
Source File: KRBSafe.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public KRBSafe(DerValue encoding) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(encoding);
}
 
Example #18
Source File: TGSRep.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void init(DerValue encoding) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(encoding, Krb5.KRB_TGS_REP);
}
 
Example #19
Source File: KRBSafe.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public KRBSafe(byte[] data) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(new DerValue(data));
}
 
Example #20
Source File: KeyTabInputStream.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
KeyTabEntry readEntry(int entryLen, int ktVersion) throws IOException, RealmException {
    index = entryLen;
    if (index == 0) {    //in native implementation, when the last entry is deleted, a byte 0 is left.
        return null;
    }
    if (index < 0) {    //in native implementation, when one of the entries is deleted, the entry length turns to be negative, and
        skip(Math.abs(index));                //the fields are left with 0 bytes
        return null;
    }
    int principalNum = read(2);     //the number of service names.
    index -= 2;
    if (ktVersion == KRB5_KT_VNO_1) {   //V1 includes realm in the count.
        principalNum -= 1;
    }
    Realm realm = new Realm(readName());
    String[] nameParts = new String[principalNum];
    for (int i = 0; i < principalNum; i++) {
        nameParts[i] = readName();
    }
    int nameType = read(4);
    index -= 4;
    PrincipalName service = new PrincipalName(nameType, nameParts, realm);
    KerberosTime timeStamp = readTimeStamp();

    int keyVersion = read() & 0xff;
    index -= 1;
    int keyType = read(2);
    index -= 2;
    int keyLength = read(2);
    index -= 2;
    byte[] keyblock = readKey(keyLength);
    index -= keyLength;
    // There might be a 32 bit kvno here.
    // If index is zero, assume that the 8 bit key version number was
    // right, otherwise trust the new nonzero value.
    if (index >= 4) {
        int extKvno = read(4);
        if (extKvno != 0) {
            keyVersion = extKvno;
        }
        index -= 4;
    }

    // if index is negative, the keytab format must be wrong.
    if (index < 0) {
        throw new RealmException("Keytab is corrupted");
    }

    // ignore the left bytes.
    skip(index);

    return new KeyTabEntry(service, realm, timeStamp, keyVersion, keyType, keyblock);
}
 
Example #21
Source File: TGSRep.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void init(DerValue encoding) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(encoding, Krb5.KRB_TGS_REP);
}
 
Example #22
Source File: KRBError.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initializes a KRBError 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.
 * @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, subDer;
    if (((encoding.getTag() & (byte)0x1F) != (byte)0x1E)
            || (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) {

        pvno = subDer.getData().getBigInteger().intValue();
        if (pvno != Krb5.PVNO)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) == (byte)0x01) {
        msgType = subDer.getData().getBigInteger().intValue();
        if (msgType != Krb5.KRB_ERROR) {
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    cTime = KerberosTime.parse(der.getData(), (byte)0x02, true);
    if ((der.getData().peekByte() & 0x1F) == 0x03) {
        subDer = der.getData().getDerValue();
        cuSec = new Integer(subDer.getData().getBigInteger().intValue());
    }
    else cuSec = null;
    sTime = KerberosTime.parse(der.getData(), (byte)0x04, false);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) == (byte)0x05) {
        suSec = new Integer (subDer.getData().getBigInteger().intValue());
    }
    else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) == (byte)0x06) {
        errorCode = subDer.getData().getBigInteger().intValue();
    }
    else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    crealm = Realm.parse(der.getData(), (byte)0x07, true);
    cname = PrincipalName.parse(der.getData(), (byte)0x08, true, crealm);
    Realm realm = Realm.parse(der.getData(), (byte)0x09, false);
    sname = PrincipalName.parse(der.getData(), (byte)0x0A, false, realm);
    eText = null;
    eData = null;
    eCksum = null;
    if (der.getData().available() >0) {
        if ((der.getData().peekByte() & 0x1F) == 0x0B) {
            subDer = der.getData().getDerValue();
            eText = new KerberosString(subDer.getData().getDerValue())
                    .toString();
        }
    }
    if (der.getData().available() >0) {
        if ((der.getData().peekByte() & 0x1F) == 0x0C) {
            subDer = der.getData().getDerValue();
            eData = subDer.getData().getOctetString();
        }
    }
    if (der.getData().available() >0) {
        eCksum = Checksum.parse(der.getData(), (byte)0x0D, true);
    }
    if (der.getData().available() >0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
 
Example #23
Source File: TGSRep.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public TGSRep(byte[] data) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(new DerValue(data));
}
 
Example #24
Source File: KeyTab.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns fresh keys for the given Kerberos principal.
 * <p>
 * Implementation of this method should make sure the returned keys match
 * the latest content of the keytab file. The result is a newly created
 * copy that can be modified by the caller without modifying the keytab
 * object. The caller should {@link KerberosKey#destroy() destroy} the
 * result keys after they are used.
 * <p>
 * Please note that the keytab file can be created after the
 * {@code KeyTab} object is instantiated and its content may change over
 * time. Therefore, an application should call this method only when it
 * needs to use the keys. Any previous result from an earlier invocation
 * could potentially be expired.
 * <p>
 * If there is any error (say, I/O error or format error)
 * during the reading process of the KeyTab file, a saved result should be
 * returned. If there is no saved result (say, this is the first time this
 * method is called, or, all previous read attempts failed), an empty array
 * should be returned. This can make sure the result is not drastically
 * changed during the (probably slow) update of the keytab file.
 * <p>
 * Each time this method is called and the reading of the file succeeds
 * with no exception (say, I/O error or file format error),
 * the result should be saved for {@code principal}. The implementation can
 * also save keys for other principals having keys in the same keytab object
 * if convenient.
 * <p>
 * Any unsupported key read from the keytab is ignored and not included
 * in the result.
 * <p>
 * If this keytab is bound to a specific principal, calling this method on
 * another principal will return an empty array.
 *
 * @param principal the Kerberos principal, must not be null.
 * @return the keys (never null, may be empty)
 * @throws NullPointerException if the {@code principal}
 * argument is null
 * @throws SecurityException if a security manager exists and the read
 * access to the keytab file is not permitted
 */
public KerberosKey[] getKeys(KerberosPrincipal principal) {
    try {
        if (princ != null && !principal.equals(princ)) {
            return new KerberosKey[0];
        }
        PrincipalName pn = new PrincipalName(principal.getName());
        EncryptionKey[] keys = takeSnapshot().readServiceKeys(pn);
        KerberosKey[] kks = new KerberosKey[keys.length];
        for (int i=0; i<kks.length; i++) {
            Integer tmp = keys[i].getKeyVersionNumber();
            kks[i] = new KerberosKey(
                    principal,
                    keys[i].getBytes(),
                    keys[i].getEType(),
                    tmp == null ? 0 : tmp.intValue());
            keys[i].destroy();
        }
        return kks;
    } catch (RealmException re) {
        return new KerberosKey[0];
    }
}
 
Example #25
Source File: KRBCred.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initializes an KRBCred 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 {
    if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x16)
            || (encoding.isApplication() != true)
            || (encoding.isConstructed() != true)) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    DerValue der, subDer;
    der = encoding.getData().getDerValue();
    if (der.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x00) {
        pvno = subDer.getData().getBigInteger().intValue();
        if (pvno != Krb5.PVNO) {
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x01) {
        msgType = subDer.getData().getBigInteger().intValue();
        if (msgType != Krb5.KRB_CRED) {
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & 0x1F) == 0x02) {
        DerValue subsubDer = subDer.getData().getDerValue();
        if (subsubDer.getTag() != DerValue.tag_SequenceOf) {
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
        }
        Vector<Ticket> v = new Vector<>();
        while (subsubDer.getData().available() > 0) {
            v.addElement(new Ticket(subsubDer.getData().getDerValue()));
        }
        if (v.size() > 0) {
            tickets = new Ticket[v.size()];
            v.copyInto(tickets);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    encPart = EncryptedData.parse(der.getData(), (byte) 0x03, false);

    if (der.getData().available() > 0) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
}
 
Example #26
Source File: KRBSafe.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public KRBSafe(byte[] data) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(new DerValue(data));
}
 
Example #27
Source File: Ticket.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public Ticket(DerValue encoding) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(encoding);
}
 
Example #28
Source File: Ticket.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public Ticket(byte[] data) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(new DerValue(data));
}
 
Example #29
Source File: Ticket.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public Ticket(DerValue encoding) throws Asn1Exception,
RealmException, KrbApErrException, IOException {
    init(encoding);
}
 
Example #30
Source File: KRBError.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initializes a KRBError 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.
 * @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, subDer;
    if (((encoding.getTag() & (byte)0x1F) != (byte)0x1E)
            || (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) {

        pvno = subDer.getData().getBigInteger().intValue();
        if (pvno != Krb5.PVNO)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) == (byte)0x01) {
        msgType = subDer.getData().getBigInteger().intValue();
        if (msgType != Krb5.KRB_ERROR) {
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
        }
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    cTime = KerberosTime.parse(der.getData(), (byte)0x02, true);
    if ((der.getData().peekByte() & 0x1F) == 0x03) {
        subDer = der.getData().getDerValue();
        cuSec = new Integer(subDer.getData().getBigInteger().intValue());
    }
    else cuSec = null;
    sTime = KerberosTime.parse(der.getData(), (byte)0x04, false);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) == (byte)0x05) {
        suSec = new Integer (subDer.getData().getBigInteger().intValue());
    }
    else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    subDer = der.getData().getDerValue();
    if ((subDer.getTag() & (byte)0x1F) == (byte)0x06) {
        errorCode = subDer.getData().getBigInteger().intValue();
    }
    else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    Realm crealm = Realm.parse(der.getData(), (byte)0x07, true);
    cname = PrincipalName.parse(der.getData(), (byte)0x08, true, crealm);
    Realm realm = Realm.parse(der.getData(), (byte)0x09, false);
    sname = PrincipalName.parse(der.getData(), (byte)0x0A, false, realm);
    eText = null;
    eData = null;
    eCksum = null;
    if (der.getData().available() >0) {
        if ((der.getData().peekByte() & 0x1F) == 0x0B) {
            subDer = der.getData().getDerValue();
            eText = new KerberosString(subDer.getData().getDerValue())
                    .toString();
        }
    }
    if (der.getData().available() >0) {
        if ((der.getData().peekByte() & 0x1F) == 0x0C) {
            subDer = der.getData().getDerValue();
            eData = subDer.getData().getOctetString();
        }
    }
    if (der.getData().available() >0) {
        eCksum = Checksum.parse(der.getData(), (byte)0x0D, true);
    }
    if (der.getData().available() >0)
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}