Java Code Examples for sun.security.jgss.krb5.Krb5Util#keysFromJavaxKeyTab()

The following examples show how to use sun.security.jgss.krb5.Krb5Util#keysFromJavaxKeyTab() . 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: KrbAsReqBuilder.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key) throws KrbException, IOException {
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    return new KrbAsReq(key,
        options,
        cname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses);
}
 
Example 2
Source File: KrbAsReqBuilder.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key) throws KrbException, IOException {
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    return new KrbAsReq(key,
        options,
        cname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses);
}
 
Example 3
Source File: KrbAsReqBuilder.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key) throws KrbException, IOException {
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    return new KrbAsReq(key,
        options,
        cname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses);
}
 
Example 4
Source File: KrbAsReqBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key) throws KrbException, IOException {
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    return new KrbAsReq(key,
        options,
        cname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses);
}
 
Example 5
Source File: KrbAsReqBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key) throws KrbException, IOException {
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    return new KrbAsReq(key,
        options,
        cname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses);
}
 
Example 6
Source File: KrbAsReqBuilder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key) throws KrbException, IOException {
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    return new KrbAsReq(key,
        options,
        cname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses);
}
 
Example 7
Source File: KrbAsReqBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key) throws KrbException, IOException {
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    return new KrbAsReq(key,
        options,
        cname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses);
}
 
Example 8
Source File: KerberosTest.java    From jcifs-ng with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static KerberosTicket getKerberosTicket ( KeyTab keytab, final KerberosPrincipal principal )
        throws Asn1Exception, KrbException, IOException {
    PrincipalName principalName = convertPrincipal(principal);
    EncryptionKey[] keys = Krb5Util.keysFromJavaxKeyTab(keytab, principalName);

    if ( keys == null || keys.length == 0 ) {
        throw new KrbException("Could not find any keys in keytab for " + principalName); //$NON-NLS-1$
    }

    KrbAsReqBuilder builder = new KrbAsReqBuilder(principalName, keytab);
    Credentials creds = builder.action().getCreds();
    builder.destroy();

    return Krb5Util.credsToTicket(creds);
}
 
Example 9
Source File: KerberosTest.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static KerberosTicket getKerberosTicket ( KeyTab keytab, final KerberosPrincipal principal )
        throws Asn1Exception, KrbException, IOException {
    PrincipalName principalName = convertPrincipal(principal);
    EncryptionKey[] keys = Krb5Util.keysFromJavaxKeyTab(keytab, principalName);

    if ( keys == null || keys.length == 0 ) {
        throw new KrbException("Could not find any keys in keytab for " + principalName); //$NON-NLS-1$
    }

    KrbAsReqBuilder builder = new KrbAsReqBuilder(principalName, keytab);
    Credentials creds = builder.action().getCreds();
    builder.destroy();

    return Krb5Util.credsToTicket(creds);
}
 
Example 10
Source File: KrbAsReqBuilder.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key, ReferralsState referralsState)
        throws KrbException, IOException {
    PAData[] extraPAs = null;
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    options = (options == null) ? new KDCOptions() : options;
    if (referralsState.isEnabled()) {
        options.set(KDCOptions.CANONICALIZE, true);
        extraPAs = new PAData[]{ new PAData(Krb5.PA_REQ_ENC_PA_REP,
                new byte[]{}) };
    } else {
        options.set(KDCOptions.CANONICALIZE, false);
    }
    return new KrbAsReq(key,
        options,
        refCname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses,
        extraPAs);
}
 
Example 11
Source File: KrbAsReqBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key, ReferralsState referralsState)
        throws KrbException, IOException {
    PAData[] extraPAs = null;
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    options = (options == null) ? new KDCOptions() : options;
    if (referralsState.isEnabled()) {
        options.set(KDCOptions.CANONICALIZE, true);
        extraPAs = new PAData[]{ new PAData(Krb5.PA_REQ_ENC_PA_REP,
                new byte[]{}) };
    } else {
        options.set(KDCOptions.CANONICALIZE, false);
    }
    return new KrbAsReq(key,
        options,
        refCname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses,
        extraPAs);
}
 
Example 12
Source File: KrbAsReqBuilder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build a KrbAsReq object from all info fed above. Normally this method
 * will be called twice: initial AS-REQ and second with pakey
 * @param key null (initial AS-REQ) or pakey (with preauth)
 * @return the KrbAsReq object
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReq build(EncryptionKey key, ReferralsState referralsState)
        throws KrbException, IOException {
    PAData[] extraPAs = null;
    int[] eTypes;
    if (password != null) {
        eTypes = EType.getDefaults("default_tkt_enctypes");
    } else {
        EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
        eTypes = EType.getDefaults("default_tkt_enctypes",
                ks);
        for (EncryptionKey k: ks) k.destroy();
    }
    options = (options == null) ? new KDCOptions() : options;
    if (referralsState.isEnabled()) {
        options.set(KDCOptions.CANONICALIZE, true);
        extraPAs = new PAData[]{ new PAData(Krb5.PA_REQ_ENC_PA_REP,
                new byte[]{}) };
    } else {
        options.set(KDCOptions.CANONICALIZE, false);
    }
    return new KrbAsReq(key,
        options,
        refCname,
        sname,
        from,
        till,
        rtime,
        eTypes,
        addresses,
        extraPAs);
}
 
