sun.security.krb5.internal.ktab.KeyTab Java Examples
The following examples show how to use
sun.security.krb5.internal.ktab.KeyTab.
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: KtabZero.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // 0. Non-existing keytab Files.deleteIfExists(Paths.get(NAME)); check(true); // 1. Create with KeyTab Files.deleteIfExists(Paths.get(NAME)); KeyTab.getInstance(NAME).save(); check(false); // 2. Create with the tool Files.deleteIfExists(Paths.get(NAME)); try { Class ktab = Class.forName("sun.security.krb5.internal.tools.Ktab"); ktab.getDeclaredMethod("main", String[].class).invoke(null, (Object)(("-k " + NAME + " -a me@HERE pass").split(" "))); } catch (ClassNotFoundException cnfe) { // Only Windows has ktab tool System.out.println("No ktab tool here. Ignored."); return; } check(false); }
Example #2
Source File: KeyTabIndex.java From TencentKona-8 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 #3
Source File: KtabZero.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // 0. Non-existing keytab Files.deleteIfExists(Paths.get(NAME)); check(true); // 1. Create with KeyTab Files.deleteIfExists(Paths.get(NAME)); KeyTab.getInstance(NAME).save(); check(false); // 2. Create with the tool Files.deleteIfExists(Paths.get(NAME)); try { Class ktab = Class.forName("sun.security.krb5.internal.tools.Ktab"); ktab.getDeclaredMethod("main", String[].class).invoke(null, (Object)(("-k " + NAME + " -a me@HERE pass").split(" "))); } catch (ClassNotFoundException cnfe) { // Only Windows has ktab tool System.out.println("No ktab tool here. Ignored."); return; } check(false); }
Example #4
Source File: KtabCheck.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }
Example #5
Source File: KtabCheck.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }
Example #6
Source File: KtabCheck.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }
Example #7
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 #8
Source File: FileKeyTab.java From openjdk-jdk8u-backup 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 #9
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 #10
Source File: KeyTabIndex.java From dragonwell8_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 #11
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 #12
Source File: KeyTabIndex.java From openjdk-jdk8u 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: KtabZero.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // 0. Non-existing keytab Files.deleteIfExists(Paths.get(NAME)); check(true); // 1. Create with KeyTab Files.deleteIfExists(Paths.get(NAME)); KeyTab.getInstance(NAME).save(); check(false); // 2. Create with the tool Files.deleteIfExists(Paths.get(NAME)); try { Class ktab = Class.forName("sun.security.krb5.internal.tools.Ktab"); ktab.getDeclaredMethod("main", String[].class).invoke(null, (Object)(("-k " + NAME + " -a me@HERE pass").split(" "))); } catch (ClassNotFoundException cnfe) { // Only Windows has ktab tool System.out.println("No ktab tool here. Ignored."); return; } check(false); }
Example #14
Source File: KtabCheck.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }
Example #15
Source File: FileKeyTab.java From openjdk-jdk8u 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 #16
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 #17
Source File: KtabCheck.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }
Example #18
Source File: KtabZero.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // 0. Non-existing keytab Files.deleteIfExists(Paths.get(NAME)); check(true); // 1. Create with KeyTab Files.deleteIfExists(Paths.get(NAME)); KeyTab.getInstance(NAME).save(); check(false); // 2. Create with the tool Files.deleteIfExists(Paths.get(NAME)); try { Class ktab = Class.forName("sun.security.krb5.internal.tools.Ktab"); ktab.getDeclaredMethod("main", String[].class).invoke(null, (Object)(("-k " + NAME + " -a me@HERE pass").split(" "))); } catch (ClassNotFoundException cnfe) { // Only Windows has ktab tool System.out.println("No ktab tool here. Ignored."); return; } check(false); }
Example #19
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 #20
Source File: KDC.java From openjdk-jdk9 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 #21
Source File: FileKeyTab.java From hottub 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 #22
Source File: KeyTabIndex.java From jdk8u60 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 #23
Source File: KtabCheck.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }
Example #24
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 #25
Source File: KtabZero.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // 0. Non-existing keytab Files.deleteIfExists(Paths.get(NAME)); check(true); // 1. Create with KeyTab Files.deleteIfExists(Paths.get(NAME)); KeyTab.getInstance(NAME).save(); check(false); // 2. Create with the tool Files.deleteIfExists(Paths.get(NAME)); try { Class ktab = Class.forName("sun.security.krb5.internal.tools.Ktab"); ktab.getDeclaredMethod("main", String[].class).invoke(null, (Object)(("-k " + NAME + " -a me@HERE pass").split(" "))); } catch (ClassNotFoundException cnfe) { // Only Windows has ktab tool System.out.println("No ktab tool here. Ignored."); return; } check(false); }
Example #26
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 #27
Source File: KtabCheck.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }
Example #28
Source File: KDC.java From openjdk-8-source 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 #29
Source File: FileKeyTab.java From openjdk-jdk9 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 #30
Source File: KtabCheck.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Checks if a keytab contains exactly the keys (kvno and etype) * @param args keytabname kvno etype... */ public static void main(String[] args) throws Exception { System.out.println("Checking " + Arrays.toString(args)); KeyTab ktab = KeyTab.getInstance(args[0]); Set<String> expected = new HashSet<>(); for (int i=1; i<args.length; i += 2) { expected.add(args[i]+":"+args[i+1]); } for (KeyTabEntry e: ktab.getEntries()) { // KVNO and etype String vne = e.getKey().getKeyVersionNumber() + ":" + e.getKey().getEType(); if (!expected.contains(vne)) { throw new Exception("No " + vne + " in expected"); } expected.remove(vne); } if (!expected.isEmpty()) { throw new Exception("Extra elements in expected"); } }