Search in sources :

Example 31 with ASN1Exception

use of com.unboundid.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.

the class EncKrbPrivPart method init.

/**
     * Initializes an EncKrbPrivPart 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.
     */
private void init(DerValue encoding) throws Asn1Exception, IOException {
    DerValue der, subDer;
    if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1C) || (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) {
        userData = subDer.getData().getOctetString();
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true);
    if ((der.getData().peekByte() & 0x1F) == 0x02) {
        subDer = der.getData().getDerValue();
        usec = new Integer(subDer.getData().getBigInteger().intValue());
    } else {
        usec = null;
    }
    if ((der.getData().peekByte() & 0x1F) == 0x03) {
        subDer = der.getData().getDerValue();
        seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
    } else {
        seqNumber = null;
    }
    sAddress = HostAddress.parse(der.getData(), (byte) 0x04, false);
    if (der.getData().available() > 0) {
        rAddress = HostAddress.parse(der.getData(), (byte) 0x05, true);
    }
    if (der.getData().available() > 0) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
}
Also used : BigInteger(java.math.BigInteger) Asn1Exception(sun.security.krb5.Asn1Exception)

Example 32 with ASN1Exception

use of com.unboundid.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.

the class EncKrbCredPart method init.

/**
     * 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);
    }
}
Also used : BigInteger(java.math.BigInteger) Asn1Exception(sun.security.krb5.Asn1Exception)

Example 33 with ASN1Exception

use of com.unboundid.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.

the class Ticket method init.

/**
     * 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);
}
Also used : Asn1Exception(sun.security.krb5.Asn1Exception) Realm(sun.security.krb5.Realm)

Example 34 with ASN1Exception

use of com.unboundid.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.

the class KRBError method init.

/**
     * 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);
}
Also used : BigInteger(java.math.BigInteger) KerberosString(sun.security.krb5.internal.util.KerberosString) Asn1Exception(sun.security.krb5.Asn1Exception) Realm(sun.security.krb5.Realm)

Example 35 with ASN1Exception

use of com.unboundid.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.

the class KerberosTime method toKerberosTime.

private static long toKerberosTime(String time) throws Asn1Exception {
    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"));
    // so that millisecond is zero
    calendar.clear();
    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();
}
Also used : Calendar(java.util.Calendar) Asn1Exception(sun.security.krb5.Asn1Exception)

Aggregations

IOException (java.io.IOException)18 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)16 ASN1Exception (com.unboundid.asn1.ASN1Exception)12 TlvException (es.gob.jmulticard.asn1.TlvException)12 Asn1Exception (sun.security.krb5.Asn1Exception)11 ASN1Element (com.unboundid.asn1.ASN1Element)8 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)8 NotNull (com.unboundid.util.NotNull)8 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)7 CertificateException (java.security.cert.CertificateException)7 X509Certificate (java.security.cert.X509Certificate)7 Asn1Exception (org.kse.utilities.asn1.Asn1Exception)7 ASN1Exception (org.wildfly.security.asn1.ASN1Exception)6 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)5 Cdf (es.gob.jmulticard.asn1.der.pkcs15.Cdf)5 CryptoCardException (es.gob.jmulticard.card.CryptoCardException)5 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)4 DecoderObject (es.gob.jmulticard.asn1.DecoderObject)4 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)4 ArrayList (java.util.ArrayList)4