Search in sources :

Example 6 with Realm

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

the class KerberosPrincipal method writeObject.

/**
     * Save the KerberosPrincipal object to a stream
     *
     * @serialData this {@code KerberosPrincipal} is serialized
     *          by writing out the PrincipalName and the
     *          realm in their DER-encoded form as specified in Section 5.2.2 of
     *          <a href=http://www.ietf.org/rfc/rfc4120.txt> RFC4120</a>.
     */
private void writeObject(ObjectOutputStream oos) throws IOException {
    PrincipalName krb5Principal;
    try {
        krb5Principal = new PrincipalName(fullName, nameType);
        oos.writeObject(krb5Principal.asn1Encode());
        oos.writeObject(krb5Principal.getRealm().asn1Encode());
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : PrincipalName(sun.security.krb5.PrincipalName) KrbException(sun.security.krb5.KrbException)

Example 7 with Realm

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

the class PrincipalName method parseName.

// XXX Error checkin consistent with MIT krb5_parse_name
// Code repetition, realm parsed again by class Realm
private static String[] parseName(String name) {
    Vector<String> tempStrings = new Vector<>();
    String temp = name;
    int i = 0;
    int componentStart = 0;
    String component;
    while (i < temp.length()) {
        if (temp.charAt(i) == NAME_COMPONENT_SEPARATOR) {
            /*
                 * If this separator is escaped then don't treat it
                 * as a separator
                 */
            if (i > 0 && temp.charAt(i - 1) == '\\') {
                temp = temp.substring(0, i - 1) + temp.substring(i, temp.length());
                continue;
            } else {
                if (componentStart <= i) {
                    component = temp.substring(componentStart, i);
                    tempStrings.addElement(component);
                }
                componentStart = i + 1;
            }
        } else {
            if (temp.charAt(i) == NAME_REALM_SEPARATOR) {
                /*
                     * If this separator is escaped then don't treat it
                     * as a separator
                     */
                if (i > 0 && temp.charAt(i - 1) == '\\') {
                    temp = temp.substring(0, i - 1) + temp.substring(i, temp.length());
                    continue;
                } else {
                    if (componentStart < i) {
                        component = temp.substring(componentStart, i);
                        tempStrings.addElement(component);
                    }
                    componentStart = i + 1;
                    break;
                }
            }
        }
        i++;
    }
    if (i == temp.length()) {
        component = temp.substring(componentStart, i);
        tempStrings.addElement(component);
    }
    String[] result = new String[tempStrings.size()];
    tempStrings.copyInto(result);
    return result;
}
Also used : KerberosString(sun.security.krb5.internal.util.KerberosString) Vector(java.util.Vector)

Example 8 with Realm

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

the class Realm method parseRealmAtSeparator.

// Extract realm from a string like dummy@REALM
public static String parseRealmAtSeparator(String name) throws RealmException {
    if (name == null) {
        throw new IllegalArgumentException("null input name is not allowed");
    }
    String temp = new String(name);
    String result = null;
    int i = 0;
    while (i < temp.length()) {
        if (temp.charAt(i) == PrincipalName.NAME_REALM_SEPARATOR) {
            if (i == 0 || temp.charAt(i - 1) != '\\') {
                if (i + 1 < temp.length()) {
                    result = temp.substring(i + 1, temp.length());
                } else {
                    throw new IllegalArgumentException("empty realm part not allowed");
                }
                break;
            }
        }
        i++;
    }
    if (result != null) {
        if (result.length() == 0)
            throw new RealmException(Krb5.REALM_NULL);
        if (!isValidRealmString(result))
            throw new RealmException(Krb5.REALM_ILLCHAR);
    }
    return result;
}
Also used : KerberosString(sun.security.krb5.internal.util.KerberosString)

Example 9 with Realm

use of sun.security.krb5.Realm 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 10 with Realm

use of sun.security.krb5.Realm 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)

Aggregations

PrincipalName (sun.security.krb5.PrincipalName)5 KerberosString (sun.security.krb5.internal.util.KerberosString)5 Asn1Exception (sun.security.krb5.Asn1Exception)4 KrbException (sun.security.krb5.KrbException)4 Realm (sun.security.krb5.Realm)4 BigInteger (java.math.BigInteger)3 Config (sun.security.krb5.Config)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Vector (java.util.Vector)1 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)1 ServicePermission (javax.security.auth.kerberos.ServicePermission)1 sun.security.krb5 (sun.security.krb5)1 RealmException (sun.security.krb5.RealmException)1 sun.security.krb5.internal (sun.security.krb5.internal)1 CredentialsCache (sun.security.krb5.internal.ccache.CredentialsCache)1 DerOutputStream (sun.security.util.DerOutputStream)1 DerValue (sun.security.util.DerValue)1