Search in sources :

Example 1 with Asn1Exception

use of sun.security.krb5.Asn1Exception in project jdk8u_jdk by JetBrains.

the class KerberosTime method parse.

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

Example 2 with Asn1Exception

use of sun.security.krb5.Asn1Exception in project jdk8u_jdk by JetBrains.

the class PAData method getSaltAndParams.

/**
     * Fetches salt and s2kparams value for eType in a series of PA-DATAs.
     * 1. ETYPE-INFO2-ENTRY with unknown s2kparams ignored
     * 2. PA-ETYPE-INFO2 preferred to PA-ETYPE-INFO preferred to PA-PW-SALT.
     * 3. multiple entries for same etype in one PA-DATA, use the first one.
     * 4. Multiple PA-DATA with same type, choose the last one
     * (This is useful when PA-DATAs from KRB-ERROR and AS-REP are combined).
     * @return salt and s2kparams. can be null if not found
     */
public static SaltAndParams getSaltAndParams(int eType, PAData[] pas) throws Asn1Exception, IOException {
    if (pas == null)
        return null;
    DerValue d = null, d2 = null;
    String paPwSalt = null;
    for (PAData p : pas) {
        if (p.getValue() == null)
            continue;
        switch(p.getType()) {
            case Krb5.PA_PW_SALT:
                paPwSalt = new String(p.getValue(), KerberosString.MSNAME ? "UTF8" : "8859_1");
                break;
            case Krb5.PA_ETYPE_INFO:
                d = new DerValue(p.getValue());
                break;
            case Krb5.PA_ETYPE_INFO2:
                d2 = new DerValue(p.getValue());
                break;
        }
    }
    if (d2 != null) {
        while (d2.data.available() > 0) {
            DerValue value = d2.data.getDerValue();
            ETypeInfo2 tmp = new ETypeInfo2(value);
            if (tmp.getParams() == null && tmp.getEType() == eType) {
                // we don't support non-null s2kparams
                return new SaltAndParams(tmp.getSalt(), tmp.getParams());
            }
        }
    }
    if (d != null) {
        while (d.data.available() > 0) {
            DerValue value = d.data.getDerValue();
            ETypeInfo tmp = new ETypeInfo(value);
            if (tmp.getEType() == eType) {
                return new SaltAndParams(tmp.getSalt(), null);
            }
        }
    }
    if (paPwSalt != null) {
        return new SaltAndParams(paPwSalt, null);
    }
    return null;
}
Also used : KerberosString(sun.security.krb5.internal.util.KerberosString)

Example 3 with Asn1Exception

use of sun.security.krb5.Asn1Exception in project jdk8u_jdk by JetBrains.

the class KRBPriv method init.

/**
     * Initializes an KRBPriv 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 {
    DerValue der, subDer;
    if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x15) || (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_PRIV)
            throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
    } 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);
}
Also used : Asn1Exception(sun.security.krb5.Asn1Exception)

Example 4 with Asn1Exception

use of sun.security.krb5.Asn1Exception in project jdk8u_jdk by JetBrains.

the class KRBSafe method init.

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

Example 5 with Asn1Exception

use of sun.security.krb5.Asn1Exception in project jdk8u_jdk by JetBrains.

the class PAForUserEnc method asn1Encode.

public byte[] asn1Encode() throws Asn1Exception, IOException {
    DerOutputStream bytes = new DerOutputStream();
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), name.asn1Encode());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), name.getRealm().asn1Encode());
    try {
        Checksum cks = new Checksum(Checksum.CKSUMTYPE_HMAC_MD5_ARCFOUR, getS4UByteArray(), key, KeyUsage.KU_PA_FOR_USER_ENC_CKSUM);
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cks.asn1Encode());
    } catch (KrbException ke) {
        throw new IOException(ke);
    }
    DerOutputStream temp = new DerOutputStream();
    temp.putDerValue(new KerberosString(AUTH_PACKAGE).toDerValue());
    bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), temp);
    temp = new DerOutputStream();
    temp.write(DerValue.tag_Sequence, bytes);
    return temp.toByteArray();
}
Also used : DerOutputStream(sun.security.util.DerOutputStream) IOException(java.io.IOException) KerberosString(sun.security.krb5.internal.util.KerberosString)

Aggregations

IOException (java.io.IOException)13 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)10 Asn1Exception (sun.security.krb5.Asn1Exception)9 TlvException (es.gob.jmulticard.asn1.TlvException)8 DError (org.kse.gui.error.DError)6 Asn1Exception (org.kse.utilities.asn1.Asn1Exception)6 DecoderObject (es.gob.jmulticard.asn1.DecoderObject)4 Tlv (es.gob.jmulticard.asn1.Tlv)4 X509Certificate (java.security.cert.X509Certificate)4 ASN1Exception (codec.asn1.ASN1Exception)3 PFX (codec.pkcs12.PFX)3 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)3 InvalidCardException (es.gob.jmulticard.card.InvalidCardException)3 FileNotFoundException (es.gob.jmulticard.card.iso7816four.FileNotFoundException)3 Iso7816FourCardException (es.gob.jmulticard.card.iso7816four.Iso7816FourCardException)3 BigInteger (java.math.BigInteger)3 KerberosString (sun.security.krb5.internal.util.KerberosString)3 Cdf (es.gob.jmulticard.asn1.der.pkcs15.Cdf)2 Odf (es.gob.jmulticard.asn1.der.pkcs15.Odf)2 Path (es.gob.jmulticard.asn1.der.pkcs15.Path)2