Search in sources :

Example 6 with Config

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

the class PrincipalName method mapHostToRealm.

static String mapHostToRealm(String name) {
    String result = null;
    try {
        String subname = null;
        Config c = Config.getInstance();
        if ((result = c.get("domain_realm", name)) != null)
            return result;
        else {
            for (int i = 1; i < name.length(); i++) {
                if ((name.charAt(i) == '.') && (i != name.length() - 1)) {
                    //mapping could be .ibm.com = AUSTIN.IBM.COM
                    subname = name.substring(i);
                    result = c.get("domain_realm", subname);
                    if (result != null) {
                        break;
                    } else {
                        //or mapping could be ibm.com = AUSTIN.IBM.COM
                        subname = name.substring(i + 1);
                        result = c.get("domain_realm", subname);
                        if (result != null) {
                            break;
                        }
                    }
                }
            }
        }
    } catch (KrbException e) {
    }
    return result;
}
Also used : KerberosString(sun.security.krb5.internal.util.KerberosString)

Example 7 with Config

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

the class EType method initStatic.

public static void initStatic() {
    boolean allowed = false;
    try {
        Config cfg = Config.getInstance();
        String temp = cfg.get("libdefaults", "allow_weak_crypto");
        if (temp != null && temp.equals("true"))
            allowed = true;
    } catch (Exception exc) {
        if (DEBUG) {
            System.out.println("Exception in getting allow_weak_crypto, " + "using default value " + exc.getMessage());
        }
    }
    allowWeakCrypto = allowed;
}
Also used : Config(sun.security.krb5.Config) KrbCryptoException(sun.security.krb5.KrbCryptoException) KrbException(sun.security.krb5.KrbException)

Example 8 with Config

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

the class KDC method writeKtab.

/**
     * Writes or appends keys into a keytab.
     * <p>
     * Attention: This is the most basic one of a series of methods below on
     * keytab creation or modification. All these methods reference krb5.conf
     * settings. If you need to modify krb5.conf or switch to another krb5.conf
     * later, please call <code>Config.refresh()</code> again. For example:
     * <pre>
     * kdc.writeKtab("/etc/kdc/ktab", true);  // Config is initialized,
     * System.setProperty("java.security.krb5.conf", "/home/mykrb5.conf");
     * Config.refresh();
     * </pre>
     * Inside this method there are 2 places krb5.conf is used:
     * <ol>
     * <li> (Fatal) Generating keys: EncryptionKey.acquireSecretKeys
     * <li> (Has workaround) Creating PrincipalName
     * </ol>
     * @param tab the keytab file name
     * @param append true if append, otherwise, overwrite.
     * @param names the names to write into, write all if names is empty
     */
public void writeKtab(String tab, boolean append, String... names) throws IOException, KrbException {
    KeyTab ktab = append ? KeyTab.getInstance(tab) : KeyTab.create(tab);
    Iterable<String> entries = (names.length != 0) ? Arrays.asList(names) : passwords.keySet();
    for (String name : entries) {
        char[] pass = passwords.get(name);
        int kvno = 0;
        if (Character.isDigit(pass[pass.length - 1])) {
            kvno = pass[pass.length - 1] - '0';
        }
        PrincipalName pn = new PrincipalName(name, name.indexOf('/') < 0 ? PrincipalName.KRB_NT_UNKNOWN : PrincipalName.KRB_NT_SRV_HST);
        ktab.addEntry(pn, getSalt(pn), pass, kvno, true);
    }
    ktab.save();
}
Also used : KeyTab(sun.security.krb5.internal.ktab.KeyTab)

Example 9 with Config

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

the class DNS method main.

public static void main(String[] args) throws Exception {
    System.setProperty("java.security.krb5.conf", System.getProperty("test.src", ".") + "/no-such-file.conf");
    Config config = Config.getInstance();
    try {
        String r = config.getDefaultRealm();
        throw new Exception("What? There is a default realm " + r + "?");
    } catch (KrbException ke) {
        ke.printStackTrace();
        if (ke.getCause() != null) {
            throw new Exception("There should be no cause. Won't try DNS");
        }
    }
    String kdcs = config.getKDCList("X");
    if (!kdcs.equals("a.com.:88 b.com.:99") && !kdcs.equals("a.com. b.com.:99")) {
        throw new Exception("Strange KDC: [" + kdcs + "]");
    }
    ;
}
Also used : Config(sun.security.krb5.Config) KrbException(sun.security.krb5.KrbException) KrbException(sun.security.krb5.KrbException)

Example 10 with Config

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

the class SCDynamicConfigTest method main.

public static void main(String[] args) throws Exception {
    // Reconstruct a typical SCDynamicConfig.getKerberosConfig() output
    Hashtable<String, Object> conf = new Hashtable<>();
    Hashtable<String, Object> libdefaults = new Hashtable<>();
    libdefaults.put("default_realm", "REALM.COM");
    conf.put("libdefaults", libdefaults);
    Hashtable<String, Object> realms = new Hashtable<>();
    Hashtable<String, Object> thisRealm = new Hashtable<>();
    realms.put("REALM.COM", thisRealm);
    thisRealm.put("kpasswd", hosts());
    thisRealm.put("kadmin", hosts());
    thisRealm.put("kdc", hosts());
    conf.put("realms", realms);
    Hashtable<String, Object> domain_realm = new Hashtable<>();
    domain_realm.put(".realm.com", "REALM.COM");
    domain_realm.put("realm.com", "REALM.COM");
    conf.put("domain_realm", domain_realm);
    System.out.println("SCDynamicConfig:\n");
    System.out.println(conf);
    // Simulate SCDynamicConfig.getConfig() output
    Method m = SCDynamicStoreConfig.class.getDeclaredMethod("convertNativeConfig", Hashtable.class);
    m.setAccessible(true);
    conf = (Hashtable) m.invoke(null, conf);
    System.out.println("\nkrb5.conf:\n");
    System.out.println(conf);
    // Feed it into a Config object
    System.setProperty("java.security.krb5.conf", "not-a-file");
    Config cf = Config.getInstance();
    Field f = Config.class.getDeclaredField("stanzaTable");
    f.setAccessible(true);
    f.set(cf, conf);
    System.out.println("\nConfig:\n");
    System.out.println(cf);
    if (!cf.getDefaultRealm().equals("REALM.COM")) {
        throw new Exception();
    }
    if (!cf.getKDCList("REALM.COM").equals("127.0.0.1 127.0.0.2")) {
        throw new Exception();
    }
    if (!cf.get("domain_realm", ".realm.com").equals("REALM.COM")) {
        throw new Exception();
    }
}
Also used : Field(java.lang.reflect.Field) Hashtable(java.util.Hashtable) SCDynamicStoreConfig(sun.security.krb5.SCDynamicStoreConfig) Config(sun.security.krb5.Config) Method(java.lang.reflect.Method)

Aggregations

Config (sun.security.krb5.Config)8 KrbException (sun.security.krb5.KrbException)3 KeyTab (sun.security.krb5.internal.ktab.KeyTab)2 KerberosString (sun.security.krb5.internal.util.KerberosString)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)1 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)1 JULogging (org.neo4j.driver.internal.logging.JULogging)1 BoltServerAddress (org.neo4j.driver.internal.net.BoltServerAddress)1 Config (org.neo4j.driver.v1.Config)1 Driver (org.neo4j.driver.v1.Driver)1 Session (org.neo4j.driver.v1.Session)1 ClientException (org.neo4j.driver.v1.exceptions.ClientException)1 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)1