/** * 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(); }
@Test(timeout = 60000) public void testKeytabGen() throws Exception { MiniKdc kdc = getKdc(); File workDir = getWorkDir(); kdc.createPrincipal(new File(workDir, "keytab"), "foo/bar", "bar/foo"); List<PrincipalName> principalNameList = Keytab.loadKeytab(new File(workDir, "keytab")).getPrincipals(); Set<String> principals = new HashSet<String>(); for (PrincipalName principalName : principalNameList) { principals.add(principalName.getName()); } Assert.assertEquals(new HashSet<String>(Arrays.asList( "foo/bar@" + kdc.getRealm(), "bar/foo@" + kdc.getRealm())), principals); }
/** * @return The NameType of this PirncipalName */ public NameType getNameType() { Integer value = getFieldAsInteger(PrincipalNameField.NAME_TYPE); return NameType.fromValue(value); }
/** * Sets the {@link EncryptionType} value * * @param eType the {@link EncryptionType} value to store */ public void setEType(EncryptionType eType) { setFieldAsInt(EncryptedDataField.ETYPE, eType.getValue()); }
/** * @return The {@link EncryptionType} of this instance */ public EncryptionType getEType() { Integer value = getFieldAsInteger(EncryptedDataField.ETYPE); return EncryptionType.fromValue(value); }
/** * @return The HostAddrType for this instance */ public HostAddrType getAddrType() { Integer value = getFieldAsInteger(HostAddressField.ADDR_TYPE); return HostAddrType.fromValue(value); }
/** * @return The {@link CheckSumType} used for this instance */ public CheckSumType getCksumtype() { Integer value = getFieldAsInteger(CheckSumField.CKSUM_TYPE); return CheckSumType.fromValue(value); }
/** * Creates a new instance of a KrbMessage. It's not possible to invoque this * constructor directly. * * @param msgType The Kerberos messag etype * @param fieldInfos The fields to use */ protected KrbMessage(KrbMessageType msgType, Asn1FieldInfo[] fieldInfos) { super(msgType.getValue(), fieldInfos); setPvno(pvno); setMsgType(msgType); }
/** * Set token format. * @param tokenFormat The token format */ public void setTokenFormat(TokenFormat tokenFormat) { setFieldAsInt(KrbTokenField.TOKEN_FORMAT, tokenFormat.getValue()); }
/** * @return The Kerberos message type field */ public KrbMessageType getMsgType() { Integer value = getFieldAsInteger(KrbMessageField.MSG_TYPE); return KrbMessageType.fromValue(value); }
/** * Sets the Kerberos Message Type field * @param msgType The Kerberos Message Type to set */ public void setMsgType(KrbMessageType msgType) { setFieldAsInt(KrbMessageField.MSG_TYPE, msgType.getValue()); } }
/** * Get token format. * @return The token format */ public TokenFormat getTokenFormat() { Integer value = getFieldAsInteger(KrbTokenField.TOKEN_FORMAT); return TokenFormat.fromValue(value); }
/** * Set the {@link CheckSumType} * * @param cksumtype The {@link CheckSumType} to set */ public void setCksumtype(CheckSumType cksumtype) { setFieldAsInt(CheckSumField.CKSUM_TYPE, cksumtype.getValue()); }
/** * @return The NameType of this PirncipalName */ public NameType getNameType() { Integer value = getFieldAsInteger(PrincipalNameField.NAME_TYPE); return NameType.fromValue(value); }
/** * @return The HostAddrType for this instance */ public HostAddrType getAddrType() { Integer value = getFieldAsInteger(HostAddressField.ADDR_TYPE); return HostAddrType.fromValue(value); }
/** * @return The {@link CheckSumType} used for this instance */ public CheckSumType getCksumtype() { Integer value = getFieldAsInteger(CheckSumField.CKSUM_TYPE); return CheckSumType.fromValue(value); }
/** * Set token format. * @param tokenFormat The token format */ public void setTokenFormat(TokenFormat tokenFormat) { setFieldAsInt(KrbTokenField.TOKEN_FORMAT, tokenFormat.getValue()); }
/** * @return The Kerberos message type field */ public KrbMessageType getMsgType() { Integer value = getFieldAsInteger(KrbMessageField.MSG_TYPE); return KrbMessageType.fromValue(value); }
/** * Sets the Kerberos Message Type field * @param msgType The Kerberos Message Type to set */ public void setMsgType(KrbMessageType msgType) { setFieldAsInt(KrbMessageField.MSG_TYPE, msgType.getValue()); } }
/** * Get token format. * @return The token format */ public TokenFormat getTokenFormat() { Integer value = getFieldAsInteger(KrbTokenField.TOKEN_FORMAT); return TokenFormat.fromValue(value); }