Example 13
Source File: KrbAsReqBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = null;
    EncryptionKey pakey = null;
    ReferralsState referralsState = new ReferralsState();
    while (true) {
        if (referralsState.refreshComm()) {
            comm = new KdcComm(refCname.getRealmAsString());
        }
        try {
            req = build(pakey, referralsState);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                if (referralsState.handleError(ke)) {
                    pakey = null;
                    preAuthFailedOnce = false;
                    continue;
                }
                throw ke;
            }
        }
    }
}
 
Example 14
Source File: KrbAsReqBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = new KdcComm(cname.getRealmAsString());
    EncryptionKey pakey = null;
    while (true) {
        try {
            req = build(pakey);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                throw ke;
            }
        }
    }
}
 
Example 15
Source File: KrbAsReqBuilder.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = new KdcComm(cname.getRealmAsString());
    EncryptionKey pakey = null;
    while (true) {
        try {
            req = build(pakey);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                throw ke;
            }
        }
    }
}
 
Example 16
Source File: KrbAsReqBuilder.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = new KdcComm(cname.getRealmAsString());
    EncryptionKey pakey = null;
    while (true) {
        try {
            req = build(pakey);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                throw ke;
            }
        }
    }
}
 
Example 17
Source File: KrbAsReqBuilder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = null;
    EncryptionKey pakey = null;
    ReferralsState referralsState = new ReferralsState();
    while (true) {
        if (referralsState.refreshComm()) {
            comm = new KdcComm(refCname.getRealmAsString());
        }
        try {
            req = build(pakey, referralsState);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                if (referralsState.handleError(ke)) {
                    pakey = null;
                    preAuthFailedOnce = false;
                    continue;
                }
                throw ke;
            }
        }
    }
}
 
Example 18
Source File: KrbAsReqBuilder.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = new KdcComm(cname.getRealmAsString());
    EncryptionKey pakey = null;
    while (true) {
        try {
            req = build(pakey);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                throw ke;
            }
        }
    }
}
 
Example 19
Source File: KrbAsReqBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = null;
    EncryptionKey pakey = null;
    ReferralsState referralsState = new ReferralsState();
    while (true) {
        if (referralsState.refreshComm()) {
            comm = new KdcComm(refCname.getRealmAsString());
        }
        try {
            req = build(pakey, referralsState);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                if (referralsState.handleError(ke)) {
                    pakey = null;
                    preAuthFailedOnce = false;
                    continue;
                }
                throw ke;
            }
        }
    }
}
 
Example 20
Source File: KrbAsReqBuilder.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Communication until AS-REP or non preauth-related KRB-ERROR received
 * @throws KrbException
 * @throws IOException
 */
private KrbAsReqBuilder send() throws KrbException, IOException {
    boolean preAuthFailedOnce = false;
    KdcComm comm = null;
    EncryptionKey pakey = null;
    ReferralsState referralsState = new ReferralsState();
    while (true) {
        if (referralsState.refreshComm()) {
            comm = new KdcComm(refCname.getRealmAsString());
        }
        try {
            req = build(pakey, referralsState);
            rep = new KrbAsRep(comm.send(req.encoding()));
            return this;
        } catch (KrbException ke) {
            if (!preAuthFailedOnce && (
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED ||
                    ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED)) {
                if (Krb5.DEBUG) {
                    System.out.println("KrbAsReqBuilder: " +
                            "PREAUTH FAILED/REQ, re-send AS-REQ");
                }
                preAuthFailedOnce = true;
                KRBError kerr = ke.getError();
                int paEType = PAData.getPreferredEType(kerr.getPA(),
                        EType.getDefaults("default_tkt_enctypes")[0]);
                if (password == null) {
                    EncryptionKey[] ks = Krb5Util.keysFromJavaxKeyTab(ktab, cname);
                    pakey = EncryptionKey.findKey(paEType, ks);
                    if (pakey != null) pakey = (EncryptionKey)pakey.clone();
                    for (EncryptionKey k: ks) k.destroy();
                } else {
                    pakey = EncryptionKey.acquireSecretKey(cname,
                            password,
                            paEType,
                            PAData.getSaltAndParams(
                                paEType, kerr.getPA()));
                }
                paList = kerr.getPA();  // Update current paList
            } else {
                if (referralsState.handleError(ke)) {
                    pakey = null;
                    preAuthFailedOnce = false;
                    continue;
                }
                throw ke;
            }
        }
    }
}