Java Code Examples for sun.security.krb5.internal.ktab.KeyTab#create()
The following examples show how to use
sun.security.krb5.internal.ktab.KeyTab#create() .
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: FileKeyTab.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String name = "ktab"; KeyTab kt = KeyTab.create(name); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); check(name); check("FILE:" + name); name = new File(name).getAbsolutePath().toString(); check(name); check("FILE:" + name); // The bug reporter uses this style, should only work for // absolute path check("FILE:/" + name); }
Example 2
Source File: FileKeyTab.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String name = "ktab"; KeyTab kt = KeyTab.create(name); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); check(name); check("FILE:" + name); name = new File(name).getAbsolutePath().toString(); check(name); check("FILE:" + name); // The bug reporter uses this style, should only work for // absolute path check("FILE:/" + name); }
Example 3
Source File: KDC.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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(); }
Example 4
Source File: FileKeyTab.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String name = "ktab"; KeyTab kt = KeyTab.create(name); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); check(name); check("FILE:" + name); name = new File(name).getAbsolutePath().toString(); check(name); check("FILE:" + name); // The bug reporter uses this style, should only work for // absolute path check("FILE:/" + name); }
Example 5
Source File: KeyTabIndex.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { KeyTab kt = KeyTab.create("ktab"); // Two entries with very different length, so that it's easy to // observice the abnormal change of "index" field. kt.addEntry(new PrincipalName( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@A"), "x".toCharArray(), 1, true); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); Runnable t = new Runnable() { @Override public void run() { KeyTab.getInstance("ktab").getClass(); } }; for (int i=0; i<10; i++) { new Thread(t).start(); } }
Example 6
Source File: KeyTabIndex.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { KeyTab kt = KeyTab.create("ktab"); // Two entries with very different length, so that it's easy to // observice the abnormal change of "index" field. kt.addEntry(new PrincipalName( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@A"), "x".toCharArray(), 1, true); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); Runnable t = new Runnable() { @Override public void run() { KeyTab.getInstance("ktab").getClass(); } }; for (int i=0; i<10; i++) { new Thread(t).start(); } }
Example 7
Source File: KeyTabIndex.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { KeyTab kt = KeyTab.create("ktab"); // Two entries with very different length, so that it's easy to // observice the abnormal change of "index" field. kt.addEntry(new PrincipalName( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@A"), "x".toCharArray(), 1, true); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); Runnable t = new Runnable() { @Override public void run() { KeyTab.getInstance("ktab").getClass(); } }; for (int i=0; i<10; i++) { new Thread(t).start(); } }
Example 8
Source File: KDC.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * 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(); }
Example 9
Source File: KDC.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * 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(); }
Example 10
Source File: FileKeyTab.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String name = "ktab"; KeyTab kt = KeyTab.create(name); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); check(name); check("FILE:" + name); name = new File(name).getAbsolutePath().toString(); check(name); check("FILE:" + name); // The bug reporter uses this style, should only work for // absolute path check("FILE:/" + name); }
Example 11
Source File: FileKeyTab.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String name = "ktab"; KeyTab kt = KeyTab.create(name); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); check(name); check("FILE:" + name); name = new File(name).getAbsolutePath().toString(); check(name); check("FILE:" + name); // The bug reporter uses this style, should only work for // absolute path check("FILE:/" + name); }
Example 12
Source File: KeyTabIndex.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { KeyTab kt = KeyTab.create("ktab"); // Two entries with very different length, so that it's easy to // observice the abnormal change of "index" field. kt.addEntry(new PrincipalName( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@A"), "x".toCharArray(), 1, true); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); Runnable t = new Runnable() { @Override public void run() { KeyTab.getInstance("ktab").getClass(); } }; for (int i=0; i<10; i++) { new Thread(t).start(); } }
Example 13
Source File: FileKeyTab.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String name = "ktab"; KeyTab kt = KeyTab.create(name); kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1, true); kt.save(); check(name); check("FILE:" + name); name = new File(name).getAbsolutePath().toString(); check(name); check("FILE:" + name); // The bug reporter uses this style, should only work for // absolute path check("FILE:/" + name); }
Example 14
Source File: KDC.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 = null; if (nativeKdc == null) { ktab = append ? KeyTab.getInstance(tab) : KeyTab.create(tab); } Iterable<String> entries = (names.length != 0) ? Arrays.asList(names): passwords.keySet(); for (String name : entries) { if (name.indexOf('@') < 0) { name = name + "@" + realm; } if (nativeKdc == null) { 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); } else { nativeKdc.ktadd(name, tab); } } if (nativeKdc == null) { ktab.save(); } }
Example 15
Source File: MoreKvno.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { OneKDC kdc = new OneKDC(null); kdc.writeJAASConf(); // Rewrite keytab, 3 set of keys with different kvno KeyTab ktab = KeyTab.create(OneKDC.KTAB); p = new PrincipalName( OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST); ktab.addEntry(p, "pass1".toCharArray(), 1, true); ktab.addEntry(p, "pass3".toCharArray(), 3, true); ktab.addEntry(p, "pass2".toCharArray(), 2, true); ktab.save(); char[] pass = "pass2".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); pass = "pass3".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); // "server" initiate also, check pass2 is used at authentication go(OneKDC.SERVER, "server", pass); try { pass = "pass4".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); throw new Exception("This test should fail"); } catch (GSSException gsse) { // Since 7197159, different kvno is accepted, this return code // will never be thrown out again. //KrbException ke = (KrbException)gsse.getCause(); //if (ke.returnCode() != Krb5.KRB_AP_ERR_BADKEYVER) { // throw new Exception("Not expected failure code: " + // ke.returnCode()); //} } }
Example 16
Source File: MoreKvno.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { OneKDC kdc = new OneKDC(null); kdc.writeJAASConf(); // Rewrite keytab, 3 set of keys with different kvno KeyTab ktab = KeyTab.create(OneKDC.KTAB); p = new PrincipalName( OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST); ktab.addEntry(p, "pass1".toCharArray(), 1, true); ktab.addEntry(p, "pass3".toCharArray(), 3, true); ktab.addEntry(p, "pass2".toCharArray(), 2, true); ktab.save(); char[] pass = "pass2".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); pass = "pass3".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); // "server" initiate also, check pass2 is used at authentication go(OneKDC.SERVER, "server", pass); try { pass = "pass4".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); throw new Exception("This test should fail"); } catch (GSSException gsse) { // Since 7197159, different kvno is accepted, this return code // will never be thrown out again. //KrbException ke = (KrbException)gsse.getCause(); //if (ke.returnCode() != Krb5.KRB_AP_ERR_BADKEYVER) { // throw new Exception("Not expected failure code: " + // ke.returnCode()); //} } }
Example 17
Source File: KvnoNA.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { OneKDC kdc = new OneKDC(null); kdc.writeJAASConf(); // In KDC, it's 2 char[] pass = "pass2".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); // In ktab, kvno is 1 or 3, 3 has the same password KeyTab ktab = KeyTab.create(OneKDC.KTAB); PrincipalName p = new PrincipalName( OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST); ktab.addEntry(p, "pass1".toCharArray(), 1, true); ktab.addEntry(p, "pass2".toCharArray(), 3, true); ktab.save(); Context c, s; c = Context.fromUserPass("dummy", "bogus".toCharArray(), false); s = Context.fromJAAS("server"); c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID); s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID); Context.handshake(c, s); s.dispose(); c.dispose(); }
Example 18
Source File: KvnoNA.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { OneKDC kdc = new OneKDC(null); kdc.writeJAASConf(); // In KDC, it's 2 char[] pass = "pass2".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); // In ktab, kvno is 1 or 3, 3 has the same password KeyTab ktab = KeyTab.create(OneKDC.KTAB); PrincipalName p = new PrincipalName( OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST); ktab.addEntry(p, "pass1".toCharArray(), 1, true); ktab.addEntry(p, "pass2".toCharArray(), 3, true); ktab.save(); Context c, s; c = Context.fromUserPass("dummy", "bogus".toCharArray(), false); s = Context.fromJAAS("server"); c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID); s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID); Context.handshake(c, s); s.dispose(); c.dispose(); }
Example 19
Source File: KvnoNA.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { OneKDC kdc = new OneKDC(null); kdc.writeJAASConf(); // In KDC, it's 2 char[] pass = "pass2".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); // In ktab, kvno is 1 or 3, 3 has the same password KeyTab ktab = KeyTab.create(OneKDC.KTAB); PrincipalName p = new PrincipalName( OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST); ktab.addEntry(p, "pass1".toCharArray(), 1, true); ktab.addEntry(p, "pass2".toCharArray(), 3, true); ktab.save(); Context c, s; c = Context.fromUserPass("dummy", "bogus".toCharArray(), false); s = Context.fromJAAS("server"); c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID); s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID); Context.handshake(c, s); s.dispose(); c.dispose(); }
Example 20
Source File: MoreKvno.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { OneKDC kdc = new OneKDC(null); kdc.writeJAASConf(); // Rewrite keytab, 3 set of keys with different kvno KeyTab ktab = KeyTab.create(OneKDC.KTAB); p = new PrincipalName( OneKDC.SERVER+"@"+OneKDC.REALM, PrincipalName.KRB_NT_SRV_HST); ktab.addEntry(p, "pass1".toCharArray(), 1, true); ktab.addEntry(p, "pass3".toCharArray(), 3, true); ktab.addEntry(p, "pass2".toCharArray(), 2, true); ktab.save(); char[] pass = "pass2".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); pass = "pass3".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); // "server" initiate also, check pass2 is used at authentication go(OneKDC.SERVER, "server", pass); try { pass = "pass4".toCharArray(); kdc.addPrincipal(OneKDC.SERVER, pass); go(OneKDC.SERVER, "com.sun.security.jgss.krb5.accept", pass); throw new Exception("This test should fail"); } catch (GSSException gsse) { // Since 7197159, different kvno is accepted, this return code // will never be thrown out again. //KrbException ke = (KrbException)gsse.getCause(); //if (ke.returnCode() != Krb5.KRB_AP_ERR_BADKEYVER) { // throw new Exception("Not expected failure code: " + // ke.returnCode()); //} } }