/** * Dump a keytab: list all principals. * * @param keytabFile the keytab file * @throws IOException IO problems */ private void dumpKeytab(File keytabFile) throws IOException { title("Examining keytab %s", keytabFile); File kt = keytabFile.getCanonicalFile(); verifyFileIsValid(kt, CAT_KERBEROS, "keytab"); Keytab loadKeytab = Keytab.loadKeytab(kt); List<PrincipalName> principals = loadKeytab.getPrincipals(); println("keytab principal count: %d", principals.size()); int entrySize = 0; for (PrincipalName princ : principals) { List<KeytabEntry> entries = loadKeytab.getKeytabEntries(princ); entrySize = entrySize + entries.size(); for (KeytabEntry entry : entries) { EncryptionKey key = entry.getKey(); println(" %s: version=%d expires=%s encryption=%s", entry.getPrincipal(), entry.getKvno(), entry.getTimestamp(), key.getKeyType()); } } println("keytab entry count: %d", entrySize); endln(); }
@Override public void removeKeytabEntries(PrincipalName principal, int kvno) { List<KeytabEntry> entries = getKeytabEntries(principal); for (KeytabEntry entry : entries) { if (entry.getKvno() == kvno) { removeKeytabEntry(entry); } } }
@Override public void removeKeytabEntries(PrincipalName principal, int kvno) { List<KeytabEntry> entries = getKeytabEntries(principal); for (KeytabEntry entry : entries) { if (entry.getKvno() == kvno) { removeKeytabEntry(entry); } } }
List<PrincipalName> principals = keytab.getPrincipals(); for (PrincipalName principal : principals) { List<KeytabEntry> keytabEntries = keytab.getKeytabEntries(principal); for (KeytabEntry entry : keytabEntries) { StringBuilder sb = new StringBuilder();
List<PrincipalName> principals = keytab.getPrincipals(); for (PrincipalName principal : principals) { List<KeytabEntry> keytabEntries = keytab.getKeytabEntries(principal); for (KeytabEntry entry : keytabEntries) { StringBuilder sb = new StringBuilder();
@Override public EncryptionKey getKey(PrincipalName principal, EncryptionType keyType) { List<KeytabEntry> entries = getKeytabEntries(principal); for (KeytabEntry ke : entries) { if (ke.getKey().getKeyType() == keyType) { return ke.getKey(); } } // Maybe we have a key stored under a different name for the same type int keyTypeValue = keyType.getValue(); for (KeytabEntry ke : entries) { if (keyTypeValue == ke.getKey().getKeyType().getValue()) { return ke.getKey(); } } return null; }
@Override public EncryptionKey getKey(PrincipalName principal, EncryptionType keyType) { List<KeytabEntry> entries = getKeytabEntries(principal); for (KeytabEntry ke : entries) { if (ke.getKey().getKeyType() == keyType) { return ke.getKey(); } } // Maybe we have a key stored under a different name for the same type int keyTypeValue = keyType.getValue(); for (KeytabEntry ke : entries) { if (keyTypeValue == ke.getKey().getKeyType().getValue()) { return ke.getKey(); } } return null; }
/** * Remove all the old keys of the specified principal * in the specified keytab file. * * @param keytabFile The keytab file * @param principalName The principal name * @throws KrbException If there is a problem in removing the old keys of the specified principal */ public static void removeOldKeytabEntriesOf(File keytabFile, String principalName) throws KrbException { Keytab keytab = loadKeytab(keytabFile); List<KeytabEntry> entries = keytab.getKeytabEntries( new PrincipalName(principalName)); int maxKvno = 0; for (KeytabEntry entry : entries) { if (maxKvno < entry.getKvno()) { maxKvno = entry.getKvno(); } } for (KeytabEntry entry : entries) { if (entry.getKvno() < maxKvno) { keytab.removeKeytabEntry(entry); } } storeKeytab(keytab, keytabFile); }
/** * Remove all the old keys of the specified principal * in the specified keytab file. * * @param keytabFile The keytab file * @param principalName The principal name * @throws KrbException If there is a problem in removing the old keys of the specified principal */ public static void removeOldKeytabEntriesOf(File keytabFile, String principalName) throws KrbException { Keytab keytab = loadKeytab(keytabFile); List<KeytabEntry> entries = keytab.getKeytabEntries( new PrincipalName(principalName)); int maxKvno = 0; for (KeytabEntry entry : entries) { if (maxKvno < entry.getKvno()) { maxKvno = entry.getKvno(); } } for (KeytabEntry entry : entries) { if (entry.getKvno() < maxKvno) { keytab.removeKeytabEntry(entry); } } storeKeytab(keytab, keytabFile); }